function PhpUnitTestRunner::runCommand

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Test/PhpUnitTestRunner.php \Drupal\Core\Test\PhpUnitTestRunner::runCommand()
  2. 8.9.x core/lib/Drupal/Core/Test/PhpUnitTestRunner.php \Drupal\Core\Test\PhpUnitTestRunner::runCommand()
  3. 10 core/lib/Drupal/Core/Test/PhpUnitTestRunner.php \Drupal\Core\Test\PhpUnitTestRunner::runCommand()

Executes the PHPUnit command.

@internal

Parameters

string $test_class_name: A fully qualified test class name.

string $log_junit_file_path: A filepath to use for PHPUnit's --log-junit option.

int|null $status: (optional) The exit status code of the PHPUnit process will be assigned to this variable.

string[]|null $output: (optional) The output by running the phpunit command. If provided, this array will contain the lines output by the command.

string[]|null $error: (optional) The error returned by running the phpunit command. If provided, this array will contain the error lines output by the command.

bool $colors: (optional) Whether to use colors in output. Defaults to FALSE.

1 call to PhpUnitTestRunner::runCommand()
PhpUnitTestRunner::execute in core/lib/Drupal/Core/Test/PhpUnitTestRunner.php
Executes PHPUnit tests and returns the results of the run.

File

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

Class

PhpUnitTestRunner
Run PHPUnit-based tests.

Namespace

Drupal\Core\Test

Code

protected function runCommand(string $test_class_name, string $log_junit_file_path, ?int &$status = NULL, ?array &$output = NULL, ?array &$error = NULL, bool $colors = FALSE) : void {
  global $base_url;
  $process_environment_variables = [];
  // Setup an environment variable containing the database connection if
  // available, so that non-unit tests can connect to the database.
  try {
    $process_environment_variables['SIMPLETEST_DB'] = Database::getConnectionInfoAsUrl();
  } catch (\RuntimeException) {
    // Just continue with no variable set.
  }
  // Setup an environment variable containing the base URL, if it is
  // available. This allows functional tests to browse the site under test.
  // When running tests via CLI, core/phpunit.xml.dist or
  // core/scripts/run-tests.sh can set this variable.
  if ($base_url) {
    $process_environment_variables['SIMPLETEST_BASE_URL'] = $base_url;
    $process_environment_variables['BROWSERTEST_OUTPUT_DIRECTORY'] = $this->workingDirectory;
  }
  $phpunit_bin = $this->phpUnitCommand();
  // Build the command line for the PHPUnit CLI invocation.
  $command = [
    $phpunit_bin,
    '--testdox',
    '--log-junit',
    $log_junit_file_path,
  ];
  if ($colors) {
    $command[] = '--colors=always';
  }
  // If the deprecation handler bridge is active, we need to fail when there
  // are deprecations that get reported (i.e. not ignored or expected).
  $deprecationConfiguration = DeprecationHandler::getConfiguration();
  if ($deprecationConfiguration !== FALSE) {
    $command[] = '--fail-on-deprecation';
    if ($deprecationConfiguration['failOnPhpunitDeprecation']) {
      $command[] = '--fail-on-phpunit-deprecation';
    }
  }
  // Add to the command the file containing the test class to be run.
  $reflectedClass = new \ReflectionClass($test_class_name);
  $command[] = $reflectedClass->getFileName();
  // Invoke PHPUnit CLI with the built command line.
  $process = new Process($command, \Drupal::root() . "/core", $process_environment_variables);
  $process->setTimeout(NULL);
  $process->run();
  $output = explode("\n", $process->getOutput());
  $errorOutput = $process->getErrorOutput();
  if (!empty($errorOutput)) {
    $error = explode("\n", $process->getErrorOutput());
  }
  $status = $process->getExitCode();
}

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