[HttpKernel] Better exception page when the invokable controller returns nothing
This commit is contained in:
parent
91c5b14d8b
commit
f6c1622fb5
@ -67,9 +67,15 @@ class ControllerDoesNotReturnResponseException extends \LogicException
|
||||
if (\is_object($controller)) {
|
||||
$r = new \ReflectionClass($controller);
|
||||
|
||||
try {
|
||||
$line = $r->getMethod('__invoke')->getEndLine();
|
||||
} catch (\ReflectionException $e) {
|
||||
$line = $r->getEndLine();
|
||||
}
|
||||
|
||||
return [
|
||||
'file' => $r->getFileName(),
|
||||
'line' => $r->getEndLine(),
|
||||
'line' => $line,
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -215,20 +215,19 @@ class HttpKernelTest extends TestCase
|
||||
public function testHandleWhenTheControllerDoesNotReturnAResponse()
|
||||
{
|
||||
$dispatcher = new EventDispatcher();
|
||||
$kernel = $this->getHttpKernel($dispatcher, function () { return 'foo'; });
|
||||
$kernel = $this->getHttpKernel($dispatcher, function () {});
|
||||
|
||||
try {
|
||||
$kernel->handle(new Request());
|
||||
|
||||
$this->fail('The kernel should throw an exception.');
|
||||
} catch (ControllerDoesNotReturnResponseException $e) {
|
||||
$first = $e->getTrace()[0];
|
||||
|
||||
// `file` index the array starting at 0, and __FILE__ starts at 1
|
||||
$line = file($first['file'])[$first['line'] - 2];
|
||||
$this->assertContains('// call controller', $line);
|
||||
}
|
||||
|
||||
$first = $e->getTrace()[0];
|
||||
|
||||
// `file` index the array starting at 0, and __FILE__ starts at 1
|
||||
$line = file($first['file'])[$first['line'] - 2];
|
||||
$this->assertContains('// call controller', $line);
|
||||
}
|
||||
|
||||
public function testHandleWhenTheControllerDoesNotReturnAResponseButAViewIsRegistered()
|
||||
|
Reference in New Issue
Block a user