function PhpUnitTestRunner::runCommand
Same name in other branches
- 9 core/lib/Drupal/Core/Test/PhpUnitTestRunner.php \Drupal\Core\Test\PhpUnitTestRunner::runCommand()
- 8.9.x core/lib/Drupal/Core/Test/PhpUnitTestRunner.php \Drupal\Core\Test\PhpUnitTestRunner::runCommand()
- 11.x core/lib/Drupal/Core/Test/PhpUnitTestRunner.php \Drupal\Core\Test\PhpUnitTestRunner::runCommand()
Executes the PHPUnit command.
@internal
Parameters
string[] $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.
string[] $output: (optional) The output by running the phpunit command. If provided, this array will contain the lines output by the command.
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 112
Class
- PhpUnitTestRunner
- Run PHPUnit-based tests.
Namespace
Drupal\Core\TestCode
public function runCommand(array $unescaped_test_classnames, string $phpunit_file, ?int &$status = NULL, ?array &$output = NULL) : void {
global $base_url;
// Setup an environment variable containing the database connection so that
// functional tests can connect to the database.
$process_environment_variables = [
'SIMPLETEST_DB' => Database::getConnectionInfoAsUrl(),
];
// 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();
$command = [
$phpunit_bin,
'--log-junit',
$phpunit_file,
];
// Optimized for running a single test.
if (count($unescaped_test_classnames) == 1) {
$class = new \ReflectionClass($unescaped_test_classnames[0]);
$command[] = $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, [
'--filter',
$filter_string,
]);
}
$process = new Process($command, \Drupal::root() . "/core", $process_environment_variables);
$process->setTimeout(NULL);
$process->run();
$output = explode("\n", $process->getOutput());
$status = $process->getExitCode();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.