I'm trying to test Event Listener in Laravel. This is my listener:
class FlashNotifier
{
public function handleMenuItemWasStored()
{
Session::flash('flash-status', 'success');
Session::flash('flash-message', 'Item was stored.');
}
public function subscribe($events)
{
$events->listen(
MenuItemWasStored::class,
'\App\Listeners\Menu\FlashNotifier@handleMenuItemWasStored'
);
}
}
And this is the test I came up so far:
public function testEventListenerWasTriggered()
{
$listener = Mockery::mock('App\Listeners\Menu\FlashNotifier');
$d = new Dispatcher;
$listener->shouldReceive('handleMenuItemWasStored')->once();
$d->fire('App\Events\Menu\MenuItemWasStored');
}
However, I get the following exception:
Mockery\Exception\InvalidCountException: Method handleMenuItemWasStored()
from Mockery_1_App_Listeners_Menu_FlashNotifier
should be called exactly 1 times but called 0 times.
What am I doing wrong?
Aucun commentaire:
Enregistrer un commentaire