8000 suppress side effects in 'get' or 'has' methods of NamespacedAttribut… · symfony/symfony@5f59ad4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5f59ad4

Browse files
webnet-frfabpot
authored andcommitted
suppress side effects in 'get' or 'has' methods of NamespacedAttributeBag
1 parent 3b90bc7 commit 5f59ad4

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/Symfony/Component/HttpFoundation/Session/Attribute/NamespacedAttributeBag.php

Lines changed: 7 additions & 1 deletion
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];

src/Symfony/Component/HttpFoundation/Tests/Session/Attribute/NamespacedAttributeBagTest.php

Lines changed: 22 additions & 0 deletions
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)
0