private function TestRequirementsTrait::checkModuleRequirements in Drupal 10
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/TestRequirementsTrait.php \Drupal\Tests\TestRequirementsTrait::checkModuleRequirements()
- 9 core/tests/Drupal/Tests/TestRequirementsTrait.php \Drupal\Tests\TestRequirementsTrait::checkModuleRequirements()
Checks missing module requirements.
Iterates through a list of requires annotations and looks for missing modules. The test will be skipped if any of the required modules is missing.
Parameters
string $root: The path to the root of the Drupal installation to scan.
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.
File
- core/
tests/ Drupal/ Tests/ TestRequirementsTrait.php, line 82
Class
- TestRequirementsTrait
- Allows test classes to require Drupal modules as dependencies.
Namespace
Drupal\TestsCode
private function checkModuleRequirements($root, array $annotations) {
// Make a list of required modules.
$required_modules = [];
foreach ($annotations as $requirement) {
if (strpos($requirement, 'module ') === 0) {
$required_modules[] = trim(str_replace('module ', '', $requirement));
}
}
// If there are required modules, check if they're available.
if (!empty($required_modules)) {
// Scan for modules.
$discovery = new ExtensionDiscovery($root, FALSE);
$discovery
->setProfileDirectories([]);
$list = array_keys($discovery
->scan('module'));
$not_available = array_diff($required_modules, $list);
if (!empty($not_available)) {
throw new SkippedTestError('Required modules: ' . implode(', ', $not_available));
}
}
}