function 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 1302

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 = [
            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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.