bug #18018 [HttpFoundation] exception when registering bags for started sessions (xabbuh)

This PR was merged into the 2.3 branch.

Discussion
----------

[HttpFoundation] exception when registering bags for started sessions

| Q             | A
| ------------- | ---
| Branch        | 2.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #10707, #16136
| License       | MIT
| Doc PR        |

Commits
-------

c4a5b67 exception when registering bags for started sessions
This commit is contained in:
Fabien Potencier 2016-03-08 22:59:00 +01:00
commit 5d8067f32d
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();