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()
- 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 $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
protected function runCommand(string $test_class_name, string $log_junit_file_path, ?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();
// Build the command line for the PHPUnit CLI invocation.
$command = [
$phpunit_bin,
'--log-junit',
$log_junit_file_path,
];
// If the deprecation handler bridge is active, we need to fail when there
// are deprecations that get reported (i.e. not ignored or expected).
if (DeprecationHandler::getConfiguration() !== FALSE) {
$command[] = '--fail-on-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());
$status = $process->getExitCode();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.