You are here

protected function DrupalKernelTest::getTestKernel in Drupal 8

Same name and namespace in other branches
  1. 9 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.

2 calls to DrupalKernelTest::getTestKernel()
DrupalKernelTest::testCompileDIC in core/tests/Drupal/KernelTests/Core/DrupalKernel/DrupalKernelTest.php
Tests DIC compilation.
DrupalKernelTest::testPreventChangeOfSitePath in core/tests/Drupal/KernelTests/Core/DrupalKernel/DrupalKernelTest.php
Tests setting of site path after kernel boot.

File

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

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;
}