Skip to content

Conversation

@taylorotwell
Copy link
Member

Currently, it's not obvious how to assert that a job was released, deleted, or manually failed from within the job itself. For example, given this job handle method:

public function handle(): void
{
    if ($someCondition) {
        $this->release(30);
    }
}

It is not clear to the end user how to test this nor is it documented. The best way to do this currently would be to extend your job class and define stub / fake methods for release, delete, and fail.

This PR introduces a new withFakeQueueInteractions method on the InteractsWithQueue trait as well as relevant assertions. Now the job above could be tested like so:

public function test_job_is_released(): void
{
    $job = (new TestJob)->withFakeQueueInteractions();

    $job->handle();

    $job->assertReleased(30);

    // $job->assertDeleted();
    // $job->assertFailed();
}

@driesvints driesvints changed the title Fake Queue Interactions [11.x] Fake Queue Interactions Jan 22, 2024
@taylorotwell taylorotwell merged commit dfc24d1 into master Jan 22, 2024
@taylorotwell taylorotwell deleted the fake-job branch January 22, 2024 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants