Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8f60a8a

Browse files
committed
Allow reuse of MockArraySessionStorage between requests
1 parent 86a5d92 commit 8f60a8a

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/Symfony/Component/HttpFoundation/Session/Storage/MockArraySessionStorage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public function getId()
123123
*/
124124
public function setId($id)
125125
{
126-
if ($this->started) {
126+
if ($this->started && $this->id !== $id) {
127127
throw new \LogicException('Cannot set session ID after the session has started.');
128128
}
129129

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/MockArraySessionStorageTest.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protected function setUp()
4848
$this->data = array(
4949
$this->attributes->getStorageKey() => array('foo' => 'bar'),
5050
$this->flashes->getStorageKey() => array('notice' => 'hello'),
51-
);
51+
);
5252

5353
$this->storage = new MockArraySessionStorage();
5454
$this->storage->registerBag($this->flashes);
@@ -97,6 +97,30 @@ public function testGetId()
9797
$this->assertNotEquals('', $this->storage->getId());
9898
}
9999

100+
public function testSetId()
101+
{
102+
$this->storage->start();
103+
$id = $this->storage->getId();
104+
105+
$exception = null;
106+
try {
107+
$this->storage->setId($id);
108+
} catch (\Exception $e) {
109+
$exception = $e;
110+
}
111+
112+
$this->assertNull($exception);
113+
114+
$exception = null;
115+
try {
116+
$this->storage->setId('different');
117+
} catch (\Exception $e) {
118+
$exception = $e;
119+
}
120+
121+
$this->assertInstanceOf('\LogicException', $exception);
122+
}
123+
100124
public function testClearClearsBags()
101125
{
102126
$this->storage->clear();

0 commit comments

Comments
 (0)