Home > other >  Laravel testing how to make sure job is pushed to the queue multiple times with Queue::assertPushed
Laravel testing how to make sure job is pushed to the queue multiple times with Queue::assertPushed

Time:06-10

I am writing some tests for a website and I can't seem to figure out how to test that a job was dispatched let's say 5 times using Queue::fake() and Queue::assertPushed().

I've tried putting multiple Queue::assertPushed(SomeJob::class) but that always passes the test no matter how many of those I put.

I've tried googling various things but found no useful info. Any ideas?

CodePudding user response:

The second parameter of assertPushed() is the amount of jobs pushed to the queue. This is also described in the documentation.

Queue::assertPushed(SomeJob::class, 5);

CodePudding user response:

To assert that a job was pushed $n no of times

Queue::assertPushed(SomeJob::class, $n);

Laravel Docs - Mocking - Queue

  • Related