diff --git a/core/modules/simpletest/src/TestDiscovery.php b/core/modules/simpletest/src/TestDiscovery.php index 903a64a..8b3573d 100644 --- a/core/modules/simpletest/src/TestDiscovery.php +++ b/core/modules/simpletest/src/TestDiscovery.php @@ -103,6 +103,11 @@ public function registerTestNamespaces() { $this->testNamespaces['Drupal\\FunctionalTests\\'] = [$this->root . '/core/tests/Drupal/FunctionalTests']; $this->testNamespaces['Drupal\\FunctionalJavascriptTests\\'] = [$this->root . '/core/tests/Drupal/FunctionalJavascriptTests']; + // Add core namespaces to autoloader. + foreach ($this->testNamespaces as $prefix => $paths) { + $this->classLoader->addPsr4($prefix, $paths); + } + $this->availableExtensions = array(); foreach ($this->getExtensions() as $name => $extension) { $this->availableExtensions[$extension->getType()][$name] = $name; @@ -116,12 +121,17 @@ public function registerTestNamespaces() { // Add Simpletest test namespace. $this->testNamespaces["Drupal\\$name\\Tests\\"][] = "$base_path/src/Tests"; - // Add PHPUnit-based test namespaces. - $this->testNamespaces["Drupal\\Tests\\$name\\"][] = "$base_path/tests/src"; - } - - foreach ($this->testNamespaces as $prefix => $paths) { - $this->classLoader->addPsr4($prefix, $paths); + // Add PHPUnit test suite namespaces. + $this->testNamespaces["Drupal\\Tests\\$name\\Unit\\"][] = "$base_path/tests/src/Unit"; + $this->testNamespaces["Drupal\\Tests\\$name\\Kernel\\"][] = "$base_path/tests/src/Kernel"; + $this->testNamespaces["Drupal\\Tests\\$name\\Functional\\"][] = "$base_path/tests/src/Functional"; + $this->testNamespaces["Drupal\\Tests\\$name\\FunctionalJavascript\\"][] = "$base_path/tests/src/FunctionalJavascript"; + + // Register module namespace with classloader. We support loading from a + // more lenient namespace for traits and helpers. + // @see drupal_phpunit_populate_class_loader() + // @see drupal_phpunit_get_extension_namespaces() + $this->classLoader->addPsr4("Drupal\\Tests\\$name\\", "$base_path/tests/src"); } return $this->testNamespaces; @@ -438,8 +448,8 @@ public static function parseTestClassAnnotations(\ReflectionClass $class) { /** * Determines the phpunit testsuite for a given classname. * - * The current PHPUnit test suites are: Unit, Kernel, Functional, - * FunctionalJavascript, and Unclassified. + * The current PHPUnit test suites are: Unit, Kernel, Functional, and + * FunctionalJavascript * * @param string $classname * The test classname. @@ -461,9 +471,7 @@ public static function getPhpunitTestSuite($classname) { if (in_array($matches[2], ['Unit', 'Kernel', 'Functional', 'FunctionalJavascript'])) { return $matches[2]; } - // If there is no match with the defined suites fallback to 'Unclassified' - // as all tests must have a non-empty value for a test suite. - return 'Unclassified'; + return FALSE; } // Core tests. elseif (preg_match('/Drupal\\\\(\w*)Tests\\\\/', $classname, $matches)) { diff --git a/core/modules/simpletest/tests/src/Unit/TestDiscoveryTest.php b/core/modules/simpletest/tests/src/Unit/TestDiscoveryTest.php index a7dd062..2dbb8b7 100644 --- a/core/modules/simpletest/tests/src/Unit/TestDiscoveryTest.php +++ b/core/modules/simpletest/tests/src/Unit/TestDiscoveryTest.php @@ -127,11 +127,15 @@ public function testRegisterTestNamespaces() { // the classloader if the module is not 'enabled'. $src_namespace = 'Drupal\\test_module\\'; $this->assertArrayHasKey($src_namespace, $classloader_psr4); + $this->assertArrayHasKey('Drupal\\Tests\\test_module\\', $classloader_psr4); $this->assertFalse(isset($discovery_psr4[$src_namespace])); $test_namespaces = [ 'Drupal\\test_module\\Tests\\', - 'Drupal\\Tests\\test_module\\', + 'Drupal\\Tests\\test_module\\Unit\\', + 'Drupal\\Tests\\test_module\\Kernel\\', + 'Drupal\\Tests\\test_module\\Functional\\', + 'Drupal\\Tests\\test_module\\FunctionalJavascript\\', ]; foreach ($test_namespaces as $test_namespace) { $this->assertArrayHasKey($test_namespace, $discovery_psr4); @@ -168,7 +172,6 @@ public function testGetTestClasses() { 'Drupal\Tests\test_module\Functional\FunctionalExampleTest2' => 'PHPUnit-Functional', 'Drupal\Tests\test_module\Kernel\KernelExampleTest' => 'PHPUnit-Kernel', 'Drupal\Tests\test_module\FunctionalJavascript\FunctionalJavascriptTest' => 'PHPUnit-FunctionalJavascript', - 'Drupal\Tests\test_module\Integration\IntegrationTest' => 'PHPUnit-Unclassified', 'Drupal\Tests\test_module\Unit\UnitTest' => 'PHPUnit-Unit', ]; foreach ($expected_classes as $expected_class => $expected_testsuite) { @@ -220,7 +223,7 @@ public function providerTestGetPhpunitTestSuite() { ]; $data['module-unclassified'] = [ '\Drupal\Tests\rules\Integration\RulesIntegrationTest', - 'Unclassified', + FALSE, ]; $data['core-unittest'] = [ '\Drupal\Tests\ComposerIntegrationTest', diff --git a/core/phpunit.xml.dist b/core/phpunit.xml.dist index 507ee16..2b45c64 100644 --- a/core/phpunit.xml.dist +++ b/core/phpunit.xml.dist @@ -71,33 +71,6 @@ ./drush/tests - - ./modules/*/tests/src - ../modules/*/tests/src - ../profiles/*/tests/src - ../sites/*/modules/*/tests/src - - ./vendor - - ./drush/tests - - ./modules/*/tests/src/Unit - ../modules/*/tests/src/Unit - ../profiles/*/tests/src/Unit - ../sites/*/modules/*/tests/src/Unit - ./modules/*/tests/src/Kernel - ../modules/*/tests/src/Kernel - ../profiles/*/tests/src/Kernel - ../sites/*/modules/*/tests/src/Kernel - ./modules/*/tests/src/Functional - ../modules/*/tests/src/Functional - ../profiles/*/tests/src/Functional - ../sites/*/modules/*/tests/src/Functional - ./modules/*/tests/src/FunctionalJavascript - ../modules/*/tests/src/FunctionalJavascript - ../profiles/*/tests/src/FunctionalJavascript - ../sites/*/modules/*/tests/src/FunctionalJavascript -