Skip to content

Commit 0eea1d5

Browse files
[Debug] fix and enhance exception messages
1 parent 38f4dee commit 0eea1d5

File tree

2 files changed

+59
-5
lines changed

2 files changed

+59
-5
lines changed

EventListener/DebugHandlersListener.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use Psr\Log\LoggerInterface;
1515
use Symfony\Component\Debug\ErrorHandler;
16-
use Symfony\Component\Debug\AbstractExceptionHandler;
16+
use Symfony\Component\Debug\ExceptionHandler;
1717
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1818
use Symfony\Component\HttpKernel\KernelEvents;
1919

@@ -37,9 +37,7 @@ class DebugHandlersListener implements EventSubscriberInterface
3737
*/
3838
public function __construct($exceptionHandler, LoggerInterface $logger = null, $levels = null, $debug = true)
3939
{
40-
if (is_callable($exceptionHandler)) {
41-
$this->exceptionHandler = $exceptionHandler;
42-
}
40+
$this->exceptionHandler = $exceptionHandler;
4341
$this->logger = $logger;
4442
$this->levels = $levels;
4543
$this->debug = $debug;
@@ -76,7 +74,7 @@ public function configure()
7674
$handler->setExceptionHandler($h);
7775
$handler = is_array($h) ? $h[0] : null;
7876
}
79-
if ($handler instanceof AbstractExceptionHandler) {
77+
if ($handler instanceof ExceptionHandler) {
8078
$handler->setHandler($this->exceptionHandler);
8179
}
8280
$this->exceptionHandler = null;
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\HttpKernel\Tests\EventListener;
13+
14+
use Psr\Log\LogLevel;
15+
use Symfony\Component\Debug\ErrorHandler;
16+
use Symfony\Component\Debug\ExceptionHandler;
17+
use Symfony\Component\HttpKernel\EventListener\DebugHandlersListener;
18+
19+
/**
20+
* DebugHandlersListenerTest
21+
*
22+
* @author Nicolas Grekas <[email protected]>
23+
*/
24+
class DebugHandlersListenerTest extends \PHPUnit_Framework_TestCase
25+
{
26+
public function testConfigure()
27+
{
28+
$logger = $this->getMock('Psr\Log\LoggerInterface');
29+
$userHandler = function() {};
30+
$listener = new DebugHandlersListener($userHandler, $logger);
31+
$xHandler = new ExceptionHandler();
32+
$eHandler = new ErrorHandler();
33+
$eHandler->setExceptionHandler(array($xHandler, 'handle'));
34+
35+
$exception = null;
36+
set_error_handler(array($eHandler, 'handleError'));
37+
set_exception_handler(array($eHandler, 'handleException'));
38+
try {
39+
$listener->configure();
40+
} catch (\Exception $exception) {
41+
}
42+
restore_exception_handler();
43+
restore_error_handler();
44+
45+
if (null !== $exception) {
46+
throw $exception;
47+
}
48+
49+
$this->assertSame($userHandler, $xHandler->setHandler('var_dump'));
50+
51+
$loggers = $eHandler->setLoggers(array());
52+
53+
$this->assertArrayHasKey(E_DEPRECATED, $loggers);
54+
$this->assertSame(array($logger, LogLevel::INFO), $loggers[E_DEPRECATED]);
55+
}
56+
}

0 commit comments

Comments
 (0)