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

[8.x] Add Event::fakeExcept() to fake all but certain events #39752

Merged
merged 2 commits into from Nov 25, 2021
Merged

[8.x] Add Event::fakeExcept() to fake all but certain events #39752

merged 2 commits into from Nov 25, 2021

Conversation

devfrey
Copy link
Contributor

@devfrey devfrey commented Nov 24, 2021

I sometimes find myself working on feature tests that trigger multiple events. I try to fake all events to avoid unexpected side effects, but sometimes certain events may be required to simulate expected behaviour. I would use this to fake all but certain events:

Event::fake([
    fn (string $eventClass) => $eventClass !== ServiceSaving::class,
]);

This PR adds a new fakeExcept() method to the Event facade to allow this:

Event::fakeExcept(ServiceSaving::class);
Event::fakeExcept([ServiceSaving::class, 'some-other-event']);

@taylorotwell taylorotwell merged commit a8b9642 into laravel:8.x Nov 25, 2021
@taylorotwell
Copy link
Member

Thanks for contributing to Laravel! ❤️

@devfrey devfrey deleted the event-fake-except branch December 9, 2021 08:55
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