@@ -225,6 +225,30 @@ public function testAssertDispatchedAfterResponseWithCallbackFunction()
225
225
});
226
226
}
227
227
228
+ public function testAssertDispatchedAfterResponseTimesWithCallbackFunction ()
229
+ {
230
+ $ this ->fake ->dispatchAfterResponse (new OtherBusJobStub (0 ));
231
+ $ this ->fake ->dispatchAfterResponse (new OtherBusJobStub (1 ));
232
+ $ this ->fake ->dispatchAfterResponse (new OtherBusJobStub (1 ));
233
+
234
+ try {
235
+ $ this ->fake ->assertDispatchedAfterResponseTimes (function (OtherBusJobStub $ job ) {
236
+ return $ job ->id === 0 ;
237
+ }, 2 );
238
+ $ this ->fail ();
239
+ } catch (ExpectationFailedException $ e ) {
240
+ $ this ->assertThat ($ e , new ExceptionMessage ('The expected [Illuminate\Tests\Support\OtherBusJobStub] job was pushed 1 times instead of 2 times. ' ));
241
+ }
242
+
243
+ $ this ->fake ->assertDispatchedAfterResponseTimes (function (OtherBusJobStub $ job ) {
244
+ return $ job ->id === 0 ;
245
+ });
246
+
247
+ $ this ->fake ->assertDispatchedAfterResponseTimes (function (OtherBusJobStub $ job ) {
248
+ return $ job ->id === 1 ;
249
+ }, 2 );
250
+ }
251
+
228
252
public function testAssertDispatchedSyncWithCallbackFunction ()
229
253
{
230
254
$ this ->fake ->dispatchSync (new OtherBusJobStub );
@@ -263,6 +287,30 @@ public function testAssertDispatchedTimes()
263
287
$ this ->fake ->assertDispatchedTimes (BusJobStub::class, 2 );
264
288
}
265
289
290
+ public function testAssertDispatchedTimesWithCallbackFunction ()
291
+ {
292
+ $ this ->fake ->dispatch (new OtherBusJobStub (0 ));
293
+ $ this ->fake ->dispatchNow (new OtherBusJobStub (1 ));
294
+ $ this ->fake ->dispatchAfterResponse (new OtherBusJobStub (1 ));
295
+
296
+ try {
297
+ $ this ->fake ->assertDispatchedTimes (function (OtherBusJobStub $ job ) {
298
+ return $ job ->id === 0 ;
299
+ }, 2 );
300
+ $ this ->fail ();
301
+ } catch (ExpectationFailedException $ e ) {
302
+ $ this ->assertThat ($ e , new ExceptionMessage ('The expected [Illuminate\Tests\Support\OtherBusJobStub] job was pushed 1 times instead of 2 times. ' ));
303
+ }
304
+
305
+ $ this ->fake ->assertDispatchedTimes (function (OtherBusJobStub $ job ) {
306
+ return $ job ->id === 0 ;
307
+ });
308
+
309
+ $ this ->fake ->assertDispatchedTimes (function (OtherBusJobStub $ job ) {
310
+ return $ job ->id === 1 ;
311
+ }, 2 );
312
+ }
313
+
266
314
public function testAssertDispatchedAfterResponseTimes ()
267
315
{
268
316
$ this ->fake ->dispatchAfterResponse (new BusJobStub );
@@ -293,6 +341,30 @@ public function testAssertDispatchedSyncTimes()
293
341
$ this ->fake ->assertDispatchedSyncTimes (BusJobStub::class, 2 );
294
342
}
295
343
344
+ public function testAssertDispatchedSyncTimesWithCallbackFunction ()
345
+ {
346
+ $ this ->fake ->dispatchSync (new OtherBusJobStub (0 ));
347
+ $ this ->fake ->dispatchSync (new OtherBusJobStub (1 ));
348
+ $ this ->fake ->dispatchSync (new OtherBusJobStub (1 ));
349
+
350
+ try {
351
+ $ this ->fake ->assertDispatchedSyncTimes (function (OtherBusJobStub $ job ) {
352
+ return $ job ->id === 0 ;
353
+ }, 2 );
354
+ $ this ->fail ();
355
+ } catch (ExpectationFailedException $ e ) {
356
+ $ this ->assertThat ($ e , new ExceptionMessage ('The expected [Illuminate\Tests\Support\OtherBusJobStub] job was synchronously pushed 1 times instead of 2 times. ' ));
357
+ }
358
+
359
+ $ this ->fake ->assertDispatchedSyncTimes (function (OtherBusJobStub $ job ) {
360
+ return $ job ->id === 0 ;
361
+ });
362
+
363
+ $ this ->fake ->assertDispatchedSyncTimes (function (OtherBusJobStub $ job ) {
364
+ return $ job ->id === 1 ;
365
+ }, 2 );
366
+ }
367
+
296
368
public function testAssertNotDispatched ()
297
369
{
298
370
$ this ->fake ->assertNotDispatched (BusJobStub::class);
0 commit comments