Skip to content

Commit 33eb76b

Browse files
committed
Merge branch '3.1' into 3.2
* 3.1: [TwigBundle] fixed usage when Templating is not installed [Validator] Check cascasdedGroups for being countable [Cache] Add changelog [Filesystem] Check that the directory is writable after created it in dumpFile() [HttpFoundation] Improved set cookie header tests [Serializer] int is valid when float is expected when deserializing JSON [Console] increased code coverage of Output classes Added missing headers in fixture files [Profiler][VarDumper] Fix minor color issue & duplicated selector
2 parents c1bf268 + cef0ad4 commit 33eb76b

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

Tests/ResponseHeaderBagTest.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,11 @@ public function testToStringIncludesCookieHeaders()
124124
$bag = new ResponseHeaderBag(array());
125125
$bag->setCookie(new Cookie('foo', 'bar'));
126126

127-
$this->assertContains('Set-Cookie: foo=bar; path=/; httponly', explode("\r\n", $bag->__toString()));
127+
$this->assertSetCookieHeader('foo=bar; path=/; httponly', $bag);
128128

129129
$bag->clearCookie('foo');
130130

131-
$this->assertRegExp('#^Set-Cookie: foo=deleted; expires='.gmdate('D, d-M-Y H:i:s T', time() - 31536001).'; path=/; httponly#m', $bag->__toString());
131+
$this->assertSetCookieHeader('foo=deleted; expires='.gmdate('D, d-M-Y H:i:s T', time() - 31536001).'; path=/; httponly', $bag);
132132
}
133133

134134
public function testClearCookieSecureNotHttpOnly()
@@ -137,7 +137,7 @@ public function testClearCookieSecureNotHttpOnly()
137137

138138
$bag->clearCookie('foo', '/', null, true, false);
139139

140-
$this->assertRegExp('#^Set-Cookie: foo=deleted; expires='.gmdate('D, d-M-Y H:i:s T', time() - 31536001).'; path=/; secure#m', $bag->__toString());
140+
$this->assertSetCookieHeader('foo=deleted; expires='.gmdate('D, d-M-Y H:i:s T', time() - 31536001).'; path=/; secure', $bag);
141141
}
142142

143143
public function testReplace()
@@ -173,11 +173,10 @@ public function testCookiesWithSameNames()
173173

174174
$this->assertCount(4, $bag->getCookies());
175175

176-
$headers = explode("\r\n", $bag->__toString());
177-
$this->assertContains('Set-Cookie: foo=bar; path=/path/foo; domain=foo.bar; httponly', $headers);
178-
$this->assertContains('Set-Cookie: foo=bar; path=/path/foo; domain=foo.bar; httponly', $headers);
179-
$this->assertContains('Set-Cookie: foo=bar; path=/path/bar; domain=bar.foo; httponly', $headers);
180-
$this->assertContains('Set-Cookie: foo=bar; path=/; httponly', $headers);
176+
$this->assertSetCookieHeader('foo=bar; path=/path/foo; domain=foo.bar; httponly', $bag);
177+
$this->assertSetCookieHeader('foo=bar; path=/path/bar; domain=foo.bar; httponly', $bag);
178+
$this->assertSetCookieHeader('foo=bar; path=/path/bar; domain=bar.foo; httponly', $bag);
179+
$this->assertSetCookieHeader('foo=bar; path=/; httponly', $bag);
181180

182181
$cookies = $bag->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
183182
$this->assertTrue(isset($cookies['foo.bar']['/path/foo']['foo']));
@@ -231,7 +230,7 @@ public function testGetCookiesWithInvalidArgument()
231230
{
232231
$bag = new ResponseHeaderBag();
233232

234-
$cookies = $bag->getCookies('invalid_argument');
233+
$bag->getCookies('invalid_argument');
235234
}
236235

237236
/**
@@ -302,4 +301,9 @@ public function provideMakeDispositionFail()
302301
array('attachment', 'föö.html'),
303302
);
304303
}
304+
305+
private function assertSetCookieHeader($expected, ResponseHeaderBag $actual)
306+
{
307+
$this->assertRegExp('#^Set-Cookie:\s+'.preg_quote($expected, '#').'$#m', str_replace("\r\n", "\n", (string) $actual));
308+
}
305309
}

0 commit comments

Comments
 (0)