Use Queue::fakeExceptFor() to execute specific background jobs synchronously during a test while preventing all other jobs from running.
When testing a feature that dispatches multiple background jobs, using Queue::fake() prevents all jobs from executing. If your test relies on a critical job running inline, total faking breaks test setup.
Queue::fakeExceptFor() lets you specify jobs that should execute normally while faking the rest:
use App\Jobs\CriticalSystemJob;
use App\Jobs\EmailNotification;
use Illuminate\Support\Facades\Queue;
test('queue dispatches email while executing critical system job inline', function () {
Queue::fakeExceptFor(function () {
Queue::push(new CriticalSystemJob); // Executes inline
Queue::push(new EmailNotification); // Faked
// Faked jobs are tracked by assertion helpers
Queue::assertPushed(EmailNotification::class);
}, [CriticalSystemJob::class]);
});
- Allows real execution for essential side effects during integration tests
- Keeps unneeded jobs (emails, webhooks) isolated and faked
- Also available on
Event::fakeExceptFor()andBus::fakeExceptFor()
Related Tips
View all tips →Monitor Aggregate Queue Metrics with Total Size Helpers in Laravel 13.27
Laravel 13.27 adds totalPendingSize(), totalDelayedSize(), and totalReservedSize() to the Queue facade, making it easy to aggregate queue metrics for dashboards and health checks.
Debounce Queued Event Listeners with #[DebounceFor] in Laravel 13.26
Laravel 13.26 extends the #[DebounceFor] attribute to queued event listeners, collapsing bursts of repeated events into a single execution based on the latest resource state.