You are here

function simpletest_phpunit_run_command in Zircon Profile 8

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

Executes the PHPUnit command.

Parameters

array $unescaped_test_classnames: An array of test class names, including full namespaces, to be passed as a regular expression to PHPUnit's --filter option.

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

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

Return value

string The results as returned by exec().

1 call to simpletest_phpunit_run_command()
simpletest_run_phpunit_tests in core/modules/simpletest/simpletest.module
Executes PHPUnit tests and returns the results of the run.

File

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

Code

function simpletest_phpunit_run_command(array $unescaped_test_classnames, $phpunit_file, &$status = NULL) {

  // Setup an environment variable containing the database connection so that
  // functional tests can connect to the database.
  putenv('SIMPLETEST_DB=' . Database::getConnectionInfoAsUrl());
  $phpunit_bin = simpletest_phpunit_command();
  $command = array(
    $phpunit_bin,
    '--log-junit',
    escapeshellarg($phpunit_file),
  );

  // Optimized for running a single test.
  if (count($unescaped_test_classnames) == 1) {
    $class = new \ReflectionClass($unescaped_test_classnames[0]);
    $command[] = escapeshellarg($class
      ->getFileName());
  }
  else {

    // Double escape namespaces so they'll work in a regexp.
    $escaped_test_classnames = array_map(function ($class) {
      return addslashes($class);
    }, $unescaped_test_classnames);
    $filter_string = implode("|", $escaped_test_classnames);
    $command = array_merge($command, array(
      '--filter',
      escapeshellarg($filter_string),
    ));
  }

  // Need to change directories before running the command so that we can use
  // relative paths in the configuration file's exclusions.
  $old_cwd = getcwd();
  chdir(\Drupal::root() . "/core");

  // exec in a subshell so that the environment is isolated when running tests
  // via the simpletest UI.
  $ret = exec(join($command, " "), $output, $status);
  chdir($old_cwd);
  putenv('SIMPLETEST_DB=');
  return $ret;
}