Skip to content

Commit 08c9e34

Browse files
committed
Merge branch '3.4' into 4.0
* 3.4: [FrameworkBundle] fixed brackets position in method calls [Form] Fix PHPDoc for FormConfigBuilder $dataClass argument [Security] Update user phpdoc on tokens [WebProfilerBundle] Fixed icon alignment issue using Bootstrap 4.1.2 suppress side effects in 'get' or 'has' methods of NamespacedAttributeBag [HttpFoundation] reset callback on StreamedResponse when setNotModified() is called [HttpFoundation] Fixed phpdoc for get method of HeaderBag fix typo in ContainerBuilder docblock [Form/Profiler] Massively reducing memory footprint of form profiling pages by removing redundant 'form' variable from view variables. [Console] correctly return parameter's default value on "--"
2 parents 1e859f6 + 7cfa35c commit 08c9e34

File tree

6 files changed

+69
-6
lines changed

6 files changed

+69
-6
lines changed

HeaderBag.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ public function add(array $headers)
101101
/**
102102
* Returns a header value by name.
103103
*
104-
* @param string $key The header name
105-
* @param string|string[] $default The default value
106-
* @param bool $first Whether to return the first value or all header values
104+
* @param string $key The header name
105+
* @param string|string[]|null $default The default value
106+
* @param bool $first Whether to return the first value or all header values
107107
*
108-
* @return string|string[] The first header value or default value if $first is true, an array of values otherwise
108+
* @return string|string[]|null The first header value or default value if $first is true, an array of values otherwise
109109
*/
110110
public function get($key, $default = null, $first = true)
111111
{

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];

StreamedResponse.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,16 @@ public function getContent()
141141
{
142142
return false;
143143
}
144+
145+
/**
146+
* {@inheritdoc}
147+
*
148+
* @return $this
149+
*/
150+
public function setNotModified()
151+
{
152+
$this->setCallback(function () {});
153+
154+
return parent::setNotModified();
155+
}
144156
}

Tests/ResponseTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function testMustRevalidateWithProxyRevalidateCacheControlHeader()
126126

127127
public function testSetNotModified()
128128
{
129-
$response = new Response();
129+
$response = new Response('foo');
130130
$modified = $response->setNotModified();
131131
$this->assertObjectHasAttribute('headers', $modified);
132132
$this->assertObjectHasAttribute('content', $modified);
@@ -135,6 +135,11 @@ public function testSetNotModified()
135135
$this->assertObjectHasAttribute('statusText', $modified);
136136
$this->assertObjectHasAttribute('charset', $modified);
137137
$this->assertEquals(304, $modified->getStatusCode());
138+
139+
ob_start();
140+
$modified->sendContent();
141+
$string = ob_get_clean();
142+
$this->assertEmpty($string);
138143
}
139144

140145
public function testIsSuccessful()

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
*/

Tests/StreamedResponseTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,22 @@ public function testReturnThis()
123123
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendHeaders());
124124
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendHeaders());
125125
}
126+
127+
public function testSetNotModified()
128+
{
129+
$response = new StreamedResponse(function () { echo 'foo'; });
130+
$modified = $response->setNotModified();
131+
$this->assertObjectHasAttribute('headers', $modified);
132+
$this->assertObjectHasAttribute('content', $modified);
133+
$this->assertObjectHasAttribute('version', $modified);
134+
$this->assertObjectHasAttribute('statusCode', $modified);
135+
$this->assertObjectHasAttribute('statusText', $modified);
136+
$this->assertObjectHasAttribute('charset', $modified);
137+
$this->assertEquals(304, $modified->getStatusCode());
138+
139+
ob_start();
140+
$modified->sendContent();
141+
$string = ob_get_clean();
142+
$this->assertEmpty($string);
143+
}
126144
}

0 commit comments

Comments
 (0)