diff --git a/src/Routing/Hook/HeadHook.php b/src/Routing/Hook/HeadHook.php index d89bfd9..6cd4341 100644 --- a/src/Routing/Hook/HeadHook.php +++ b/src/Routing/Hook/HeadHook.php @@ -12,7 +12,7 @@ use WellRESTed\Routing\MiddlewareInterface; */ class HeadHook implements MiddlewareInterface { - public function dispatch(ServerRequestInterface $request, ResponseInterface &$response) + public function dispatch(ServerRequestInterface $request, ResponseInterface $response, $next) { $method = strtoupper($request->getMethod()); if ($method === "HEAD") { @@ -20,5 +20,6 @@ class HeadHook implements MiddlewareInterface $response = $response->withBody(new NullStream()); } } + return $next($request, $response); } } diff --git a/test/tests/unit/Routing/Hook/HeadHookTest.php b/test/tests/unit/Routing/Hook/HeadHookTest.php index 6506f74..c80e04a 100644 --- a/test/tests/unit/Routing/Hook/HeadHookTest.php +++ b/test/tests/unit/Routing/Hook/HeadHookTest.php @@ -13,6 +13,7 @@ class HeadHookTest extends \PHPUnit_Framework_TestCase { private $request; private $response; + private $next; private $body; public function setUp() @@ -27,36 +28,33 @@ class HeadHookTest extends \PHPUnit_Framework_TestCase $this->getBody()->willReturn($args[0]); return $this; }); + $this->next = function ($request, $response) { + return $response; + }; } public function testReplacesBodyForHeadRequest() { $this->request->getMethod()->willReturn("HEAD"); - $request = $this->request->reveal(); - $response = $this->response->reveal(); $hook = new HeadHook(); - $hook->dispatch($request, $response); + $response = $hook->dispatch($this->request->reveal(), $this->response->reveal(), $this->next); $this->assertSame(0, $response->getBody()->getSize()); } public function testMultipleDispatchesHaveNoEffect() { $this->request->getMethod()->willReturn("HEAD"); - $request = $this->request->reveal(); - $response = $this->response->reveal(); $hook = new HeadHook(); - $hook->dispatch($request, $response); - $hook->dispatch($request, $response); + $response = $hook->dispatch($this->request->reveal(), $this->response->reveal(), $this->next); + $hook->dispatch($this->request->reveal(), $response, $this->next); $this->response->withBody(Argument::any())->shouldHaveBeenCalledTimes(1); } public function testDoesNotReplaceBodyForNonHeadRequests() { $this->request->getMethod()->willReturn("GET"); - $request = $this->request->reveal(); - $response = $this->response->reveal(); $hook = new HeadHook(); - $hook->dispatch($request, $response); + $hook->dispatch($this->request->reveal(), $this->response->reveal(), $this->next); $this->response->withBody(Argument::any())->shouldNotHaveBeenCalled(); } }