Prevent Router from trying to call respond on non responses.
This commit is contained in:
parent
13e683225d
commit
fdeff57a79
|
|
@ -123,8 +123,10 @@ class Router implements HandlerInterface
|
|||
if (!$response) {
|
||||
$response = $this->getNoRouteResponse($request);
|
||||
}
|
||||
if ($response instanceof ResponseInterface) {
|
||||
$response->respond();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the response built by the handler based on the request
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue