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]);
 }
Beispiel #2
0
 public function testBootstrappingLogger()
 {
     $bootLogger = new BufferingLogger();
     $handler = new ErrorHandler($bootLogger);
     $loggers = array(E_DEPRECATED => array($bootLogger, LogLevel::INFO), E_USER_DEPRECATED => array($bootLogger, LogLevel::INFO), E_NOTICE => array($bootLogger, LogLevel::WARNING), E_USER_NOTICE => array($bootLogger, LogLevel::WARNING), E_STRICT => array($bootLogger, LogLevel::WARNING), E_WARNING => array($bootLogger, LogLevel::WARNING), E_USER_WARNING => array($bootLogger, LogLevel::WARNING), E_COMPILE_WARNING => array($bootLogger, LogLevel::WARNING), E_CORE_WARNING => array($bootLogger, LogLevel::WARNING), E_USER_ERROR => array($bootLogger, LogLevel::CRITICAL), E_RECOVERABLE_ERROR => array($bootLogger, LogLevel::CRITICAL), E_COMPILE_ERROR => array($bootLogger, LogLevel::CRITICAL), E_PARSE => array($bootLogger, LogLevel::CRITICAL), E_ERROR => array($bootLogger, LogLevel::CRITICAL), E_CORE_ERROR => array($bootLogger, LogLevel::CRITICAL));
     $this->assertSame($loggers, $handler->setLoggers(array()));
     $handler->handleError(E_DEPRECATED, 'Foo message', __FILE__, 123, array());
     $expectedLog = array(LogLevel::INFO, 'Foo message', array('type' => E_DEPRECATED, 'file' => __FILE__, 'line' => 123, 'level' => error_reporting()));
     $logs = $bootLogger->cleanLogs();
     unset($logs[0][2]['stack']);
     $this->assertSame(array($expectedLog), $logs);
     $bootLogger->log($expectedLog[0], $expectedLog[1], $expectedLog[2]);
     $mockLogger = $this->getMock('Psr\\Log\\LoggerInterface');
     $mockLogger->expects($this->once())->method('log')->with(LogLevel::WARNING, 'Foo message', $expectedLog[2]);
     $handler->setLoggers(array(E_DEPRECATED => array($mockLogger, LogLevel::WARNING)));
 }
Beispiel #3
0
 public function testBootstrappingLogger()
 {
     $bootLogger = new BufferingLogger();
     $handler = new ErrorHandler($bootLogger);
     $loggers = array(E_DEPRECATED => array($bootLogger, LogLevel::INFO), E_USER_DEPRECATED => array($bootLogger, LogLevel::INFO), E_NOTICE => array($bootLogger, LogLevel::WARNING), E_USER_NOTICE => array($bootLogger, LogLevel::WARNING), E_STRICT => array($bootLogger, LogLevel::WARNING), E_WARNING => array($bootLogger, LogLevel::WARNING), E_USER_WARNING => array($bootLogger, LogLevel::WARNING), E_COMPILE_WARNING => array($bootLogger, LogLevel::WARNING), E_CORE_WARNING => array($bootLogger, LogLevel::WARNING), E_USER_ERROR => array($bootLogger, LogLevel::CRITICAL), E_RECOVERABLE_ERROR => array($bootLogger, LogLevel::CRITICAL), E_COMPILE_ERROR => array($bootLogger, LogLevel::CRITICAL), E_PARSE => array($bootLogger, LogLevel::CRITICAL), E_ERROR => array($bootLogger, LogLevel::CRITICAL), E_CORE_ERROR => array($bootLogger, LogLevel::CRITICAL));
     $this->assertSame($loggers, $handler->setLoggers(array()));
     $handler->handleError(E_DEPRECATED, 'Foo message', __FILE__, 123, array());
     $logs = $bootLogger->cleanLogs();
     $this->assertCount(1, $logs);
     $log = $logs[0];
     $this->assertSame('info', $log[0]);
     $this->assertSame('Deprecated: Foo message', $log[1]);
     $this->assertArrayHasKey('exception', $log[2]);
     $exception = $log[2]['exception'];
     $this->assertInstanceOf(\ErrorException::class, $exception);
     $this->assertSame('Deprecated: Foo message', $exception->getMessage());
     $this->assertSame(__FILE__, $exception->getFile());
     $this->assertSame(123, $exception->getLine());
     $this->assertSame(E_DEPRECATED, $exception->getSeverity());
     $bootLogger->log(LogLevel::WARNING, 'Foo message', array('exception' => $exception));
     $mockLogger = $this->getMock('Psr\\Log\\LoggerInterface');
     $mockLogger->expects($this->once())->method('log')->with(LogLevel::WARNING, 'Foo message', array('exception' => $exception));
     $handler->setLoggers(array(E_DEPRECATED => array($mockLogger, LogLevel::WARNING)));
 }