function DrupalKernelTest::getTestKernel

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

File

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

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.