Skip to content
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

When Batch uses the add method to add jobs, the totalJobs count of the batch is incorrect in the test after using Bus::fake() #51741

Closed
yankewei opened this issue Jun 7, 2024 · 0 comments

Comments

@yankewei
Copy link
Contributor

yankewei commented Jun 7, 2024

Laravel Version

11.10.0

PHP Version

8.3.3

Database Driver & Version

Mysql 8.3.0

Description

The method add of the BatchFake class is not update the totalJobs property, the behaviour is not same as the Batch class.

Steps To Reproduce

  1. Paste the following code into a command:
$batch = Bus::batch([])
            ->onQueue('batch-test')
            ->dispatch();

for ($i = 0; $i < 5; $i++) {
    $batch = $batch->add([function (): void {
        Log::info('Executing job');
    }]);
}

Log::info("The batch has {$batch->totalJobs} jobs");

Execute the command, and you should see the message in the log file:
local.INFO: The batch has 5 jobs
2. Paste the following code into a test to test the command:

public function testBatch()
{
      $bus = Bus::fake();

      $this->artisan("app:batch-test");

      $bus->assertBatchCount(1);
}

Run this test, and you will find the message in the log file. However, I expect the message to be testing.INFO: The batch has 5 jobs instead of:
testing.INFO: The batch has 0 jobs

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

No branches or pull requests

1 participant