In this article, we'll explore two improved methods to make testing same class dispatched Laravel jobs a breeze. While the standard way gets the job done, it's like searching for a needle in a haystack when something goes wrong. We'll go through two approaches that shed light on exactly what's causing issues, making troubleshooting a whole lot easier. Before we dive in, let's take a quick look at the code we're dealing with: // web.php get('dispatch-jobs'); Queue::assertPushed(TestJob::class, 2); // be aware this callable is called twice // and passes if at least one job returns true Queue::assertPushed(function (TestJob $job) { return $job->name === 'John' && $job->age === 30 && $job->email === 'john@example.com'; }); Queue::assertPushed(function (TestJob $job) { return $job->name === 'Will' && $job->age === 20 && $job->email === 'will@example.com'; }); }}

So, the takeaway is this: while these testing approaches might not be the fanciest and for everybody, they sure help when you're testing dispatched Laravel jobs.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners