Router uses only the request's path for routing

This commit is contained in:
PJ Dietz 2015-05-13 21:52:55 -04:00
parent 3b18d1dcdb
commit 1be4ff7691
2 changed files with 21 additions and 1 deletions

View File

@ -77,7 +77,8 @@ class Router implements RouterInterface
public function dispatch(ServerRequestInterface $request, ResponseInterface $response, $next)
{
$requestTarget = $request->getRequestTarget();
// Use only the path for routing.
$requestTarget = parse_url($request->getRequestTarget(), PHP_URL_PATH);
$route = $this->getStaticRoute($requestTarget);
if ($route) {

View File

@ -363,6 +363,25 @@ class RouterTest extends \PHPUnit_Framework_TestCase
$this->request->withAttribute("pathVariables", $variables)->shouldHaveBeenCalled();
}
/**
* @covers ::dispatch
* @covers ::registerRouteForTarget
*/
public function testMatchesPathAgainstRouteWithoutQuery()
{
$target = "/my/path?cat=molly&dog=bear";
$this->request->getRequestTarget()->willReturn($target);
$this->route->getTarget()->willReturn($target);
$this->route->getType()->willReturn(RouteInterface::TYPE_PATTERN);
$this->route->matchesRequestTarget(Argument::cetera())->willReturn(true);
$this->router->register("GET", $target, "middleware");
$this->router->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
$this->route->matchesRequestTarget("/my/path")->shouldHaveBeenCalled();
}
// ------------------------------------------------------------------------
// No Matching Routes