diff --git a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php index ef0f3ce4fa..3a0750113c 100644 --- a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php +++ b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php @@ -517,42 +517,4 @@ public function testLocalTimeZone() { $this->assertEquals('Australia/Sydney', $value); } - /** - * 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. - */ - public function testMethodRequiresModule() { - require __DIR__ . '/../../fixtures/BrowserMissingDependentModuleMethodTest.php'; - - $test = new BrowserMissingDependentModuleMethodTest(); - // We have to setName() to the method name we're concerned with. - $test->setName('testRequiresModule'); - $this->setExpectedException( - \PHPUnit_Framework_SkippedTestError::class, - 'Module module_does_not_exist is required.' - ); - $test->checkRequirements(); - } - - /** - * 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. - */ - public function testRequiresModule() { - require __DIR__ . '/../../fixtures/BrowserMissingDependentModuleTest.php'; - - $test = new BrowserMissingDependentModuleTest(); - // We have to setName() to the method name we're concerned with. - $test->setName('testRequiresModule'); - $this->setExpectedException( - \PHPUnit_Framework_SkippedTestError::class, - 'Module module_does_not_exist is required.' - ); - $test->checkRequirements(); - } - } diff --git a/core/tests/Drupal/KernelTests/Core/Test/BrowserTestBaseTest.php b/core/tests/Drupal/KernelTests/Core/Test/BrowserTestBaseTest.php index 056441ae1e..c93069c8e4 100644 --- a/core/tests/Drupal/KernelTests/Core/Test/BrowserTestBaseTest.php +++ b/core/tests/Drupal/KernelTests/Core/Test/BrowserTestBaseTest.php @@ -29,14 +29,11 @@ public function testMethodRequiresModule() { $stub_test = new BrowserMissingDependentModuleMethodTest(); // We have to setName() to the method name we're concerned with. $stub_test->setName('testRequiresModule'); - $class = new \ReflectionClass($stub_test); - $check_requirements = $class->getMethod('checkRequirements'); - $check_requirements->setAccessible(TRUE); // We cannot use $this->setExpectedException() because PHPUnit would skip // the test before comparing the exception type. try { - $check_requirements->invoke($stub_test); + $stub_test->publicCheckRequirements(); $this->fail('Missing required module throws skipped test exception.'); } catch (\PHPUnit_Framework_SkippedTestError $e) { @@ -59,14 +56,11 @@ public function testRequiresModule() { $stub_test = new BrowserMissingDependentModuleTest(); // We have to setName() to the method name we're concerned with. $stub_test->setName('testRequiresModule'); - $class = new \ReflectionClass($stub_test); - $check_requirements = $class->getMethod('checkRequirements'); - $check_requirements->setAccessible(TRUE); // We cannot use $this->setExpectedException() because PHPUnit would skip // the test before comparing the exception type. try { - $check_requirements->invoke($stub_test); + $stub_test->publicCheckRequirements(); $this->fail('Missing required module throws skipped test exception.'); } catch (\PHPUnit_Framework_SkippedTestError $e) { diff --git a/core/tests/Drupal/KernelTests/KernelTestBaseTest.php b/core/tests/Drupal/KernelTests/KernelTestBaseTest.php index 6560c7a69a..720963f51d 100644 --- a/core/tests/Drupal/KernelTests/KernelTestBaseTest.php +++ b/core/tests/Drupal/KernelTests/KernelTestBaseTest.php @@ -4,6 +4,8 @@ use Drupal\Component\FileCache\FileCacheFactory; use Drupal\Core\Database\Database; +use Drupal\KernelTests\KernelMissingDependentModuleMethodTest; +use Drupal\KernelTests\KernelMissingDependentModuleTest; use org\bovigo\vfs\vfsStream; use org\bovigo\vfs\visitor\vfsStreamStructureVisitor; @@ -238,14 +240,11 @@ public function testMethodRequiresModule() { $stub_test = new KernelMissingDependentModuleMethodTest(); // We have to setName() to the method name we're concerned with. $stub_test->setName('testRequiresModule'); - $class = new \ReflectionClass($stub_test); - $check_requirements = $class->getMethod('checkRequirements'); - $check_requirements->setAccessible(TRUE); // We cannot use $this->setExpectedException() because PHPUnit would skip // the test before comparing the exception type. try { - $check_requirements->invoke($stub_test); + $stub_test->publicCheckRequirements(); $this->fail('Missing required module throws skipped test exception.'); } catch (\PHPUnit_Framework_SkippedTestError $e) { @@ -268,14 +267,11 @@ public function testRequiresModule() { $stub_test = new KernelMissingDependentModuleTest(); // We have to setName() to the method name we're concerned with. $stub_test->setName('testRequiresModule'); - $class = new \ReflectionClass($stub_test); - $check_requirements = $class->getMethod('checkRequirements'); - $check_requirements->setAccessible(TRUE); // We cannot use $this->setExpectedException() because PHPUnit would skip // the test before comparing the exception type. try { - $check_requirements->invoke($stub_test); + $stub_test->publicCheckRequirements(); $this->fail('Missing required module throws skipped test exception.'); } catch (\PHPUnit_Framework_SkippedTestError $e) { diff --git a/core/tests/fixtures/BrowserMissingDependentModuleMethodTest.php b/core/tests/fixtures/BrowserMissingDependentModuleMethodTest.php index 9d6778b1cf..4a94a53691 100644 --- a/core/tests/fixtures/BrowserMissingDependentModuleMethodTest.php +++ b/core/tests/fixtures/BrowserMissingDependentModuleMethodTest.php @@ -25,4 +25,11 @@ public function testRequiresModule() { $this->fail('Running test with missing required module.'); } + /** + * Public access for checkRequirements() to avoid reflection. + */ + public function publicCheckRequirements() { + return parent::checkRequirements(); + } + } diff --git a/core/tests/fixtures/BrowserMissingDependentModuleTest.php b/core/tests/fixtures/BrowserMissingDependentModuleTest.php index 78633bfa60..9650fc1b95 100644 --- a/core/tests/fixtures/BrowserMissingDependentModuleTest.php +++ b/core/tests/fixtures/BrowserMissingDependentModuleTest.php @@ -27,4 +27,11 @@ public function testRequiresModule() { $this->fail('Running test with missing required module.'); } + /** + * Public access for checkRequirements() to avoid reflection. + */ + public function publicCheckRequirements() { + return parent::checkRequirements(); + } + } diff --git a/core/tests/fixtures/KernelMissingDependentModuleMethodTest.php b/core/tests/fixtures/KernelMissingDependentModuleMethodTest.php index 40b73da208..33dc79389f 100644 --- a/core/tests/fixtures/KernelMissingDependentModuleMethodTest.php +++ b/core/tests/fixtures/KernelMissingDependentModuleMethodTest.php @@ -23,4 +23,11 @@ public function testRequiresModule() { $this->fail('Running test with missing required module.'); } + /** + * Public access for checkRequirements() to avoid reflection. + */ + public function publicCheckRequirements() { + return parent::checkRequirements(); + } + } diff --git a/core/tests/fixtures/KernelMissingDependentModuleTest.php b/core/tests/fixtures/KernelMissingDependentModuleTest.php index 6ca5c328b3..3b8f316b22 100644 --- a/core/tests/fixtures/KernelMissingDependentModuleTest.php +++ b/core/tests/fixtures/KernelMissingDependentModuleTest.php @@ -25,4 +25,11 @@ public function testRequiresModule() { $this->fail('Running test with missing required module.'); } + /** + * Public access for checkRequirements() to avoid reflection. + */ + public function publicCheckRequirements() { + return parent::checkRequirements(); + } + }