|
6 | 6 | use Illuminate\Contracts\Container\BindingResolutionException; |
7 | 7 | use Illuminate\Support\Facades\Queue; |
8 | 8 |
|
| 9 | +use Spatie\EventSourcing\Tests\TestClasses\Projectors\ProjectorWithDynamicWeight; |
9 | 10 | use function PHPUnit\Framework\assertCount; |
10 | 11 | use function PHPUnit\Framework\assertEquals; |
11 | 12 | use function PHPUnit\Framework\assertInstanceOf; |
|
66 | 67 | assertEquals(1, ProjectorThatThrowsAnException::$exceptionsHandled); |
67 | 68 | }); |
68 | 69 |
|
69 | | -it('will call projectors ordered by weight', function () { |
| 70 | +it('will call projectors ordered by weight', function (string $eventClass, array $sortedProjectors) { |
70 | 71 | app()->singleton(ProjectorWithWeightTestHelper::class); |
71 | 72 |
|
| 73 | + Projectionist::addProjector(ProjectorWithDynamicWeight::class); |
72 | 74 | Projectionist::addProjector(ProjectorWithHighWeight::class); |
73 | 75 | Projectionist::addProjector(ProjectorWithoutWeight::class); |
74 | 76 | Projectionist::addProjector(ProjectorWithNegativeWeight::class); |
75 | 77 | Projectionist::addProjector(ProjectorWithLowWeight::class); |
76 | 78 |
|
77 | | - event(new MoneyAddedEvent($this->account, 1000)); |
| 79 | + event(new $eventClass($this->account, 1000)); |
78 | 80 |
|
79 | | - assertSame([ |
| 81 | + assertSame($sortedProjectors, app(ProjectorWithWeightTestHelper::class)->calledBy); |
| 82 | +})->with([ |
| 83 | + [MoneyAddedEvent::class, [ |
80 | 84 | ProjectorWithNegativeWeight::class, |
81 | 85 | ProjectorWithoutWeight::class, |
82 | 86 | ProjectorWithLowWeight::class, |
| 87 | + ProjectorWithDynamicWeight::class, |
83 | 88 | ProjectorWithHighWeight::class, |
84 | | - ], app(ProjectorWithWeightTestHelper::class)->calledBy); |
85 | | -}); |
| 89 | + ]], |
| 90 | + [MoneySubtractedEvent::class, [ |
| 91 | + ProjectorWithNegativeWeight::class, |
| 92 | + ProjectorWithDynamicWeight::class, |
| 93 | + ProjectorWithoutWeight::class, |
| 94 | + ProjectorWithLowWeight::class, |
| 95 | + ProjectorWithHighWeight::class, |
| 96 | + ]], |
| 97 | +]); |
86 | 98 |
|
87 | | -it('will replay projectors ordered by weight', function () { |
| 99 | +it('will replay projectors ordered by weight', function (string $eventClass, array $sortedProjectors) { |
88 | 100 | app()->singleton(ProjectorWithWeightTestHelper::class); |
89 | 101 |
|
90 | | - event(new MoneyAddedEvent($this->account, 1000)); |
| 102 | + event(new $eventClass($this->account, 1000)); |
91 | 103 |
|
92 | 104 | Projectionist::addProjectors([ |
| 105 | + ProjectorWithDynamicWeight::class, |
93 | 106 | ProjectorWithHighWeight::class, |
94 | 107 | ProjectorWithoutWeight::class, |
95 | 108 | ProjectorWithNegativeWeight::class, |
|
98 | 111 |
|
99 | 112 | Projectionist::replay(Projectionist::getProjectors()); |
100 | 113 |
|
101 | | - assertSame([ |
| 114 | + assertSame($sortedProjectors, app(ProjectorWithWeightTestHelper::class)->calledBy); |
| 115 | +})->with([ |
| 116 | + [MoneyAddedEvent::class, [ |
102 | 117 | ProjectorWithNegativeWeight::class, |
103 | 118 | ProjectorWithoutWeight::class, |
104 | 119 | ProjectorWithLowWeight::class, |
| 120 | + ProjectorWithDynamicWeight::class, |
105 | 121 | ProjectorWithHighWeight::class, |
106 | | - ], app(ProjectorWithWeightTestHelper::class)->calledBy); |
107 | | -}); |
| 122 | + ]], |
| 123 | + [MoneySubtractedEvent::class, [ |
| 124 | + ProjectorWithNegativeWeight::class, |
| 125 | + ProjectorWithDynamicWeight::class, |
| 126 | + ProjectorWithoutWeight::class, |
| 127 | + ProjectorWithLowWeight::class, |
| 128 | + ProjectorWithHighWeight::class, |
| 129 | + ]], |
| 130 | +]); |
108 | 131 |
|
109 | 132 | it('can catch exceptions and still continue calling other projectors', function () { |
110 | 133 | $this->setConfig('event-sourcing.catch_exceptions', true); |
|
0 commit comments