8000 [HttpKernel] Better exception page when the invokable controller returns nothing by dimabory · Pull Request #30408 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpKernel] Better exception page when the invokable controller returns nothing #30408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[HttpKernel] Better exception page when the invokable controller retu…
…rns nothing
  • Loading branch information
dimabory committed Mar 5, 2019
commit f6c1622fb581534b6f36b5c92eba7ff1bd8375be
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,15 @@ private function parseControllerDefinition(callable $controller): ?array
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,
];
}

Expand Down
13 changes: 6 additions & 7 deletions src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,20 +215,19 @@ public function testHandleWhenTheControllerIsAStaticArray()
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];

$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);
// `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()
Expand Down
0