-
Notifications
You must be signed in to change notification settings - Fork 11.3k
[9.x] Fake Batches #44104
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] Fake Batches #44104
Conversation
Tempting to make [$job, $batch] = (new ExampleJob)->withFakeBatch(); Edit: ✅ |
Maybe adding an array shape would help with autocomplete in IDEs? |
What about good old call by reference: $batch = new TestBatch();
$job = (new TestJob)->withFakeBatch($batch);
$job->handle();
$this->assertTrue($batch->cancelled());
$this->assertNotEmpty($batch->added); |
Not to be grammar police, but isn't the job within a batch? So maybe |
Yes, you are right. That Sounds better. |
Grammar police are the best kind of police 🚓 @jasonmccreary |
I don't think I can edit this directly, but the BusFake and BatchRepositoryFake should be updated to use this new It'd also be nice if the |
🚀 |
Co-authored-by: Mior Muhammad Zaki <crynobone@gmail.com>
Seems since this update, I have a few tests that fail now, due to calling
I have a batch created, and then use a lazy collection/chunk to add jobs to the batch. private function addToBatch(Model $model, Batch $batch): void
{
$model->relations()
->cursor()
->map(fn (Relation $relation): ThumbnailJob => $this->createThumbnailJob($relation))
->chunk(500)
->each(fn (LazyCollection $jobs) => $batch->add($jobs));
} Wondering if I am going about this the wrong way, or should the |
It's currently hard to test things like if a batch was cancelled by a job or if a job added additional jobs to a batch. You have to create a FakeBatch manually and override the cancel / add methods, etc.
This solves that.