suppress side effects in 'get' or 'has' methods of NamespacedAttributeBag
This commit is contained in:
parent
3b90bc71c1
commit
5f59ad4600
@ -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];
|
||||
|
@ -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
|
||||
*/
|
||||
|
Reference in New Issue
Block a user