Skip to content

Commit ca37f19

Browse files
v0.0.4
1 parent da7cf18 commit ca37f19

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

src/Validation.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,25 @@ public function fixWith(FixtureStrategyInterface $fixtureStrategy)
6666
*/
6767
public function run()
6868
{
69+
$errorList = [];
70+
6971
$index = 0;
7072
foreach ($this->strategyList as $strategy) {
7173
try {
7274
$this->doValidation($strategy);
7375
} catch (\Exception $exception) {
74-
$this->applyFixtureStrategy($exception, $index);
76+
try {
77+
$this->applyFixtureStrategy($exception, $index);
78+
} catch (\Exception $afterFixtureException){
79+
$errorList[] = $afterFixtureException->getMessage();
80+
}
7581
}
7682
$index++;
7783
}
84+
85+
if (count($errorList) > 0){
86+
throw new \Exception(implode("\n", $errorList));
87+
}
7888
}
7989

8090
private function doValidation(ValidationStrategyInterface $validationStrategy): void

tests/ValidationTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,4 +257,42 @@ public function testWhenValidationWithFixtureStrategyIsMadeThenValidationFailsAn
257257
// assert
258258
$this->assertSame($secondExceptionFromValidation, $exceptionResult);
259259
}
260+
261+
/**
262+
*
263+
*/
264+
public function testValidationWithTwoStrategiesThrowingOneExceptionForEach()
265+
{
266+
// arrange
267+
268+
$firstExceptionMessage = 'First exception';
269+
$secondExceptionMessage = 'Second exception';
270+
271+
$firstException = new \Exception($firstExceptionMessage);
272+
$firstStrategy = $this->prepareValidationStrategyWithException($firstException);
273+
274+
$secondException = new \Exception($secondExceptionMessage);
275+
$secondStrategy = $this->prepareValidationStrategyWithException($secondException);
276+
277+
$subject = new TestEntity();
278+
$factory = new ValidationFactory();
279+
$exceptionResult = null;
280+
281+
// act
282+
try {
283+
$factory->createFor($subject)
284+
->validateWith($firstStrategy)
285+
->validateWith($secondStrategy)
286+
->run();
287+
} catch (\Exception $ex){
288+
$exceptionResult = $ex;
289+
}
290+
291+
// assert
292+
$this->assertContains($firstExceptionMessage, $exceptionResult->getMessage());
293+
$this->assertContains($secondExceptionMessage, $exceptionResult->getMessage());
294+
var_dump($exceptionResult->getMessage());
295+
}
296+
297+
260298
}

0 commit comments

Comments
 (0)