Skip to content

Commit

Permalink
Fix #144: Fix route did not override dispatcher middlewares (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik committed Dec 26, 2021
1 parent 077d4bc commit f0dc0cb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
4 changes: 0 additions & 4 deletions src/Route.php
Expand Up @@ -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)) {
Expand Down
7 changes: 4 additions & 3 deletions tests/RouteTest.php
Expand Up @@ -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
Expand Down

0 comments on commit f0dc0cb

Please sign in to comment.