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

[9.x] Allow BusFake to use custom BusRepository #45202

Merged
merged 2 commits into from Dec 7, 2022
Merged

[9.x] Allow BusFake to use custom BusRepository #45202

merged 2 commits into from Dec 7, 2022

Conversation

mihaliak
Copy link
Contributor

@mihaliak mihaliak commented Dec 6, 2022

As described in PR name, allow BusFake to use custom BusRepository. This is useful in tests where we use Bus::fake() and later in code we use resolve(BusRepository::class)->find(...).

Before this change that test would fail since Bus::fake() is creating always new BusRepository so using resolve(BusRepository::class)->find(...) will not use BatchRepositoryFake and throw error that it cant find batch in unit tests.

Usage:

$myBusRepository = new BatchRepositoryFake;

Bus::fake([JobsToFake::class], $myBusRepository);


// either bind $myBusRepository to \Illuminate\Bus\BatchRepository interface or send as constructor param to user defined class

app()->bind(\Illuminate\Bus\BatchRepository::class, $myBusRepository);


...
$myTestedService->method(); // this method calls  -> resolve(BatchRepository::class)->find(...)  -> correctly found fake batch

@mihaliak mihaliak changed the title Allow BusFake to use custom BusRepository [9.x] Allow BusFake to use custom BusRepository Dec 7, 2022
@taylorotwell taylorotwell merged commit 8ec69f8 into laravel:9.x Dec 7, 2022
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