You are here

protected function KernelTestBase::bootEnvironment in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/KernelTestBase.php \Drupal\KernelTests\KernelTestBase::bootEnvironment()

Bootstraps a basic test environment.

Should not be called by tests. Only visible for DrupalKernel integration tests.

@internal

See also

\Drupal\KernelTests\Core\DrupalKernel\DrupalKernelTest

2 calls to KernelTestBase::bootEnvironment()
DrupalKernelTest::setUp in core/tests/Drupal/KernelTests/Core/DrupalKernel/DrupalKernelTest.php
KernelTestBase::setUp in core/tests/Drupal/KernelTests/KernelTestBase.php

File

core/tests/Drupal/KernelTests/KernelTestBase.php, line 258

Class

KernelTestBase
Base class for functional integration tests.

Namespace

Drupal\KernelTests

Code

protected function bootEnvironment() {
  $this->streamWrappers = [];
  \Drupal::unsetContainer();
  $this->classLoader = (require $this->root . '/autoload.php');
  require_once $this->root . '/core/includes/bootstrap.inc';

  // Set up virtual filesystem.
  Database::addConnectionInfo('default', 'test-runner', $this
    ->getDatabaseConnectionInfo()['default']);
  $test_db = new TestDatabase();
  $this->siteDirectory = $test_db
    ->getTestSitePath();

  // Ensure that all code that relies on drupal_valid_test_ua() can still be
  // safely executed. This primarily affects the (test) site directory
  // resolution (used by e.g. LocalStream and PhpStorage).
  $this->databasePrefix = $test_db
    ->getDatabasePrefix();
  drupal_valid_test_ua($this->databasePrefix);
  $settings = [
    'hash_salt' => get_class($this),
    'file_public_path' => $this->siteDirectory . '/files',
    // Skip the "path_alias" schema check for kernel tests, since they do not
    // rely on the full schema being installed.
    'system.path_alias_schema_check' => FALSE,
    // Disable Twig template caching/dumping.
    'twig_cache' => FALSE,
  ];
  new Settings($settings);
  $this
    ->setUpFilesystem();
  foreach (Database::getAllConnectionInfo() as $key => $targets) {
    Database::removeConnection($key);
  }
  Database::addConnectionInfo('default', 'default', $this
    ->getDatabaseConnectionInfo()['default']);
}