function ExternalCommandRequirementsTrait::checkExternalCommandRequirements

Same name and namespace in other branches
  1. 9 core/tests/Drupal/BuildTests/Framework/ExternalCommandRequirementsTrait.php \Drupal\BuildTests\Framework\ExternalCommandRequirementsTrait::checkExternalCommandRequirements()
  2. 10 core/tests/Drupal/BuildTests/Framework/ExternalCommandRequirementsTrait.php \Drupal\BuildTests\Framework\ExternalCommandRequirementsTrait::checkExternalCommandRequirements()

Checks missing external command requirements.

Parameters

string[] $annotations: A list of requires annotations from either a method or class annotation.

Throws

\PHPUnit\Framework\SkippedTestError Thrown when the requirements are not met, and this test should be skipped. Callers should not catch this exception.

2 calls to ExternalCommandRequirementsTrait::checkExternalCommandRequirements()
ExternalCommandRequirementsTrait::checkClassCommandRequirements in core/tests/Drupal/BuildTests/Framework/ExternalCommandRequirementsTrait.php
Checks whether required external commands are available per test class.
ExternalCommandRequirementsTrait::checkMethodCommandRequirements in core/tests/Drupal/BuildTests/Framework/ExternalCommandRequirementsTrait.php
Checks whether required external commands are available per method.

File

core/tests/Drupal/BuildTests/Framework/ExternalCommandRequirementsTrait.php, line 61

Class

ExternalCommandRequirementsTrait
Allows test classes to require external command line applications.

Namespace

Drupal\BuildTests\Framework

Code

private static function checkExternalCommandRequirements(array $annotations) {
    // Make a list of required commands.
    $required_commands = [];
    foreach ($annotations as $requirement) {
        if (strpos($requirement, 'externalCommand ') === 0) {
            $command = trim(str_replace('externalCommand ', '', $requirement));
            // Use named keys to avoid duplicates.
            $required_commands[$command] = $command;
        }
    }
    // Figure out which commands are not available.
    $unavailable = [];
    foreach ($required_commands as $required_command) {
        if (!in_array($required_command, self::$existingCommands)) {
            if (static::externalCommandIsAvailable($required_command)) {
                // Cache existing commands so we don't have to ask again.
                self::$existingCommands[] = $required_command;
            }
            else {
                $unavailable[] = $required_command;
            }
        }
    }
    // Skip the test if there were some we couldn't find.
    if (!empty($unavailable)) {
        throw new SkippedTestError('Required external commands: ' . implode(', ', $unavailable));
    }
}

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