Skip to content

PushedJob Inspection

For assertions on individual queued jobs, use the PushedJob wrapper via the where() filter:

php
use Havn\Executable\Testing\Queueing\PushedJob;

it("queues with full configuration", function () {
    Queue::fake();

    ProcessOrder::onQueue("orders")->delay(60)->shouldBeEncrypted()->execute($order);

    ProcessOrder::assert()
        ->queued()
        ->where(function (PushedJob $job) {
            return $job->isOnQueue("orders") &&
                $job->isDelayed(60) &&
                $job->isEncrypted() &&
                $job->executedWith($order);
        })
        ->once();
});

it("queues unique job with correct ID", function () {
    Queue::fake();

    ImportProducts::onQueue()
        ->shouldBeUnique()
        ->withUniqueId("import-{$store->id}")
        ->execute($store);

    ImportProducts::assert()->queued()->where(fn(PushedJob $job) => $job->isUnique("import-{$store->id}"))->once();
});

Chainable Assert Methods

Like PushedBatch, PushedJob also has chainable assert* methods that throw with descriptive messages on failure. Same caveat: only use these when exactly one matching job is dispatched, since where() iterates all jobs and an assert throwing will stop the search early.

php
it("queues with full configuration using assert methods", function () {
    Queue::fake();

    ProcessOrder::onQueue("orders")->delay(60)->shouldBeEncrypted()->execute($order);

    ProcessOrder::assert()
        ->queued()
        ->where(function (PushedJob $job) {
            return (bool) $job
                ->assertIsOnQueue("orders")
                ->assertIsDelayed(60)
                ->assertIsEncrypted()
                ->assertExecutedWith($order);
        })
        ->once();
});

Available PushedJob Checks

CheckAssert variantWhat it checks
is(string|Closure)assertIs()Job/executable class match
isOnQueue(string)assertIsOnQueue()Queue name
isOnConnection(string)assertIsOnConnection()Connection name
isEncrypted()assertIsEncrypted()Encryption flag
isDelayed(?$delay)assertIsDelayed()Delay value
isUnique(?$id)assertIsUnique()Unique with optional ID
isUniqueFor(int)assertIsUniqueFor()Unique lock duration
isUniqueUntilProcessing(?$id)assertIsUniqueUntilProcessing()Unique-until-processing variant
hasUniqueId(?$id)assertHasUniqueId()Unique lock identifier
executedWith(...$args)assertExecutedWith()Exact argument match
executedWithArgs(callable)assertExecutedWithArgs()Callback-based argument check
hasChain(?array)assertHasChain()Job chain contents
hasNoChain()assertHasNoChain()No chain attached
hasMiddleware(?string|callable)assertHasMiddleware()Middleware presence
hasTags(?array)assertHasTags()Horizon tags

When called without arguments, isDelayed(), isUnique(), isUniqueUntilProcessing(), hasUniqueId(), hasChain(), hasMiddleware(), and hasTags() check for presence rather than matching a specific value.

is() Closure Type Inference

The is() method infers the closure parameter type to determine what to pass:

php
// String match against executable or job class
$job->is(ProcessOrder::class);

// Closure with executable type hint: receives the executable instance
$job->is(fn(ProcessOrder $exec) => $exec->someProperty);

// Closure with PushedJob type hint: receives the PushedJob wrapper
$job->is(fn(PushedJob $pj) => $pj->isOnQueue("high"));

Accessing the Underlying Job

PushedJob::job() returns the raw job object for direct access:

php
$pushedJob->job(); // the ExecutableJob instance
$pushedJob->job()->executable(); // the executable instance
$pushedJob->job()->arguments(); // named arguments array
$pushedJob->job()->executableClass(); // class name string