function DrupalKernelTest::getTestKernel

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/DrupalKernel/DrupalKernelTest.php \Drupal\KernelTests\Core\DrupalKernel\DrupalKernelTest::getTestKernel()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/DrupalKernel/DrupalKernelTest.php \Drupal\KernelTests\Core\DrupalKernel\DrupalKernelTest::getTestKernel()
  3. 10 core/tests/Drupal/KernelTests/Core/DrupalKernel/DrupalKernelTest.php \Drupal\KernelTests\Core\DrupalKernel\DrupalKernelTest::getTestKernel()

Build a kernel for testings.

Because the bootstrap is in DrupalKernel::boot and that involved loading settings from the filesystem we need to go to extra lengths to build a kernel for testing.

Parameters

\Symfony\Component\HttpFoundation\Request $request: A request object to use in booting the kernel.

array $modules_enabled: A list of modules to enable on the kernel.

Return value

\Drupal\Core\DrupalKernel New kernel for testing.

4 calls to DrupalKernelTest::getTestKernel()
DrupalKernelTest::testCompileDIC in core/tests/Drupal/KernelTests/Core/DrupalKernel/DrupalKernelTest.php
Tests DIC compilation.
DrupalKernelTest::testLocale in core/tests/Drupal/KernelTests/Core/DrupalKernel/DrupalKernelTest.php
Tests system locale.
DrupalKernelTest::testPreventChangeOfSitePath in core/tests/Drupal/KernelTests/Core/DrupalKernel/DrupalKernelTest.php
Tests setting of site path after kernel boot.
DrupalKernelTest::testResetContainer in core/tests/Drupal/KernelTests/Core/DrupalKernel/DrupalKernelTest.php
@covers ::resetContainer

File

core/tests/Drupal/KernelTests/Core/DrupalKernel/DrupalKernelTest.php, line 59

Class

DrupalKernelTest
Tests DIC compilation to disk.

Namespace

Drupal\KernelTests\Core\DrupalKernel

Code

protected function getTestKernel(Request $request, ?array $modules_enabled = NULL) {
    // Manually create kernel to avoid replacing settings.
    $class_loader = (require $this->root . '/autoload.php');
    $kernel = DrupalKernel::createFromRequest($request, $class_loader, 'testing');
    $this->setSetting('container_yamls', []);
    $this->setSetting('hash_salt', $this->databasePrefix);
    if (isset($modules_enabled)) {
        $kernel->updateModules($modules_enabled);
    }
    $kernel->boot();
    return $kernel;
}

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