Mercurial > hg > cmmr2012-drupal-site
diff core/modules/simpletest/src/TestDiscovery.php @ 4:a9cd425dd02b
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:11:55 +0000 |
parents | c75dbcec494b |
children | 12f9dff5fda9 |
line wrap: on
line diff
--- a/core/modules/simpletest/src/TestDiscovery.php Thu Feb 28 11:14:44 2019 +0000 +++ b/core/modules/simpletest/src/TestDiscovery.php Thu Feb 28 13:11:55 2019 +0000 @@ -6,7 +6,6 @@ use Doctrine\Common\Reflection\StaticReflectionParser; use Drupal\Component\Annotation\Reflection\MockFileFinder; use Drupal\Component\Utility\NestedArray; -use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Extension\ExtensionDiscovery; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\simpletest\Exception\MissingGroupException; @@ -25,11 +24,11 @@ protected $classLoader; /** - * Backend for caching discovery results. + * Statically cached list of test classes. * - * @var \Drupal\Core\Cache\CacheBackendInterface + * @var array */ - protected $cacheBackend; + protected $testClasses; /** * Cached map of all test namespaces to respective directories. @@ -70,14 +69,11 @@ * \Symfony\Component\ClassLoader\ApcClassLoader. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler. - * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend - * (optional) Backend for caching discovery results. */ - public function __construct($root, $class_loader, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache_backend = NULL) { + public function __construct($root, $class_loader, ModuleHandlerInterface $module_handler) { $this->root = $root; $this->classLoader = $class_loader; $this->moduleHandler = $module_handler; - $this->cacheBackend = $cache_backend; } /** @@ -159,9 +155,9 @@ $reader = new SimpleAnnotationReader(); $reader->addNamespace('Drupal\\simpletest\\Annotation'); - if (!isset($extension)) { - if ($this->cacheBackend && $cache = $this->cacheBackend->get('simpletest:discovery:classes')) { - return $cache->data; + if (!isset($extension) && empty($types)) { + if (!empty($this->testClasses)) { + return $this->testClasses; } } $list = []; @@ -213,12 +209,10 @@ } // Allow modules extending core tests to disable originals. - $this->moduleHandler->alter('simpletest', $list); + $this->moduleHandler->alterDeprecated('Convert your test to a PHPUnit-based one and implement test listeners. See: https://www.drupal.org/node/2939892', 'simpletest', $list); - if (!isset($extension)) { - if ($this->cacheBackend) { - $this->cacheBackend->set('simpletest:discovery:classes', $list); - } + if (!isset($extension) && empty($types)) { + $this->testClasses = $list; } if ($types) { @@ -288,13 +282,21 @@ $flags |= \FilesystemIterator::SKIP_DOTS; $flags |= \FilesystemIterator::FOLLOW_SYMLINKS; $flags |= \FilesystemIterator::CURRENT_AS_SELF; + $flags |= \FilesystemIterator::KEY_AS_FILENAME; $iterator = new \RecursiveDirectoryIterator($path, $flags); - $filter = new \RecursiveCallbackFilterIterator($iterator, function ($current, $key, $iterator) { + $filter = new \RecursiveCallbackFilterIterator($iterator, function ($current, $file_name, $iterator) { if ($iterator->hasChildren()) { return TRUE; } - return $current->isFile() && $current->getExtension() === 'php'; + // We don't want to discover abstract TestBase classes, traits or + // interfaces. They can be deprecated and will call @trigger_error() + // during discovery. + return + substr($file_name, -4) === '.php' && + substr($file_name, -12) !== 'TestBase.php' && + substr($file_name, -9) !== 'Trait.php' && + substr($file_name, -13) !== 'Interface.php'; }); $files = new \RecursiveIteratorIterator($filter); $classes = [];