diff --git a/core/lib/Drupal/Core/Test/TestKernel.php b/core/lib/Drupal/Core/Test/TestKernel.php new file mode 100644 index 0000000000000000000000000000000000000000..55909a0d10a40d32217ea7abb66a380271d0bef8 --- /dev/null +++ b/core/lib/Drupal/Core/Test/TestKernel.php @@ -0,0 +1,55 @@ +<?php + +/** + * @file + * Contains \Drupal\Core\Test\TestKernel. + */ + +namespace Drupal\Core\Test; + +use Drupal\Core\DrupalKernel; +use Drupal\Core\Extension\Extension; +use Drupal\Core\Installer\InstallerServiceProvider; +use Composer\Autoload\ClassLoader; + +/** + * Kernel for run-tests.sh. + */ +class TestKernel extends DrupalKernel { + + /** + * Constructs a TestKernel. + * + * @param \Composer\Autoload\ClassLoader $class_loader + * The classloader. + */ + public function __construct(ClassLoader $class_loader) { + parent::__construct('test_runner', $class_loader, FALSE); + + // Prime the module list and corresponding Extension objects. + // @todo Remove System module. Needed because \Drupal\Core\Datetime\Date + // has a (needless) dependency on the 'date_format' entity, so calls to + // format_date()/format_interval() cause a plugin not found exception. + $this->moduleList = array( + 'system' => 0, + 'simpletest' => 0, + ); + $this->moduleData = array( + 'system' => new Extension('module', 'core/modules/system/system.info.yml', 'system.module'), + 'simpletest' => new Extension('module', 'core/modules/simpletest/simpletest.info.yml', 'simpletest.module'), + ); + } + + /** + * {@inheritdoc} + */ + public function discoverServiceProviders() { + $providers = parent::discoverServiceProviders(); + // The test runner does not require an installed Drupal site to exist. + // Therefore, its environment is identical to that of the early installer. + $this->serviceProviderClasses[] = 'Drupal\Core\Installer\InstallerServiceProvider'; + $providers[] = new InstallerServiceProvider(); + return $providers; + } + +} diff --git a/core/scripts/run-tests.sh b/core/scripts/run-tests.sh index 3134a5c534db665095daab8402774edfafacb86c..643bcb77dd6202acea229e14673722f427963507 100755 --- a/core/scripts/run-tests.sh +++ b/core/scripts/run-tests.sh @@ -7,8 +7,8 @@ use Drupal\Component\Utility\Timer; use Drupal\Core\Database\Database; -use Drupal\Core\DrupalKernel; use Drupal\Core\Site\Settings; +use Drupal\Core\Test\TestKernel; use Symfony\Component\HttpFoundation\Request; require_once __DIR__ . '/../vendor/autoload.php'; @@ -364,9 +364,6 @@ function simpletest_script_bootstrap() { require_once $include; } - // Replace services with in-memory and null implementations. - $GLOBALS['conf']['container_service_providers']['InstallerServiceProvider'] = 'Drupal\Core\Installer\InstallerServiceProvider'; - drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION); // Remove Drupal's error/exception handlers; they are designed for HTML @@ -384,7 +381,7 @@ function simpletest_script_bootstrap() { )); } - $kernel = new DrupalKernel('testing', drupal_classloader(), FALSE); + $kernel = new TestKernel(drupal_classloader()); $kernel->boot(); $request = Request::createFromGlobals(); @@ -394,14 +391,7 @@ function simpletest_script_bootstrap() { $container->get('request_stack')->push($request); $module_handler = $container->get('module_handler'); - // @todo Remove System module. Only needed because \Drupal\Core\Datetime\Date - // has a (needless) dependency on the 'date_format' entity, so calls to - // format_date()/format_interval() cause a plugin not found exception. - $module_handler->addModule('system', 'core/modules/system'); - $module_handler->addModule('simpletest', 'core/modules/simpletest'); $module_handler->loadAll(); - $module_filenames = $module_handler->getModuleList(); - $kernel->updateModules($module_filenames, $module_filenames); simpletest_classloader_register(); }