5
5
use PHPUnit \Framework \MockObject \MockObject ;
6
6
use PHPUnit \Framework \TestCase ;
7
7
use Tests \Utils \TestEntity ;
8
- use validation \Custom \FixtureStrategyInterface ;
9
- use validation \Custom \ValidationStrategyInterface ;
8
+ use validation \Custom \AbstractFixtureStrategy ;
9
+ use validation \Custom \AbstractValidationStrategy ;
10
10
use validation \ValidationFactory ;
11
11
12
12
class ValidationTest extends TestCase
13
13
{
14
14
private function prepareValidationStrategy (): MockObject
15
15
{
16
16
$ validationStrategy = $ this
17
- ->getMockBuilder (ValidationStrategyInterface ::class)
17
+ ->getMockBuilder (AbstractValidationStrategy ::class)
18
18
->disableOriginalConstructor ()
19
19
->getMock ();
20
20
@@ -32,7 +32,7 @@ private function prepareValidationStrategy(): MockObject
32
32
private function prepareValidationStrategyWithException (\Exception $ exception ): MockObject
33
33
{
34
34
$ validationStrategy = $ this
35
- ->getMockBuilder (ValidationStrategyInterface ::class)
35
+ ->getMockBuilder (AbstractValidationStrategy ::class)
36
36
->disableOriginalConstructor ()
37
37
->getMock ();
38
38
@@ -45,7 +45,7 @@ private function prepareValidationStrategyWithException(\Exception $exception):
45
45
private function prepareValidationStrategyWithExceptionOnFirstCall (\Exception $ exception ): MockObject
46
46
{
47
47
$ validationStrategy = $ this
48
- ->getMockBuilder (ValidationStrategyInterface ::class)
48
+ ->getMockBuilder (AbstractValidationStrategy ::class)
49
49
->disableOriginalConstructor ()
50
50
->getMock ();
51
51
@@ -64,7 +64,7 @@ private function prepareValidationStrategyWithExceptionOnFirstCall(\Exception $e
64
64
private function prepareFixtureStrategyWithException (\Exception $ exception ): MockObject
65
65
{
66
66
$ fixtureStrategy = $ this
67
- ->getMockBuilder (FixtureStrategyInterface ::class)
67
+ ->getMockBuilder (AbstractFixtureStrategy ::class)
68
68
->disableOriginalConstructor ()
69
69
->getMock ();
70
70
@@ -78,7 +78,7 @@ private function prepareFixtureStrategyWithException(\Exception $exception): Moc
78
78
private function prepareFixtureStrategy (): MockObject
79
79
{
80
80
$ fixtureStrategy = $ this
81
- ->getMockBuilder (FixtureStrategyInterface ::class)
81
+ ->getMockBuilder (AbstractFixtureStrategy ::class)
82
82
->disableOriginalConstructor ()
83
83
->getMock ();
84
84
@@ -92,7 +92,7 @@ private function prepareFixtureStrategy(): MockObject
92
92
private function prepareFixtureStrategyWithoutException (): MockObject
93
93
{
94
94
$ fixtureStrategy = $ this
95
- ->getMockBuilder (FixtureStrategyInterface ::class)
95
+ ->getMockBuilder (AbstractFixtureStrategy ::class)
96
96
->disableOriginalConstructor ()
97
97
->getMock ();
98
98
@@ -110,7 +110,7 @@ private function prepareFixtureStrategyWithoutException(): MockObject
110
110
private function prepareValidationStrategyWithTwoExecutionsAndOneExceptionForEach (\Exception $ firstException , \Exception $ secondException ): MockObject
111
111
{
112
112
$ validationStrategy = $ this
113
- ->getMockBuilder (ValidationStrategyInterface ::class)
113
+ ->getMockBuilder (AbstractValidationStrategy ::class)
114
114
->disableOriginalConstructor ()
115
115
->getMock ();
116
116
@@ -177,7 +177,8 @@ public function testWhenValidationFailThenCallFixMethodFromFixtureStrategy()
177
177
public function testWhenValidationWithoutFixtureStrategyIsMadeThenFailsMustThrowsExceptionFromValidation ()
178
178
{
179
179
// arrange
180
- $ exceptionFromValidation = new \Exception ();
180
+ $ message = 'This message ' ;
181
+ $ exceptionFromValidation = new \Exception ($ message );
181
182
182
183
$ validationStrategy = $ this ->prepareValidationStrategyWithException ($ exceptionFromValidation );
183
184
@@ -197,16 +198,18 @@ public function testWhenValidationWithoutFixtureStrategyIsMadeThenFailsMustThrow
197
198
}
198
199
199
200
// assert
200
- $ this ->assertSame ( $ exceptionFromValidation , $ exceptionResult );
201
+ $ this ->assertContains ( $ message , $ exceptionResult-> getMessage () );
201
202
}
202
203
203
204
public function testWhenValidationWithFixtureStrategyIsMadeThenFixtureFailsMustThrowsExceptionFromFixture ()
204
205
{
205
206
// arrange
206
- $ exceptionFromValidation = new \Exception ();
207
+ $ messageFromValidation = 'From validation ' ;
208
+ $ exceptionFromValidation = new \Exception ($ messageFromValidation );
207
209
$ validationStrategy = $ this ->prepareValidationStrategyWithException ($ exceptionFromValidation );
208
210
209
- $ exceptionFromFixture = new \Exception ();
211
+ $ messageFromFixture = 'From fixture ' ;
212
+ $ exceptionFromFixture = new \Exception ($ messageFromFixture );
210
213
$ fixtureStrategy = $ this ->prepareFixtureStrategyWithException ($ exceptionFromFixture );
211
214
212
215
$ subject = new TestEntity ();
@@ -226,14 +229,17 @@ public function testWhenValidationWithFixtureStrategyIsMadeThenFixtureFailsMustT
226
229
}
227
230
228
231
// assert
229
- $ this ->assertSame ($ exceptionFromFixture , $ exceptionResult );
232
+ $ this ->assertContains ($ messageFromFixture , $ exceptionResult ->getMessage ());
233
+ $ this ->assertNotContains ($ messageFromValidation , $ exceptionResult ->getMessage ());
230
234
}
231
235
232
- public function testWhenValidationWithFixtureStrategyIsMadeThenValidationFailsAndFixtureDontWorkMustThrowsExceptionFromSecondValidation ()
236
+ public function testWhenValidationWithFixtureStrategyIsMadeThenValidationFailsAndFixtureDontWorkMustThrowsExceptionFromSecondValidationCall ()
233
237
{
234
238
// arrange
235
- $ firstExceptionFromValidation = new \Exception ('First exception ' );
236
- $ secondExceptionFromValidation = new \Exception ('Second exception ' );
239
+ $ firstExceptionMessage = 'First exception ' ;
240
+ $ firstExceptionFromValidation = new \Exception ($ firstExceptionMessage );
241
+ $ secondExceptionMessage = 'Second exception ' ;
242
+ $ secondExceptionFromValidation = new \Exception ($ secondExceptionMessage );
237
243
$ validationStrategy = $ this ->prepareValidationStrategyWithTwoExecutionsAndOneExceptionForEach ($ firstExceptionFromValidation , $ secondExceptionFromValidation );
238
244
239
245
$ fixtureStrategy = $ this ->prepareFixtureStrategyWithoutException ();
@@ -255,7 +261,9 @@ public function testWhenValidationWithFixtureStrategyIsMadeThenValidationFailsAn
255
261
}
256
262
257
263
// assert
258
- $ this ->assertSame ($ secondExceptionFromValidation , $ exceptionResult );
264
+ $ this ->assertContains ($ secondExceptionMessage , $ exceptionResult ->getMessage ());
265
+ $ this ->assertNotContains ($ firstExceptionMessage , $ exceptionResult ->getMessage ());
266
+ //$this->assertSame($secondExceptionFromValidation, $exceptionResult);
259
267
}
260
268
261
269
/**
0 commit comments