Skip to content

Commit fab76ba

Browse files
committed
Only load test bootstrap when PHPUnit available
1 parent 7730292 commit fab76ba

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/Drupal/DrupalAutoloader.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,18 @@ public function register(Container $container): void
100100
$this->addThemeNamespaces();
101101
$this->registerPs4Namespaces($this->namespaces);
102102
$this->loadLegacyIncludes();
103-
require_once $this->drupalRoot . '/core/tests/bootstrap.php';
104-
105-
// class_alias is not supported by OptimizedDirectorySourceLocator or AutoloadSourceLocator,
106-
// so we manually load this PHPUnit compatibility trait that exists in Drupal 8.
107-
$phpunitCompatTraitFilepath = $this->drupalRoot . '/core/tests/Drupal/Tests/PhpunitCompatibilityTrait.php';
108-
if (file_exists($phpunitCompatTraitFilepath)) {
109-
require_once $phpunitCompatTraitFilepath;
110-
$this->autoloader->addClassMap(['Drupal\\Tests\\PhpunitCompatibilityTrait' => $phpunitCompatTraitFilepath]);
103+
104+
// @todo stop requiring the bootstrap.php and just copy what is needed.
105+
if (interface_exists(\PHPUnit\Framework\Test::class)) {
106+
require_once $this->drupalRoot . '/core/tests/bootstrap.php';
107+
108+
// class_alias is not supported by OptimizedDirectorySourceLocator or AutoloadSourceLocator,
109+
// so we manually load this PHPUnit compatibility trait that exists in Drupal 8.
110+
$phpunitCompatTraitFilepath = $this->drupalRoot . '/core/tests/Drupal/Tests/PhpunitCompatibilityTrait.php';
111+
if (file_exists($phpunitCompatTraitFilepath)) {
112+
require_once $phpunitCompatTraitFilepath;
113+
$this->autoloader->addClassMap(['Drupal\\Tests\\PhpunitCompatibilityTrait' => $phpunitCompatTraitFilepath]);
114+
}
111115
}
112116

113117
foreach ($this->moduleData as $extension) {

0 commit comments

Comments
 (0)