You are here

public function DrupalKernelTest::testPreventChangeOfSitePath in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/DrupalKernel/DrupalKernelTest.php \Drupal\KernelTests\Core\DrupalKernel\DrupalKernelTest::testPreventChangeOfSitePath()
  2. 9 core/tests/Drupal/KernelTests/Core/DrupalKernel/DrupalKernelTest.php \Drupal\KernelTests\Core\DrupalKernel\DrupalKernelTest::testPreventChangeOfSitePath()

Tests setting of site path after kernel boot.

File

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

Class

DrupalKernelTest
Tests DIC compilation to disk.

Namespace

Drupal\KernelTests\Core\DrupalKernel

Code

public function testPreventChangeOfSitePath() {

  // @todo: write a memory based storage backend for testing.
  $modules_enabled = [
    'system' => 'system',
    'user' => 'user',
  ];
  $request = Request::createFromGlobals();
  $kernel = $this
    ->getTestKernel($request, $modules_enabled);
  $pass = FALSE;
  try {
    $kernel
      ->setSitePath('/dev/null');
  } catch (\LogicException $e) {
    $pass = TRUE;
  }
  $this
    ->assertTrue($pass, 'Throws LogicException if DrupalKernel::setSitePath() is called after boot');

  // Ensure no LogicException if DrupalKernel::setSitePath() is called with
  // identical path after boot.
  $path = $kernel
    ->getSitePath();
  $kernel
    ->setSitePath($path);
}