From 4a75f4e3a64bc95b361d82b6c77a4cc95dd40aaf Mon Sep 17 00:00:00 2001 From: PJ Dietz Date: Mon, 13 Apr 2015 19:46:03 -0400 Subject: [PATCH] Update tests to to avoid passing a reveal() return value by reference. --- test/tests/unit/Routing/MethodMapTest.php | 41 +++++++++++++++------ test/tests/unit/Routing/Route/RouteTest.php | 4 +- test/tests/unit/Routing/RouteTableTest.php | 37 ++++++++++++++----- test/tests/unit/Routing/RouterTest.php | 25 ++++++++++--- 4 files changed, 81 insertions(+), 26 deletions(-) diff --git a/test/tests/unit/Routing/MethodMapTest.php b/test/tests/unit/Routing/MethodMapTest.php index ce67c60..293251a 100644 --- a/test/tests/unit/Routing/MethodMapTest.php +++ b/test/tests/unit/Routing/MethodMapTest.php @@ -30,9 +30,12 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase $middleware->dispatch(Argument::cetera())->willReturn(); $map = new MethodMap(["GET" => $middleware->reveal()]); - $map->dispatch($this->request->reveal(), $this->response->reveal()); - $middleware->dispatch($this->request->reveal(), $this->response->reveal())->shouldHaveBeenCalled(); + $request = $this->request->reveal(); + $response = $this->response->reveal(); + $map->dispatch($request, $response); + + $middleware->dispatch($request, $response)->shouldHaveBeenCalled(); } public function testDispatchesGetMiddlewareForHeadByDefault() @@ -43,9 +46,12 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase $middleware->dispatch(Argument::cetera())->willReturn(); $map = new MethodMap(["GET" => $middleware->reveal()]); - $map->dispatch($this->request->reveal(), $this->response->reveal()); - $middleware->dispatch($this->request->reveal(), $this->response->reveal())->shouldHaveBeenCalled(); + $request = $this->request->reveal(); + $response = $this->response->reveal(); + $map->dispatch($request, $response); + + $middleware->dispatch($request, $response)->shouldHaveBeenCalled(); } public function testRegistersMiddlewareForMultipleMethods() @@ -56,13 +62,16 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase $map = new MethodMap(); $map->add("GET,POST", $middleware->reveal()); + $request = $this->request->reveal(); + $response = $this->response->reveal(); + $this->request->getMethod()->willReturn("GET"); - $map->dispatch($this->request->reveal(), $this->response->reveal()); + $map->dispatch($request, $response); $this->request->getMethod()->willReturn("POST"); - $map->dispatch($this->request->reveal(), $this->response->reveal()); + $map->dispatch($request, $response); - $middleware->dispatch($this->request->reveal(), $this->response->reveal())->shouldHaveBeenCalledTimes(2); + $middleware->dispatch($request, $response)->shouldHaveBeenCalledTimes(2); } public function testSetsStatusTo200ForOptions() @@ -72,7 +81,10 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase $middleware = $this->prophesize("\\WellRESTed\\Routing\\MiddlewareInterface"); $map = new MethodMap(["GET" => $middleware->reveal()]); - $map->dispatch($this->request->reveal(), $this->response->reveal()); + + $request = $this->request->reveal(); + $response = $this->response->reveal(); + $map->dispatch($request, $response); $this->response->withStatus(200)->shouldHaveBeenCalled(); } @@ -91,7 +103,9 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase $map->add($method, $middleware->reveal()); } - $map->dispatch($this->request->reveal(), $this->response->reveal()); + $request = $this->request->reveal(); + $response = $this->response->reveal(); + $map->dispatch($request, $response); $containsAllMethods = function ($headerValue) use ($methodsAllowed) { foreach ($methodsAllowed as $method) { @@ -111,7 +125,10 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase $middleware = $this->prophesize("\\WellRESTed\\Routing\\MiddlewareInterface"); $map = new MethodMap(["GET" => $middleware->reveal()]); - $map->dispatch($this->request->reveal(), $this->response->reveal()); + + $request = $this->request->reveal(); + $response = $this->response->reveal(); + $map->dispatch($request, $response); $this->response->withStatus(405)->shouldHaveBeenCalled(); } @@ -130,7 +147,9 @@ class MethodMapTest extends \PHPUnit_Framework_TestCase $map->add($method, $middleware->reveal()); } - $map->dispatch($this->request->reveal(), $this->response->reveal()); + $request = $this->request->reveal(); + $response = $this->response->reveal(); + $map->dispatch($request, $response); $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 968e9f2..bcbff69 100644 --- a/test/tests/unit/Routing/Route/RouteTest.php +++ b/test/tests/unit/Routing/Route/RouteTest.php @@ -28,7 +28,9 @@ class RouteTest extends \PHPUnit_Framework_TestCase $response = $response->withStatus(200); }; $route = new StaticRoute("/", $middleware); - $route->dispatch($this->request->reveal(), $this->response->reveal()); + $request = $this->request->reveal(); + $response = $this->response->reveal(); + $route->dispatch($request, $response); $this->response->withStatus(200)->shouldHaveBeenCalled(); } } diff --git a/test/tests/unit/Routing/RouteTableTest.php b/test/tests/unit/Routing/RouteTableTest.php index 76fcc47..0f1b04e 100644 --- a/test/tests/unit/Routing/RouteTableTest.php +++ b/test/tests/unit/Routing/RouteTableTest.php @@ -27,9 +27,11 @@ class RouteTableTest extends \PHPUnit_Framework_TestCase $table = new RouteTable(); $table->addStaticRoute($route->reveal()); - $table->dispatch($this->request->reveal(), $this->response->reveal()); - $route->dispatch($this->request->reveal(), $this->response->reveal())->shouldHaveBeenCalled(); + $request = $this->request->reveal(); + $response = $this->response->reveal(); + $table->dispatch($request, $response); + $route->dispatch($request, $response)->shouldHaveBeenCalled(); } public function testMatchesPrefixRoute() @@ -42,9 +44,11 @@ class RouteTableTest extends \PHPUnit_Framework_TestCase $table = new RouteTable(); $table->addPrefixRoute($route->reveal()); - $table->dispatch($this->request->reveal(), $this->response->reveal()); - $route->dispatch($this->request->reveal(), $this->response->reveal())->shouldHaveBeenCalled(); + $request = $this->request->reveal(); + $response = $this->response->reveal(); + $table->dispatch($request, $response); + $route->dispatch($request, $response)->shouldHaveBeenCalled(); } public function testMatchesBestPrefixRoute() @@ -62,7 +66,10 @@ class RouteTableTest extends \PHPUnit_Framework_TestCase $table = new RouteTable(); $table->addPrefixRoute($route1->reveal()); $table->addPrefixRoute($route2->reveal()); - $table->dispatch($this->request->reveal(), $this->response->reveal()); + + $request = $this->request->reveal(); + $response = $this->response->reveal(); + $table->dispatch($request, $response); $route1->dispatch(Argument::cetera())->shouldNotHaveBeenCalled(); $route2->dispatch(Argument::cetera())->shouldHaveBeenCalled(); @@ -83,7 +90,10 @@ class RouteTableTest extends \PHPUnit_Framework_TestCase $table = new RouteTable(); $table->addPrefixRoute($route1->reveal()); $table->addStaticRoute($route2->reveal()); - $table->dispatch($this->request->reveal(), $this->response->reveal()); + + $request = $this->request->reveal(); + $response = $this->response->reveal(); + $table->dispatch($request, $response); $route1->dispatch(Argument::cetera())->shouldNotHaveBeenCalled(); $route2->dispatch(Argument::cetera())->shouldHaveBeenCalled(); @@ -103,7 +113,10 @@ class RouteTableTest extends \PHPUnit_Framework_TestCase $table = new RouteTable(); $table->addPrefixRoute($route1->reveal()); $table->addRoute($route2->reveal()); - $table->dispatch($this->request->reveal(), $this->response->reveal()); + + $request = $this->request->reveal(); + $response = $this->response->reveal(); + $table->dispatch($request, $response); $route1->dispatch(Argument::cetera())->shouldHaveBeenCalled(); $route2->dispatch(Argument::cetera())->shouldNotHaveBeenCalled(); @@ -128,7 +141,10 @@ class RouteTableTest extends \PHPUnit_Framework_TestCase $table = new RouteTable(); $table->addRoute($route); - $table->dispatch($this->request->reveal(), $this->response->reveal()); + + $request = $this->request->reveal(); + $response = $this->response->reveal(); + $table->dispatch($request, $response); $this->request->withAttribute("id", "molly")->shouldHaveBeenCalled(); } @@ -151,7 +167,10 @@ class RouteTableTest extends \PHPUnit_Framework_TestCase $table->addRoute($route1->reveal()); $table->addRoute($route2->reveal()); $table->addRoute($route3->reveal()); - $table->dispatch($this->request->reveal(), $this->response->reveal()); + + $request = $this->request->reveal(); + $response = $this->response->reveal(); + $table->dispatch($request, $response); $route1->dispatch(Argument::cetera())->shouldNotHaveBeenCalled(); $route2->dispatch(Argument::cetera())->shouldHaveBeenCalled(); diff --git a/test/tests/unit/Routing/RouterTest.php b/test/tests/unit/Routing/RouterTest.php index 506706f..06b6ae7 100644 --- a/test/tests/unit/Routing/RouterTest.php +++ b/test/tests/unit/Routing/RouterTest.php @@ -48,7 +48,10 @@ class RouterTest extends \PHPUnit_Framework_TestCase $router = new Router(); $router->add("/cats/", $this->middleware->reveal()); - $router->dispatch($this->request->reveal(), $this->response->reveal()); + + $request = $this->request->reveal(); + $response = $this->response->reveal(); + $router->dispatch($request, $response); $this->middleware->dispatch(Argument::cetera())->shouldHaveBeenCalled(); } @@ -63,7 +66,10 @@ class RouterTest extends \PHPUnit_Framework_TestCase $router = new Router(); $router->addPreRouteHook($hook->reveal()); $router->add("/cats/", $this->middleware->reveal()); - $router->dispatch($this->request->reveal(), $this->response->reveal()); + + $request = $this->request->reveal(); + $response = $this->response->reveal(); + $router->dispatch($request, $response); $hook->dispatch(Argument::cetera())->shouldHaveBeenCalled(); } @@ -78,7 +84,10 @@ class RouterTest extends \PHPUnit_Framework_TestCase $router = new Router(); $router->addPostRouteHook($hook->reveal()); $router->add("/cats/", $this->middleware->reveal()); - $router->dispatch($this->request->reveal(), $this->response->reveal()); + + $request = $this->request->reveal(); + $response = $this->response->reveal(); + $router->dispatch($request, $response); $hook->dispatch(Argument::cetera())->shouldHaveBeenCalled(); } @@ -90,7 +99,10 @@ class RouterTest extends \PHPUnit_Framework_TestCase $router = new Router(); $router->add("/cats/", $this->middleware->reveal()); - $router->dispatch($this->request->reveal(), $this->response->reveal()); + + $request = $this->request->reveal(); + $response = $this->response->reveal(); + $router->dispatch($request, $response); $this->response->withStatus(404)->shouldHaveBeenCalled(); } @@ -105,7 +117,10 @@ class RouterTest extends \PHPUnit_Framework_TestCase $router = new Router(); $router->add("/cats/", $this->middleware->reveal()); $router->setStatusHandler(403, $statusMiddleware->reveal()); - $router->dispatch($this->request->reveal(), $this->response->reveal()); + + $request = $this->request->reveal(); + $response = $this->response->reveal(); + $router->dispatch($request, $response); $statusMiddleware->dispatch(Argument::cetera())->shouldHaveBeenCalled(); }