diff --git a/src/Routing/Route/StaticRoute.php b/src/Routing/Route/StaticRoute.php index acb7d43..bee0bbc 100644 --- a/src/Routing/Route/StaticRoute.php +++ b/src/Routing/Route/StaticRoute.php @@ -2,31 +2,20 @@ namespace WellRESTed\Routing\Route; -class StaticRoute extends Route implements StaticRouteInterface +class StaticRoute extends Route { - private $path; - - public function __construct($path, $middleware) + public function getType() { - parent::__construct($middleware); - $this->path = $path; + return RouteInterface::TYPE_STATIC; } /** - * @param string $requestTarget - * @param array $captures - * @return bool + * Examines a path (request target) to see if it is a match for the route. + * + * @return boolean */ - public function matchesRequestTarget($requestTarget, &$captures = null) + public function matchesRequestTarget($requestTarget) { - return $requestTarget == $this->path; - } - - /** - * @return string - */ - public function getPath() - { - return $this->path; + return $requestTarget === $this->getTarget(); } } diff --git a/src/Routing/Route/StaticRouteInterface.php b/src/Routing/Route/StaticRouteInterface.php deleted file mode 100644 index e64ab21..0000000 --- a/src/Routing/Route/StaticRouteInterface.php +++ /dev/null @@ -1,11 +0,0 @@ -request = $this->prophesize("\\Psr\\Http\\Message\\ServerRequestInterface"); - $this->response = $this->prophesize("\\Psr\\Http\\Message\\ResponseInterface"); - $this->middleware = $this->prophesize("\\WellRESTed\\Routing\\MiddlewareInterface"); + $methodMap = $this->prophesize('WellRESTed\Routing\MethodMapInterface'); + $route = new StaticRoute("/", $methodMap->reveal()); + $this->assertSame(RouteInterface::TYPE_STATIC, $route->getType()); } - public function testMatchesPath() + /** + * @covers ::matchesRequestTarget + */ + public function testMatchesExactRequestTarget() { - $route = new StaticRoute("/cats/", $this->middleware->reveal()); - $this->assertTrue($route->matchesRequestTarget("/cats/")); + $methodMap = $this->prophesize('WellRESTed\Routing\MethodMapInterface'); + $route = new StaticRoute("/", $methodMap->reveal()); + $this->assertTrue($route->matchesRequestTarget("/")); } - public function testFailsToMatchWrongPath() + /** + * @covers ::matchesRequestTarget + */ + public function testDoesNotMatchNonmatchingRequestTarget() { - $route = new StaticRoute("/dogs/", $this->middleware->reveal()); + $methodMap = $this->prophesize('WellRESTed\Routing\MethodMapInterface'); + $route = new StaticRoute("/", $methodMap->reveal()); $this->assertFalse($route->matchesRequestTarget("/cats/")); } - - public function testReturnsPaths() - { - $route = new StaticRoute("/cats/", $this->middleware->reveal()); - $this->assertEquals("/cats/", $route->getPath()); - } }