exception when registering bags for started sessions

This commit is contained in:
Christian Flothmann 2016-03-05 08:50:24 +01:00
parent ce60be5729
commit c4a5b67a5a
2 changed files with 14 additions and 0 deletions

View File

@ -260,6 +260,10 @@ class NativeSessionStorage implements SessionStorageInterface
*/
public function registerBag(SessionBagInterface $bag)
{
if ($this->started) {
throw new \LogicException('Cannot register a bag when the session is already started.');
}
$this->bags[$bag->getName()] = $bag;
}

View File

@ -83,6 +83,16 @@ class NativeSessionStorageTest extends \PHPUnit_Framework_TestCase
$storage->getBag('non_existing');
}
/**
* @expectedException \LogicException
*/
public function testRegisterBagForAStartedSessionThrowsException()
{
$storage = $this->getStorage();
$storage->start();
$storage->registerBag(new AttributeBag());
}
public function testGetId()
{
$storage = $this->getStorage();