[5.6] Non faked events should be properly dispatched #25185
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently the
EventFake
can receive an array of events which should be faked. If you specify exactly which events should be faked, I'd expect that all other events should be properly dispatched and their listeners executed. That's currently not the case as theEventFake
listen
andsubscribe
methods do nothing.I stumbled upon this problem when I was writing some tests:
In this case I have an observer on the User model which creates a "slug" for the model. So when doing User::observe([UserObserver::class]); this gets called
As the dispatcher is now the
EventFake
instance and the listen method in it does nothing my observer listeners weren't registered. This resulted in aIlluminate\Database\QueryException: SQLSTATE[HY000]: General error: 1364 Field 'slug' doesn't have a default value
exception when the above test was run which I totally didn't expect since I explicitly told the faker that I want only
FoobarEvent
to be faked.I fixed this to behave as expected and I also added a test for it.