Skip to content

Commit

Permalink
[HttpKernel] fixed a regression when no exception listeners are regis…
Browse files Browse the repository at this point in the history
…tered
  • Loading branch information
fabpot committed Apr 11, 2015
1 parent bab6db5 commit 27930fb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
6 changes: 5 additions & 1 deletion src/Symfony/Component/HttpKernel/HttpKernel.php
Expand Up @@ -229,7 +229,11 @@ private function handleException(\Exception $e, $request, $type)
if (!$event->hasResponse()) {
$this->finishRequest($request, $type);

throw new \LogicException('No listeners of the "kernel.exception" event set a Response', 0, $e);
if ($this->dispatcher->hasListeners(KernelEvents::EXCEPTION)) {
throw new \LogicException('No listeners of the "kernel.exception" event set a Response', 0, $e);
}

throw $e;
}

$response = $event->getResponse();
Expand Down
Expand Up @@ -102,8 +102,8 @@ public function testHandleRestoresThePreviousRequestOnException($type)
$this->fail('->handle() suppresses the controller exception');
} catch (\PHPUnit_Framework_Exception $exception) {
throw $exception;
} catch (\LogicException $actual) {
$this->assertSame($expected, $actual->getPrevious(), '->handle() throws the controller exception, wrapped when no listener');
} catch (\Exception $actual) {
$this->assertSame($expected, $actual, '->handle() throws the controller exception');
}
}

Expand Down
13 changes: 5 additions & 8 deletions src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php
Expand Up @@ -23,17 +23,14 @@

class HttpKernelTest extends \PHPUnit_Framework_TestCase
{
/**
* @expectedException \RuntimeException
*/
public function testHandleWhenControllerThrowsAnExceptionAndCatchIsTrue()
{
$exception = new \RuntimeException();
$kernel = new HttpKernel(new EventDispatcher(), $this->getResolver(function () use ($exception) { throw $exception; }));
$kernel = new HttpKernel(new EventDispatcher(), $this->getResolver(function () { throw new \RuntimeException(); }));

try {
$kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, true);
$this->fail('LogicException expected');
} catch (\LogicException $e) {
$this->assertSame($exception, $e->getPrevious());
}
$kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, true);
}

/**
Expand Down

0 comments on commit 27930fb

Please sign in to comment.