private function mockEventDispatcher()
    {
        // Even if events are disabled we still want to record the triggered events.
        // But by mocking the event dispatcher the wildcard listener registered in the initialize method is removed.
        // So to record the triggered events we have to catch the calls to the fire method of the event dispatcher mock.
        $callback = function ($event) {
            $this->triggeredEvents[] = $this->normalizeEvent($event);

            return [];
        };

        // In Laravel 5.4 the Illuminate\Contracts\Events\Dispatcher interface was changed,
        // the 'fire' method was renamed to 'dispatch'. This code determines the correct method to mock.
        $method = method_exists($this->app['events'], 'dispatch') ? 'dispatch' : 'fire';

        $mock = Stub::makeEmpty('Illuminate\Contracts\Events\Dispatcher', [
           $method => $callback
        ]);

        $this->app->instance('events', $mock);
    }