@@ -32,9 +32,7 @@ trait EventsAssertionsTrait
32
32
*/
33
33
public function dontSeeEvent (array |string |null $ expected = null ): void
34
34
{
35
- $ actualEvents = $ this ->getDispatchedEventNames ();
36
- $ actual = [$ this ->getOrphanedEvents (), $ actualEvents ];
37
- $ this ->assertEventTriggered (false , $ expected , $ actual );
35
+ $ this ->handleEventAssertion (false , $ expected , false );
38
36
}
39
37
40
38
/**
@@ -96,8 +94,7 @@ public function dontSeeEventTriggered(array|object|string $expected): void
96
94
*/
97
95
public function dontSeeOrphanEvent (array |string |null $ expected = null ): void
98
96
{
99
- $ actual = [$ this ->getOrphanedEvents ()];
100
- $ this ->assertEventTriggered (false , $ expected , $ actual );
97
+ $ this ->handleEventAssertion (false , $ expected , true );
101
98
}
102
99
103
100
/**
@@ -112,9 +109,7 @@ public function dontSeeOrphanEvent(array|string|null $expected = null): void
112
109
*/
113
110
public function seeEvent (array |string $ expected ): void
114
111
{
115
- $ actualEvents = $ this ->getDispatchedEventNames ();
116
- $ actual = [$ this ->getOrphanedEvents (), $ actualEvents ];
117
- $ this ->assertEventTriggered (true , $ expected , $ actual );
112
+ $ this ->handleEventAssertion (true , $ expected , false );
118
113
}
119
114
120
115
/**
@@ -175,8 +170,7 @@ public function seeEventTriggered(array|object|string $expected): void
175
170
*/
176
171
public function seeOrphanEvent (array |string $ expected ): void
177
172
{
178
- $ actual = [$ this ->getOrphanedEvents ()];
179
- $ this ->assertEventTriggered (true , $ expected , $ actual );
173
+ $ this ->handleEventAssertion (true , $ expected , true );
180
174
}
181
175
182
176
/** @return list<array{event: string, pretty: string}> */
@@ -191,16 +185,6 @@ protected function getDispatchedEvents(): array
191
185
return $ events ;
192
186
}
193
187
194
- /** @return list<string> */
195
- private function getDispatchedEventNames (): array
196
- {
197
- $ names = [];
198
- foreach ($ this ->getDispatchedEvents () as $ listener ) {
199
- $ names [] = $ listener ['event ' ];
200
- }
201
- return $ names ;
202
- }
203
-
204
188
/** @return list<string> */
205
189
protected function getOrphanedEvents (): array
206
190
{
@@ -213,6 +197,16 @@ protected function getOrphanedEvents(): array
213
197
return $ events ;
214
198
}
215
199
200
+ /** @param string|object|list<string|object>|null $expected */
201
+ private function handleEventAssertion (bool $ assertTrue , array |object |string |null $ expected , bool $ orphanOnly ): void
202
+ {
203
+ $ actual = $ orphanOnly
204
+ ? [$ this ->getOrphanedEvents ()]
205
+ : [$ this ->getOrphanedEvents (), array_column ($ this ->getDispatchedEvents (), 'event ' )];
206
+
207
+ $ this ->assertEventTriggered ($ assertTrue , $ expected , $ actual );
208
+ }
209
+
216
210
/**
217
211
* @param string|object|list<string|object>|null $expected
218
212
* @param list<list<string>> $actual
@@ -257,7 +251,7 @@ protected function assertListenerCalled(
257
251
if ($ expectedEvents === []) {
258
252
$ expectedEvents = [null ];
259
253
} elseif (count ($ expectedListeners ) > 1 ) {
260
- Assert::fail ('Cannot check multiple listeners with specific events; split assertions. ' );
254
+ Assert::fail ('Cannot check for events when using multiple listeners. Make multiple assertions instead . ' );
261
255
}
262
256
263
257
$ actualEvents = $ this ->getDispatchedEvents ();
0 commit comments