diff --git a/src/Symfony/Component/HttpKernel/Exception/ControllerDoesNotReturnResponseException.php b/src/Symfony/Component/HttpKernel/Exception/ControllerDoesNotReturnResponseException.php index 517313db60..1e87690ff1 100644 --- a/src/Symfony/Component/HttpKernel/Exception/ControllerDoesNotReturnResponseException.php +++ b/src/Symfony/Component/HttpKernel/Exception/ControllerDoesNotReturnResponseException.php @@ -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, ]; } diff --git a/src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php b/src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php index 4d1e267e3a..40a63f4d07 100644 --- a/src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php @@ -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()