bug #22138 [HttpFoundation][bugfix] $bags should always be initialized (MacDada)

This PR was squashed before being merged into the 2.7 branch (closes #22138).

Discussion
----------

[HttpFoundation][bugfix] $bags should always be initialized

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #21990
| License       | MIT

Commits
-------

d984c73e66 [HttpFoundation][bugfix]  should always be initialized
This commit is contained in:
Fabien Potencier 2017-03-24 07:50:56 -07:00
commit 2606c48f69
2 changed files with 25 additions and 1 deletions

View File

@ -60,7 +60,7 @@ class MockArraySessionStorage implements SessionStorageInterface
/**
* @var array
*/
protected $bags;
protected $bags = array();
/**
* Constructor.

View File

@ -97,6 +97,30 @@ class MockArraySessionStorageTest extends TestCase
$this->assertNotEquals('', $this->storage->getId());
}
public function testClearClearsBags()
{
$this->storage->clear();
$this->assertSame(array(), $this->storage->getBag('attributes')->all());
$this->assertSame(array(), $this->storage->getBag('flashes')->peekAll());
}
public function testClearStartsSession()
{
$this->storage->clear();
$this->assertTrue($this->storage->isStarted());
}
public function testClearWithNoBagsStartsSession()
{
$storage = new MockArraySessionStorage();
$storage->clear();
$this->assertTrue($storage->isStarted());
}
/**
* @expectedException \RuntimeException
*/