function TestDatabase::logRead

Same name and namespace in other branches
  1. 8.9.x core/lib/Drupal/Core/Test/TestDatabase.php \Drupal\Core\Test\TestDatabase::logRead()

Reads the 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.

@internal

Parameters

int $test_id: The test ID to which the log relates.

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/TestDatabase.php, line 290

Class

TestDatabase
Provides helper methods for interacting with the fixture database.

Namespace

Drupal\Core\Test

Code

public function logRead($test_id, $test_class) {
    $log = DRUPAL_ROOT . '/' . $this->getTestSitePath() . '/error.log';
    $found = FALSE;
    if (file_exists($log)) {
        foreach (file($log) 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
                $caller = [
                    'line' => $match[4],
                    'file' => $match[3],
                ];
                static::insertAssert($test_id, $test_class, FALSE, $match[2], $match[1], $caller);
            }
            else {
                // Unknown format, place the entire message in the log.
                static::insertAssert($test_id, $test_class, FALSE, $line, 'Fatal error');
            }
            $found = TRUE;
        }
    }
    return $found;
}

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