You are here

function simpletest_log_read in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/simpletest/simpletest.module \simpletest_log_read()

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.

Parameters

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

$database_prefix: The database prefix to which the log relates.

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

Return value

bool Whether any fatal errors were found.

2 calls to simpletest_log_read()
TestBase::restoreEnvironment in core/modules/simpletest/src/TestBase.php
Cleans up the test environment and restores the original environment.
_simpletest_batch_finished in core/modules/simpletest/simpletest.module
Implements callback_batch_finished().

File

core/modules/simpletest/simpletest.module, line 461
Provides testing functionality.

Code

function simpletest_log_read($test_id, $database_prefix, $test_class) {
  $log = DRUPAL_ROOT . '/sites/simpletest/' . substr($database_prefix, 10) . '/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 = array(
          'line' => $match[4],
          'file' => $match[3],
        );
        TestBase::insertAssert($test_id, $test_class, FALSE, $match[2], $match[1], $caller);
      }
      else {

        // Unknown format, place the entire message in the log.
        TestBase::insertAssert($test_id, $test_class, FALSE, $line, 'Fatal error');
      }
      $found = TRUE;
    }
  }
  return $found;
}