diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/MockArraySessionStorage.php b/src/Symfony/Component/HttpFoundation/Session/Storage/MockArraySessionStorage.php index 6f643cc0160bf..e540d229e0228 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/MockArraySessionStorage.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/MockArraySessionStorage.php @@ -162,6 +162,7 @@ public function save() if (!$this->started || $this->closed) { throw new \RuntimeException("Trying to save a session that was not started yet or was already closed"); } + // nothing to do since we don't persist the session data $this->closed = false; $this->started = false; diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php b/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php index e9d2e176dd47d..3616a33853e76 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php @@ -239,7 +239,6 @@ public function save() } $this->closed = true; - $this->started = false; } /** @@ -314,7 +313,7 @@ public function getMetadataBag() */ public function isStarted() { - return $this->started; + return $this->started && !$this->closed; } /** diff --git a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/MockArraySessionStorageTest.php b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/MockArraySessionStorageTest.php index 2a6f6bb7e8fe5..87986a3e60140 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/MockArraySessionStorageTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/MockArraySessionStorageTest.php @@ -103,4 +103,21 @@ public function testUnstartedSave() { $this->storage->save(); } + + public function testClosedIsStarted() + { + $this->storage->start(); + + $refl = new \ReflectionProperty($this->storage, 'started'); + $refl->setAccessible(true); + + $this->assertTrue($this->storage->isStarted()); + $this->assertTrue($refl->getValue($this->storage)); + + $this->storage->save(); + + // isStarted should return false once the storage saves the session + $this->assertFalse($this->storage->isStarted()); + $this->assertFalse($refl->getValue($this->storage)); + } } diff --git a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php index 31dd41ab00f27..898cc41035c0d 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php @@ -249,6 +249,24 @@ public function testCanStartOutside54() $this->assertFalse(isset($_SESSION[$key])); $storage->start(); } + + public function testClosedIsStarted() + { + $storage = $this->getStorage(); + $storage->start(); + + $refl = new \ReflectionProperty($storage, 'started'); + $refl->setAccessible(true); + + $this->assertTrue($storage->isStarted()); + $this->assertTrue($refl->getValue($storage)); + + $storage->save(); + + // isStarted should return false once the storage saves the session + $this->assertFalse($storage->isStarted()); + $this->assertTrue($refl->getValue($storage)); + } } class SessionHandler implements \SessionHandlerInterface