Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[11.x] assertChain and assertNoChain on job instance #50858

Merged
merged 5 commits into from
Apr 1, 2024

Conversation

gdebrauwer
Copy link
Contributor

If you are testing a job in isolation and that job appends or prepends job(s) to its chain, then there is currently no easy way to test that.

public function handle(): void
{
    $this->prependToChain(new FooBarJob());
}

This PR fixes that by introducing the assertChain method (and assertNoChain method):

public function test_job_chains_foo_bar_job(): void
{
    $job = new TestJob();

    $job->handle();

    $job->assertChain([
        new FooBarJob();
    ]);

    // $job->assertNoChain();
}

@taylorotwell
Copy link
Member

taylorotwell commented Apr 1, 2024

@gdebrauwer what if someone were to prepend a mixture of job instances of string class names to the chain?

@gdebrauwer
Copy link
Contributor Author

@taylorotwell prepending or appending just a job class name is not something that is possible I think. In the background the serializeJob always uses the serialize global method unless the provided job is a closure. So if you provide a job class name, then prepending or appending would not work I think 🤔

I allowed the expectedChain to be either an array of job classes or an array of job objects as the Queuefake also allows that when performing chained job assertions.

@taylorotwell taylorotwell merged commit f389d79 into laravel:11.x Apr 1, 2024
28 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants