diff --git a/core/modules/simpletest/src/TestDiscovery.php b/core/modules/simpletest/src/TestDiscovery.php index 02bf7071fb..9270b5fe2b 100644 --- a/core/modules/simpletest/src/TestDiscovery.php +++ b/core/modules/simpletest/src/TestDiscovery.php @@ -189,14 +189,17 @@ public function getTestClasses($extension = NULL, array $types = []) { // abstract class, trait or test fixture. continue; } - // Skip this test class if it requires unavailable modules. - // @todo PHPUnit skips tests with unmet requirements when executing a test - // (instead of excluding them upfront). Refactor test runner to follow - // that approach. + // Skip this test class if it is a Simpletest-based test and requires + // unavailable modules. TestDiscovery should not filter out module + // requirements for PHPUnit-based test classes. + // @todo Move this behavior to \Drupal\simpletest\TestBase so tests can be + // marked as skipped, instead. // @see https://www.drupal.org/node/1273478 - if (!empty($info['requires']['module'])) { - if (array_diff($info['requires']['module'], $this->availableExtensions['module'])) { - continue; + if (!is_subclass_of($classname, \PHPUnit_Framework_TestCase::class)) { + if (!empty($info['requires']['module'])) { + if (array_diff($info['requires']['module'], $this->availableExtensions['module'])) { + continue; + } } } diff --git a/core/modules/simpletest/tests/src/Functional/MissingDependentModuleUnitTest.php b/core/modules/simpletest/tests/src/Functional/MissingDependentModuleUnitTest.php deleted file mode 100644 index 885a44c706..0000000000 --- a/core/modules/simpletest/tests/src/Functional/MissingDependentModuleUnitTest.php +++ /dev/null @@ -1,22 +0,0 @@ -fail('Running test with missing required module.'); - } - -} diff --git a/core/tests/Drupal/KernelTests/KernelTestBaseTest.php b/core/tests/Drupal/KernelTests/KernelTestBaseTest.php index 66765d9bd5..9880132b2f 100644 --- a/core/tests/Drupal/KernelTests/KernelTestBaseTest.php +++ b/core/tests/Drupal/KernelTests/KernelTestBaseTest.php @@ -206,6 +206,12 @@ public function testRenderWithTheme() { } /** + * 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. + * * @covers ::checkRequirements * @covers ::checkModuleRequirements */ diff --git a/core/tests/fixtures/MissingDependentModuleMethodTest.php b/core/tests/fixtures/MissingDependentModuleMethodTest.php index 6e59af2846..15f0a23759 100644 --- a/core/tests/fixtures/MissingDependentModuleMethodTest.php +++ b/core/tests/fixtures/MissingDependentModuleMethodTest.php @@ -2,11 +2,18 @@ namespace Drupal\KernelTests; -use Drupal\Component\FileCache\FileCacheFactory; -use Drupal\Core\Database\Database; -use org\bovigo\vfs\vfsStream; -use org\bovigo\vfs\visitor\vfsStreamStructureVisitor; +use Drupal\KernelTests\KernelTestBase; +/** + * A fixture test class with @requires annotation. + * + * This is a fixture class for + * \Drupal\KernelTests\KernelTestBaseTest::testRequiresModule(). + * + * This test class should not be discovered by run-tests.sh or phpunit. + * + * @group fixture + */ class MissingDependentModuleMethodTest extends KernelTestBase { /** diff --git a/core/tests/fixtures/MissingDependentModuleTest.php b/core/tests/fixtures/MissingDependentModuleTest.php index fbd405193b..ce2c49e593 100644 --- a/core/tests/fixtures/MissingDependentModuleTest.php +++ b/core/tests/fixtures/MissingDependentModuleTest.php @@ -2,7 +2,29 @@ namespace Drupal\KernelTests; +use Drupal\KernelTests\KernelTestBase; + /** + * A fixture test class with @requires annotation. + * + * This is a fixture class for + * \Drupal\KernelTests\KernelTestBaseTest::testRequiresModule(). + * + * This test class should not be discovered by run-tests.sh or phpunit. + * * @requires module drupal_dne_module + * @group fixture */ -class MissingDependentModuleTest extends KernelTestBase {} +class MissingDependentModuleTest extends KernelTestBase { + + /** + * Placeholder test method. + * + * Depending on configuration, PHPUnit might fail a test if it has no test + * methods, so we must provide one. This method should never be executed. + */ + public function testRequiresModule() { + $this->fail('Running test with missing required module.'); + } + +}