|
| 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