Skip to content

Commit

Permalink
[Debug] Fix fatal error when changing ErrorHandler loggers if an exce…
Browse files Browse the repository at this point in the history
…ption is buffered
  • Loading branch information
skalpa committed Jan 16, 2017
1 parent 7a90fcb commit a6527f8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Symfony/Component/Debug/ErrorHandler.php
Expand Up @@ -225,7 +225,7 @@ public function setLoggers(array $loggers)

if ($flush) {
foreach ($this->bootstrappingLogger->cleanLogs() as $log) {
$type = $log[2]['exception']->getSeverity();
$type = $log[2]['exception'] instanceof \ErrorException ? $log[2]['exception']->getSeverity() : E_ERROR;
if (!isset($flush[$type])) {
$this->bootstrappingLogger->log($log[0], $log[1], $log[2]);
} elseif ($this->loggers[$type][0]) {
Expand Down
19 changes: 19 additions & 0 deletions src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php
Expand Up @@ -417,6 +417,25 @@ public function testBootstrappingLogger()
$handler->setLoggers(array(E_DEPRECATED => array($mockLogger, LogLevel::WARNING)));
}

public function testSettingLoggerWhenExceptionIsBuffered()
{
$bootLogger = new BufferingLogger();
$handler = new ErrorHandler($bootLogger);

$exception = new \Exception('Foo message');

$mockLogger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
$mockLogger->expects($this->once())
->method('log')
->with(LogLevel::CRITICAL, 'Uncaught Exception: Foo message', array('exception' => $exception));

$handler->setExceptionHandler(function () use ($handler, $mockLogger) {
$handler->setDefaultLogger($mockLogger);
});

$handler->handleException($exception);
}

public function testHandleFatalError()
{
try {
Expand Down

0 comments on commit a6527f8

Please sign in to comment.