function PhpUnitTestRunner::phpUnitCommand

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

Returns the command to run PHPUnit.

@internal

Return value

string The command that can be run through exec().

1 call to PhpUnitTestRunner::phpUnitCommand()
PhpUnitTestRunner::runCommand in core/lib/Drupal/Core/Test/PhpUnitTestRunner.php
Executes the PHPUnit command.

File

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

Class

PhpUnitTestRunner
Run PHPUnit-based tests.

Namespace

Drupal\Core\Test

Code

public function phpUnitCommand() : string {
    // Load the actual autoloader being used and determine its filename using
    // reflection. We can determine the vendor directory based on that filename.
    $autoloader = (require $this->appRoot . '/autoload.php');
    $reflector = new \ReflectionClass($autoloader);
    $vendor_dir = dirname($reflector->getFileName(), 2);
    // The file in Composer's bin dir is a *nix link, which does not work when
    // extracted from a tarball and generally not on Windows.
    $command = $vendor_dir . '/phpunit/phpunit/phpunit';
    if (str_starts_with(PHP_OS, 'WIN')) {
        // On Windows it is necessary to run the script using the PHP executable.
        $php_executable_finder = new PhpExecutableFinder();
        $php = $php_executable_finder->find();
        $command = $php . ' -f ' . escapeshellarg($command) . ' --';
    }
    return $command;
}

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