You are here

protected function TestRequirementsTrait::checkRequirements in Drupal 10

Same name and namespace in other branches
  1. 8 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.

4 calls to TestRequirementsTrait::checkRequirements()
BrowserMissingDependentModuleMethodTest::publicCheckRequirements in core/tests/fixtures/BrowserMissingDependentModuleMethodTest.php
Public access for checkRequirements() to avoid reflection.
BrowserMissingDependentModuleTest::publicCheckRequirements in core/tests/fixtures/BrowserMissingDependentModuleTest.php
Public access for checkRequirements() to avoid reflection.
KernelMissingDependentModuleMethodTest::publicCheckRequirements in core/tests/fixtures/KernelMissingDependentModuleMethodTest.php
Public access for checkRequirements() to avoid reflection.
KernelMissingDependentModuleTest::publicCheckRequirements in core/tests/fixtures/KernelMissingDependentModuleTest.php
Public access for checkRequirements() to avoid reflection.

File

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

Class

TestRequirementsTrait
Allows test classes to require Drupal modules as dependencies.

Namespace

Drupal\Tests

Code

protected function checkRequirements() {
  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']);
  }
}