1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace hanneskod\readmetester; |
||
6 | |||
7 | use hanneskod\readmetester\Event; |
||
8 | use hanneskod\readmetester\Example\ExampleStoreInterface; |
||
9 | use hanneskod\readmetester\Expectation\ExpectationEvaluator; |
||
10 | use hanneskod\readmetester\Runner\RunnerInterface; |
||
11 | use hanneskod\readmetester\Runner\SkippedOutcome; |
||
12 | use Psr\EventDispatcher\EventDispatcherInterface; |
||
13 | |||
14 | final class TestMarshal |
||
15 | { |
||
16 | public function __construct( |
||
17 | private ExpectationEvaluator $evaluator, |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
18 | private EventDispatcherInterface $dispatcher, |
||
19 | ) {} |
||
20 | |||
21 | public function test(ExampleStoreInterface $exampleStore, RunnerInterface $runner, bool $stopOnFailure): void |
||
22 | { |
||
23 | foreach ($runner->run($exampleStore) as $outcome) { |
||
24 | if ($outcome instanceof SkippedOutcome) { |
||
25 | $this->dispatcher->dispatch(new Event\EvaluationSkipped($outcome)); |
||
26 | continue; |
||
27 | } |
||
28 | |||
29 | $this->dispatcher->dispatch(new Event\EvaluationStarted($outcome)); |
||
30 | |||
31 | foreach ($this->evaluator->evaluate($outcome) as $status) { |
||
32 | $this->dispatcher->dispatch( |
||
33 | $status->isSuccess() ? new Event\TestPassed($status) : new Event\TestFailed($status) |
||
34 | ); |
||
35 | |||
36 | if ($stopOnFailure && !$status->isSuccess()) { |
||
37 | $this->dispatcher->dispatch(new Event\TestingAborted()); |
||
38 | break 2; |
||
39 | } |
||
40 | } |
||
41 | |||
42 | $this->dispatcher->dispatch(new Event\EvaluationDone($outcome)); |
||
43 | } |
||
44 | } |
||
45 | } |
||
46 |