You are here

public function ErrorHandlerTest::testHandleException in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/debug/Tests/ErrorHandlerTest.php \Symfony\Component\Debug\Tests\ErrorHandlerTest::testHandleException()

File

vendor/symfony/debug/Tests/ErrorHandlerTest.php, line 293

Class

ErrorHandlerTest
ErrorHandlerTest.

Namespace

Symfony\Component\Debug\Tests

Code

public function testHandleException() {
  try {
    $handler = ErrorHandler::register();
    $exception = new \Exception('foo');
    $logger = $this
      ->getMock('Psr\\Log\\LoggerInterface');
    $that = $this;
    $logArgCheck = function ($level, $message, $context) use ($that) {
      $that
        ->assertEquals('Uncaught Exception: foo', $message);
      $that
        ->assertArrayHasKey('type', $context);
      $that
        ->assertEquals($context['type'], E_ERROR);
    };
    $logger
      ->expects($this
      ->exactly(2))
      ->method('log')
      ->will($this
      ->returnCallback($logArgCheck));
    $handler
      ->setDefaultLogger($logger, E_ERROR);
    try {
      $handler
        ->handleException($exception);
      $this
        ->fail('Exception expected');
    } catch (\Exception $e) {
      $this
        ->assertSame($exception, $e);
    }
    $that = $this;
    $handler
      ->setExceptionHandler(function ($e) use ($exception, $that) {
      $that
        ->assertSame($exception, $e);
    });
    $handler
      ->handleException($exception);
    restore_error_handler();
    restore_exception_handler();
  } catch (\Exception $e) {
    restore_error_handler();
    restore_exception_handler();
    throw $e;
  }
}