public function expectsEvents($events)
{
$events = is_array($events) ? $events : func_get_args();
$mock = Mockery::spy('Illuminate\\Contracts\\Events\\Dispatcher');
$mock->shouldReceive('fire')->andReturnUsing(function ($called) use(&$events) {
foreach ($events as $key => $event) {
if (is_string($called) && $called === $event || is_string($called) && is_subclass_of($called, $event) || is_object($called) && $called instanceof $event) {
unset($events[$key]);
}
}
});
$this->beforeApplicationDestroyed(function () use(&$events) {
if ($events) {
throw new Exception('The following events were not fired: [' . implode(', ', $events) . ']');
}
});
$this->app->instance('events', $mock);
return $this;
}