diff --git a/src/Symfony/Component/Debug/ExceptionHandler.php b/src/Symfony/Component/Debug/ExceptionHandler.php index 09de0244a1..31a1da1751 100644 --- a/src/Symfony/Component/Debug/ExceptionHandler.php +++ b/src/Symfony/Component/Debug/ExceptionHandler.php @@ -210,9 +210,11 @@ class ExceptionHandler $class = $this->formatClass($e['class']); $message = nl2br(self::utf8Htmlize($e['message'])); $content .= sprintf(<< -

%d/%d %s%s:
%s

- +

+ %d/%d + %s%s: + %s +

    @@ -269,12 +271,14 @@ EOF; .sf-reset abbr { border-bottom: 1px dotted #000; cursor: help; } .sf-reset p { font-size:14px; line-height:20px; color:#868686; padding-bottom:20px } .sf-reset strong { font-weight:bold; } - .sf-reset a { color:#6c6159; } + .sf-reset a { color:#6c6159; cursor: default; } .sf-reset a img { border:none; } .sf-reset a:hover { text-decoration:underline; } .sf-reset em { font-style:italic; } .sf-reset h1, .sf-reset h2 { font: 20px Georgia, "Times New Roman", Times, serif } - .sf-reset h2 span { background-color: #fff; color: #333; padding: 6px; float: left; margin-right: 10px; } + .sf-reset .exception_counter { background-color: #fff; color: #333; padding: 6px; float: left; margin-right: 10px; float: left; display: block; } + .sf-reset .exception_title { margin-left: 3em; margin-bottom: 0.7em; display: block; } + .sf-reset .exception_message { margin-left: 3em; display: block; } .sf-reset .traces li { font-size:12px; padding: 2px 4px; list-style-type:decimal; margin-left:20px; } .sf-reset .block { background-color:#FFFFFF; padding:10px 28px; margin-bottom:20px; -webkit-border-bottom-right-radius: 16px; @@ -352,10 +356,10 @@ EOF; if ($linkFormat = ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format')) { $link = str_replace(array('%f', '%l'), array($path, $line), $linkFormat); - return sprintf(' in %s line %d', $link, $file, $line); + return sprintf(' in %s line %d', $link, $file, $line); } - return sprintf(' in %s line %d', $path, $file, $line); + return sprintf(' in %s line %d', $path, $file, $line); } /** diff --git a/src/Symfony/Component/Debug/FatalErrorHandler/ClassNotFoundFatalErrorHandler.php b/src/Symfony/Component/Debug/FatalErrorHandler/ClassNotFoundFatalErrorHandler.php index a19feb4672..e1601703dd 100644 --- a/src/Symfony/Component/Debug/FatalErrorHandler/ClassNotFoundFatalErrorHandler.php +++ b/src/Symfony/Component/Debug/FatalErrorHandler/ClassNotFoundFatalErrorHandler.php @@ -67,7 +67,7 @@ class ClassNotFoundFatalErrorHandler implements FatalErrorHandlerInterface $tail = ' for "'.$tail; } } - $message .= ' Did you forget a "use" statement'.$tail; + $message .= "\nDid you forget a \"use\" statement".$tail; return new ClassNotFoundException($message, $exception); } diff --git a/src/Symfony/Component/Debug/FatalErrorHandler/UndefinedFunctionFatalErrorHandler.php b/src/Symfony/Component/Debug/FatalErrorHandler/UndefinedFunctionFatalErrorHandler.php index 551d160ce2..c6f391a79c 100644 --- a/src/Symfony/Component/Debug/FatalErrorHandler/UndefinedFunctionFatalErrorHandler.php +++ b/src/Symfony/Component/Debug/FatalErrorHandler/UndefinedFunctionFatalErrorHandler.php @@ -76,7 +76,7 @@ class UndefinedFunctionFatalErrorHandler implements FatalErrorHandlerInterface } else { $candidates = '"'.$last; } - $message .= ' Did you mean to call '.$candidates; + $message .= "\nDid you mean to call ".$candidates; } return new UndefinedFunctionException($message, $exception); diff --git a/src/Symfony/Component/Debug/FatalErrorHandler/UndefinedMethodFatalErrorHandler.php b/src/Symfony/Component/Debug/FatalErrorHandler/UndefinedMethodFatalErrorHandler.php index bdd9fec2dc..917794cfa0 100644 --- a/src/Symfony/Component/Debug/FatalErrorHandler/UndefinedMethodFatalErrorHandler.php +++ b/src/Symfony/Component/Debug/FatalErrorHandler/UndefinedMethodFatalErrorHandler.php @@ -52,7 +52,7 @@ class UndefinedMethodFatalErrorHandler implements FatalErrorHandlerInterface } else { $candidates = '"'.$last; } - $message .= ' Did you mean to call '.$candidates; + $message .= "\nDid you mean to call ".$candidates; } return new UndefinedMethodException($message, $exception); diff --git a/src/Symfony/Component/Debug/Tests/ExceptionHandlerTest.php b/src/Symfony/Component/Debug/Tests/ExceptionHandlerTest.php index 1e0859ebd8..26f889288f 100644 --- a/src/Symfony/Component/Debug/Tests/ExceptionHandlerTest.php +++ b/src/Symfony/Component/Debug/Tests/ExceptionHandlerTest.php @@ -25,13 +25,13 @@ class ExceptionHandlerTest extends \PHPUnit_Framework_TestCase $response = $handler->createResponse(new \RuntimeException('Foo')); $this->assertContains('

    Whoops, looks like something went wrong.

    ', $response->getContent()); - $this->assertNotContains('
    ', $response->getContent()); + $this->assertNotContains('

    ', $response->getContent()); $handler = new ExceptionHandler(true); $response = $handler->createResponse(new \RuntimeException('Foo')); $this->assertContains('

    Whoops, looks like something went wrong.

    ', $response->getContent()); - $this->assertContains('
    ', $response->getContent()); + $this->assertContains('

    ', $response->getContent()); } public function testStatusCode() diff --git a/src/Symfony/Component/Debug/Tests/FatalErrorHandler/ClassNotFoundFatalErrorHandlerTest.php b/src/Symfony/Component/Debug/Tests/FatalErrorHandler/ClassNotFoundFatalErrorHandlerTest.php index 6d256e3d22..0dbb7b2fdd 100644 --- a/src/Symfony/Component/Debug/Tests/FatalErrorHandler/ClassNotFoundFatalErrorHandlerTest.php +++ b/src/Symfony/Component/Debug/Tests/FatalErrorHandler/ClassNotFoundFatalErrorHandlerTest.php @@ -41,7 +41,7 @@ class ClassNotFoundFatalErrorHandlerTest extends \PHPUnit_Framework_TestCase 'file' => 'foo.php', 'message' => 'Class \'WhizBangFactory\' not found', ), - 'Attempted to load class "WhizBangFactory" from the global namespace. Did you forget a "use" statement?', + "Attempted to load class \"WhizBangFactory\" from the global namespace.\nDid you forget a \"use\" statement?", ), array( array( @@ -50,7 +50,7 @@ class ClassNotFoundFatalErrorHandlerTest extends \PHPUnit_Framework_TestCase 'file' => 'foo.php', 'message' => 'Class \'Foo\\Bar\\WhizBangFactory\' not found', ), - 'Attempted to load class "WhizBangFactory" from namespace "Foo\\Bar". Did you forget a "use" statement for another namespace?', + "Attempted to load class \"WhizBangFactory\" from namespace \"Foo\\Bar\".\nDid you forget a \"use\" statement for another namespace?", ), array( array( @@ -59,7 +59,7 @@ class ClassNotFoundFatalErrorHandlerTest extends \PHPUnit_Framework_TestCase 'file' => 'foo.php', 'message' => 'Class \'UndefinedFunctionException\' not found', ), - 'Attempted to load class "UndefinedFunctionException" from the global namespace. Did you forget a "use" statement for "Symfony\Component\Debug\Exception\UndefinedFunctionException"?', + "Attempted to load class \"UndefinedFunctionException\" from the global namespace.\nDid you forget a \"use\" statement for \"Symfony\Component\Debug\Exception\UndefinedFunctionException\"?", ), array( array( @@ -68,7 +68,7 @@ class ClassNotFoundFatalErrorHandlerTest extends \PHPUnit_Framework_TestCase 'file' => 'foo.php', 'message' => 'Class \'PEARClass\' not found', ), - 'Attempted to load class "PEARClass" from the global namespace. Did you forget a "use" statement for "Symfony_Component_Debug_Tests_Fixtures_PEARClass"?', + "Attempted to load class \"PEARClass\" from the global namespace.\nDid you forget a \"use\" statement for \"Symfony_Component_Debug_Tests_Fixtures_PEARClass\"?", ), array( array( @@ -77,7 +77,7 @@ class ClassNotFoundFatalErrorHandlerTest extends \PHPUnit_Framework_TestCase 'file' => 'foo.php', 'message' => 'Class \'Foo\\Bar\\UndefinedFunctionException\' not found', ), - 'Attempted to load class "UndefinedFunctionException" from namespace "Foo\Bar". Did you forget a "use" statement for "Symfony\Component\Debug\Exception\UndefinedFunctionException"?', + "Attempted to load class \"UndefinedFunctionException\" from namespace \"Foo\Bar\".\nDid you forget a \"use\" statement for \"Symfony\Component\Debug\Exception\UndefinedFunctionException\"?", ), ); } diff --git a/src/Symfony/Component/Debug/Tests/FatalErrorHandler/UndefinedFunctionFatalErrorHandlerTest.php b/src/Symfony/Component/Debug/Tests/FatalErrorHandler/UndefinedFunctionFatalErrorHandlerTest.php index 563fd7b530..ffe9edb062 100644 --- a/src/Symfony/Component/Debug/Tests/FatalErrorHandler/UndefinedFunctionFatalErrorHandlerTest.php +++ b/src/Symfony/Component/Debug/Tests/FatalErrorHandler/UndefinedFunctionFatalErrorHandlerTest.php @@ -42,7 +42,7 @@ class UndefinedFunctionFatalErrorHandlerTest extends \PHPUnit_Framework_TestCase 'file' => 'foo.php', 'message' => 'Call to undefined function test_namespaced_function()', ), - 'Attempted to call function "test_namespaced_function" from the global namespace. Did you mean to call "\\symfony\\component\\debug\\tests\\fatalerrorhandler\\test_namespaced_function"?', + "Attempted to call function \"test_namespaced_function\" from the global namespace.\nDid you mean to call \"\\symfony\\component\\debug\\tests\\fatalerrorhandler\\test_namespaced_function\"?", ), array( array( @@ -51,7 +51,7 @@ class UndefinedFunctionFatalErrorHandlerTest extends \PHPUnit_Framework_TestCase 'file' => 'foo.php', 'message' => 'Call to undefined function Foo\\Bar\\Baz\\test_namespaced_function()', ), - 'Attempted to call function "test_namespaced_function" from namespace "Foo\\Bar\\Baz". Did you mean to call "\\symfony\\component\\debug\\tests\\fatalerrorhandler\\test_namespaced_function"?', + "Attempted to call function \"test_namespaced_function\" from namespace \"Foo\\Bar\\Baz\".\nDid you mean to call \"\\symfony\\component\\debug\\tests\\fatalerrorhandler\\test_namespaced_function\"?", ), array( array( diff --git a/src/Symfony/Component/Debug/Tests/FatalErrorHandler/UndefinedMethodFatalErrorHandlerTest.php b/src/Symfony/Component/Debug/Tests/FatalErrorHandler/UndefinedMethodFatalErrorHandlerTest.php index c6ca877480..7837d1daa6 100644 --- a/src/Symfony/Component/Debug/Tests/FatalErrorHandler/UndefinedMethodFatalErrorHandlerTest.php +++ b/src/Symfony/Component/Debug/Tests/FatalErrorHandler/UndefinedMethodFatalErrorHandlerTest.php @@ -50,7 +50,7 @@ class UndefinedMethodFatalErrorHandlerTest extends \PHPUnit_Framework_TestCase 'file' => 'foo.php', 'message' => 'Call to undefined method SplObjectStorage::walid()', ), - 'Attempted to call method "walid" on class "SplObjectStorage". Did you mean to call "valid"?', + "Attempted to call method \"walid\" on class \"SplObjectStorage\".\nDid you mean to call \"valid\"?", ), array( array( @@ -59,7 +59,7 @@ class UndefinedMethodFatalErrorHandlerTest extends \PHPUnit_Framework_TestCase 'file' => 'foo.php', 'message' => 'Call to undefined method SplObjectStorage::offsetFet()', ), - 'Attempted to call method "offsetFet" on class "SplObjectStorage". Did you mean to call e.g. "offsetGet", "offsetSet" or "offsetUnset"?', + "Attempted to call method \"offsetFet\" on class \"SplObjectStorage\".\nDid you mean to call e.g. \"offsetGet\", \"offsetSet\" or \"offsetUnset\"?", ), ); } diff --git a/src/Symfony/Component/HttpKernel/EventListener/DebugHandlersListener.php b/src/Symfony/Component/HttpKernel/EventListener/DebugHandlersListener.php index 3625c08c81..cbb7ba0d68 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/DebugHandlersListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/DebugHandlersListener.php @@ -13,7 +13,7 @@ namespace Symfony\Component\HttpKernel\EventListener; use Psr\Log\LoggerInterface; use Symfony\Component\Debug\ErrorHandler; -use Symfony\Component\Debug\AbstractExceptionHandler; +use Symfony\Component\Debug\ExceptionHandler; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\KernelEvents; @@ -37,9 +37,7 @@ class DebugHandlersListener implements EventSubscriberInterface */ public function __construct($exceptionHandler, LoggerInterface $logger = null, $levels = null, $debug = true) { - if (is_callable($exceptionHandler)) { - $this->exceptionHandler = $exceptionHandler; - } + $this->exceptionHandler = $exceptionHandler; $this->logger = $logger; $this->levels = $levels; $this->debug = $debug; @@ -76,7 +74,7 @@ class DebugHandlersListener implements EventSubscriberInterface $handler->setExceptionHandler($h); $handler = is_array($h) ? $h[0] : null; } - if ($handler instanceof AbstractExceptionHandler) { + if ($handler instanceof ExceptionHandler) { $handler->setHandler($this->exceptionHandler); } $this->exceptionHandler = null; diff --git a/src/Symfony/Component/HttpKernel/Tests/EventListener/DebugHandlersListenerTest.php b/src/Symfony/Component/HttpKernel/Tests/EventListener/DebugHandlersListenerTest.php new file mode 100644 index 0000000000..1a9898133e --- /dev/null +++ b/src/Symfony/Component/HttpKernel/Tests/EventListener/DebugHandlersListenerTest.php @@ -0,0 +1,56 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\HttpKernel\Tests\EventListener; + +use Psr\Log\LogLevel; +use Symfony\Component\Debug\ErrorHandler; +use Symfony\Component\Debug\ExceptionHandler; +use Symfony\Component\HttpKernel\EventListener\DebugHandlersListener; + +/** + * DebugHandlersListenerTest + * + * @author Nicolas Grekas + */ +class DebugHandlersListenerTest extends \PHPUnit_Framework_TestCase +{ + public function testConfigure() + { + $logger = $this->getMock('Psr\Log\LoggerInterface'); + $userHandler = function() {}; + $listener = new DebugHandlersListener($userHandler, $logger); + $xHandler = new ExceptionHandler(); + $eHandler = new ErrorHandler(); + $eHandler->setExceptionHandler(array($xHandler, 'handle')); + + $exception = null; + set_error_handler(array($eHandler, 'handleError')); + set_exception_handler(array($eHandler, 'handleException')); + try { + $listener->configure(); + } catch (\Exception $exception) { + } + restore_exception_handler(); + restore_error_handler(); + + if (null !== $exception) { + throw $exception; + } + + $this->assertSame($userHandler, $xHandler->setHandler('var_dump')); + + $loggers = $eHandler->setLoggers(array()); + + $this->assertArrayHasKey(E_DEPRECATED, $loggers); + $this->assertSame(array($logger, LogLevel::INFO), $loggers[E_DEPRECATED]); + } +}