You are here

public function TestBase::errorHandler in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/simpletest/src/TestBase.php \Drupal\simpletest\TestBase::errorHandler()

Handle errors during test runs.

Because this is registered in set_error_handler(), it has to be public.

See also

set_error_handler

File

core/modules/simpletest/src/TestBase.php, line 1435
Contains \Drupal\simpletest\TestBase.

Class

TestBase
Base class for Drupal tests.

Namespace

Drupal\simpletest

Code

public function errorHandler($severity, $message, $file = NULL, $line = NULL) {
  if ($severity & error_reporting()) {
    $error_map = array(
      E_STRICT => 'Run-time notice',
      E_WARNING => 'Warning',
      E_NOTICE => 'Notice',
      E_CORE_ERROR => 'Core error',
      E_CORE_WARNING => 'Core warning',
      E_USER_ERROR => 'User error',
      E_USER_WARNING => 'User warning',
      E_USER_NOTICE => 'User notice',
      E_RECOVERABLE_ERROR => 'Recoverable error',
      E_DEPRECATED => 'Deprecated',
      E_USER_DEPRECATED => 'User deprecated',
    );
    $backtrace = debug_backtrace();

    // Add verbose backtrace for errors, but not for debug() messages.
    if ($severity !== E_USER_NOTICE) {
      $verbose_backtrace = $backtrace;
      array_shift($verbose_backtrace);
      $message .= '<pre class="backtrace">' . Error::formatBacktrace($verbose_backtrace) . '</pre>';
    }
    $this
      ->error($message, $error_map[$severity], Error::getLastCaller($backtrace));
  }
  return TRUE;
}