1 simpletest.module simpletest_log_read($test_id, $prefix, $test_class, $during_test = FALSE)

Read the error log and report 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.

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

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

$during_test: Indicates that the current file directory path is a temporary file file directory used during testing.

Return value

Found any entries in log.

File

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

Code

function simpletest_log_read($test_id, $prefix, $test_class, $during_test = FALSE) {
  $log = 'public://' . ($during_test ? '' : '/simpletest/' . substr($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],
        );
        BackdropTestCase::insertAssert($test_id, $test_class, FALSE, $match[2], $match[1], $caller);
      }
      else {
        // Unknown format, place the entire message in the log.
        BackdropTestCase::insertAssert($test_id, $test_class, FALSE, $line, 'Fatal error');
      }
      $found = TRUE;
    }
  }
  return $found;
}