From f0dc0cb58a62e56e9d4ecfb6d24628d64c7ebcfc Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Sun, 26 Dec 2021 11:52:22 +0300 Subject: [PATCH] Fix #144: Fix route did not override dispatcher middlewares (#146) --- src/Route.php | 4 ---- tests/RouteTest.php | 7 ++++--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/Route.php b/src/Route.php index 08b61bfd..f65288a2 100644 --- a/src/Route.php +++ b/src/Route.php @@ -370,10 +370,6 @@ private function getDispatcherWithMiddlewares(): MiddlewareDispatcher throw new RuntimeException(sprintf('There is no dispatcher in the route %s.', $this->getData('name'))); } - if ($this->dispatcher->hasMiddlewares()) { - return $this->dispatcher; - } - /** @var mixed $definition */ foreach ($this->middlewareDefinitions as $index => $definition) { if (in_array($definition, $this->disabledMiddlewareDefinitions, true)) { diff --git a/tests/RouteTest.php b/tests/RouteTest.php index 8d04dc97..e0d4f797 100644 --- a/tests/RouteTest.php +++ b/tests/RouteTest.php @@ -229,18 +229,19 @@ public function testGetDispatcherWithMiddlewares(): void ]) )->withMiddlewares([ TestMiddleware1::class, - TestMiddleware2::class, [TestController::class, 'index'], ]); - $route = Route::get('/'); + $route = Route::get('/') + ->middleware(TestMiddleware2::class) + ->action([TestController::class, 'index']); $route->injectDispatcher($injectDispatcher); $dispatcher = $route->getData('dispatcherWithMiddlewares'); $response = $dispatcher->dispatch($request, $this->getRequestHandler()); $this->assertSame(200, $response->getStatusCode()); - $this->assertSame('12', (string) $response->getBody()); + $this->assertSame('2', (string) $response->getBody()); } public function testDebugInfo(): void