NativeSessionStorageFactory example

$this->assertTrue($request->hasSession());
        $this->assertSame($sessionId$request->getSession()->getId());
    }

    /** * @runInSeparateProcess */
    public function testSessionCookieWrittenNoCookieGiven()
    {
        $request = new Request();
        $listener = $this->createListener($requestnew NativeSessionStorageFactory());

        $kernel = $this->createMock(HttpKernelInterface::class);

        $listener->onKernelRequest(new RequestEvent($kernel$request, HttpKernelInterface::MAIN_REQUEST));
        $session = $request->getSession();
        $session->set('hello', 'world');

        $response = new Response();
        $listener->onKernelResponse(new ResponseEvent($kernel$request, HttpKernelInterface::MAIN_REQUEST, $response));

        $cookies = $response->headers->getCookies();
        
$sessionId = 'vqd4dpbtst3af0k4sdl18nebkn';
session_id($sessionId);
$sessionName = session_name();
$_COOKIE[$sessionName] = $sessionId;

$request = new Request();
$request->cookies->set($sessionName$sessionId);

$requestStack = new RequestStack();
$requestStack->push($request);

$sessionFactory = new SessionFactory($requestStacknew NativeSessionStorageFactory());

$container = new Container();
$container->set('request_stack', $requestStack);
$container->set('session_factory', $sessionFactory);

$listener = new SessionListener($container);

$kernel = new class($r) implements HttpKernelInterface {
    private Response $response;

    public function __construct(Response $response)
    {
Home | Imprint | This part of the site doesn't use cookies.