-
Notifications
You must be signed in to change notification settings - Fork 11k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[9.x] Adds partial queue faking #41344
Conversation
One potential problem I see here is the following situation: Queue::fake(ChildJob::class);
ParentJob::dispatch()->onConnection('non-default-connection'); The This may be solvable by checking the |
I'm not sure I understand what the problem is. Don't we want to run |
The queue driver in the |
I pushed some changes and I suppose this works now. I'd recommend you to check it yourself since you know a lot more about the queueing system than I do. |
OK - just thinking through this from the very beginning. I would test your original example like so: Queue::fake();
(new ParentJob)->handle();
Queue::assertPushed(ChildJob::class); Is there another example you are trying to test that isn't currently already possible? |
In that example you'd lose automatic dependency injection in the The example that made me attempt this PR is when using batches. When you want to test that a job is added to a batch. class ParentJob
{
use Batchable, Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function handle()
{
$this->batch()->add(new ChildJob);
}
{ Queue::fake();
Bus::batch(new ParentJob)->dispatch();
Queue::assertPushed(ChildJob::class); You can't do Thinking of it we could also add this: Queue::fake(ChildJob::class);
$batch = Bus::batch(new ParentJob)->dispatch();
Queue::assertAddedToBatch($batch, ChildJob::class); |
Added here: #41425 Thanks |
This PR allows you to only fake certain jobs.
Useful if you want to test if one job dispatches another job.
When using
Queue::fake()
all jobs will be faked. Therefore theParentJob
won't run and will never dispatch theChildJob
.With this addition you can choose which job to fake. Not passing a parameter will fake all jobs like before.
Example: I run a web scraper which scrapes the homepage of a news site in a job. That job will then dispatch a job for every article it found.