diff --git a/core/tests/Drupal/KernelTests/KernelTestBaseTest.php b/core/tests/Drupal/KernelTests/KernelTestBaseTest.php index 4ddf095d26..be45e13051 100644 --- a/core/tests/Drupal/KernelTests/KernelTestBaseTest.php +++ b/core/tests/Drupal/KernelTests/KernelTestBaseTest.php @@ -206,37 +206,47 @@ public function testRenderWithTheme() { } /** + * Tests that a test method 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 + */ + public function testMethodRequiresModule() { + $this->setExpectedException( + \PHPUnit_Framework_SkippedTestError::class, + 'Module drupal_dne_module is required.' + ); + + require __DIR__ . '/../../fixtures/MissingDependentModuleMethodTest.php'; + + $test = new MissingDependentModuleMethodTest(); + $test->setName('testMethodRequiresModule'); + $test->checkRequirements(); + } + + /** * Tests that a test case is skipped when it @requires a module not present. * - * In order to have a failing test when the annotated test classes run, we - * have to run the tests here and discover whether they threw - * \PHPUnit_Framework_SkippedTestError. + * In order to catch checkRequirements() regressions, we have to make a new + * test object and run checkRequirements() here. * * @covers ::checkRequirements * @covers ::checkModuleRequirements */ public function testRequiresModule() { - require __DIR__ . '/../../fixtures/MissingDependentModuleMethodTest.php'; - require __DIR__ . '/../../fixtures/MissingDependentModuleTest.php'; + $this->setExpectedException( + \PHPUnit_Framework_SkippedTestError::class, + 'Module drupal_dne_module is required.' + ); - $test1 = new MissingDependentModuleMethodTest(); - $test1->setName('testRequiresModule'); - try { - $test1->checkRequirements(); - $this->fail('Requirement on method not found.'); - } - catch (\PHPUnit_Framework_SkippedTestError $e) { - $this->assertEquals('Module drupal_dne_module is required.', $e->getMessage()); - } + require __DIR__ . '/../../fixtures/MissingDependentModuleTest.php'; - $test2 = new MissingDependentModuleTest(); - try { - $test2->checkRequirements(); - $this->fail('Requirement on class not found.'); - } - catch (\PHPUnit_Framework_SkippedTestError $e) { - $this->assertEquals('Module drupal_dne_module is required.', $e->getMessage()); - } + $test = new MissingDependentModuleTest(); + $test->setName('testRequiresModule'); + $test->checkRequirements(); } /**