Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/Tests/TestRequirementsTrait.php \Drupal\Tests\TestRequirementsTrait::checkRequirements()
  2. 9 core/tests/Drupal/Tests/TestRequirementsTrait.php \Drupal\Tests\TestRequirementsTrait::checkRequirements()

Check module requirements for the Drupal use case.

This method is assumed to override \PHPUnit\Framework\TestCase::checkRequirements().

Throws

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

Deprecated

in drupal:10.3.0 and is removed from drupal:11.0.0. There is no replacement.

See also

https://www.drupal.org/node/3418480

File

core/tests/Drupal/Tests/TestRequirementsTrait.php, line 44

Class

TestRequirementsTrait
Allows test classes to require Drupal modules as dependencies.

Namespace

Drupal\Tests

Code

protected function checkRequirements() {
  @trigger_error(__METHOD__ . '() is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3418480', E_USER_DEPRECATED);
  if (!$this
    ->getName(FALSE) || !method_exists($this, $this
    ->getName(FALSE))) {
    return;
  }
  $missingRequirements = Test::getMissingRequirements(static::class, $this
    ->getName(FALSE));
  if (!empty($missingRequirements)) {
    $this
      ->markTestSkipped(implode(PHP_EOL, $missingRequirements));
  }
  $root = static::getDrupalRoot();

  // Check if required dependencies exist.
  $annotations = Test::parseTestMethodAnnotations(static::class, $this
    ->getName());
  if (!empty($annotations['class']['requires'])) {
    $this
      ->checkModuleRequirements($root, $annotations['class']['requires']);
  }
  if (!empty($annotations['method']['requires'])) {
    $this
      ->checkModuleRequirements($root, $annotations['method']['requires']);
  }
}