diff --git a/core/modules/simpletest/src/TestDiscovery.php b/core/modules/simpletest/src/TestDiscovery.php index f3b4169..05c81ef 100644 --- a/core/modules/simpletest/src/TestDiscovery.php +++ b/core/modules/simpletest/src/TestDiscovery.php @@ -33,13 +33,6 @@ class TestDiscovery { protected $cacheBackend; /** - * Cached ExtensionDiscovery. - * - * @var \Drupal\Core\Extension\ExtensionDiscovery - */ - protected $extensionDiscovery; - - /** * Cached map of all test namespaces to respective directories. * * @var array @@ -89,17 +82,19 @@ public function __construct($root, $class_loader, ModuleHandlerInterface $module } /** - * Registers test namespaces of all available extensions. + * Registers the test namespaces of all available extensions. * * @return array * An associative array whose keys are PSR-4 namespace prefixes and whose * values are directory names. + * + * @see https://www.drupal.org/node/2116043 */ public function registerTestNamespaces() { if (isset($this->testNamespaces)) { return $this->testNamespaces; } - $this->testNamespaces = []; + $this->testNamespaces = array(); $existing = $this->classLoader->getPrefixesPsr4(); @@ -109,7 +104,7 @@ public function registerTestNamespaces() { $this->testNamespaces['Drupal\\FunctionalTests\\'] = [$this->root . '/core/tests/Drupal/FunctionalTests']; $this->testNamespaces['Drupal\\FunctionalJavascriptTests\\'] = [$this->root . '/core/tests/Drupal/FunctionalJavascriptTests']; - $this->availableExtensions = []; + $this->availableExtensions = array(); foreach ($this->getExtensions() as $name => $extension) { $this->availableExtensions[$extension->getType()][$name] = $name; @@ -126,9 +121,11 @@ public function registerTestNamespaces() { // 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); } + return $this->testNamespaces; } @@ -158,6 +155,7 @@ public function registerTestNamespaces() { public function getTestClasses($extension = NULL, array $types = []) { $reader = new SimpleAnnotationReader(); $reader->addNamespace('Drupal\\simpletest\\Annotation'); + if (!isset($extension)) { if ($this->cacheBackend && $cache = $this->cacheBackend->get('simpletest:discovery:classes')) { return $cache->data; @@ -465,17 +463,21 @@ public static function getTestSuite($classname) { return 'Simpletest'; } } - throw new TestInWrongNamespaceException('Test class ' . $classname . ' is in the wrong place.'); + throw new TestInWrongNamespaceException(' -- Test class ' . $classname . ' cannot be assigned to a test suite. See https://www.drupal.org/phpunit. -- '); } /** * Determines the phpunit testsuite for a given classname. * + * The current PHPUnit test suites are: Unit, Kernel, Functional, and + * FunctionalJavascript. + * * @param string $classname * The test classname. * * @return string|false - * The testsuite name or FALSE if its not a phpunit test. + * The testsuite name or FALSE if the class name does not reflect one of + * Unit, Kernel, Functional, or FunctionalJavascript. */ public static function getPhpunitTestSuite($classname) { if (preg_match('/Drupal\\\\Tests\\\\Core\\\\(\w+)/', $classname, $matches)) { @@ -510,14 +512,12 @@ public static function getPhpunitTestSuite($classname) { * An array of Extension objects, keyed by extension name. */ protected function getExtensions() { - if (empty($this->extensionDiscovery)) { - $this->extensionDiscovery = new ExtensionDiscovery($this->root); - // Ensure that tests in all profiles are discovered. - $this->extensionDiscovery->setProfileDirectories([]); - } - $extensions = $this->extensionDiscovery->scan('module', TRUE); - $extensions += $this->extensionDiscovery->scan('profile', TRUE); - $extensions += $this->extensionDiscovery->scan('theme', TRUE); + $listing = new ExtensionDiscovery($this->root); + // Ensure that tests in all profiles are discovered. + $listing->setProfileDirectories(array()); + $extensions = $listing->scan('module', TRUE); + $extensions += $listing->scan('profile', TRUE); + $extensions += $listing->scan('theme', TRUE); return $extensions; }