dispatcher : static::getFacadeRoot(); return tap(new EventFake($actualDispatcher, $eventsToFake), function ($fake) { static::swap($fake); Model::setEventDispatcher($fake); Cache::refreshEventDispatcher(); }); } /** * Replace the bound instance with a fake that fakes all events except the given events. * * @param string[]|string $eventsToAllow * @return \Illuminate\Support\Testing\Fakes\EventFake */ public static function fakeExcept($eventsToAllow) { return static::fake([ function ($eventName) use ($eventsToAllow) { return ! in_array($eventName, (array) $eventsToAllow); }, ]); } /** * Replace the bound instance with a fake during the given callable's execution. * * @param callable $callable * @param array $eventsToFake * @return mixed */ public static function fakeFor(callable $callable, array $eventsToFake = []) { $originalDispatcher = static::getFacadeRoot(); static::fake($eventsToFake); return tap($callable(), function () use ($originalDispatcher) { static::swap($originalDispatcher); Model::setEventDispatcher($originalDispatcher); Cache::refreshEventDispatcher(); }); } /** * Replace the bound instance with a fake during the given callable's execution. * * @param callable $callable * @param array $eventsToAllow * @return mixed */ public static function fakeExceptFor(callable $callable, array $eventsToAllow = []) { $originalDispatcher = static::getFacadeRoot(); static::fakeExcept($eventsToAllow); return tap($callable(), function () use ($originalDispatcher) { static::swap($originalDispatcher); Model::setEventDispatcher($originalDispatcher); Cache::refreshEventDispatcher(); }); } /** * Get the registered name of the component. * * @return string */ protected static function getFacadeAccessor() { return 'events'; } }