diff --git a/src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php b/src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php index aeccd42144..c7f4fda12f 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php @@ -83,20 +83,15 @@ class ExceptionListener implements EventSubscriberInterface * * @param \Exception $exception The \Exception instance * @param string $message The error message to log - * @param bool $original False when the handling of the exception thrown another exception */ - protected function logException(\Exception $exception, $message, $original = true) + protected function logException(\Exception $exception, $message) { - $isCritical = !$exception instanceof HttpExceptionInterface || $exception->getStatusCode() >= 500; - $context = array('exception' => $exception); if (null !== $this->logger) { - if ($isCritical) { - $this->logger->critical($message, $context); + if (!$exception instanceof HttpExceptionInterface || $exception->getStatusCode() >= 500) { + $this->logger->critical($message, array('exception' => $exception)); } else { - $this->logger->error($message, $context); + $this->logger->error($message, array('exception' => $exception)); } - } elseif (!$original || $isCritical) { - error_log($message); } } diff --git a/src/Symfony/Component/HttpKernel/HttpKernel.php b/src/Symfony/Component/HttpKernel/HttpKernel.php index ca79f62b97..9811366948 100644 --- a/src/Symfony/Component/HttpKernel/HttpKernel.php +++ b/src/Symfony/Component/HttpKernel/HttpKernel.php @@ -229,7 +229,7 @@ class HttpKernel implements HttpKernelInterface, TerminableInterface if (!$event->hasResponse()) { $this->finishRequest($request, $type); - throw $e; + throw new \LogicException('No listeners of the "kernel.exception" event set a Response', 0, $e); } $response = $event->getResponse(); diff --git a/src/Symfony/Component/HttpKernel/Tests/DependencyInjection/ContainerAwareHttpKernelTest.php b/src/Symfony/Component/HttpKernel/Tests/DependencyInjection/ContainerAwareHttpKernelTest.php index 83182e63ea..0b110d4a21 100644 --- a/src/Symfony/Component/HttpKernel/Tests/DependencyInjection/ContainerAwareHttpKernelTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/DependencyInjection/ContainerAwareHttpKernelTest.php @@ -102,8 +102,8 @@ class ContainerAwareHttpKernelTest extends \PHPUnit_Framework_TestCase $this->fail('->handle() suppresses the controller exception'); } catch (\PHPUnit_Framework_Exception $exception) { throw $exception; - } catch (\Exception $actual) { - $this->assertSame($expected, $actual, '->handle() throws the controller exception'); + } catch (\LogicException $actual) { + $this->assertSame($expected, $actual->getPrevious(), '->handle() throws the controller exception, wrapped when no listener'); } } diff --git a/src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php b/src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php index 700b111228..55cf7f553d 100644 --- a/src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php @@ -23,14 +23,17 @@ use Symfony\Component\EventDispatcher\EventDispatcher; class HttpKernelTest extends \PHPUnit_Framework_TestCase { - /** - * @expectedException \RuntimeException - */ public function testHandleWhenControllerThrowsAnExceptionAndRawIsTrue() { - $kernel = new HttpKernel(new EventDispatcher(), $this->getResolver(function () { throw new \RuntimeException(); })); + $exception = new \RuntimeException(); + $kernel = new HttpKernel(new EventDispatcher(), $this->getResolver(function () use ($exception) { throw $exception; })); - $kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, true); + try { + $kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, true); + $this->fail('LogicException expected'); + } catch (\LogicException $e) { + $this->assertSame($exception, $e->getPrevious()); + } } /** @@ -132,7 +135,7 @@ class HttpKernelTest extends \PHPUnit_Framework_TestCase $dispatcher = new EventDispatcher(); $kernel = new HttpKernel($dispatcher, $this->getResolver(false)); - $kernel->handle(new Request()); + $kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, false); } /**