Prevent Router from trying to call respond on non responses.
This commit is contained in:
parent
13e683225d
commit
fdeff57a79
|
|
@ -123,7 +123,9 @@ class Router implements HandlerInterface
|
||||||
if (!$response) {
|
if (!$response) {
|
||||||
$response = $this->getNoRouteResponse($request);
|
$response = $this->getNoRouteResponse($request);
|
||||||
}
|
}
|
||||||
$response->respond();
|
if ($response instanceof ResponseInterface) {
|
||||||
|
$response->respond();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -72,4 +72,28 @@ class RouterTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$this->assertEquals("Hello, cat!", $captured);
|
$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