14 use PHPUnit\Framework\TestCase;
38 $this->iniSet(
'session.save_handler',
'files');
39 $this->iniSet(
'session.save_path', $this->savePath = sys_get_temp_dir().
'/sf2test');
40 if (!is_dir($this->savePath)) {
41 mkdir($this->savePath);
47 session_write_close();
48 array_map(
'unlink', glob($this->savePath.
'/*'));
49 if (is_dir($this->savePath)) {
50 rmdir($this->savePath);
53 $this->savePath =
null;
74 $this->assertSame($bag,
$storage->getBag($bag->getName()));
99 $this->assertSame(
'',
$storage->getId(),
'Empty ID before starting session');
103 $this->assertInternalType(
'string', $id);
104 $this->assertNotSame(
'', $id);
107 $this->assertSame($id,
$storage->getId(),
'ID stays after saving session');
115 $storage->getBag(
'attributes')->set(
'lucky', 7);
117 $this->assertNotEquals($id,
$storage->getId());
118 $this->assertEquals(7,
$storage->getBag(
'attributes')->get(
'lucky'));
126 $storage->getBag(
'attributes')->set(
'legs', 11);
128 $this->assertNotEquals($id,
$storage->getId());
129 $this->assertEquals(11,
$storage->getBag(
'attributes')->get(
'legs'));
136 $storage->getBag(
'attributes')->set(
'lucky', 7);
138 $storage->getBag(
'attributes')->set(
'lucky', 42);
140 $this->assertEquals(42, $_SESSION[
'_sf2_attributes'][
'lucky']);
146 $this->assertFalse(
$storage->regenerate());
147 $this->assertFalse(
$storage->isStarted());
152 $this->iniSet(
'session.cache_limiter',
'nocache');
155 $this->assertEquals(
'', ini_get(
'session.cache_limiter'));
160 $this->iniSet(
'session.cache_limiter',
'nocache');
163 $this->assertEquals(
'public', ini_get(
'session.cache_limiter'));
169 'cookie_lifetime' => 123456,
170 'cookie_path' =>
'/my/cookie/path',
171 'cookie_domain' =>
'symfony.example.com',
172 'cookie_secure' =>
true,
173 'cookie_httponly' =>
false,
177 $temp = session_get_cookie_params();
180 foreach ($temp as $key => $value) {
181 $gco[
'cookie_'.$key] = $value;
184 $this->assertEquals($options, $gco);
193 $storage->setSaveHandler(
new \stdClass());
198 $this->iniSet(
'session.save_handler',
'files');
201 $this->assertInstanceOf(
'Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy',
$storage->getSaveHandler());
203 $this->assertInstanceOf(
'Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy',
$storage->getSaveHandler());
205 $this->assertInstanceOf(
'Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy',
$storage->getSaveHandler());
207 $this->assertInstanceOf(
'Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy',
$storage->getSaveHandler());
209 $this->assertInstanceOf(
'Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy',
$storage->getSaveHandler());
211 $this->assertInstanceOf(
'Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy',
$storage->getSaveHandler());
221 $this->assertFalse(
$storage->getSaveHandler()->isActive());
222 $this->assertFalse(
$storage->isStarted());
225 $this->assertTrue(isset($_SESSION));
226 $this->assertTrue(
$storage->getSaveHandler()->isActive());
229 $this->assertFalse(
$storage->isStarted());
231 $key =
$storage->getMetadataBag()->getStorageKey();
232 $this->assertFalse(isset($_SESSION[$key]));
241 $storage->getBag(
'attributes')->set(
'lucky', 7);
244 $this->assertSame($id,
$storage->getId(),
'Same session ID after restarting');
245 $this->assertSame(7,
$storage->getBag(
'attributes')->get(
'lucky'),
'Data still available');