Skip to content

Commit

Permalink
Allow reuse of Session between requests
Browse files Browse the repository at this point in the history
  • Loading branch information
tgalopin committed Sep 21, 2018
1 parent 86a5d92 commit fd30f4a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Symfony/Component/HttpFoundation/Session/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ public function getId()
*/
public function setId($id)
{
$this->storage->setId($id);
if ($this->storage->getId() !== $id) {
$this->storage->setId($id);
}
}

/**
Expand Down
21 changes: 21 additions & 0 deletions src/Symfony/Component/HttpFoundation/Tests/Session/SessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,27 @@ public function testSetId()
$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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected function setUp()
$this->data = array(
$this->attributes->getStorageKey() => array('foo' => 'bar'),
$this->flashes->getStorageKey() => array('notice' => 'hello'),
);
);

$this->storage = new MockArraySessionStorage();
$this->storage->registerBag($this->flashes);
Expand Down

0 comments on commit fd30f4a

Please sign in to comment.