diff --git a/core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php b/core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php index 5b8fbba094..1d9930419f 100644 --- a/core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php +++ b/core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php @@ -4,6 +4,7 @@ use Drupal\Core\Database\Database; use Drupal\Core\DrupalKernel; +use Drupal\Core\Site\Settings; use Drupal\Core\Test\TestDatabase; use Drupal\Tests\BrowserTestBase; use Symfony\Component\Console\Command\Command; @@ -12,7 +13,6 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; -use Symfony\Component\HttpFoundation\Request; /** * Command to tear down a test Drupal site. @@ -76,7 +76,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { $db_url = $input->getOption('db_url'); putenv("SIMPLETEST_DB=$db_url"); - $kernel = $this->bootstrapDrupal(); + $kernel = $this->bootstrapDrupal($test_database); // Handle the cleanup of the test site. $this->tearDown($test_database, $db_url, $kernel->getAppRoot()); @@ -103,7 +103,8 @@ protected function tearDown(TestDatabase $test_database, $db_url, $app_root) { // Remove all the tables. $schema = Database::getConnection('default', __CLASS__)->schema(); - array_walk($schema->findTables('%'), [$schema, 'dropTable']); + $tables = $schema->findTables('%'); + array_walk($tables, [$schema, 'dropTable']); // Delete test site directory. file_unmanaged_delete_recursive($test_database->getTestSitePath(), [BrowserTestBase::class, 'filePreDeleteCallback']); @@ -112,12 +113,18 @@ protected function tearDown(TestDatabase $test_database, $db_url, $app_root) { /** * Bootstraps the drupal kernel. * + * @param \Drupal\Core\Test\TestDatabase $test_database + * The test database object. + * * @return \Drupal\Core\DrupalKernel * The Drupal kernel. */ - protected function bootstrapDrupal() { - $request = Request::createFromGlobals(); - $kernel = DrupalKernel::createFromRequest($request, $this->autoloader, $this->getApplication()->getName()); + protected function bootstrapDrupal(TestDatabase $test_database) { + $kernel = new DrupalKernel($this->getApplication()->getName(), $this->autoloader, FALSE); + $kernel->setSitePath($test_database->getTestSitePath()); + Settings::initialize($kernel->getAppRoot(), $kernel->getSitePath(), $this->autoloader); + require_once $kernel->getAppRoot() . '/core/includes/bootstrap.inc'; + drupal_valid_test_ua($test_database->getDatabasePrefix()); // Finish booting Drupal in order to use functions like // file_unmanaged_delete_recursive().