You are here

public function KernelTestBaseTest::testRequiresModule in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/KernelTestBaseTest.php \Drupal\KernelTests\KernelTestBaseTest::testRequiresModule()
  2. 10 core/tests/Drupal/KernelTests/KernelTestBaseTest.php \Drupal\KernelTests\KernelTestBaseTest::testRequiresModule()

Tests that a test case is skipped when it requires a module not present.

In order to catch checkRequirements() regressions, we have to make a new test object and run checkRequirements() here.

@covers ::checkRequirements @covers ::checkModuleRequirements

File

core/tests/Drupal/KernelTests/KernelTestBaseTest.php, line 283

Class

KernelTestBaseTest
@coversDefaultClass \Drupal\KernelTests\KernelTestBase

Namespace

Drupal\KernelTests

Code

public function testRequiresModule() {
  require __DIR__ . '/../../fixtures/KernelMissingDependentModuleTest.php';
  $stub_test = new KernelMissingDependentModuleTest();

  // We have to setName() to the method name we're concerned with.
  $stub_test
    ->setName('testRequiresModule');

  // We cannot use $this->setExpectedException() because PHPUnit would skip
  // the test before comparing the exception type.
  try {
    $stub_test
      ->publicCheckRequirements();
    $this
      ->fail('Missing required module throws skipped test exception.');
  } catch (SkippedTestError $e) {
    $this
      ->assertEqual('Required modules: module_does_not_exist', $e
      ->getMessage());
  }
}