1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Spatie\EventProjector; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Arr; |
6
|
|
|
use PHPUnit\Framework\Assert; |
7
|
|
|
|
8
|
|
|
class FakeAggregateRoot |
9
|
|
|
{ |
10
|
|
|
/** @var \Spatie\EventProjector\AggregateRoot */ |
11
|
|
|
private $aggregateRoot; |
12
|
|
|
|
13
|
|
|
public function __construct(AggregateRoot $aggregateRoot) |
14
|
|
|
{ |
15
|
|
|
$this->aggregateRoot = $aggregateRoot; |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
public function given(array $events) |
19
|
|
|
{ |
20
|
|
|
foreach ($events as $event) { |
21
|
|
|
$this->aggregateRoot->recordThat($event); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
$this->aggregateRoot->persist(); |
25
|
|
|
|
26
|
|
|
return $this; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function when($callable) |
30
|
|
|
{ |
31
|
|
|
$callable($this->aggregateRoot); |
32
|
|
|
|
33
|
|
|
return $this; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function assertNothingRecorded() |
37
|
|
|
{ |
38
|
|
|
Assert::assertCount(0, $this->aggregateRoot->getRecordedEvents()); |
|
|
|
|
39
|
|
|
|
40
|
|
|
return $this; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function assertRecorded(array $expectedEvents) |
44
|
|
|
{ |
45
|
|
|
Assert::assertEquals($expectedEvents, $this->aggregateRoot->getRecordedEvents()); |
46
|
|
|
|
47
|
|
|
return $this; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function assertNotRecorded($unexpectedEventClasses): void |
51
|
|
|
{ |
52
|
|
|
$actualEventClasses = array_map(function (ShouldBeStored $event) { |
53
|
|
|
return get_class($event); |
54
|
|
|
}, $this->aggregateRoot->getRecordedEvents()); |
55
|
|
|
|
56
|
|
|
$unexpectedEventClasses = Arr::wrap($unexpectedEventClasses); |
57
|
|
|
|
58
|
|
|
foreach ($unexpectedEventClasses as $nonExceptedEventClass) { |
59
|
|
|
Assert::assertNotContains($nonExceptedEventClass, $actualEventClasses, "Did not expect to record {$nonExceptedEventClass}, but it was recorded."); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function __call($name, $arguments) |
64
|
|
|
{ |
65
|
|
|
$this->aggregateRoot->$name(...$arguments); |
66
|
|
|
|
67
|
|
|
return $this; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: