@@ -180,7 +180,7 @@ public function testWorkersEventFiring(): void
180
180
$ worker ->start ();
181
181
182
182
foreach ($ expected_events as $ expected_event ) {
183
- $ fake_events ->assertDispatchedTimes ($ expected_event , 1 );
183
+ $ this ->assertDispatchedTimes ($ fake_events , $ expected_event , 1 );
184
184
}
185
185
}
186
186
@@ -238,7 +238,7 @@ public function testWorkerErrorHandling(): void
238
238
239
239
$ worker ->start ();
240
240
241
- $ fake_events ->assertDispatchedTimes (Events \LoopErrorOccurredEvent::class, 1 );
241
+ $ this ->assertDispatchedTimes ($ fake_events , Events \LoopErrorOccurredEvent::class, 1 );
242
242
243
243
$ this ->assertSame (
244
244
$ exception ,
@@ -296,7 +296,7 @@ public function testWorkerErrorHandlingWithMaskedException(): void
296
296
297
297
$ worker ->start ();
298
298
299
- $ fake_events ->assertDispatchedTimes (Events \LoopErrorOccurredEvent::class, 1 );
299
+ $ this ->assertDispatchedTimes ($ fake_events , Events \LoopErrorOccurredEvent::class, 1 );
300
300
301
301
$ this ->assertSame (
302
302
$ exception ,
@@ -339,7 +339,7 @@ public function testWorkerErrorHandlingAfterRespond(): void
339
339
340
340
$ worker ->start ();
341
341
342
- $ fake_events ->assertDispatchedTimes (Events \LoopErrorOccurredEvent::class, 1 );
342
+ $ this ->assertDispatchedTimes ($ fake_events , Events \LoopErrorOccurredEvent::class, 1 );
343
343
344
344
$ this ->assertSame (
345
345
$ exception ,
@@ -440,4 +440,19 @@ private function getPSR7ClientSuccessfulMock()
440
440
->withArgs ($ this ->getHtmlResponseValidationClosure ())
441
441
->getMock ();
442
442
}
443
+
444
+ /**
445
+ * @param EventFake $dispatcher
446
+ * @param $event
447
+ * @param int $times
448
+ */
449
+ private function assertDispatchedTimes (EventFake $ dispatcher , $ event , int $ times )
450
+ {
451
+ $ count = $ dispatcher ->dispatched ($ event )->count ();
452
+
453
+ $ this ->assertSame (
454
+ $ times , $ count ,
455
+ "The expected [ {$ event }] event was dispatched {$ count } times instead of {$ times } times. "
456
+ );
457
+ }
443
458
}
0 commit comments