Prevent Router from trying to call respond on non responses.

This commit is contained in:
PJ Dietz 2015-02-22 17:17:56 -05:00
parent 13e683225d
commit fdeff57a79
2 changed files with 27 additions and 1 deletions

View File

@ -123,7 +123,9 @@ class Router implements HandlerInterface
if (!$response) {
$response = $this->getNoRouteResponse($request);
}
$response->respond();
if ($response instanceof ResponseInterface) {
$response->respond();
}
}
/**

View File

@ -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);
}
}