Peridot\Core\Test::handleErrors PHP Method

handleErrors() protected method

Set an error handler to handle errors within the test
protected handleErrors ( Peridot\Core\TestResult $result, array &$action ) : callable | null
$result Peridot\Core\TestResult
$action array
return callable | null
    protected function handleErrors(TestResult $result, array &$action)
    {
        $handler = null;
        $handler = set_error_handler(function ($severity, $message, $path, $line) use($result, &$action, &$handler) {
            // if there is an existing error handler, call it and record the result
            $isHandled = $handler && false !== $handler($severity, $message, $path, $line);
            if (!$isHandled) {
                $result->getEventEmitter()->emit('error', [$severity, $message, $path, $line]);
                // honor the error reporting configuration - this also takes care of the error control operator (@)
                $errorReporting = error_reporting();
                $shouldHandle = $severity === ($severity & $errorReporting);
                if ($shouldHandle) {
                    $this->failIfPassing($action, new ErrorException($message, 0, $severity, $path, $line));
                }
            }
        });
        return $handler;
    }