function TestRun::processPhpErrorLogFile

Same name in other branches
  1. 11.x core/lib/Drupal/Core/Test/TestRun.php \Drupal\Core\Test\TestRun::processPhpErrorLogFile()

Reads the PHP error log and reports any errors as assertion failures.

The errors in the log should only be fatal errors since any other errors will have been recorded by the error handler.

Parameters

string $error_log_path: The path of log file.

string $test_class: The test class to which the log relates.

Return value

bool Whether any fatal errors were found.

File

core/lib/Drupal/Core/Test/TestRun.php, line 171

Class

TestRun
Implements an object that tracks execution of a test run.

Namespace

Drupal\Core\Test

Code

public function processPhpErrorLogFile(string $error_log_path, string $test_class) : bool {
    $found = FALSE;
    if (file_exists($error_log_path)) {
        foreach (file($error_log_path) as $line) {
            if (preg_match('/\\[.*?\\] (.*?): (.*?) in (.*) on line (\\d+)/', $line, $match)) {
                // Parse PHP fatal errors for example: PHP Fatal error: Call to
                // undefined function break_me() in /path/to/file.php on line 17
                $this->insertLogEntry([
                    'test_class' => $test_class,
                    'status' => 'fail',
                    'message' => $match[2],
                    'message_group' => $match[1],
                    'line' => $match[4],
                    'file' => $match[3],
                ]);
            }
            else {
                // Unknown format, place the entire message in the log.
                $this->insertLogEntry([
                    'test_class' => $test_class,
                    'status' => 'fail',
                    'message' => $line,
                    'message_group' => 'Fatal error',
                ]);
            }
            $found = TRUE;
        }
    }
    return $found;
}

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