Revise StaticRoute
This commit is contained in:
parent
58b5107289
commit
86d36e8c15
|
|
@ -2,31 +2,20 @@
|
||||||
|
|
||||||
namespace WellRESTed\Routing\Route;
|
namespace WellRESTed\Routing\Route;
|
||||||
|
|
||||||
class StaticRoute extends Route implements StaticRouteInterface
|
class StaticRoute extends Route
|
||||||
{
|
{
|
||||||
private $path;
|
public function getType()
|
||||||
|
|
||||||
public function __construct($path, $middleware)
|
|
||||||
{
|
{
|
||||||
parent::__construct($middleware);
|
return RouteInterface::TYPE_STATIC;
|
||||||
$this->path = $path;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $requestTarget
|
* Examines a path (request target) to see if it is a match for the route.
|
||||||
* @param array $captures
|
*
|
||||||
* @return bool
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function matchesRequestTarget($requestTarget, &$captures = null)
|
public function matchesRequestTarget($requestTarget)
|
||||||
{
|
{
|
||||||
return $requestTarget == $this->path;
|
return $requestTarget === $this->getTarget();
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getPath()
|
|
||||||
{
|
|
||||||
return $this->path;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace WellRESTed\Routing\Route;
|
|
||||||
|
|
||||||
interface StaticRouteInterface extends RouteInterface
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getPath();
|
|
||||||
}
|
|
||||||
|
|
@ -3,40 +3,43 @@
|
||||||
namespace WellRESTed\Test\Unit\Routing\Route;
|
namespace WellRESTed\Test\Unit\Routing\Route;
|
||||||
|
|
||||||
use Prophecy\Argument;
|
use Prophecy\Argument;
|
||||||
|
use WellRESTed\Routing\Route\RouteInterface;
|
||||||
use WellRESTed\Routing\Route\StaticRoute;
|
use WellRESTed\Routing\Route\StaticRoute;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers WellRESTed\Routing\Route\StaticRoute
|
* @coversDefaultClass WellRESTed\Routing\Route\StaticRoute
|
||||||
|
* @uses WellRESTed\Routing\Route\StaticRoute
|
||||||
* @uses WellRESTed\Routing\Route\Route
|
* @uses WellRESTed\Routing\Route\Route
|
||||||
*/
|
*/
|
||||||
class StaticRouteTest extends \PHPUnit_Framework_TestCase
|
class StaticRouteTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
private $request;
|
/**
|
||||||
private $response;
|
* @covers ::getType
|
||||||
private $middleware;
|
*/
|
||||||
|
public function testReturnsStaticType()
|
||||||
public function setUp()
|
|
||||||
{
|
{
|
||||||
$this->request = $this->prophesize("\\Psr\\Http\\Message\\ServerRequestInterface");
|
$methodMap = $this->prophesize('WellRESTed\Routing\MethodMapInterface');
|
||||||
$this->response = $this->prophesize("\\Psr\\Http\\Message\\ResponseInterface");
|
$route = new StaticRoute("/", $methodMap->reveal());
|
||||||
$this->middleware = $this->prophesize("\\WellRESTed\\Routing\\MiddlewareInterface");
|
$this->assertSame(RouteInterface::TYPE_STATIC, $route->getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMatchesPath()
|
/**
|
||||||
|
* @covers ::matchesRequestTarget
|
||||||
|
*/
|
||||||
|
public function testMatchesExactRequestTarget()
|
||||||
{
|
{
|
||||||
$route = new StaticRoute("/cats/", $this->middleware->reveal());
|
$methodMap = $this->prophesize('WellRESTed\Routing\MethodMapInterface');
|
||||||
$this->assertTrue($route->matchesRequestTarget("/cats/"));
|
$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/"));
|
$this->assertFalse($route->matchesRequestTarget("/cats/"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReturnsPaths()
|
|
||||||
{
|
|
||||||
$route = new StaticRoute("/cats/", $this->middleware->reveal());
|
|
||||||
$this->assertEquals("/cats/", $route->getPath());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue