suppress side effects in 'get' or 'has' methods of NamespacedAttributeBag

This commit is contained in:
Webnet team 2018-07-11 15:26:07 +02:00 committed by Fabien Potencier
parent 3b90bc71c1
commit 5f59ad4600
2 changed files with 29 additions and 1 deletions

View File

@ -124,7 +124,13 @@ class NamespacedAttributeBag extends AttributeBag
foreach ($parts as $part) {
if (null !== $array && !array_key_exists($part, $array)) {
$array[$part] = $writeContext ? array() : null;
if (!$writeContext) {
$null = null;
return $null;
}
$array[$part] = array();
}
$array = &$array[$part];

View File

@ -82,6 +82,17 @@ class NamespacedAttributeBagTest extends TestCase
$this->assertEquals($exists, $this->bag->has($key));
}
/**
* @dataProvider attributesProvider
*/
public function testHasNoSideEffect($key, $value, $expected)
{
$expected = json_encode($this->bag->all());
$this->bag->has($key);
$this->assertEquals($expected, json_encode($this->bag->all()));
}
/**
* @dataProvider attributesProvider
*/
@ -96,6 +107,17 @@ class NamespacedAttributeBagTest extends TestCase
$this->assertEquals('default', $this->bag->get('user2.login', 'default'));
}
/**
* @dataProvider attributesProvider
*/
public function testGetNoSideEffect($key, $value, $expected)
{
$expected = json_encode($this->bag->all());
$this->bag->get($key);
$this->assertEquals($expected, json_encode($this->bag->all()));
}
/**
* @dataProvider attributesProvider
*/