Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 05bce71

Browse files
ro0NLfabpot
authored andcommitted
[HttpFoundation] Improved set cookie header tests
1 parent 0a4a92b commit 05bce71

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/Symfony/Component/HttpFoundation/Tests/ResponseHeaderBagTest.php

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

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

121121
$bag->clearCookie('foo');
122122

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

126126
public function testClearCookieSecureNotHttpOnly()
@@ -129,7 +129,7 @@ public function testClearCookieSecureNotHttpOnly()
129129

130130
$bag->clearCookie('foo', '/', null, true, false);
131131

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

135135
public function testReplace()
@@ -165,11 +165,10 @@ public function testCookiesWithSameNames()
165165

166166
$this->assertCount(4, $bag->getCookies());
167167

168-
$headers = explode("\r\n", $bag->__toString());
169-
$this->assertContains('Set-Cookie: foo=bar; path=/path/foo; domain=foo.bar; httponly', $headers);
170-
$this->assertContains('Set-Cookie: foo=bar; path=/path/foo; domain=foo.bar; httponly', $headers);
171-
$this->assertContains('Set-Cookie: foo=bar; path=/path/bar; domain=bar.foo; httponly', $headers);
172-
$this->assertContains('Set-Cookie: foo=bar; path=/; httponly', $headers);
168+
$this->assertSetCookieHeader('foo=bar; path=/path/foo; domain=foo.bar; httponly', $bag);
169+
$this->assertSetCookieHeader('foo=bar; path=/path/bar; domain=foo.bar; httponly', $bag);
170+
$this->assertSetCookieHeader('foo=bar; path=/path/bar; domain=bar.foo; httponly', $bag);
171+
$this->assertSetCookieHeader('foo=bar; path=/; httponly', $bag);
173172

174173
$cookies = $bag->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
175174
$this->assertTrue(isset($cookies['foo.bar']['/path/foo']['foo']));
@@ -223,7 +222,7 @@ public function testGetCookiesWithInvalidArgument()
223222
{
224223
$bag = new ResponseHeaderBag();
225224

226-
$cookies = $bag->getCookies('invalid_argument');
225+
$bag->getCookies('invalid_argument');
227226
}
228227

229228
/**
@@ -294,4 +293,9 @@ public function provideMakeDispositionFail()
294293
array('attachment', 'föö.html'),
295294
);
296295
}
296+
297+
private function assertSetCookieHeader($expected, ResponseHeaderBag $actual)
298+
{
299+
$this->assertRegExp('#^Set-Cookie:\s+'.preg_quote($expected, '#').'$#m', str_replace("\r\n", "\n", (string) $actual));
300+
}
297301
}

0 commit comments

Comments
 (0)