当前位置: 首页>>代码示例>>PHP>>正文


PHP ErrorHandler::setExceptionHandler方法代码示例

本文整理汇总了PHP中Symfony\Component\Debug\ErrorHandler::setExceptionHandler方法的典型用法代码示例。如果您正苦于以下问题:PHP ErrorHandler::setExceptionHandler方法的具体用法?PHP ErrorHandler::setExceptionHandler怎么用?PHP ErrorHandler::setExceptionHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Debug\ErrorHandler的用法示例。


在下文中一共展示了ErrorHandler::setExceptionHandler方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testConsoleEvent

 public function testConsoleEvent()
 {
     $dispatcher = new EventDispatcher();
     $listener = new DebugHandlersListener(null);
     $app = $this->getMock('Symfony\\Component\\Console\\Application');
     $app->expects($this->once())->method('getHelperSet')->will($this->returnValue(new HelperSet()));
     $command = new Command(__FUNCTION__);
     $command->setApplication($app);
     $event = new ConsoleEvent($command, new ArgvInput(), new ConsoleOutput());
     $dispatcher->addSubscriber($listener);
     $xListeners = array(KernelEvents::REQUEST => array(array($listener, 'configure')), ConsoleEvents::COMMAND => array(array($listener, 'configure')));
     $this->assertSame($xListeners, $dispatcher->getListeners());
     $exception = null;
     $eHandler = new ErrorHandler();
     set_error_handler(array($eHandler, 'handleError'));
     set_exception_handler(array($eHandler, 'handleException'));
     try {
         $dispatcher->dispatch(ConsoleEvents::COMMAND, $event);
     } catch (\Exception $exception) {
     }
     restore_exception_handler();
     restore_error_handler();
     if (null !== $exception) {
         throw $exception;
     }
     $xHandler = $eHandler->setExceptionHandler('var_dump');
     $this->assertInstanceOf('Closure', $xHandler);
     $app->expects($this->once())->method('renderException');
     $xHandler(new \Exception());
 }
开发者ID:scrobot,项目名称:Lumen,代码行数:30,代码来源:DebugHandlersListenerTest.php

示例2: testConfigure

 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]);
 }
开发者ID:alexbogo,项目名称:symfony,代码行数:26,代码来源:DebugHandlersListenerTest.php

示例3: testHandleErrorException

 /**
  * @requires PHP 7
  */
 public function testHandleErrorException()
 {
     $exception = new \Error("Class 'Foo' not found");
     $handler = new ErrorHandler();
     $handler->setExceptionHandler(function () use(&$args) {
         $args = func_get_args();
     });
     $handler->handleException($exception);
     $this->assertInstanceOf('Symfony\\Component\\Debug\\Exception\\ClassNotFoundException', $args[0]);
     $this->assertStringStartsWith("Attempted to load class \"Foo\" from the global namespace.\nDid you forget a \"use\" statement", $args[0]->getMessage());
 }
开发者ID:levanigongadze,项目名称:Labweb,代码行数:14,代码来源:ErrorHandlerTest.php


注:本文中的Symfony\Component\Debug\ErrorHandler::setExceptionHandler方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。