diff --git a/src/pjdietz/WellRESTed/Router.php b/src/pjdietz/WellRESTed/Router.php index 18b8696..27bb87b 100644 --- a/src/pjdietz/WellRESTed/Router.php +++ b/src/pjdietz/WellRESTed/Router.php @@ -123,7 +123,9 @@ class Router implements HandlerInterface if (!$response) { $response = $this->getNoRouteResponse($request); } - $response->respond(); + if ($response instanceof ResponseInterface) { + $response->respond(); + } } /** diff --git a/test/tests/integration/RouterTest.php b/test/tests/integration/RouterTest.php index 79edcf3..f3b1a37 100644 --- a/test/tests/integration/RouterTest.php +++ b/test/tests/integration/RouterTest.php @@ -72,4 +72,28 @@ class RouterTest extends \PHPUnit_Framework_TestCase $this->assertEquals("Hello, cat!", $captured); } + + /** + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function testRouterRespondsWithNoisyCallable() + { + $_SERVER["REQUEST_URI"] = "/cats/molly"; + $_SERVER["HTTP_HOST"] = "localhost"; + $_SERVER["REQUEST_METHOD"] = "GET"; + + $router = new Router(); + $router->add("/cats/{cat}", function () { + echo "Hello, cat!"; + return true; + }); + + ob_start(); + @$router->respond(); + $captured = ob_get_contents(); + ob_end_clean(); + + $this->assertEquals("Hello, cat!", $captured); + } }