You are here

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

File

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

Class

ErrorHandlerTest
ErrorHandlerTest.

Namespace

Symfony\Component\Debug\Tests

Code

public function testNotice() {
  ErrorHandler::register();
  try {
    self::triggerNotice($this);
    $this
      ->fail('ContextErrorException expected');
  } catch (ContextErrorException $exception) {

    // if an exception is thrown, the test passed
    restore_error_handler();
    restore_exception_handler();
    $this
      ->assertEquals(E_NOTICE, $exception
      ->getSeverity());
    $this
      ->assertEquals(__FILE__, $exception
      ->getFile());
    $this
      ->assertRegExp('/^Notice: Undefined variable: (foo|bar)/', $exception
      ->getMessage());
    $this
      ->assertArrayHasKey('foobar', $exception
      ->getContext());
    $trace = $exception
      ->getTrace();
    $this
      ->assertEquals(__FILE__, $trace[0]['file']);
    $this
      ->assertEquals('Symfony\\Component\\Debug\\ErrorHandler', $trace[0]['class']);
    $this
      ->assertEquals('handleError', $trace[0]['function']);
    $this
      ->assertEquals('->', $trace[0]['type']);
    $this
      ->assertEquals(__FILE__, $trace[1]['file']);
    $this
      ->assertEquals(__CLASS__, $trace[1]['class']);
    $this
      ->assertEquals('triggerNotice', $trace[1]['function']);
    $this
      ->assertEquals('::', $trace[1]['type']);
    $this
      ->assertEquals(__FILE__, $trace[1]['file']);
    $this
      ->assertEquals(__CLASS__, $trace[2]['class']);
    $this
      ->assertEquals(__FUNCTION__, $trace[2]['function']);
    $this
      ->assertEquals('->', $trace[2]['type']);
  } catch (\Exception $e) {
    restore_error_handler();
    restore_exception_handler();
    throw $e;
  }
}