diff --git a/core/modules/simpletest/tests/modules/phpunit_test/phpunit_test.info.yml b/core/modules/simpletest/tests/modules/phpunit_test/phpunit_test.info.yml new file mode 100644 index 0000000..0fd89ae --- /dev/null +++ b/core/modules/simpletest/tests/modules/phpunit_test/phpunit_test.info.yml @@ -0,0 +1,7 @@ +name: PHPUnit Test +type: module +description: 'Provides dummy classes for use by SimpleTest tests.' +package: Testing +version: VERSION +core: 8.x +hidden: TRUE diff --git a/core/tests/bootstrap.php b/core/tests/bootstrap.php index 08d8871..b82cd22 100644 --- a/core/tests/bootstrap.php +++ b/core/tests/bootstrap.php @@ -1,21 +1,87 @@ getPathname(), 'info.yml') !== FALSE) { + // Cut of ".info.yml" from the filename and use that as module name. + $module_directories[substr($d->getFilename(), 0, -9)] = $d->getPathInfo()->getRealPath(); + } + } + + return $module_directories; +} + +/** + * Finds site-specific module directories given the path to the sites folder. + * + * @param string $sites_path + * The path to the sites folder. + * @return array + * An array of site-specific module directories. + */ +function drupal_phpunit_find_site_module_directories($sites_path) { + $module_paths = array_map(function($dir) use ($sites_path) { + $module_dir = "$sites_path/$dir/modules"; + if (is_dir($module_dir)) { + return realpath($module_dir); + } + }, scandir($sites_path)); + return array_filter($module_paths); +} + +/** + * Registers the namespace for each module directory with the autoloader. + * + * @param Composer\Autoload\ClassLoader $loader + * The supplied autoloader. + * @param array $dirs + * An array of module directories. + */ +function drupal_phpunit_register_module_dirs(Composer\Autoload\ClassLoader $loader, $dirs) { + foreach ($dirs as $module => $dir) { + $lib_path = $dir . '/lib'; + if (is_dir($lib_path)) { + $loader->add('Drupal\\' . $module, $lib_path); + } + $tests_path = $dir . '/tests'; + if (is_dir($tests_path)) { + $loader->add('Drupal\\' . $module, $tests_path); + } + } +} + +// Start with classes in known locations. $loader = require __DIR__ . "/../vendor/autoload.php"; $loader->add('Drupal\\', __DIR__); $loader->add('Drupal\Core', __DIR__ . "/../../core/lib"); $loader->add('Drupal\Component', __DIR__ . "/../../core/lib"); -foreach (scandir(__DIR__ . "/../modules") as $module) { - $loader->add('Drupal\\' . $module, __DIR__ . "/../modules/" . $module . "/lib"); - // Add test module classes. - $test_modules_dir = __DIR__ . "/../modules/$module/tests/modules"; - if (is_dir($test_modules_dir)) { - foreach (scandir($test_modules_dir) as $test_module) { - $loader->add('Drupal\\' . $test_module, $test_modules_dir . '/' . $test_module . '/lib'); - } - } -} +// Scan for arbitrary module namespaces. +$module_locations = array_merge(array( + __DIR__ . "/../modules", + __DIR__ . "/../../modules", +), drupal_phpunit_find_site_module_directories(__DIR__ . "/../../sites")); + +$dirs = array_map('drupal_phpunit_find_module_directories', $module_locations); +$dirs = array_reduce($dirs, 'array_merge', array()); +drupal_phpunit_register_module_dirs($loader, $dirs); require __DIR__ . "/../../core/lib/Drupal.php"; // Look into removing this later.