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

Event::fake($eventsToFake) executing events listed to be faked #25077

Closed
srottem opened this issue Aug 3, 2018 · 2 comments
Closed

Event::fake($eventsToFake) executing events listed to be faked #25077

srottem opened this issue Aug 3, 2018 · 2 comments

Comments

@srottem
Copy link

srottem commented Aug 3, 2018

  • Laravel Version: 5.6.29
  • PHP Version: 7.2
  • Database Driver & Version: N/A

Description:

When passing an array of event types to fake to the Event facade's fake() method the list of events in the array are executed normally while the unlisted events are faked. Based on the name of the parameter '$eventsToFake' I would expect the opposite behavior.

The origin of the problem appears to come from the Illuminate\Support\Testing\Fakes\EventFake class's shouldFakeEvent() method.

In this method the following statement returns true if the event is not in the list of events to fake:

return collect($this->eventsToFake)
            ->filter(function ($event) use ($eventName, $payload) {
                return $event instanceof Closure
                            ? $event($eventName, $payload)
                            : $event === $eventName;
            })
            ->isEmpty();

I believe the result should be inverted:

return collect($this->eventsToFake)
            ->filter(function ($event) use ($eventName, $payload) {
                return $event instanceof Closure
                            ? $event($eventName, $payload)
                            : $event === $eventName;
            })
            ->isEmpty() == false;

Steps To Reproduce:

Call the Event::fake([SomeEvent::class]). At the moment the real handler for the SomeEvent class would be executed rather than the event being faked.

@derekmd
Copy link
Contributor

derekmd commented Aug 3, 2018

It's fixed in the 5.6 branch but hasn't been tagged as 5.6.30 yet: #24985

I'd suggest using 5.6.28 until the next release.

@derekmd
Copy link
Contributor

derekmd commented Aug 17, 2018

Upgrading to 5.6.33 fixes this issue.

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

3 participants