diff --git a/src/Dispatching/DispatchStack.php b/src/Dispatching/DispatchStack.php index d4c8faf..6bf2cd5 100644 --- a/src/Dispatching/DispatchStack.php +++ b/src/Dispatching/DispatchStack.php @@ -54,7 +54,7 @@ class DispatchStack implements DispatchStackInterface * @param callable $next * @return ResponseInterface */ - public function dispatch(ServerRequestInterface $request, ResponseInterface $response, $next) + public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next) { $dispatcher = $this->dispatcher; diff --git a/src/Dispatching/DispatchStackInterface.php b/src/Dispatching/DispatchStackInterface.php index c878bf7..53182f4 100644 --- a/src/Dispatching/DispatchStackInterface.php +++ b/src/Dispatching/DispatchStackInterface.php @@ -48,5 +48,5 @@ interface DispatchStackInterface extends MiddlewareInterface * @param callable $next * @return ResponseInterface */ - public function dispatch(ServerRequestInterface $request, ResponseInterface $response, $next); + public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next); } diff --git a/src/Dispatching/Dispatcher.php b/src/Dispatching/Dispatcher.php index 45d33c7..178e523 100644 --- a/src/Dispatching/Dispatcher.php +++ b/src/Dispatching/Dispatcher.php @@ -25,8 +25,8 @@ class Dispatcher implements DispatcherInterface } elseif (is_array($middleware)) { $middleware = $this->getDispatchStack($middleware); } - if ($middleware instanceof MiddlewareInterface) { - return $middleware->dispatch($request, $response, $next); + if (is_callable($middleware)) { + return $middleware($request, $response, $next); } elseif ($middleware instanceof ResponseInterface) { return $middleware; } else { diff --git a/src/MiddlewareInterface.php b/src/MiddlewareInterface.php index eb54eff..a7ccb25 100644 --- a/src/MiddlewareInterface.php +++ b/src/MiddlewareInterface.php @@ -13,5 +13,5 @@ interface MiddlewareInterface * @param callable $next * @return ResponseInterface */ - public function dispatch(ServerRequestInterface $request, ResponseInterface $response, $next); + public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next); } diff --git a/src/Routing/MethodMap.php b/src/Routing/MethodMap.php index a678829..2791a23 100644 --- a/src/Routing/MethodMap.php +++ b/src/Routing/MethodMap.php @@ -5,9 +5,8 @@ namespace WellRESTed\Routing; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use WellRESTed\Dispatching\DispatcherInterface; -use WellRESTed\MiddlewareInterface; -class MethodMap implements MiddlewareInterface, MethodMapInterface +class MethodMap implements MethodMapInterface { private $dispatcher; private $map; @@ -63,7 +62,7 @@ class MethodMap implements MiddlewareInterface, MethodMapInterface * @param callable $next * @return ResponseInterface */ - public function dispatch(ServerRequestInterface $request, ResponseInterface $response, $next) + public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next) { $method = $request->getMethod(); // Dispatch middleware registered with the explicitly matching method. diff --git a/src/Routing/Route/Route.php b/src/Routing/Route/Route.php index 875df79..630f1d6 100644 --- a/src/Routing/Route/Route.php +++ b/src/Routing/Route/Route.php @@ -37,8 +37,9 @@ abstract class Route implements RouteInterface 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); } } diff --git a/src/Routing/Router.php b/src/Routing/Router.php index 3160709..ad316f1 100644 --- a/src/Routing/Router.php +++ b/src/Routing/Router.php @@ -75,19 +75,19 @@ class Router implements RouterInterface return $this; } - public function dispatch(ServerRequestInterface $request, ResponseInterface $response, $next) + public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next) { // Use only the path for routing. $requestTarget = parse_url($request->getRequestTarget(), PHP_URL_PATH); $route = $this->getStaticRoute($requestTarget); if ($route) { - return $route->dispatch($request, $response, $next); + return $route($request, $response, $next); } $route = $this->getPrefixRoute($requestTarget); if ($route) { - return $route->dispatch($request, $response, $next); + return $route($request, $response, $next); } // Try each of the routes. @@ -95,7 +95,7 @@ class Router implements RouterInterface if ($route->matchesRequestTarget($requestTarget)) { $pathVariables = $route->getPathVariables(); $request = $request->withAttribute($this->pathVariablesAttributeKey, $pathVariables); - return $route->dispatch($request, $response, $next); + return $route($request, $response, $next); } } diff --git a/src/Server.php b/src/Server.php index 2bfae67..624945d 100644 --- a/src/Server.php +++ b/src/Server.php @@ -6,14 +6,13 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use WellRESTed\Dispatching\Dispatcher; use WellRESTed\Dispatching\DispatcherInterface; -use WellRESTed\Dispatching\DispatchStackInterface; use WellRESTed\Message\Response; use WellRESTed\Message\ServerRequest; use WellRESTed\Routing\Router; use WellRESTed\Transmission\Transmitter; use WellRESTed\Transmission\TransmitterInterface; -class Server implements DispatchStackInterface +class Server { /** @var array */ private $attributes; diff --git a/test/tests/integration/RoutingTest.php b/test/tests/integration/RoutingTest.php index 5717bb2..497eb2c 100644 --- a/test/tests/integration/RoutingTest.php +++ b/test/tests/integration/RoutingTest.php @@ -164,7 +164,7 @@ class StringMiddleware implements MiddlewareInterface * @param callable $next * @return ResponseInterface */ - public function dispatch(ServerRequestInterface $request, ResponseInterface $response, $next) + public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next) { $body = $response->getBody(); if ($body->isWritable()) { @@ -188,7 +188,7 @@ class BenderMiddleware implements MiddlewareInterface * @param callable $next * @return ResponseInterface */ - public function dispatch(ServerRequestInterface $request, ResponseInterface $response, $next) + public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next) { $message = "Bender Bending Rodriguez"; $body = $response->getBody(); diff --git a/test/tests/unit/Dispatching/DispatchStackTest.php b/test/tests/unit/Dispatching/DispatchStackTest.php index 04957c7..d732f4d 100644 --- a/test/tests/unit/Dispatching/DispatchStackTest.php +++ b/test/tests/unit/Dispatching/DispatchStackTest.php @@ -51,7 +51,7 @@ class DispatchStackTest extends \PHPUnit_Framework_TestCase } /** - * @covers ::dispatch + * @covers ::__invoke */ public function testDispachesMiddlewareInOrderAdded() { @@ -71,12 +71,12 @@ class DispatchStackTest extends \PHPUnit_Framework_TestCase $callOrder[] = "third"; 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); } /** - * @covers ::dispatch + * @covers ::__invoke */ public function testCallsNextAfterDispatchingEmptyStack() { @@ -87,12 +87,12 @@ class DispatchStackTest extends \PHPUnit_Framework_TestCase }; $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); } /** - * @covers ::dispatch + * @covers ::__invoke */ public function testCallsNextAfterDispatchingStack() { @@ -111,12 +111,12 @@ class DispatchStackTest extends \PHPUnit_Framework_TestCase $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); } /** - * @covers ::dispatch + * @covers ::__invoke */ public function testDoesNotCallNextWhenStackStopsEarly() { @@ -138,7 +138,7 @@ class DispatchStackTest extends \PHPUnit_Framework_TestCase $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); } } diff --git a/test/tests/unit/Dispatching/DispatcherTest.php b/test/tests/unit/Dispatching/DispatcherTest.php index c3b7c83..1a21b7f 100644 --- a/test/tests/unit/Dispatching/DispatcherTest.php +++ b/test/tests/unit/Dispatching/DispatcherTest.php @@ -99,7 +99,7 @@ class DispatcherTest extends \PHPUnit_Framework_TestCase 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); return $next($request, $response); diff --git a/test/tests/unit/Routing/MethodMapTest.php b/test/tests/unit/Routing/MethodMapTest.php index 8e45a41..fc6a44c 100644 --- a/test/tests/unit/Routing/MethodMapTest.php +++ b/test/tests/unit/Routing/MethodMapTest.php @@ -29,12 +29,12 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase return $response; }; $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->dispatch(Argument::cetera())->will( function ($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 ::register */ @@ -59,9 +59,9 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase $map = new MethodMap($this->dispatcher->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->response->reveal(), $this->next @@ -76,17 +76,17 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase $this->request->getMethod()->willReturn("get"); $middlewareUpper = $this->prophesize('WellRESTed\MiddlewareInterface'); - $middlewareUpper->dispatch(Argument::cetera())->willReturn(); + $middlewareUpper->__invoke(Argument::cetera())->willReturn(); $middlewareLower = $this->prophesize('WellRESTed\MiddlewareInterface'); - $middlewareLower->dispatch(Argument::cetera())->willReturn(); + $middlewareLower->__invoke(Argument::cetera())->willReturn(); $map = new MethodMap($this->dispatcher->reveal()); $map->register("GET", $middlewareUpper->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->response->reveal(), $this->next @@ -94,7 +94,7 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase } /** - * @covers ::dispatch + * @covers ::__invoke * @covers ::dispatchMiddleware * @covers ::register */ @@ -104,9 +104,9 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase $map = new MethodMap($this->dispatcher->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->response->reveal(), $this->next @@ -114,7 +114,7 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase } /** - * @covers ::dispatch + * @covers ::__invoke */ public function testDispatchesGetMiddlewareForHeadByDefault() { @@ -122,9 +122,9 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase $map = new MethodMap($this->dispatcher->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->response->reveal(), $this->next @@ -140,12 +140,12 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase $map->register("GET,POST", $this->middleware->reveal()); $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"); - $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->response->reveal(), $this->next @@ -159,13 +159,13 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase $map = new MethodMap($this->dispatcher->reveal()); $map->register("POST", $this->middleware->reveal()); $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(); } /** - * @covers ::dispatch + * @covers ::__invoke * @covers ::addAllowHeader * @covers ::getAllowedMethods */ @@ -175,13 +175,13 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase $map = new MethodMap($this->dispatcher->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(); } /** - * @covers ::dispatch + * @covers ::__invoke * @covers ::addAllowHeader * @covers ::getAllowedMethods * @dataProvider allowedMethodProvider @@ -194,7 +194,7 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase foreach ($methodsDeclared as $method) { $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) { foreach ($methodsAllowed as $method) { @@ -208,7 +208,7 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase } /** - * @covers ::dispatch + * @covers ::__invoke * @covers ::addAllowHeader * @covers ::getAllowedMethods * @dataProvider allowedMethodProvider @@ -219,7 +219,7 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase $map = new MethodMap($this->dispatcher->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(); } @@ -239,12 +239,12 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase $map = new MethodMap($this->dispatcher->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); } /** - * @covers ::dispatch + * @covers ::__invoke * @covers ::addAllowHeader * @covers ::getAllowedMethods * @dataProvider allowedMethodProvider @@ -257,7 +257,7 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase foreach ($methodsDeclared as $method) { $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) { foreach ($methodsAllowed as $method) { diff --git a/test/tests/unit/Routing/Route/RouteTest.php b/test/tests/unit/Routing/Route/RouteTest.php index 6163b8d..342e222 100644 --- a/test/tests/unit/Routing/Route/RouteTest.php +++ b/test/tests/unit/Routing/Route/RouteTest.php @@ -49,12 +49,12 @@ class RouteTest extends \PHPUnit_Framework_TestCase } /** - * @covers ::dispatch + * @covers ::__invoke */ public function testDispatchesMethodMap() { $methodMap = $this->prophesize('WellRESTed\Routing\MethodMapInterface'); - $methodMap->dispatch(Argument::cetera())->willReturn(); + $methodMap->__invoke(Argument::cetera())->willReturn(); $route = $this->getMockForAbstractClass( 'WellRESTed\Routing\Route\Route', @@ -65,8 +65,8 @@ class RouteTest extends \PHPUnit_Framework_TestCase $next = function ($request, $response) { return $response; }; - $route->dispatch($request, $response, $next); + $route->__invoke($request, $response, $next); - $methodMap->dispatch(Argument::cetera())->shouldHaveBeenCalled(); + $methodMap->__invoke(Argument::cetera())->shouldHaveBeenCalled(); } } diff --git a/test/tests/unit/Routing/RouterTest.php b/test/tests/unit/Routing/RouterTest.php index 24ebab4..9d2a56b 100644 --- a/test/tests/unit/Routing/RouterTest.php +++ b/test/tests/unit/Routing/RouterTest.php @@ -30,7 +30,7 @@ class RouterTest extends \PHPUnit_Framework_TestCase $this->methodMap->register(Argument::cetera()); $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->getType()->willReturn(RouteInterface::TYPE_STATIC); $this->route->getTarget()->willReturn("/"); @@ -129,7 +129,7 @@ class RouterTest extends \PHPUnit_Framework_TestCase // Dispatching /** - * @covers ::dispatch + * @covers ::__invoke * @covers ::getStaticRoute * @covers ::registerRouteForTarget */ @@ -142,13 +142,13 @@ class RouterTest extends \PHPUnit_Framework_TestCase $this->route->getType()->willReturn(RouteInterface::TYPE_STATIC); $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 ::registerRouteForTarget */ @@ -160,13 +160,13 @@ class RouterTest extends \PHPUnit_Framework_TestCase $this->route->getType()->willReturn(RouteInterface::TYPE_PREFIX); $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 */ public function testDispatchesPatternRoute() @@ -179,9 +179,9 @@ class RouterTest extends \PHPUnit_Framework_TestCase $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->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->getTarget()->willReturn("/cats/"); $staticRoute->getType()->willReturn(RouteInterface::TYPE_STATIC); - $staticRoute->dispatch(Argument::cetera())->willReturn(); + $staticRoute->__invoke(Argument::cetera())->willReturn(); $prefixRoute = $this->prophesize('WellRESTed\Routing\Route\RouteInterface'); $prefixRoute->getMethodMap()->willReturn($this->methodMap->reveal()); $prefixRoute->getTarget()->willReturn("/cats/*"); $prefixRoute->getType()->willReturn(RouteInterface::TYPE_PREFIX); - $prefixRoute->dispatch(Argument::cetera())->willReturn(); + $prefixRoute->__invoke(Argument::cetera())->willReturn(); $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->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->getTarget()->willReturn("/animals/*"); $shortRoute->getType()->willReturn(RouteInterface::TYPE_PREFIX); - $shortRoute->dispatch(Argument::cetera())->willReturn(); + $shortRoute->__invoke(Argument::cetera())->willReturn(); $longRoute = $this->prophesize('WellRESTed\Routing\Route\RouteInterface'); $longRoute->getMethodMap()->willReturn($this->methodMap->reveal()); $longRoute->getTarget()->willReturn("/animals/cats/*"); $longRoute->getType()->willReturn(RouteInterface::TYPE_PREFIX); - $longRoute->dispatch(Argument::cetera())->willReturn(); + $longRoute->__invoke(Argument::cetera())->willReturn(); $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/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->getTarget()->willReturn("/cats/*"); $prefixRoute->getType()->willReturn(RouteInterface::TYPE_PREFIX); - $prefixRoute->dispatch(Argument::cetera())->willReturn(); + $prefixRoute->__invoke(Argument::cetera())->willReturn(); $patternRoute = $this->prophesize('WellRESTed\Routing\Route\RouteInterface'); $patternRoute->getMethodMap()->willReturn($this->methodMap->reveal()); $patternRoute->getTarget()->willReturn("/cats/{id}"); $patternRoute->getType()->willReturn(RouteInterface::TYPE_PATTERN); - $patternRoute->dispatch(Argument::cetera())->willReturn(); + $patternRoute->__invoke(Argument::cetera())->willReturn(); $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/{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->getPathVariables()->willReturn([]); $patternRoute1->matchesRequestTarget(Argument::any())->willReturn(true); - $patternRoute1->dispatch(Argument::cetera())->willReturn(); + $patternRoute1->__invoke(Argument::cetera())->willReturn(); $patternRoute2 = $this->prophesize('WellRESTed\Routing\Route\RouteInterface'); $patternRoute2->getMethodMap()->willReturn($this->methodMap->reveal()); @@ -292,7 +292,7 @@ class RouterTest extends \PHPUnit_Framework_TestCase $patternRoute2->getType()->willReturn(RouteInterface::TYPE_PATTERN); $patternRoute2->getPathVariables()->willReturn([]); $patternRoute2->matchesRequestTarget(Argument::any())->willReturn(true); - $patternRoute2->dispatch(Argument::cetera())->willReturn(); + $patternRoute2->__invoke(Argument::cetera())->willReturn(); $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/{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->getPathVariables()->willReturn([]); $patternRoute1->matchesRequestTarget(Argument::any())->willReturn(true); - $patternRoute1->dispatch(Argument::cetera())->willReturn(); + $patternRoute1->__invoke(Argument::cetera())->willReturn(); $patternRoute2 = $this->prophesize('WellRESTed\Routing\Route\RouteInterface'); $patternRoute2->getMethodMap()->willReturn($this->methodMap->reveal()); @@ -325,7 +325,7 @@ class RouterTest extends \PHPUnit_Framework_TestCase $patternRoute2->getType()->willReturn(RouteInterface::TYPE_PATTERN); $patternRoute2->getPathVariables()->willReturn([]); $patternRoute2->matchesRequestTarget(Argument::any())->willReturn(true); - $patternRoute2->dispatch(Argument::cetera())->willReturn(); + $patternRoute2->__invoke(Argument::cetera())->willReturn(); $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/{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(); } /** - * @covers ::dispatch + * @covers ::__invoke * @group current */ public function testSetPathVariablesAttributeBeforeDispatchingPatternRoute() @@ -358,13 +358,13 @@ class RouterTest extends \PHPUnit_Framework_TestCase $this->route->getPathVariables()->willReturn($variables); $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(); } /** - * @covers ::dispatch + * @covers ::__invoke * @covers ::registerRouteForTarget */ public function testMatchesPathAgainstRouteWithoutQuery() @@ -377,7 +377,7 @@ class RouterTest extends \PHPUnit_Framework_TestCase $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->router->__invoke($this->request->reveal(), $this->response->reveal(), $this->next); $this->route->matchesRequestTarget("/my/path")->shouldHaveBeenCalled(); } @@ -386,7 +386,7 @@ class RouterTest extends \PHPUnit_Framework_TestCase // No Matching Routes /** - * @covers ::dispatch + * @covers ::__invoke * @covers ::getStaticRoute * @covers ::getPrefixRoute */ @@ -394,12 +394,12 @@ class RouterTest extends \PHPUnit_Framework_TestCase { $this->request->getRequestTarget()->willReturn("/no/match"); $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(); } /** - * @covers ::dispatch + * @covers ::__invoke * @covers ::getStaticRoute * @covers ::getPrefixRoute */ @@ -413,7 +413,7 @@ class RouterTest extends \PHPUnit_Framework_TestCase $this->request->getRequestTarget()->willReturn("/no/match"); $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); } diff --git a/test/tests/unit/ServerTest.php b/test/tests/unit/ServerTest.php index 2308381..9009c39 100644 --- a/test/tests/unit/ServerTest.php +++ b/test/tests/unit/ServerTest.php @@ -161,7 +161,7 @@ class ServerTest extends \PHPUnit_Framework_TestCase $router = $this->server->createRouter(); $router->register("GET", "/", "middleware"); - $router->dispatch($this->request->reveal(), $this->response->reveal(), $next); + $router($this->request->reveal(), $this->response->reveal(), $next); $this->dispatcher->dispatch( "middleware",