Refactor MiddlewareInterface::dispatch to MiddlewareInterface::__invoke
This commit is contained in:
parent
474d8da61c
commit
a825654336
|
|
@ -54,7 +54,7 @@ class DispatchStack implements DispatchStackInterface
|
||||||
* @param callable $next
|
* @param callable $next
|
||||||
* @return ResponseInterface
|
* @return ResponseInterface
|
||||||
*/
|
*/
|
||||||
public function dispatch(ServerRequestInterface $request, ResponseInterface $response, $next)
|
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next)
|
||||||
{
|
{
|
||||||
$dispatcher = $this->dispatcher;
|
$dispatcher = $this->dispatcher;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,5 +48,5 @@ interface DispatchStackInterface extends MiddlewareInterface
|
||||||
* @param callable $next
|
* @param callable $next
|
||||||
* @return ResponseInterface
|
* @return ResponseInterface
|
||||||
*/
|
*/
|
||||||
public function dispatch(ServerRequestInterface $request, ResponseInterface $response, $next);
|
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,8 @@ class Dispatcher implements DispatcherInterface
|
||||||
} elseif (is_array($middleware)) {
|
} elseif (is_array($middleware)) {
|
||||||
$middleware = $this->getDispatchStack($middleware);
|
$middleware = $this->getDispatchStack($middleware);
|
||||||
}
|
}
|
||||||
if ($middleware instanceof MiddlewareInterface) {
|
if (is_callable($middleware)) {
|
||||||
return $middleware->dispatch($request, $response, $next);
|
return $middleware($request, $response, $next);
|
||||||
} elseif ($middleware instanceof ResponseInterface) {
|
} elseif ($middleware instanceof ResponseInterface) {
|
||||||
return $middleware;
|
return $middleware;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -13,5 +13,5 @@ interface MiddlewareInterface
|
||||||
* @param callable $next
|
* @param callable $next
|
||||||
* @return ResponseInterface
|
* @return ResponseInterface
|
||||||
*/
|
*/
|
||||||
public function dispatch(ServerRequestInterface $request, ResponseInterface $response, $next);
|
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,8 @@ namespace WellRESTed\Routing;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use WellRESTed\Dispatching\DispatcherInterface;
|
use WellRESTed\Dispatching\DispatcherInterface;
|
||||||
use WellRESTed\MiddlewareInterface;
|
|
||||||
|
|
||||||
class MethodMap implements MiddlewareInterface, MethodMapInterface
|
class MethodMap implements MethodMapInterface
|
||||||
{
|
{
|
||||||
private $dispatcher;
|
private $dispatcher;
|
||||||
private $map;
|
private $map;
|
||||||
|
|
@ -63,7 +62,7 @@ class MethodMap implements MiddlewareInterface, MethodMapInterface
|
||||||
* @param callable $next
|
* @param callable $next
|
||||||
* @return ResponseInterface
|
* @return ResponseInterface
|
||||||
*/
|
*/
|
||||||
public function dispatch(ServerRequestInterface $request, ResponseInterface $response, $next)
|
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next)
|
||||||
{
|
{
|
||||||
$method = $request->getMethod();
|
$method = $request->getMethod();
|
||||||
// Dispatch middleware registered with the explicitly matching method.
|
// Dispatch middleware registered with the explicitly matching method.
|
||||||
|
|
|
||||||
|
|
@ -37,8 +37,9 @@ abstract class Route implements RouteInterface
|
||||||
return $this->target;
|
return $this->target;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dispatch(ServerRequestInterface $request, ResponseInterface $response, $next)
|
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next)
|
||||||
{
|
{
|
||||||
return $this->methodMap->dispatch($request, $response, $next);
|
$map = $this->methodMap;
|
||||||
|
return $map($request, $response, $next);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -75,19 +75,19 @@ class Router implements RouterInterface
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dispatch(ServerRequestInterface $request, ResponseInterface $response, $next)
|
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next)
|
||||||
{
|
{
|
||||||
// Use only the path for routing.
|
// Use only the path for routing.
|
||||||
$requestTarget = parse_url($request->getRequestTarget(), PHP_URL_PATH);
|
$requestTarget = parse_url($request->getRequestTarget(), PHP_URL_PATH);
|
||||||
|
|
||||||
$route = $this->getStaticRoute($requestTarget);
|
$route = $this->getStaticRoute($requestTarget);
|
||||||
if ($route) {
|
if ($route) {
|
||||||
return $route->dispatch($request, $response, $next);
|
return $route($request, $response, $next);
|
||||||
}
|
}
|
||||||
|
|
||||||
$route = $this->getPrefixRoute($requestTarget);
|
$route = $this->getPrefixRoute($requestTarget);
|
||||||
if ($route) {
|
if ($route) {
|
||||||
return $route->dispatch($request, $response, $next);
|
return $route($request, $response, $next);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try each of the routes.
|
// Try each of the routes.
|
||||||
|
|
@ -95,7 +95,7 @@ class Router implements RouterInterface
|
||||||
if ($route->matchesRequestTarget($requestTarget)) {
|
if ($route->matchesRequestTarget($requestTarget)) {
|
||||||
$pathVariables = $route->getPathVariables();
|
$pathVariables = $route->getPathVariables();
|
||||||
$request = $request->withAttribute($this->pathVariablesAttributeKey, $pathVariables);
|
$request = $request->withAttribute($this->pathVariablesAttributeKey, $pathVariables);
|
||||||
return $route->dispatch($request, $response, $next);
|
return $route($request, $response, $next);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,14 +6,13 @@ use Psr\Http\Message\ResponseInterface;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use WellRESTed\Dispatching\Dispatcher;
|
use WellRESTed\Dispatching\Dispatcher;
|
||||||
use WellRESTed\Dispatching\DispatcherInterface;
|
use WellRESTed\Dispatching\DispatcherInterface;
|
||||||
use WellRESTed\Dispatching\DispatchStackInterface;
|
|
||||||
use WellRESTed\Message\Response;
|
use WellRESTed\Message\Response;
|
||||||
use WellRESTed\Message\ServerRequest;
|
use WellRESTed\Message\ServerRequest;
|
||||||
use WellRESTed\Routing\Router;
|
use WellRESTed\Routing\Router;
|
||||||
use WellRESTed\Transmission\Transmitter;
|
use WellRESTed\Transmission\Transmitter;
|
||||||
use WellRESTed\Transmission\TransmitterInterface;
|
use WellRESTed\Transmission\TransmitterInterface;
|
||||||
|
|
||||||
class Server implements DispatchStackInterface
|
class Server
|
||||||
{
|
{
|
||||||
/** @var array */
|
/** @var array */
|
||||||
private $attributes;
|
private $attributes;
|
||||||
|
|
|
||||||
|
|
@ -164,7 +164,7 @@ class StringMiddleware implements MiddlewareInterface
|
||||||
* @param callable $next
|
* @param callable $next
|
||||||
* @return ResponseInterface
|
* @return ResponseInterface
|
||||||
*/
|
*/
|
||||||
public function dispatch(ServerRequestInterface $request, ResponseInterface $response, $next)
|
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next)
|
||||||
{
|
{
|
||||||
$body = $response->getBody();
|
$body = $response->getBody();
|
||||||
if ($body->isWritable()) {
|
if ($body->isWritable()) {
|
||||||
|
|
@ -188,7 +188,7 @@ class BenderMiddleware implements MiddlewareInterface
|
||||||
* @param callable $next
|
* @param callable $next
|
||||||
* @return ResponseInterface
|
* @return ResponseInterface
|
||||||
*/
|
*/
|
||||||
public function dispatch(ServerRequestInterface $request, ResponseInterface $response, $next)
|
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next)
|
||||||
{
|
{
|
||||||
$message = "Bender Bending Rodriguez";
|
$message = "Bender Bending Rodriguez";
|
||||||
$body = $response->getBody();
|
$body = $response->getBody();
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ class DispatchStackTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ::dispatch
|
* @covers ::__invoke
|
||||||
*/
|
*/
|
||||||
public function testDispachesMiddlewareInOrderAdded()
|
public function testDispachesMiddlewareInOrderAdded()
|
||||||
{
|
{
|
||||||
|
|
@ -71,12 +71,12 @@ class DispatchStackTest extends \PHPUnit_Framework_TestCase
|
||||||
$callOrder[] = "third";
|
$callOrder[] = "third";
|
||||||
return $next($request, $response);
|
return $next($request, $response);
|
||||||
});
|
});
|
||||||
$stack->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
|
$stack($this->request->reveal(), $this->response->reveal(), $this->next);
|
||||||
$this->assertEquals(["first", "second", "third"], $callOrder);
|
$this->assertEquals(["first", "second", "third"], $callOrder);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ::dispatch
|
* @covers ::__invoke
|
||||||
*/
|
*/
|
||||||
public function testCallsNextAfterDispatchingEmptyStack()
|
public function testCallsNextAfterDispatchingEmptyStack()
|
||||||
{
|
{
|
||||||
|
|
@ -87,12 +87,12 @@ class DispatchStackTest extends \PHPUnit_Framework_TestCase
|
||||||
};
|
};
|
||||||
|
|
||||||
$stack = new DispatchStack($this->dispatcher->reveal());
|
$stack = new DispatchStack($this->dispatcher->reveal());
|
||||||
$stack->dispatch($this->request->reveal(), $this->response->reveal(), $next);
|
$stack($this->request->reveal(), $this->response->reveal(), $next);
|
||||||
$this->assertTrue($nextCalled);
|
$this->assertTrue($nextCalled);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ::dispatch
|
* @covers ::__invoke
|
||||||
*/
|
*/
|
||||||
public function testCallsNextAfterDispatchingStack()
|
public function testCallsNextAfterDispatchingStack()
|
||||||
{
|
{
|
||||||
|
|
@ -111,12 +111,12 @@ class DispatchStackTest extends \PHPUnit_Framework_TestCase
|
||||||
$stack->add($middleware);
|
$stack->add($middleware);
|
||||||
$stack->add($middleware);
|
$stack->add($middleware);
|
||||||
|
|
||||||
$stack->dispatch($this->request->reveal(), $this->response->reveal(), $next);
|
$stack($this->request->reveal(), $this->response->reveal(), $next);
|
||||||
$this->assertTrue($nextCalled);
|
$this->assertTrue($nextCalled);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ::dispatch
|
* @covers ::__invoke
|
||||||
*/
|
*/
|
||||||
public function testDoesNotCallNextWhenStackStopsEarly()
|
public function testDoesNotCallNextWhenStackStopsEarly()
|
||||||
{
|
{
|
||||||
|
|
@ -138,7 +138,7 @@ class DispatchStackTest extends \PHPUnit_Framework_TestCase
|
||||||
$stack->add($middlewareStop);
|
$stack->add($middlewareStop);
|
||||||
$stack->add($middlewareStop);
|
$stack->add($middlewareStop);
|
||||||
|
|
||||||
$stack->dispatch($this->request->reveal(), $this->response->reveal(), $next);
|
$stack($this->request->reveal(), $this->response->reveal(), $next);
|
||||||
$this->assertFalse($nextCalled);
|
$this->assertFalse($nextCalled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,7 @@ class DispatcherTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
class DispatcherTest_Middleware implements MiddlewareInterface
|
class DispatcherTest_Middleware implements MiddlewareInterface
|
||||||
{
|
{
|
||||||
public function dispatch(ServerRequestInterface $request, ResponseInterface $response, $next)
|
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next)
|
||||||
{
|
{
|
||||||
$response = $response->withStatus(200);
|
$response = $response->withStatus(200);
|
||||||
return $next($request, $response);
|
return $next($request, $response);
|
||||||
|
|
|
||||||
|
|
@ -29,12 +29,12 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase
|
||||||
return $response;
|
return $response;
|
||||||
};
|
};
|
||||||
$this->middleware = $this->prophesize('WellRESTed\MiddlewareInterface');
|
$this->middleware = $this->prophesize('WellRESTed\MiddlewareInterface');
|
||||||
$this->middleware->dispatch(Argument::cetera())->willReturn();
|
$this->middleware->__invoke(Argument::cetera())->willReturn();
|
||||||
$this->dispatcher = $this->prophesize('WellRESTed\Dispatching\DispatcherInterface');
|
$this->dispatcher = $this->prophesize('WellRESTed\Dispatching\DispatcherInterface');
|
||||||
$this->dispatcher->dispatch(Argument::cetera())->will(
|
$this->dispatcher->dispatch(Argument::cetera())->will(
|
||||||
function ($args) {
|
function ($args) {
|
||||||
list($middleware, $request, $response, $next) = $args;
|
list($middleware, $request, $response, $next) = $args;
|
||||||
return $middleware->dispatch($request, $response, $next);
|
return $middleware($request, $response, $next);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -49,7 +49,7 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ::dispatch
|
* @covers ::__invoke
|
||||||
* @covers ::dispatchMiddleware
|
* @covers ::dispatchMiddleware
|
||||||
* @covers ::register
|
* @covers ::register
|
||||||
*/
|
*/
|
||||||
|
|
@ -59,9 +59,9 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$map = new MethodMap($this->dispatcher->reveal());
|
$map = new MethodMap($this->dispatcher->reveal());
|
||||||
$map->register("GET", $this->middleware->reveal());
|
$map->register("GET", $this->middleware->reveal());
|
||||||
$map->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
|
$map($this->request->reveal(), $this->response->reveal(), $this->next);
|
||||||
|
|
||||||
$this->middleware->dispatch(
|
$this->middleware->__invoke(
|
||||||
$this->request->reveal(),
|
$this->request->reveal(),
|
||||||
$this->response->reveal(),
|
$this->response->reveal(),
|
||||||
$this->next
|
$this->next
|
||||||
|
|
@ -76,17 +76,17 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase
|
||||||
$this->request->getMethod()->willReturn("get");
|
$this->request->getMethod()->willReturn("get");
|
||||||
|
|
||||||
$middlewareUpper = $this->prophesize('WellRESTed\MiddlewareInterface');
|
$middlewareUpper = $this->prophesize('WellRESTed\MiddlewareInterface');
|
||||||
$middlewareUpper->dispatch(Argument::cetera())->willReturn();
|
$middlewareUpper->__invoke(Argument::cetera())->willReturn();
|
||||||
|
|
||||||
$middlewareLower = $this->prophesize('WellRESTed\MiddlewareInterface');
|
$middlewareLower = $this->prophesize('WellRESTed\MiddlewareInterface');
|
||||||
$middlewareLower->dispatch(Argument::cetera())->willReturn();
|
$middlewareLower->__invoke(Argument::cetera())->willReturn();
|
||||||
|
|
||||||
$map = new MethodMap($this->dispatcher->reveal());
|
$map = new MethodMap($this->dispatcher->reveal());
|
||||||
$map->register("GET", $middlewareUpper->reveal());
|
$map->register("GET", $middlewareUpper->reveal());
|
||||||
$map->register("get", $middlewareLower->reveal());
|
$map->register("get", $middlewareLower->reveal());
|
||||||
$map->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
|
$map($this->request->reveal(), $this->response->reveal(), $this->next);
|
||||||
|
|
||||||
$middlewareLower->dispatch(
|
$middlewareLower->__invoke(
|
||||||
$this->request->reveal(),
|
$this->request->reveal(),
|
||||||
$this->response->reveal(),
|
$this->response->reveal(),
|
||||||
$this->next
|
$this->next
|
||||||
|
|
@ -94,7 +94,7 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ::dispatch
|
* @covers ::__invoke
|
||||||
* @covers ::dispatchMiddleware
|
* @covers ::dispatchMiddleware
|
||||||
* @covers ::register
|
* @covers ::register
|
||||||
*/
|
*/
|
||||||
|
|
@ -104,9 +104,9 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$map = new MethodMap($this->dispatcher->reveal());
|
$map = new MethodMap($this->dispatcher->reveal());
|
||||||
$map->register("*", $this->middleware->reveal());
|
$map->register("*", $this->middleware->reveal());
|
||||||
$map->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
|
$map($this->request->reveal(), $this->response->reveal(), $this->next);
|
||||||
|
|
||||||
$this->middleware->dispatch(
|
$this->middleware->__invoke(
|
||||||
$this->request->reveal(),
|
$this->request->reveal(),
|
||||||
$this->response->reveal(),
|
$this->response->reveal(),
|
||||||
$this->next
|
$this->next
|
||||||
|
|
@ -114,7 +114,7 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ::dispatch
|
* @covers ::__invoke
|
||||||
*/
|
*/
|
||||||
public function testDispatchesGetMiddlewareForHeadByDefault()
|
public function testDispatchesGetMiddlewareForHeadByDefault()
|
||||||
{
|
{
|
||||||
|
|
@ -122,9 +122,9 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$map = new MethodMap($this->dispatcher->reveal());
|
$map = new MethodMap($this->dispatcher->reveal());
|
||||||
$map->register("GET", $this->middleware->reveal());
|
$map->register("GET", $this->middleware->reveal());
|
||||||
$map->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
|
$map($this->request->reveal(), $this->response->reveal(), $this->next);
|
||||||
|
|
||||||
$this->middleware->dispatch(
|
$this->middleware->__invoke(
|
||||||
$this->request->reveal(),
|
$this->request->reveal(),
|
||||||
$this->response->reveal(),
|
$this->response->reveal(),
|
||||||
$this->next
|
$this->next
|
||||||
|
|
@ -140,12 +140,12 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase
|
||||||
$map->register("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($this->request->reveal(), $this->response->reveal(), $this->next);
|
||||||
|
|
||||||
$this->request->getMethod()->willReturn("POST");
|
$this->request->getMethod()->willReturn("POST");
|
||||||
$map->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
|
$map($this->request->reveal(), $this->response->reveal(), $this->next);
|
||||||
|
|
||||||
$this->middleware->dispatch(
|
$this->middleware->__invoke(
|
||||||
$this->request->reveal(),
|
$this->request->reveal(),
|
||||||
$this->response->reveal(),
|
$this->response->reveal(),
|
||||||
$this->next
|
$this->next
|
||||||
|
|
@ -159,13 +159,13 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase
|
||||||
$map = new MethodMap($this->dispatcher->reveal());
|
$map = new MethodMap($this->dispatcher->reveal());
|
||||||
$map->register("POST", $this->middleware->reveal());
|
$map->register("POST", $this->middleware->reveal());
|
||||||
$map->register("POST", null);
|
$map->register("POST", null);
|
||||||
$map->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
|
$map($this->request->reveal(), $this->response->reveal(), $this->next);
|
||||||
|
|
||||||
$this->response->withStatus(405)->shouldHaveBeenCalled();
|
$this->response->withStatus(405)->shouldHaveBeenCalled();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ::dispatch
|
* @covers ::__invoke
|
||||||
* @covers ::addAllowHeader
|
* @covers ::addAllowHeader
|
||||||
* @covers ::getAllowedMethods
|
* @covers ::getAllowedMethods
|
||||||
*/
|
*/
|
||||||
|
|
@ -175,13 +175,13 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$map = new MethodMap($this->dispatcher->reveal());
|
$map = new MethodMap($this->dispatcher->reveal());
|
||||||
$map->register("GET", $this->middleware->reveal());
|
$map->register("GET", $this->middleware->reveal());
|
||||||
$map->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
|
$map($this->request->reveal(), $this->response->reveal(), $this->next);
|
||||||
|
|
||||||
$this->response->withStatus(200)->shouldHaveBeenCalled();
|
$this->response->withStatus(200)->shouldHaveBeenCalled();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ::dispatch
|
* @covers ::__invoke
|
||||||
* @covers ::addAllowHeader
|
* @covers ::addAllowHeader
|
||||||
* @covers ::getAllowedMethods
|
* @covers ::getAllowedMethods
|
||||||
* @dataProvider allowedMethodProvider
|
* @dataProvider allowedMethodProvider
|
||||||
|
|
@ -194,7 +194,7 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase
|
||||||
foreach ($methodsDeclared as $method) {
|
foreach ($methodsDeclared as $method) {
|
||||||
$map->register($method, $this->middleware->reveal());
|
$map->register($method, $this->middleware->reveal());
|
||||||
}
|
}
|
||||||
$map->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
|
$map($this->request->reveal(), $this->response->reveal(), $this->next);
|
||||||
|
|
||||||
$containsAllMethods = function ($headerValue) use ($methodsAllowed) {
|
$containsAllMethods = function ($headerValue) use ($methodsAllowed) {
|
||||||
foreach ($methodsAllowed as $method) {
|
foreach ($methodsAllowed as $method) {
|
||||||
|
|
@ -208,7 +208,7 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ::dispatch
|
* @covers ::__invoke
|
||||||
* @covers ::addAllowHeader
|
* @covers ::addAllowHeader
|
||||||
* @covers ::getAllowedMethods
|
* @covers ::getAllowedMethods
|
||||||
* @dataProvider allowedMethodProvider
|
* @dataProvider allowedMethodProvider
|
||||||
|
|
@ -219,7 +219,7 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$map = new MethodMap($this->dispatcher->reveal());
|
$map = new MethodMap($this->dispatcher->reveal());
|
||||||
$map->register("GET", $this->middleware->reveal());
|
$map->register("GET", $this->middleware->reveal());
|
||||||
$map->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
|
$map($this->request->reveal(), $this->response->reveal(), $this->next);
|
||||||
|
|
||||||
$this->response->withStatus(405)->shouldHaveBeenCalled();
|
$this->response->withStatus(405)->shouldHaveBeenCalled();
|
||||||
}
|
}
|
||||||
|
|
@ -239,12 +239,12 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$map = new MethodMap($this->dispatcher->reveal());
|
$map = new MethodMap($this->dispatcher->reveal());
|
||||||
$map->register("GET", $this->middleware->reveal());
|
$map->register("GET", $this->middleware->reveal());
|
||||||
$map->dispatch($this->request->reveal(), $this->response->reveal(), $next);
|
$map($this->request->reveal(), $this->response->reveal(), $next);
|
||||||
$this->assertTrue($calledNext);
|
$this->assertTrue($calledNext);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ::dispatch
|
* @covers ::__invoke
|
||||||
* @covers ::addAllowHeader
|
* @covers ::addAllowHeader
|
||||||
* @covers ::getAllowedMethods
|
* @covers ::getAllowedMethods
|
||||||
* @dataProvider allowedMethodProvider
|
* @dataProvider allowedMethodProvider
|
||||||
|
|
@ -257,7 +257,7 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase
|
||||||
foreach ($methodsDeclared as $method) {
|
foreach ($methodsDeclared as $method) {
|
||||||
$map->register($method, $this->middleware->reveal());
|
$map->register($method, $this->middleware->reveal());
|
||||||
}
|
}
|
||||||
$map->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
|
$map($this->request->reveal(), $this->response->reveal(), $this->next);
|
||||||
|
|
||||||
$containsAllMethods = function ($headerValue) use ($methodsAllowed) {
|
$containsAllMethods = function ($headerValue) use ($methodsAllowed) {
|
||||||
foreach ($methodsAllowed as $method) {
|
foreach ($methodsAllowed as $method) {
|
||||||
|
|
|
||||||
|
|
@ -49,12 +49,12 @@ class RouteTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ::dispatch
|
* @covers ::__invoke
|
||||||
*/
|
*/
|
||||||
public function testDispatchesMethodMap()
|
public function testDispatchesMethodMap()
|
||||||
{
|
{
|
||||||
$methodMap = $this->prophesize('WellRESTed\Routing\MethodMapInterface');
|
$methodMap = $this->prophesize('WellRESTed\Routing\MethodMapInterface');
|
||||||
$methodMap->dispatch(Argument::cetera())->willReturn();
|
$methodMap->__invoke(Argument::cetera())->willReturn();
|
||||||
|
|
||||||
$route = $this->getMockForAbstractClass(
|
$route = $this->getMockForAbstractClass(
|
||||||
'WellRESTed\Routing\Route\Route',
|
'WellRESTed\Routing\Route\Route',
|
||||||
|
|
@ -65,8 +65,8 @@ class RouteTest extends \PHPUnit_Framework_TestCase
|
||||||
$next = function ($request, $response) {
|
$next = function ($request, $response) {
|
||||||
return $response;
|
return $response;
|
||||||
};
|
};
|
||||||
$route->dispatch($request, $response, $next);
|
$route->__invoke($request, $response, $next);
|
||||||
|
|
||||||
$methodMap->dispatch(Argument::cetera())->shouldHaveBeenCalled();
|
$methodMap->__invoke(Argument::cetera())->shouldHaveBeenCalled();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ class RouterTest extends \PHPUnit_Framework_TestCase
|
||||||
$this->methodMap->register(Argument::cetera());
|
$this->methodMap->register(Argument::cetera());
|
||||||
|
|
||||||
$this->route = $this->prophesize('WellRESTed\Routing\Route\RouteInterface');
|
$this->route = $this->prophesize('WellRESTed\Routing\Route\RouteInterface');
|
||||||
$this->route->dispatch(Argument::cetera())->willReturn();
|
$this->route->__invoke(Argument::cetera())->willReturn();
|
||||||
$this->route->getMethodMap()->willReturn($this->methodMap->reveal());
|
$this->route->getMethodMap()->willReturn($this->methodMap->reveal());
|
||||||
$this->route->getType()->willReturn(RouteInterface::TYPE_STATIC);
|
$this->route->getType()->willReturn(RouteInterface::TYPE_STATIC);
|
||||||
$this->route->getTarget()->willReturn("/");
|
$this->route->getTarget()->willReturn("/");
|
||||||
|
|
@ -129,7 +129,7 @@ class RouterTest extends \PHPUnit_Framework_TestCase
|
||||||
// Dispatching
|
// Dispatching
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ::dispatch
|
* @covers ::__invoke
|
||||||
* @covers ::getStaticRoute
|
* @covers ::getStaticRoute
|
||||||
* @covers ::registerRouteForTarget
|
* @covers ::registerRouteForTarget
|
||||||
*/
|
*/
|
||||||
|
|
@ -142,13 +142,13 @@ class RouterTest extends \PHPUnit_Framework_TestCase
|
||||||
$this->route->getType()->willReturn(RouteInterface::TYPE_STATIC);
|
$this->route->getType()->willReturn(RouteInterface::TYPE_STATIC);
|
||||||
|
|
||||||
$this->router->register("GET", $target, "middleware");
|
$this->router->register("GET", $target, "middleware");
|
||||||
$this->router->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
|
$this->router->__invoke($this->request->reveal(), $this->response->reveal(), $this->next);
|
||||||
|
|
||||||
$this->route->dispatch($this->request->reveal(), $this->response->reveal(), $this->next)->shouldHaveBeenCalled();
|
$this->route->__invoke($this->request->reveal(), $this->response->reveal(), $this->next)->shouldHaveBeenCalled();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ::dispatch
|
* @covers ::__invoke
|
||||||
* @covers ::getPrefixRoute
|
* @covers ::getPrefixRoute
|
||||||
* @covers ::registerRouteForTarget
|
* @covers ::registerRouteForTarget
|
||||||
*/
|
*/
|
||||||
|
|
@ -160,13 +160,13 @@ class RouterTest extends \PHPUnit_Framework_TestCase
|
||||||
$this->route->getType()->willReturn(RouteInterface::TYPE_PREFIX);
|
$this->route->getType()->willReturn(RouteInterface::TYPE_PREFIX);
|
||||||
|
|
||||||
$this->router->register("GET", $target, "middleware");
|
$this->router->register("GET", $target, "middleware");
|
||||||
$this->router->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
|
$this->router->__invoke($this->request->reveal(), $this->response->reveal(), $this->next);
|
||||||
|
|
||||||
$this->route->dispatch($this->request->reveal(), $this->response->reveal(), $this->next)->shouldHaveBeenCalled();
|
$this->route->__invoke($this->request->reveal(), $this->response->reveal(), $this->next)->shouldHaveBeenCalled();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ::dispatch
|
* @covers ::__invoke
|
||||||
* @covers ::registerRouteForTarget
|
* @covers ::registerRouteForTarget
|
||||||
*/
|
*/
|
||||||
public function testDispatchesPatternRoute()
|
public function testDispatchesPatternRoute()
|
||||||
|
|
@ -179,9 +179,9 @@ class RouterTest extends \PHPUnit_Framework_TestCase
|
||||||
$this->route->matchesRequestTarget(Argument::cetera())->willReturn(true);
|
$this->route->matchesRequestTarget(Argument::cetera())->willReturn(true);
|
||||||
|
|
||||||
$this->router->register("GET", $target, "middleware");
|
$this->router->register("GET", $target, "middleware");
|
||||||
$this->router->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
|
$this->router->__invoke($this->request->reveal(), $this->response->reveal(), $this->next);
|
||||||
|
|
||||||
$this->route->dispatch($this->request->reveal(), $this->response->reveal(), $this->next)->shouldHaveBeenCalled();
|
$this->route->__invoke($this->request->reveal(), $this->response->reveal(), $this->next)->shouldHaveBeenCalled();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -193,13 +193,13 @@ class RouterTest extends \PHPUnit_Framework_TestCase
|
||||||
$staticRoute->getMethodMap()->willReturn($this->methodMap->reveal());
|
$staticRoute->getMethodMap()->willReturn($this->methodMap->reveal());
|
||||||
$staticRoute->getTarget()->willReturn("/cats/");
|
$staticRoute->getTarget()->willReturn("/cats/");
|
||||||
$staticRoute->getType()->willReturn(RouteInterface::TYPE_STATIC);
|
$staticRoute->getType()->willReturn(RouteInterface::TYPE_STATIC);
|
||||||
$staticRoute->dispatch(Argument::cetera())->willReturn();
|
$staticRoute->__invoke(Argument::cetera())->willReturn();
|
||||||
|
|
||||||
$prefixRoute = $this->prophesize('WellRESTed\Routing\Route\RouteInterface');
|
$prefixRoute = $this->prophesize('WellRESTed\Routing\Route\RouteInterface');
|
||||||
$prefixRoute->getMethodMap()->willReturn($this->methodMap->reveal());
|
$prefixRoute->getMethodMap()->willReturn($this->methodMap->reveal());
|
||||||
$prefixRoute->getTarget()->willReturn("/cats/*");
|
$prefixRoute->getTarget()->willReturn("/cats/*");
|
||||||
$prefixRoute->getType()->willReturn(RouteInterface::TYPE_PREFIX);
|
$prefixRoute->getType()->willReturn(RouteInterface::TYPE_PREFIX);
|
||||||
$prefixRoute->dispatch(Argument::cetera())->willReturn();
|
$prefixRoute->__invoke(Argument::cetera())->willReturn();
|
||||||
|
|
||||||
$this->request->getRequestTarget()->willReturn("/cats/");
|
$this->request->getRequestTarget()->willReturn("/cats/");
|
||||||
|
|
||||||
|
|
@ -208,9 +208,9 @@ class RouterTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$this->router->register("GET", "/cats/", "middleware");
|
$this->router->register("GET", "/cats/", "middleware");
|
||||||
$this->router->register("GET", "/cats/*", "middleware");
|
$this->router->register("GET", "/cats/*", "middleware");
|
||||||
$this->router->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
|
$this->router->__invoke($this->request->reveal(), $this->response->reveal(), $this->next);
|
||||||
|
|
||||||
$staticRoute->dispatch($this->request->reveal(), $this->response->reveal(), $this->next)->shouldHaveBeenCalled();
|
$staticRoute->__invoke($this->request->reveal(), $this->response->reveal(), $this->next)->shouldHaveBeenCalled();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -224,13 +224,13 @@ class RouterTest extends \PHPUnit_Framework_TestCase
|
||||||
$shortRoute->getMethodMap()->willReturn($this->methodMap->reveal());
|
$shortRoute->getMethodMap()->willReturn($this->methodMap->reveal());
|
||||||
$shortRoute->getTarget()->willReturn("/animals/*");
|
$shortRoute->getTarget()->willReturn("/animals/*");
|
||||||
$shortRoute->getType()->willReturn(RouteInterface::TYPE_PREFIX);
|
$shortRoute->getType()->willReturn(RouteInterface::TYPE_PREFIX);
|
||||||
$shortRoute->dispatch(Argument::cetera())->willReturn();
|
$shortRoute->__invoke(Argument::cetera())->willReturn();
|
||||||
|
|
||||||
$longRoute = $this->prophesize('WellRESTed\Routing\Route\RouteInterface');
|
$longRoute = $this->prophesize('WellRESTed\Routing\Route\RouteInterface');
|
||||||
$longRoute->getMethodMap()->willReturn($this->methodMap->reveal());
|
$longRoute->getMethodMap()->willReturn($this->methodMap->reveal());
|
||||||
$longRoute->getTarget()->willReturn("/animals/cats/*");
|
$longRoute->getTarget()->willReturn("/animals/cats/*");
|
||||||
$longRoute->getType()->willReturn(RouteInterface::TYPE_PREFIX);
|
$longRoute->getType()->willReturn(RouteInterface::TYPE_PREFIX);
|
||||||
$longRoute->dispatch(Argument::cetera())->willReturn();
|
$longRoute->__invoke(Argument::cetera())->willReturn();
|
||||||
|
|
||||||
$this->request->getRequestTarget()->willReturn("/animals/cats/molly");
|
$this->request->getRequestTarget()->willReturn("/animals/cats/molly");
|
||||||
|
|
||||||
|
|
@ -239,9 +239,9 @@ class RouterTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$this->router->register("GET", "/animals/*", "middleware");
|
$this->router->register("GET", "/animals/*", "middleware");
|
||||||
$this->router->register("GET", "/animals/cats/*", "middleware");
|
$this->router->register("GET", "/animals/cats/*", "middleware");
|
||||||
$this->router->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
|
$this->router->__invoke($this->request->reveal(), $this->response->reveal(), $this->next);
|
||||||
|
|
||||||
$longRoute->dispatch($this->request->reveal(), $this->response->reveal(), $this->next)->shouldHaveBeenCalled();
|
$longRoute->__invoke($this->request->reveal(), $this->response->reveal(), $this->next)->shouldHaveBeenCalled();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -253,13 +253,13 @@ class RouterTest extends \PHPUnit_Framework_TestCase
|
||||||
$prefixRoute->getMethodMap()->willReturn($this->methodMap->reveal());
|
$prefixRoute->getMethodMap()->willReturn($this->methodMap->reveal());
|
||||||
$prefixRoute->getTarget()->willReturn("/cats/*");
|
$prefixRoute->getTarget()->willReturn("/cats/*");
|
||||||
$prefixRoute->getType()->willReturn(RouteInterface::TYPE_PREFIX);
|
$prefixRoute->getType()->willReturn(RouteInterface::TYPE_PREFIX);
|
||||||
$prefixRoute->dispatch(Argument::cetera())->willReturn();
|
$prefixRoute->__invoke(Argument::cetera())->willReturn();
|
||||||
|
|
||||||
$patternRoute = $this->prophesize('WellRESTed\Routing\Route\RouteInterface');
|
$patternRoute = $this->prophesize('WellRESTed\Routing\Route\RouteInterface');
|
||||||
$patternRoute->getMethodMap()->willReturn($this->methodMap->reveal());
|
$patternRoute->getMethodMap()->willReturn($this->methodMap->reveal());
|
||||||
$patternRoute->getTarget()->willReturn("/cats/{id}");
|
$patternRoute->getTarget()->willReturn("/cats/{id}");
|
||||||
$patternRoute->getType()->willReturn(RouteInterface::TYPE_PATTERN);
|
$patternRoute->getType()->willReturn(RouteInterface::TYPE_PATTERN);
|
||||||
$patternRoute->dispatch(Argument::cetera())->willReturn();
|
$patternRoute->__invoke(Argument::cetera())->willReturn();
|
||||||
|
|
||||||
$this->request->getRequestTarget()->willReturn("/cats/");
|
$this->request->getRequestTarget()->willReturn("/cats/");
|
||||||
|
|
||||||
|
|
@ -268,9 +268,9 @@ class RouterTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$this->router->register("GET", "/cats/*", "middleware");
|
$this->router->register("GET", "/cats/*", "middleware");
|
||||||
$this->router->register("GET", "/cats/{id}", "middleware");
|
$this->router->register("GET", "/cats/{id}", "middleware");
|
||||||
$this->router->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
|
$this->router->__invoke($this->request->reveal(), $this->response->reveal(), $this->next);
|
||||||
|
|
||||||
$prefixRoute->dispatch($this->request->reveal(), $this->response->reveal(), $this->next)->shouldHaveBeenCalled();
|
$prefixRoute->__invoke($this->request->reveal(), $this->response->reveal(), $this->next)->shouldHaveBeenCalled();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -284,7 +284,7 @@ class RouterTest extends \PHPUnit_Framework_TestCase
|
||||||
$patternRoute1->getType()->willReturn(RouteInterface::TYPE_PATTERN);
|
$patternRoute1->getType()->willReturn(RouteInterface::TYPE_PATTERN);
|
||||||
$patternRoute1->getPathVariables()->willReturn([]);
|
$patternRoute1->getPathVariables()->willReturn([]);
|
||||||
$patternRoute1->matchesRequestTarget(Argument::any())->willReturn(true);
|
$patternRoute1->matchesRequestTarget(Argument::any())->willReturn(true);
|
||||||
$patternRoute1->dispatch(Argument::cetera())->willReturn();
|
$patternRoute1->__invoke(Argument::cetera())->willReturn();
|
||||||
|
|
||||||
$patternRoute2 = $this->prophesize('WellRESTed\Routing\Route\RouteInterface');
|
$patternRoute2 = $this->prophesize('WellRESTed\Routing\Route\RouteInterface');
|
||||||
$patternRoute2->getMethodMap()->willReturn($this->methodMap->reveal());
|
$patternRoute2->getMethodMap()->willReturn($this->methodMap->reveal());
|
||||||
|
|
@ -292,7 +292,7 @@ class RouterTest extends \PHPUnit_Framework_TestCase
|
||||||
$patternRoute2->getType()->willReturn(RouteInterface::TYPE_PATTERN);
|
$patternRoute2->getType()->willReturn(RouteInterface::TYPE_PATTERN);
|
||||||
$patternRoute2->getPathVariables()->willReturn([]);
|
$patternRoute2->getPathVariables()->willReturn([]);
|
||||||
$patternRoute2->matchesRequestTarget(Argument::any())->willReturn(true);
|
$patternRoute2->matchesRequestTarget(Argument::any())->willReturn(true);
|
||||||
$patternRoute2->dispatch(Argument::cetera())->willReturn();
|
$patternRoute2->__invoke(Argument::cetera())->willReturn();
|
||||||
|
|
||||||
$this->request->getRequestTarget()->willReturn("/cats/molly");
|
$this->request->getRequestTarget()->willReturn("/cats/molly");
|
||||||
|
|
||||||
|
|
@ -301,9 +301,9 @@ class RouterTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$this->router->register("GET", "/cats/{id}", "middleware");
|
$this->router->register("GET", "/cats/{id}", "middleware");
|
||||||
$this->router->register("GET", "/cats/{name}", "middleware");
|
$this->router->register("GET", "/cats/{name}", "middleware");
|
||||||
$this->router->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
|
$this->router->__invoke($this->request->reveal(), $this->response->reveal(), $this->next);
|
||||||
|
|
||||||
$patternRoute1->dispatch($this->request->reveal(), $this->response->reveal(), $this->next)->shouldHaveBeenCalled();
|
$patternRoute1->__invoke($this->request->reveal(), $this->response->reveal(), $this->next)->shouldHaveBeenCalled();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -317,7 +317,7 @@ class RouterTest extends \PHPUnit_Framework_TestCase
|
||||||
$patternRoute1->getType()->willReturn(RouteInterface::TYPE_PATTERN);
|
$patternRoute1->getType()->willReturn(RouteInterface::TYPE_PATTERN);
|
||||||
$patternRoute1->getPathVariables()->willReturn([]);
|
$patternRoute1->getPathVariables()->willReturn([]);
|
||||||
$patternRoute1->matchesRequestTarget(Argument::any())->willReturn(true);
|
$patternRoute1->matchesRequestTarget(Argument::any())->willReturn(true);
|
||||||
$patternRoute1->dispatch(Argument::cetera())->willReturn();
|
$patternRoute1->__invoke(Argument::cetera())->willReturn();
|
||||||
|
|
||||||
$patternRoute2 = $this->prophesize('WellRESTed\Routing\Route\RouteInterface');
|
$patternRoute2 = $this->prophesize('WellRESTed\Routing\Route\RouteInterface');
|
||||||
$patternRoute2->getMethodMap()->willReturn($this->methodMap->reveal());
|
$patternRoute2->getMethodMap()->willReturn($this->methodMap->reveal());
|
||||||
|
|
@ -325,7 +325,7 @@ class RouterTest extends \PHPUnit_Framework_TestCase
|
||||||
$patternRoute2->getType()->willReturn(RouteInterface::TYPE_PATTERN);
|
$patternRoute2->getType()->willReturn(RouteInterface::TYPE_PATTERN);
|
||||||
$patternRoute2->getPathVariables()->willReturn([]);
|
$patternRoute2->getPathVariables()->willReturn([]);
|
||||||
$patternRoute2->matchesRequestTarget(Argument::any())->willReturn(true);
|
$patternRoute2->matchesRequestTarget(Argument::any())->willReturn(true);
|
||||||
$patternRoute2->dispatch(Argument::cetera())->willReturn();
|
$patternRoute2->__invoke(Argument::cetera())->willReturn();
|
||||||
|
|
||||||
$this->request->getRequestTarget()->willReturn("/cats/molly");
|
$this->request->getRequestTarget()->willReturn("/cats/molly");
|
||||||
|
|
||||||
|
|
@ -334,13 +334,13 @@ class RouterTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$this->router->register("GET", "/cats/{id}", "middleware");
|
$this->router->register("GET", "/cats/{id}", "middleware");
|
||||||
$this->router->register("GET", "/cats/{name}", "middleware");
|
$this->router->register("GET", "/cats/{name}", "middleware");
|
||||||
$this->router->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
|
$this->router->__invoke($this->request->reveal(), $this->response->reveal(), $this->next);
|
||||||
|
|
||||||
$patternRoute2->matchesRequestTarget(Argument::any())->shouldNotHaveBeenCalled();
|
$patternRoute2->matchesRequestTarget(Argument::any())->shouldNotHaveBeenCalled();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ::dispatch
|
* @covers ::__invoke
|
||||||
* @group current
|
* @group current
|
||||||
*/
|
*/
|
||||||
public function testSetPathVariablesAttributeBeforeDispatchingPatternRoute()
|
public function testSetPathVariablesAttributeBeforeDispatchingPatternRoute()
|
||||||
|
|
@ -358,13 +358,13 @@ class RouterTest extends \PHPUnit_Framework_TestCase
|
||||||
$this->route->getPathVariables()->willReturn($variables);
|
$this->route->getPathVariables()->willReturn($variables);
|
||||||
|
|
||||||
$this->router->register("GET", $target, "middleware");
|
$this->router->register("GET", $target, "middleware");
|
||||||
$this->router->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
|
$this->router->__invoke($this->request->reveal(), $this->response->reveal(), $this->next);
|
||||||
|
|
||||||
$this->request->withAttribute("pathVariables", $variables)->shouldHaveBeenCalled();
|
$this->request->withAttribute("pathVariables", $variables)->shouldHaveBeenCalled();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ::dispatch
|
* @covers ::__invoke
|
||||||
* @covers ::registerRouteForTarget
|
* @covers ::registerRouteForTarget
|
||||||
*/
|
*/
|
||||||
public function testMatchesPathAgainstRouteWithoutQuery()
|
public function testMatchesPathAgainstRouteWithoutQuery()
|
||||||
|
|
@ -377,7 +377,7 @@ class RouterTest extends \PHPUnit_Framework_TestCase
|
||||||
$this->route->matchesRequestTarget(Argument::cetera())->willReturn(true);
|
$this->route->matchesRequestTarget(Argument::cetera())->willReturn(true);
|
||||||
|
|
||||||
$this->router->register("GET", $target, "middleware");
|
$this->router->register("GET", $target, "middleware");
|
||||||
$this->router->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
|
$this->router->__invoke($this->request->reveal(), $this->response->reveal(), $this->next);
|
||||||
|
|
||||||
$this->route->matchesRequestTarget("/my/path")->shouldHaveBeenCalled();
|
$this->route->matchesRequestTarget("/my/path")->shouldHaveBeenCalled();
|
||||||
}
|
}
|
||||||
|
|
@ -386,7 +386,7 @@ class RouterTest extends \PHPUnit_Framework_TestCase
|
||||||
// No Matching Routes
|
// No Matching Routes
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ::dispatch
|
* @covers ::__invoke
|
||||||
* @covers ::getStaticRoute
|
* @covers ::getStaticRoute
|
||||||
* @covers ::getPrefixRoute
|
* @covers ::getPrefixRoute
|
||||||
*/
|
*/
|
||||||
|
|
@ -394,12 +394,12 @@ class RouterTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$this->request->getRequestTarget()->willReturn("/no/match");
|
$this->request->getRequestTarget()->willReturn("/no/match");
|
||||||
$this->response->withStatus(Argument::any())->willReturn($this->response->reveal());
|
$this->response->withStatus(Argument::any())->willReturn($this->response->reveal());
|
||||||
$this->router->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
|
$this->router->__invoke($this->request->reveal(), $this->response->reveal(), $this->next);
|
||||||
$this->response->withStatus(404)->shouldHaveBeenCalled();
|
$this->response->withStatus(404)->shouldHaveBeenCalled();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ::dispatch
|
* @covers ::__invoke
|
||||||
* @covers ::getStaticRoute
|
* @covers ::getStaticRoute
|
||||||
* @covers ::getPrefixRoute
|
* @covers ::getPrefixRoute
|
||||||
*/
|
*/
|
||||||
|
|
@ -413,7 +413,7 @@ class RouterTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$this->request->getRequestTarget()->willReturn("/no/match");
|
$this->request->getRequestTarget()->willReturn("/no/match");
|
||||||
$this->response->withStatus(Argument::any())->willReturn($this->response->reveal());
|
$this->response->withStatus(Argument::any())->willReturn($this->response->reveal());
|
||||||
$this->router->dispatch($this->request->reveal(), $this->response->reveal(), $next);
|
$this->router->__invoke($this->request->reveal(), $this->response->reveal(), $next);
|
||||||
$this->assertTrue($calledNext);
|
$this->assertTrue($calledNext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -161,7 +161,7 @@ class ServerTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$router = $this->server->createRouter();
|
$router = $this->server->createRouter();
|
||||||
$router->register("GET", "/", "middleware");
|
$router->register("GET", "/", "middleware");
|
||||||
$router->dispatch($this->request->reveal(), $this->response->reveal(), $next);
|
$router($this->request->reveal(), $this->response->reveal(), $next);
|
||||||
|
|
||||||
$this->dispatcher->dispatch(
|
$this->dispatcher->dispatch(
|
||||||
"middleware",
|
"middleware",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue