function KernelTestBase::bootEnvironment

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/KernelTestBase.php \Drupal\KernelTests\KernelTestBase::bootEnvironment()
  2. 8.9.x core/tests/Drupal/KernelTests/KernelTestBase.php \Drupal\KernelTests\KernelTestBase::bootEnvironment()
  3. 11.x 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

1 call to KernelTestBase::bootEnvironment()
KernelTestBase::setUp in core/tests/Drupal/KernelTests/KernelTestBase.php

File

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

Class

KernelTestBase
Base class for functional integration tests.

Namespace

Drupal\KernelTests

Code

protected function bootEnvironment() {
    \Drupal::unsetContainer();
    $this->classLoader = (require $this->root . '/autoload.php');
    // 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' => static::class,
        'file_public_path' => $this->siteDirectory . '/files',
        // 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']);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.