Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit182dd8f

Browse files
committed
minor#20972 [HttpFoundation] Improved set cookie header tests (ro0NL)
This PR was squashed before being merged into the 2.7 branch (closes#20972).Discussion----------[HttpFoundation] Improved set cookie header tests| Q | A| ------------- | ---| Branch? | 2.7 (already in master)| Bug fix? | no| New feature? | no| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets | #... <!-- #-prefixed issue number(s), if any -->| License | MIT| Doc PR | symfony/symfony-docs#... <!--highly recommended for new features-->Separated from#20569Commits-------05bce71 [HttpFoundation] Improved set cookie header tests
2 parents1038221 +05bce71 commit182dd8f

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 =newResponseHeaderBag(array());
117117
$bag->setCookie(newCookie('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
publicfunctiontestClearCookieSecureNotHttpOnly()
@@ -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
publicfunctiontestReplace()
@@ -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 =newResponseHeaderBag();
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+
privatefunctionassertSetCookieHeader($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)

[8]ページ先頭

©2009-2025 Movatter.jp