/** * Ensure that exists an dispatcher middleware. * * @throws InvalidArgumentException */ protected function ensureEventDispatcherMiddleware() { if ($this->dispatcherMiddleware !== null) { return; } foreach ($this->middlewares as $priority => $collection) { foreach ($collection as $middleware) { if ($middleware instanceof EventDispatcherMiddleware) { $this->dispatcherMiddleware = $middleware; return; } } } throw NotFoundException::middlewareOfType(EventDispatcherMiddleware::class); }
/** * Test middlewareOfType method. */ public function testMiddlewareOfType() { $this->given($exception = NotFoundException::middlewareOfType('bar'))->then()->variable($exception->getPrevious())->isNull(); }