Allow reuse of Session between requests

This commit is contained in:
Titouan Galopin 2018-09-10 21:53:03 +02:00
parent 86a5d92ce7
commit fd30f4a21d
3 changed files with 25 additions and 2 deletions

View File

@ -178,7 +178,9 @@ class Session implements SessionInterface, \IteratorAggregate, \Countable
*/
public function setId($id)
{
$this->storage->setId($id);
if ($this->storage->getId() !== $id) {
$this->storage->setId($id);
}
}
/**

View File

@ -70,6 +70,27 @@ class SessionTest extends TestCase
$this->assertEquals('0123456789abcdef', $this->session->getId());
}
public function testSetIdAfterStart()
{
$this->session->start();
$id = $this->session->getId();
$e = null;
try {
$this->session->setId($id);
} catch (\Exception $e) {
}
$this->assertNull($e);
try {
$this->session->setId('different');
} catch (\Exception $e) {
}
$this->assertInstanceOf('\LogicException', $e);
}
public function testSetName()
{
$this->assertEquals('MOCKSESSID', $this->session->getName());

View File

@ -48,7 +48,7 @@ class MockArraySessionStorageTest extends TestCase
$this->data = array(
$this->attributes->getStorageKey() => array('foo' => 'bar'),
$this->flashes->getStorageKey() => array('notice' => 'hello'),
);
);
$this->storage = new MockArraySessionStorage();
$this->storage->registerBag($this->flashes);