Skip to content

Queue Assertions

When testing queued dispatches, fake the queue and use ::assert()->queued():

php
it("queues order processing", function () {
    Queue::fake();

    ProcessOrder::onQueue()->execute($order);

    ProcessOrder::assert()->queued()->with($order)->onQueue("orders")->once();
});

it("queues with correct chain", function () {
    Queue::fake();

    ProcessOrder::onQueue()
        ->chain([SendConfirmation::prepare()->execute($order)])
        ->execute($order);

    ProcessOrder::assert()
        ->queued()
        ->withChain([SendConfirmation::class])
        ->once();
});

it("does not queue cancelled orders", function () {
    Queue::fake();

    $service->handleCancelledOrder($order);

    ProcessOrder::assert()->notQueued();
});

Fluent Assertion Builder

The queued() assertion is a fluent builder. Chain filters in any order:

FilterPurpose
with(...$args)Match by exact arguments
withArgs(callable)Match by argument callback
onQueue(string)Match by queue name
withChain(array)Match by job chain
where(callable)Custom filter (fn(PushedJob $job): bool)
dump()Debug helper, see Debugging
dd()Dump and die, see Debugging

Then chain a count: once(), twice(), times(3), never().