[6.x] Replace Event Dispatcher in resolved cache repositories when Event::fake()
is used
#31119
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.
The
fake
andfakeFor
method of theEvent
facade currently fails to replace the existing Event Dispatcher with the faked dispatcher in resolved cache repositories.I've found that making assertions on cache events is a pretty useful way of testing code that uses the cache under the hood. For instance:
This PR adds a public method to the
CacheManager
used to refresh each cache repositories to which it holds a reference to with the event dispatcher that is currently bound in the service container.The method is called in the
Event::fake
andEvent::fakeFor
methods.A
getEventDispatcher
method was added to the cacheRepository
class to make testing a little easier.