Rename MethodMap::setMethod to ::register
This commit is contained in:
parent
d8352e71d9
commit
72767b74e8
|
|
@ -41,7 +41,7 @@ class MethodMap implements MiddlewareInterface, MethodMapInterface
|
||||||
* @param string $method
|
* @param string $method
|
||||||
* @param mixed $middleware
|
* @param mixed $middleware
|
||||||
*/
|
*/
|
||||||
public function setMethod($method, $middleware)
|
public function register($method, $middleware)
|
||||||
{
|
{
|
||||||
$methods = explode(",", $method);
|
$methods = explode(",", $method);
|
||||||
$methods = array_map("trim", $methods);
|
$methods = array_map("trim", $methods);
|
||||||
|
|
|
||||||
|
|
@ -26,5 +26,5 @@ interface MethodMapInterface extends MiddlewareInterface
|
||||||
* @param string $method
|
* @param string $method
|
||||||
* @param mixed $middleware
|
* @param mixed $middleware
|
||||||
*/
|
*/
|
||||||
public function setMethod($method, $middleware);
|
public function register($method, $middleware);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ class RouteMap implements RouteMapInterface
|
||||||
* - A single verb ("GET"),
|
* - A single verb ("GET"),
|
||||||
* - A comma-separated list of verbs ("GET,PUT,DELETE")
|
* - A comma-separated list of verbs ("GET,PUT,DELETE")
|
||||||
* - "*" to indicate any method.
|
* - "*" to indicate any method.
|
||||||
* @see MethodMapInterface::setMethod
|
* @see MethodMapInterface::register
|
||||||
*
|
*
|
||||||
* $target may be:
|
* $target may be:
|
||||||
* - An exact path (e.g., "/path/")
|
* - An exact path (e.g., "/path/")
|
||||||
|
|
@ -60,7 +60,7 @@ class RouteMap implements RouteMapInterface
|
||||||
public function add($method, $target, $middleware)
|
public function add($method, $target, $middleware)
|
||||||
{
|
{
|
||||||
$route = $this->getRouteForTarget($target);
|
$route = $this->getRouteForTarget($target);
|
||||||
$route->getMethodMap()->setMethod($method, $middleware);
|
$route->getMethodMap()->register($method, $middleware);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dispatch(ServerRequestInterface $request, ResponseInterface &$response)
|
public function dispatch(ServerRequestInterface $request, ResponseInterface &$response)
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ interface RouteMapInterface extends MiddlewareInterface
|
||||||
* - A single verb ("GET"),
|
* - A single verb ("GET"),
|
||||||
* - A comma-separated list of verbs ("GET,PUT,DELETE")
|
* - A comma-separated list of verbs ("GET,PUT,DELETE")
|
||||||
* - "*" to indicate any method.
|
* - "*" to indicate any method.
|
||||||
* @see MethodMapInterface::setMethod
|
* @see MethodMapInterface::register
|
||||||
*
|
*
|
||||||
* $target may be:
|
* $target may be:
|
||||||
* - An exact path (e.g., "/path/")
|
* - An exact path (e.g., "/path/")
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ class Router implements MiddlewareInterface, RouteMapInterface
|
||||||
* - A single verb ("GET"),
|
* - A single verb ("GET"),
|
||||||
* - A comma-separated list of verbs ("GET,PUT,DELETE")
|
* - A comma-separated list of verbs ("GET,PUT,DELETE")
|
||||||
* - "*" to indicate any method.
|
* - "*" to indicate any method.
|
||||||
* @see MethodMapInterface::setMethod
|
* @see MethodMapInterface::register
|
||||||
*
|
*
|
||||||
* $target may be:
|
* $target may be:
|
||||||
* - An exact path (e.g., "/path/")
|
* - An exact path (e.g., "/path/")
|
||||||
|
|
|
||||||
|
|
@ -43,14 +43,14 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase
|
||||||
* @covers ::dispatch
|
* @covers ::dispatch
|
||||||
* @covers ::dispatchMiddleware
|
* @covers ::dispatchMiddleware
|
||||||
* @covers ::getDispatcher
|
* @covers ::getDispatcher
|
||||||
* @covers ::setMethod
|
* @covers ::register
|
||||||
*/
|
*/
|
||||||
public function testDispatchesMiddlewareWithMatchingMethod()
|
public function testDispatchesMiddlewareWithMatchingMethod()
|
||||||
{
|
{
|
||||||
$this->request->getMethod()->willReturn("GET");
|
$this->request->getMethod()->willReturn("GET");
|
||||||
|
|
||||||
$map = new MethodMap();
|
$map = new MethodMap();
|
||||||
$map->setMethod("GET", $this->middleware->reveal());
|
$map->register("GET", $this->middleware->reveal());
|
||||||
$map->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
|
$map->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
|
||||||
|
|
||||||
$this->middleware->dispatch($this->request->reveal(), $this->response->reveal(), $this->next)->shouldHaveBeenCalled();
|
$this->middleware->dispatch($this->request->reveal(), $this->response->reveal(), $this->next)->shouldHaveBeenCalled();
|
||||||
|
|
@ -70,8 +70,8 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase
|
||||||
$middlewareLower->dispatch(Argument::cetera())->willReturn();
|
$middlewareLower->dispatch(Argument::cetera())->willReturn();
|
||||||
|
|
||||||
$map = new MethodMap();
|
$map = new MethodMap();
|
||||||
$map->setMethod("GET", $middlewareUpper->reveal());
|
$map->register("GET", $middlewareUpper->reveal());
|
||||||
$map->setMethod("get", $middlewareLower->reveal());
|
$map->register("get", $middlewareLower->reveal());
|
||||||
$map->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
|
$map->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
|
||||||
|
|
||||||
$middlewareLower->dispatch($this->request->reveal(), $this->response->reveal(), $this->next)->shouldHaveBeenCalled();
|
$middlewareLower->dispatch($this->request->reveal(), $this->response->reveal(), $this->next)->shouldHaveBeenCalled();
|
||||||
|
|
@ -81,14 +81,14 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase
|
||||||
* @covers ::dispatch
|
* @covers ::dispatch
|
||||||
* @covers ::dispatchMiddleware
|
* @covers ::dispatchMiddleware
|
||||||
* @covers ::getDispatcher
|
* @covers ::getDispatcher
|
||||||
* @covers ::setMethod
|
* @covers ::register
|
||||||
*/
|
*/
|
||||||
public function testDispatchesWildcardMiddlewareWithNonMatchingMethod()
|
public function testDispatchesWildcardMiddlewareWithNonMatchingMethod()
|
||||||
{
|
{
|
||||||
$this->request->getMethod()->willReturn("GET");
|
$this->request->getMethod()->willReturn("GET");
|
||||||
|
|
||||||
$map = new MethodMap();
|
$map = new MethodMap();
|
||||||
$map->setMethod("*", $this->middleware->reveal());
|
$map->register("*", $this->middleware->reveal());
|
||||||
$map->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
|
$map->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
|
||||||
|
|
||||||
$this->middleware->dispatch($this->request->reveal(), $this->response->reveal(), $this->next)->shouldHaveBeenCalled();
|
$this->middleware->dispatch($this->request->reveal(), $this->response->reveal(), $this->next)->shouldHaveBeenCalled();
|
||||||
|
|
@ -102,19 +102,19 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase
|
||||||
$this->request->getMethod()->willReturn("HEAD");
|
$this->request->getMethod()->willReturn("HEAD");
|
||||||
|
|
||||||
$map = new MethodMap();
|
$map = new MethodMap();
|
||||||
$map->setMethod("GET", $this->middleware->reveal());
|
$map->register("GET", $this->middleware->reveal());
|
||||||
$map->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
|
$map->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
|
||||||
|
|
||||||
$this->middleware->dispatch($this->request->reveal(), $this->response->reveal(), $this->next)->shouldHaveBeenCalled();
|
$this->middleware->dispatch($this->request->reveal(), $this->response->reveal(), $this->next)->shouldHaveBeenCalled();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @covers ::setMethod
|
* @covers ::register
|
||||||
*/
|
*/
|
||||||
public function testRegistersMiddlewareForMultipleMethods()
|
public function testRegistersMiddlewareForMultipleMethods()
|
||||||
{
|
{
|
||||||
$map = new MethodMap();
|
$map = new MethodMap();
|
||||||
$map->setMethod("GET,POST", $this->middleware->reveal());
|
$map->register("GET,POST", $this->middleware->reveal());
|
||||||
|
|
||||||
$this->request->getMethod()->willReturn("GET");
|
$this->request->getMethod()->willReturn("GET");
|
||||||
$map->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
|
$map->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
|
||||||
|
|
@ -130,8 +130,8 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase
|
||||||
$this->request->getMethod()->willReturn("POST");
|
$this->request->getMethod()->willReturn("POST");
|
||||||
|
|
||||||
$map = new MethodMap();
|
$map = new MethodMap();
|
||||||
$map->setMethod("POST", $this->middleware->reveal());
|
$map->register("POST", $this->middleware->reveal());
|
||||||
$map->setMethod("POST", null);
|
$map->register("POST", null);
|
||||||
$map->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
|
$map->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
|
||||||
|
|
||||||
$this->response->withStatus(405)->shouldHaveBeenCalled();
|
$this->response->withStatus(405)->shouldHaveBeenCalled();
|
||||||
|
|
@ -147,7 +147,7 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase
|
||||||
$this->request->getMethod()->willReturn("OPTIONS");
|
$this->request->getMethod()->willReturn("OPTIONS");
|
||||||
|
|
||||||
$map = new MethodMap();
|
$map = new MethodMap();
|
||||||
$map->setMethod("GET", $this->middleware->reveal());
|
$map->register("GET", $this->middleware->reveal());
|
||||||
$map->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
|
$map->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
|
||||||
|
|
||||||
$this->response->withStatus(200)->shouldHaveBeenCalled();
|
$this->response->withStatus(200)->shouldHaveBeenCalled();
|
||||||
|
|
@ -165,7 +165,7 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$map = new MethodMap();
|
$map = new MethodMap();
|
||||||
foreach ($methodsDeclared as $method) {
|
foreach ($methodsDeclared as $method) {
|
||||||
$map->setMethod($method, $this->middleware->reveal());
|
$map->register($method, $this->middleware->reveal());
|
||||||
}
|
}
|
||||||
$map->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
|
$map->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
|
||||||
|
|
||||||
|
|
@ -191,7 +191,7 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase
|
||||||
$this->request->getMethod()->willReturn("POST");
|
$this->request->getMethod()->willReturn("POST");
|
||||||
|
|
||||||
$map = new MethodMap();
|
$map = new MethodMap();
|
||||||
$map->setMethod("GET", $this->middleware->reveal());
|
$map->register("GET", $this->middleware->reveal());
|
||||||
$map->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
|
$map->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
|
||||||
|
|
||||||
$this->response->withStatus(405)->shouldHaveBeenCalled();
|
$this->response->withStatus(405)->shouldHaveBeenCalled();
|
||||||
|
|
@ -209,7 +209,7 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$map = new MethodMap();
|
$map = new MethodMap();
|
||||||
foreach ($methodsDeclared as $method) {
|
foreach ($methodsDeclared as $method) {
|
||||||
$map->setMethod($method, $this->middleware->reveal());
|
$map->register($method, $this->middleware->reveal());
|
||||||
}
|
}
|
||||||
$map->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
|
$map->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue