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

[10.x] Add Collection::wrap to add method on BatchFake #47589

Merged
merged 2 commits into from
Jun 27, 2023
Merged

[10.x] Add Collection::wrap to add method on BatchFake #47589

merged 2 commits into from
Jun 27, 2023

Conversation

schonhoff
Copy link
Contributor

Hello,

I faced an issue (#47588) with the add method on the BatchFake class. After searching through the original add Method on the Batch class I saw the line

$jobs = Collection::wrap($jobs)-> [...]

This line is missing in the BatchFake class. This results in some weird behavior on single job adds to a batch in testing. For example my InitialJob has two Jobs to be added:

    public function handle(): void
    {
        $this->batch()->add(new FirstJob());
        $this->batch()->add(new SecondJob());
    }

In my test i would expect that the count of the $batch->added will be 2. But it is something around 22 because in the BatchFake class the $jobs aren't wrapped before they are added to the array in a foreach loop.

BatchFake add method:

    public function add($jobs)
    {
        foreach ($jobs as $job) {
            $this->added[] = $job;
        }

        return $this;
    }

If the parameter would be wrapped before the for each loop, it would provide the expected result.

I could not find test for the BatchFake class in the repository. Maybe i missed them?

If more information are needed I would love to provide them.

@taylorotwell taylorotwell merged commit 9e6cb65 into laravel:10.x Jun 27, 2023
17 checks passed
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.

None yet

2 participants