Did you find a solution to this, I want to do both things as well (check the right thing is passed and the correct number)
Also, how can you make the mock job throw an exception so the parent job can handle it
Is there a way to test that a job is dispatched with the correct parameters in Laravel phpunit? For example, I have a job that searches for images that should be deleted. For each image it finds, it will dispatch another job to delete the image (and some other cleanup).
I want to test that it's only dispatching jobs for images that should actually be deleted, and not deleting anything it's not supposed to. Here's a snippet:
foreach($imagesToDelete as $image)
{
$job = (new DeleteTheImage($image);
$this->dispatch($job);
}
For tests right now I'm just using $this->expectsJobs(App\Jobs\DeleteTheImage::class). But it's not really checking anything useful. I want to check that the right $image was passed through. On a related note, is there a way to test expected number of jobs dispatched? Thanks for the help!
Please or to participate in this conversation.