Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 9 additions & 16 deletions src/Drupal/DrupalAutoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
use Drupal\Component\DependencyInjection\Container as DrupalContainer;
use Drupal\Core\DependencyInjection\ContainerNotInitializedException;
use Drupal\Core\DrupalKernelInterface;
use Drupal\TestTools\PhpUnitCompatibility\PhpUnit8\ClassWriter;
use DrupalFinder\DrupalFinderComposerRuntime;
use Drush\Drush;
use PHPStan\DependencyInjection\Container;
use PHPUnit\Framework\Test;
use ReflectionClass;
use RuntimeException;
use Symfony\Component\DependencyInjection\ContainerInterface;
Expand All @@ -24,12 +22,11 @@
use function dirname;
use function file_exists;
use function in_array;
use function interface_exists;
use function is_array;
use function is_dir;
use function is_string;
use function str_contains;
use function str_replace;
use function strpos;
use function strtr;
use function trigger_error;
use function ucwords;
Expand Down Expand Up @@ -124,8 +121,13 @@ public function register(Container $container): void
$extensionDiscovery->setProfileDirectories($profile_directories);

$this->moduleData = array_merge($extensionDiscovery->scan('module'), $profiles);
usort($this->moduleData, static function (Extension $a, Extension $b) {
return strpos($a->getName(), '_test') !== false ? 10 : 0;
// Load test extensions after regular ones. Test modules stub functions
// from their parent module behind function_exists() guards, so if the
// test module's .module file loads first the parent's unconditional
// declaration is a compile error that loadAndCatchErrors() cannot
// intercept.
usort($this->moduleData, static function (Extension $a, Extension $b): int {
return str_contains($a->getName(), '_test') <=> str_contains($b->getName(), '_test');
});
$this->themeData = $extensionDiscovery->scan('theme');
$this->addCoreTestNamespaces();
Expand Down Expand Up @@ -193,11 +195,7 @@ public function register(Container $container): void
if (class_exists(Drush::class)) {
$reflect = new ReflectionClass(Drush::class);
if ($reflect->getFileName() !== false) {
$levels = 2;
if (Drush::getMajorVersion() < 9) {
$levels = 3;
}
$drushDir = dirname($reflect->getFileName(), $levels);
$drushDir = dirname($reflect->getFileName(), 2);
foreach (Finder::create()->files()->name('*.inc')->in($drushDir . '/includes') as $file) {
require_once $file->getPathname();
}
Expand Down Expand Up @@ -259,11 +257,6 @@ class: Drupal\jsonapi\Routing\JsonApiParamEnhancer
$service_map = $container->getByType(ServiceMap::class);
$service_map->setDrupalServices($this->serviceMap);

if (interface_exists(Test::class)
&& class_exists('Drupal\TestTools\PhpUnitCompatibility\PhpUnit8\ClassWriter')) {
ClassWriter::mutateTestBase($this->autoloader);
}

$extension_map = $container->getByType(ExtensionMap::class);
$extension_map->setExtensions($this->moduleData, $this->themeData, $profiles);
}
Expand Down
Loading