Skip to content

Commit 9c69e10

Browse files
webnet-frfabpot
authored andcommitted
suppress side effects in 'get' or 'has' methods of NamespacedAttributeBag
1 parent 4887f53 commit 9c69e10

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

Session/Attribute/NamespacedAttributeBag.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,13 @@ protected function &resolveAttributePath($name, $writeContext = false)
124124

125125
foreach ($parts as $part) {
126126
if (null !== $array && !array_key_exists($part, $array)) {
127-
$array[$part] = $writeContext ? array() : null;
127+
if (!$writeContext) {
128+
$null = null;
129+
130+
return $null;
131+
}
132+
133+
$array[$part] = array();
128134
}
129135

130136
$array = &$array[$part];

Tests/Session/Attribute/NamespacedAttributeBagTest.php

+22
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,17 @@ public function testHas($key, $value, $exists)
8282
$this->assertEquals($exists, $this->bag->has($key));
8383
}
8484

85+
/**
86+
* @dataProvider attributesProvider
87+
*/
88+
public function testHasNoSideEffect($key, $value, $expected)
89+
{
90+
$expected = json_encode($this->bag->all());
91+
$this->bag->has($key);
92+
93+
$this->assertEquals($expected, json_encode($this->bag->all()));
94+
}
95+
8596
/**
8697
* @dataProvider attributesProvider
8798
*/
@@ -96,6 +107,17 @@ public function testGetDefaults()
96107
$this->assertEquals('default', $this->bag->get('user2.login', 'default'));
97108
}
98109

110+
/**
111+
* @dataProvider attributesProvider
112+
*/
113+
public function testGetNoSideEffect($key, $value, $expected)
114+
{
115+
$expected = json_encode($this->bag->all());
116+
$this->bag->get($key);
117+
118+
$this->assertEquals($expected, json_encode($this->bag->all()));
119+
}
120+
99121
/**
100122
* @dataProvider attributesProvider
101123
*/

0 commit comments

Comments
 (0)