1 | <?php |
||
15 | abstract class AggregateRootTestCase extends TestCase |
||
16 | { |
||
17 | /** |
||
18 | * @var InMemoryMessageRepository |
||
19 | */ |
||
20 | private $messageRepository; |
||
21 | |||
22 | /** |
||
23 | * @var AggregateRootRepository |
||
24 | */ |
||
25 | protected $repository; |
||
26 | |||
27 | /** |
||
28 | * @var Exception|null |
||
29 | */ |
||
30 | private $caughtException; |
||
31 | |||
32 | /** |
||
33 | * @var Event[] |
||
34 | */ |
||
35 | private $expectedEvents = []; |
||
36 | |||
37 | /** |
||
38 | * @var Exception|null |
||
39 | */ |
||
40 | private $theExpectedException; |
||
41 | |||
42 | /** |
||
43 | * @var TestClock |
||
44 | */ |
||
45 | private $clock; |
||
46 | |||
47 | /** |
||
48 | * @var bool |
||
49 | */ |
||
50 | private $assertedScenario = false; |
||
51 | |||
52 | /** |
||
53 | * @var AggregateRootId |
||
54 | */ |
||
55 | protected $aggregateRootId; |
||
56 | |||
57 | /** |
||
58 | * @before |
||
59 | */ |
||
60 | 7 | protected function setUpEventStore() |
|
61 | { |
||
62 | 7 | $className = $this->aggregateRootClassName(); |
|
63 | 7 | $this->clock = new TestClock(); |
|
64 | 7 | $this->aggregateRootId = $this->aggregateRootId(); |
|
65 | 7 | $this->messageRepository = new InMemoryMessageRepository(); |
|
66 | 7 | $dispatcher = $this->messageDispatcher(); |
|
67 | 7 | $decorator = $this->messageDecorator(); |
|
68 | 7 | $this->repository = new AggregateRootRepository($className, $this->messageRepository, $dispatcher, $decorator); |
|
69 | 7 | $this->expectedEvents = []; |
|
70 | 7 | $this->assertedScenario = false; |
|
71 | 7 | $this->theExpectedException = null; |
|
72 | 7 | $this->caughtException = null; |
|
73 | 7 | } |
|
74 | |||
75 | /** |
||
76 | * @after |
||
77 | */ |
||
78 | 7 | protected function assertScenario() |
|
96 | |||
97 | abstract protected function aggregateRootId(): AggregateRootId; |
||
98 | |||
99 | abstract protected function aggregateRootClassName(): string; |
||
100 | |||
101 | /** |
||
102 | * @return $this |
||
103 | */ |
||
104 | 1 | protected function given(Event ... $events) |
|
111 | |||
112 | 1 | public function on(AggregateRootId $id) |
|
116 | |||
117 | /** |
||
118 | * @return $this |
||
119 | */ |
||
120 | 7 | protected function when(... $arguments) |
|
134 | |||
135 | /** |
||
136 | * @return $this |
||
137 | */ |
||
138 | 3 | protected function then(Event ... $events) |
|
144 | |||
145 | /** |
||
146 | * @return $this |
||
147 | */ |
||
148 | 2 | public function thenWeAreSorry(Exception $expectedException) |
|
154 | |||
155 | /** |
||
156 | * @return $this |
||
157 | */ |
||
158 | 1 | protected function thenNothingShouldHaveHappened() |
|
164 | |||
165 | 5 | protected function assertLastCommitEqualsEvents(Event ... $events) |
|
169 | |||
170 | 7 | private function assertExpectedException(Exception $expectedException = null, Exception $caughtException = null) |
|
182 | |||
183 | 3 | protected function pointInTime(): PointInTime |
|
187 | |||
188 | 7 | protected function clock(): Clock |
|
192 | |||
193 | 7 | protected function messageDispatcher(): MessageDispatcher |
|
197 | |||
198 | /** |
||
199 | * @return Consumer[] |
||
200 | */ |
||
201 | 7 | protected function consumers(): array |
|
205 | |||
206 | 7 | private function messageDecorator(): MessageDecorator |
|
210 | } |