Skip to content

Commit

Permalink
Only load test bootstrap when PHPUnit available
Browse files Browse the repository at this point in the history
  • Loading branch information
mglaman committed May 12, 2021
1 parent 7730292 commit fab76ba
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/Drupal/DrupalAutoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,18 @@ public function register(Container $container): void
$this->addThemeNamespaces();
$this->registerPs4Namespaces($this->namespaces);
$this->loadLegacyIncludes();
require_once $this->drupalRoot . '/core/tests/bootstrap.php';

// class_alias is not supported by OptimizedDirectorySourceLocator or AutoloadSourceLocator,
// so we manually load this PHPUnit compatibility trait that exists in Drupal 8.
$phpunitCompatTraitFilepath = $this->drupalRoot . '/core/tests/Drupal/Tests/PhpunitCompatibilityTrait.php';
if (file_exists($phpunitCompatTraitFilepath)) {
require_once $phpunitCompatTraitFilepath;
$this->autoloader->addClassMap(['Drupal\\Tests\\PhpunitCompatibilityTrait' => $phpunitCompatTraitFilepath]);

// @todo stop requiring the bootstrap.php and just copy what is needed.
if (interface_exists(\PHPUnit\Framework\Test::class)) {
require_once $this->drupalRoot . '/core/tests/bootstrap.php';

// class_alias is not supported by OptimizedDirectorySourceLocator or AutoloadSourceLocator,
// so we manually load this PHPUnit compatibility trait that exists in Drupal 8.
$phpunitCompatTraitFilepath = $this->drupalRoot . '/core/tests/Drupal/Tests/PhpunitCompatibilityTrait.php';
if (file_exists($phpunitCompatTraitFilepath)) {
require_once $phpunitCompatTraitFilepath;
$this->autoloader->addClassMap(['Drupal\\Tests\\PhpunitCompatibilityTrait' => $phpunitCompatTraitFilepath]);
}
}

foreach ($this->moduleData as $extension) {
Expand Down

0 comments on commit fab76ba

Please sign in to comment.