function KernelTestBaseTest::testSessionOnRequest

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

Tests that a usable session is on the request.

@covers ::bootKernel

File

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

Class

KernelTestBaseTest
@coversDefaultClass \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.