function PhpUnitTestRunner::prepareCommand
Prepares the context to execute a PHPUnit process.
This method prepares the command line arguments necessary to execute the tests for a single test class, as well as the necessary context of working directory and environment variables.
Parameters
\Drupal\Core\Test\TestRun $test_run: The test run object.
class-string $test_class_name: A fully qualified test class name.
bool $colors: Whether to use colors in output.
bool $suppressDeprecations: If TRUE, disables the deprecation reporting.
Return value
array{cli_command: list<string>, work_dir: string, environment_vars: array<string,string>} The process execution context.
1 call to PhpUnitTestRunner::prepareCommand()
- PhpUnitTestRunner::startPhpUnitOnSingleTestClass in core/
lib/ Drupal/ Core/ Test/ PhpUnitTestRunner.php - Starts asynchronous execution of a PHPUnit process.
File
-
core/
lib/ Drupal/ Core/ Test/ PhpUnitTestRunner.php, line 235
Class
- PhpUnitTestRunner
- Run PHPUnit-based tests.
Namespace
Drupal\Core\TestCode
protected function prepareCommand(TestRun $test_run, string $test_class_name, bool $colors = FALSE, bool $suppressDeprecations = FALSE) : array {
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;
}
// Determine the JUnit file path.
$log_junit_file_path = $this->xmlLogFilePath($test_run->id());
// PHPUnit whereabouts.
$phpunit_bin = $this->phpUnitCommand();
// Build the command line for the PHPUnit CLI invocation.
$command = [
$phpunit_bin,
'--configuration',
$this->configurationFilePath,
'--testdox',
'--log-junit',
$log_junit_file_path,
];
if ($colors) {
$command[] = '--colors=always';
}
if ($suppressDeprecations) {
$process_environment_variables['SYMFONY_DEPRECATIONS_HELPER'] = 'disabled';
}
else {
// 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();
return [
'cli_command' => $command,
'work_dir' => DRUPAL_ROOT . "/core",
'environment_vars' => $process_environment_variables,
];
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.