Download the PHP package score-labs/laravel-event-fake without Composer
On this page you can find all versions of the php package score-labs/laravel-event-fake. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download score-labs/laravel-event-fake
More information about score-labs/laravel-event-fake
Files in score-labs/laravel-event-fake
Package laravel-event-fake
Short Description An enhanced event fake for Laravel event testing
License MIT
Informations about the package laravel-event-fake
Laravel Event Fake
Enhanced Laravel Event Fake for testing
Have you ever wanted more versatility when you're testing your Laravel events? If you're like me, you're uncomfortable with the idea of just testing the listeners in isolation, but leaving all of the events unfaked makes your tests a mess. Well fret no further kindred spirit! Score Labs' Laravel Event Fake is here!
So how's it work?
Score Labs' Laravel Event Fake adds two new methods to the already great Event
facade.
Installation
In your test classes, just import the new Event facade
Methods
Fake Except
There are two ways to call Event::fakeExcept
:
Will fake every event except for EventThatIWantToFire
. That event and all of its listeners will fire normally.
Will fake every event except for EventThatIWantToFire
and will spy every listener except for `TheOnlyListenerIWantToFire.
This usage is great for when you want to isolate a single listener, but you still want to test that the event setup is working
as expected.
Once you've passed listeners to spy, you can still assert that they were fired without their code running by using
:point_up: You can also pass arrays of class names for either argument to allow through multiple events/listeners at once!
Fake Except Models
If you want to fake all events, but you still want events that you manually added in your models boot
method to fire, just use
This way you can fake all events as usual, but still let your models get any necessary information they may need during a creating or saving event.
But what about all of the great existing features of Event::fake?
They are all still there! This is just a drop in enhancement and will be compatible with all usages of Event::fake in Laravel 5.5+
This code is MIT Licensed and open to all contributors. For pull requests, please try to mimic the existing code style.