function KernelTestBaseTest::testSessionOnRequest

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/KernelTests/KernelTestBaseTest.php \Drupal\KernelTests\KernelTestBaseTest::testSessionOnRequest()
  2. 10 core/tests/Drupal/KernelTests/KernelTestBaseTest.php \Drupal\KernelTests\KernelTestBaseTest::testSessionOnRequest()

Tests that a usable session is on the request.

@legacy-covers ::bootKernel

File

core/tests/Drupal/KernelTests/KernelTestBaseTest.php, line 242

Class

KernelTestBaseTest
Tests Drupal\KernelTests\KernelTestBase.

Namespace

Drupal\KernelTests

Code

public function testSessionOnRequest() : void {
  /** @var \Symfony\Component\HttpFoundation\Session\Session $session */
  $session = $this->container
    ->get('request_stack')
    ->getSession();
  $session->set('some-val', 'do-not-cleanup');
  $this->assertEquals('do-not-cleanup', $session->get('some-val'));
  $session->set('some-other-val', 'do-cleanup');
  $this->assertEquals('do-cleanup', $session->remove('some-other-val'));
}

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