You are here

public function ErrorHandlerTest::testHandleError 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::testHandleError()

File

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

Class

ErrorHandlerTest
ErrorHandlerTest.

Namespace

Symfony\Component\Debug\Tests

Code

public function testHandleError() {
  try {
    $handler = ErrorHandler::register();
    $handler
      ->throwAt(0, true);
    $this
      ->assertFalse($handler
      ->handleError(0, 'foo', 'foo.php', 12, array()));
    restore_error_handler();
    restore_exception_handler();
    $handler = ErrorHandler::register();
    $handler
      ->throwAt(3, true);
    $this
      ->assertFalse($handler
      ->handleError(4, 'foo', 'foo.php', 12, array()));
    restore_error_handler();
    restore_exception_handler();
    $handler = ErrorHandler::register();
    $handler
      ->throwAt(3, true);
    try {
      $handler
        ->handleError(4, 'foo', 'foo.php', 12, array());
    } catch (\ErrorException $e) {
      $this
        ->assertSame('Parse Error: foo', $e
        ->getMessage());
      $this
        ->assertSame(4, $e
        ->getSeverity());
      $this
        ->assertSame('foo.php', $e
        ->getFile());
      $this
        ->assertSame(12, $e
        ->getLine());
    }
    restore_error_handler();
    restore_exception_handler();
    $handler = ErrorHandler::register();
    $handler
      ->throwAt(E_USER_DEPRECATED, true);
    $this
      ->assertFalse($handler
      ->handleError(E_USER_DEPRECATED, 'foo', 'foo.php', 12, array()));
    restore_error_handler();
    restore_exception_handler();
    $handler = ErrorHandler::register();
    $handler
      ->throwAt(E_DEPRECATED, true);
    $this
      ->assertFalse($handler
      ->handleError(E_DEPRECATED, 'foo', 'foo.php', 12, array()));
    restore_error_handler();
    restore_exception_handler();
    $logger = $this
      ->getMock('Psr\\Log\\LoggerInterface');
    $that = $this;
    $warnArgCheck = function ($logLevel, $message, $context) use ($that) {
      $that
        ->assertEquals('info', $logLevel);
      $that
        ->assertEquals('foo', $message);
      $that
        ->assertArrayHasKey('type', $context);
      $that
        ->assertEquals($context['type'], E_USER_DEPRECATED);
      $that
        ->assertArrayHasKey('stack', $context);
      $that
        ->assertInternalType('array', $context['stack']);
    };
    $logger
      ->expects($this
      ->once())
      ->method('log')
      ->will($this
      ->returnCallback($warnArgCheck));
    $handler = ErrorHandler::register();
    $handler
      ->setDefaultLogger($logger, E_USER_DEPRECATED);
    $this
      ->assertTrue($handler
      ->handleError(E_USER_DEPRECATED, 'foo', 'foo.php', 12, array()));
    restore_error_handler();
    restore_exception_handler();
    $logger = $this
      ->getMock('Psr\\Log\\LoggerInterface');
    $that = $this;
    $logArgCheck = function ($level, $message, $context) use ($that) {
      $that
        ->assertEquals('Undefined variable: undefVar', $message);
      $that
        ->assertArrayHasKey('type', $context);
      $that
        ->assertEquals($context['type'], E_NOTICE);
    };
    $logger
      ->expects($this
      ->once())
      ->method('log')
      ->will($this
      ->returnCallback($logArgCheck));
    $handler = ErrorHandler::register();
    $handler
      ->setDefaultLogger($logger, E_NOTICE);
    $handler
      ->screamAt(E_NOTICE);
    unset($undefVar);
    @$undefVar++;
    restore_error_handler();
    restore_exception_handler();
  } catch (\Exception $e) {
    restore_error_handler();
    restore_exception_handler();
    throw $e;
  }
}