engelsystem/tests/Unit/Renderer/Twig/Extensions/SessionTest.php

47 lines
1.5 KiB
PHP
Raw Normal View History

2018-08-26 12:23:47 +02:00
<?php
declare(strict_types=1);
2018-08-26 12:23:47 +02:00
namespace Engelsystem\Test\Unit\Renderer\Twig\Extensions;
use Engelsystem\Renderer\Twig\Extensions\Session;
use Symfony\Component\HttpFoundation\Session\Session as SymfonySession;
2023-02-26 11:27:41 +01:00
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
2018-08-26 12:23:47 +02:00
class SessionTest extends ExtensionTest
{
/**
* @covers \Engelsystem\Renderer\Twig\Extensions\Session::__construct
* @covers \Engelsystem\Renderer\Twig\Extensions\Session::getFunctions
*/
public function testGetGlobals(): void
2018-08-26 12:23:47 +02:00
{
2023-02-26 11:27:41 +01:00
$session = new SymfonySession(new MockArraySessionStorage());
2018-08-26 12:23:47 +02:00
$extension = new Session($session);
$functions = $extension->getFunctions();
$this->assertExtensionExists('session_get', [$session, 'get'], $functions);
$this->assertExtensionExists('session_set', [$session, 'set'], $functions);
2023-02-26 11:27:41 +01:00
$this->assertExtensionExists('session_pop', [$extension, 'sessionPop'], $functions);
}
/**
* @covers \Engelsystem\Renderer\Twig\Extensions\Session::sessionPop
*/
public function testSessionPop(): void
{
$session = new SymfonySession(new MockArraySessionStorage());
$session->set('test', 'value');
$extension = new Session($session);
$result = $extension->sessionPop('test');
$this->assertEquals('value', $result);
$this->assertFalse($session->has('test'));
$result = $extension->sessionPop('foo', 'default value');
$this->assertEquals('default value', $result);
2018-08-26 12:23:47 +02:00
}
}