function PhpUnitTestRunner::processPhpUnitOnSingleTestClassOutcome

Processes PHPUnit test execution output.

Parameters

\Symfony\Component\Process\Process $process: The PHPUnit CLI process - terminated.

\Drupal\Core\Test\TestRun $test_run: The test run object.

class-string $test_class: A fully qualified test class name.

Return value

array The results.

File

core/lib/Drupal/Core/Test/PhpUnitTestRunner.php, line 113

Class

PhpUnitTestRunner
Run PHPUnit-based tests.

Namespace

Drupal\Core\Test

Code

public function processPhpUnitOnSingleTestClassOutcome(Process $process, TestRun $test_run, string $test_class) : array {
  if (!$process->isTerminated()) {
    throw new \RuntimeException('An error occurred: subprocess was not terminated before starting processing its output');
  }
  $out = $process->getOutput();
  $err = $process->getErrorOutput();
  $output = explode("\n", $out);
  $errorOutput = $err;
  if (!empty($errorOutput)) {
    $error = explode("\n", $err);
  }
  $status = $process->getExitCode();
  $log_junit_file_path = $this->xmlLogFilePath($test_run->id());
  if (file_exists($log_junit_file_path)) {
    $phpunit_results = JUnitConverter::xmlToRows($test_run->id(), $log_junit_file_path);
  }
  else {
    $phpunit_results = [];
  }
  // If not passed, add full PHPUnit run output since individual test cases
  // messages may not give full clarity (deprecations, warnings, etc.).
  if ($status > TestStatus::PASS) {
    $message = $out;
    if (!empty($error)) {
      $message .= "\nERROR:\n";
      $message .= $err;
    }
    $phpunit_results[] = [
      'test_id' => $test_run->id(),
      'test_class' => $test_class,
      'status' => $status < TestStatus::SYSTEM ? 'cli_fail' : 'exception',
      'exit_code' => $status,
      'message' => $message,
      'message_group' => 'Other',
      'function' => '*** Process execution output ***',
      'line' => '0',
      'file' => $log_junit_file_path,
      'time' => 0,
    ];
  }
  $this->processPhpUnitResults($test_run, $phpunit_results);
  $summaries = $this->summarizeResults($phpunit_results);
  return [
    'status' => $status,
    'output' => $output,
    'error_output' => $error ?? NULL,
    'phpunit_results' => $phpunit_results,
    'summaries' => $summaries,
  ];
}

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