Router delegates on failure and does not return 404

This commit is contained in:
PJ Dietz 2018-06-21 12:47:31 -04:00
parent f016b74c38
commit 29cad3687e
2 changed files with 4 additions and 24 deletions

View File

@ -83,9 +83,8 @@ class Router implements RouterInterface
} }
} }
// If no route exists, set the status code of the response to 404 and // If no route exists, delegate to the next middleware.
// return the response without propagating. return $next($request, $response);
return $response->withStatus(404);
} }
/** /**

View File

@ -129,7 +129,6 @@ class RouterTest extends TestCase
$this->route->__invoke($this->request, $this->response, $this->next)->shouldHaveBeenCalled(); $this->route->__invoke($this->request, $this->response, $this->next)->shouldHaveBeenCalled();
} }
/** @coversNothing */
public function testDispatchesStaticRouteBeforePrefixRoute() public function testDispatchesStaticRouteBeforePrefixRoute()
{ {
$staticRoute = $this->prophesize('WellRESTed\Routing\Route\RouteInterface'); $staticRoute = $this->prophesize('WellRESTed\Routing\Route\RouteInterface');
@ -357,28 +356,10 @@ class RouterTest extends TestCase
)->shouldHaveBeenCalled(); )->shouldHaveBeenCalled();
} }
// ------------------------------------------------------------------------ public function testPropagatesToNextMiddlewareWhenNoRouteMatches()
// No Matching Routes
public function testResponds404WhenNoRouteMatches()
{
$this->request = $this->request->withRequestTarget("/no/match");
$response = $this->router->__invoke($this->request, $this->response, $this->next);
$this->assertEquals(404, $response->getStatusCode());
}
public function testStopsPropagatingWhenNoRouteMatches()
{ {
$this->request = $this->request->withRequestTarget("/no/match"); $this->request = $this->request->withRequestTarget("/no/match");
$this->router->__invoke($this->request, $this->response, $this->next); $this->router->__invoke($this->request, $this->response, $this->next);
$this->assertFalse($this->next->called); $this->assertTrue($this->next->called);
}
public function testRegisterIsFluid()
{
$router = $this->router
->register("GET", "/", "middleware")
->register("POST", "/", "middleware");
$this->assertSame($this->router, $router);
} }
} }