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

Skip to content

Commit 6ba0414

Browse files
minor #20983 [HttpKernel] Fix ClientTest cookie format assertions (nicolas-grekas)
This PR was merged into the 3.1 branch. Discussion ---------- [HttpKernel] Fix ClientTest cookie format assertions | Q | A | ------------- | --- | Branch? | 3.1 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Commits ------- 20190c3 [HttpKernel] Fix ClientTest cookie format assertions
2 parents f4b3b87 + 20190c3 commit 6ba0414

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

src/Symfony/Component/HttpKernel/Tests/ClientTest.php

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
use Symfony\Component\HttpFoundation\File\UploadedFile;
1919
use Symfony\Component\HttpKernel\Tests\Fixtures\TestClient;
2020

21+
/**
22+
* @group time-sensitive
23+
*/
2124
class ClientTest extends \PHPUnit_Framework_TestCase
2225
{
2326
public function testDoRequest()
@@ -56,22 +59,38 @@ public function testFilterResponseConvertsCookies()
5659
$m = $r->getMethod('filterResponse');
5760
$m->setAccessible(true);
5861

59-
$expected = array(
62+
$expected31 = array(
6063
'foo=bar; expires=Sun, 15 Feb 2009 20:00:00 GMT; domain=http://example.com; path=/foo; secure; httponly',
6164
'foo1=bar1; expires=Sun, 15 Feb 2009 20:00:00 GMT; domain=http://example.com; path=/foo; secure; httponly',
6265
);
66+
$expected33 = array(
67+
'foo=bar; expires=Sun, 15-Feb-2009 20:00:00 GMT; max-age='.(strtotime('Sun, 15-Feb-2009 20:00:00 GMT') - time()).'; path=/foo; domain=http://example.com; secure; httponly',
68+
'foo1=bar1; expires=Sun, 15-Feb-2009 20:00:00 GMT; max-age='.(strtotime('Sun, 15-Feb-2009 20:00:00 GMT') - time()).'; path=/foo; domain=http://example.com; secure; httponly',
69+
);
6370

6471
$response = new Response();
6572
$response->headers->setCookie(new Cookie('foo', 'bar', \DateTime::createFromFormat('j-M-Y H:i:s T', '15-Feb-2009 20:00:00 GMT')->format('U'), '/foo', 'http://example.com', true, true));
6673
$domResponse = $m->invoke($client, $response);
67-
$this->assertEquals($expected[0], $domResponse->getHeader('Set-Cookie'));
74+
try {
75+
$this->assertEquals($expected31[0], $domResponse->getHeader('Set-Cookie'));
76+
} catch (\PHPUnit_Framework_ExpectationFailedException $e) {
77+
$this->assertEquals($expected33[0], $domResponse->getHeader('Set-Cookie'));
78+
}
6879

6980
$response = new Response();
7081
$response->headers->setCookie(new Cookie('foo', 'bar', \DateTime::createFromFormat('j-M-Y H:i:s T', '15-Feb-2009 20:00:00 GMT')->format('U'), '/foo', 'http://example.com', true, true));
7182
$response->headers->setCookie(new Cookie('foo1', 'bar1', \DateTime::createFromFormat('j-M-Y H:i:s T', '15-Feb-2009 20:00:00 GMT')->format('U'), '/foo', 'http://example.com', true, true));
7283
$domResponse = $m->invoke($client, $response);
73-
$this->assertEquals($expected[0], $domResponse->getHeader('Set-Cookie'));
74-
$this->assertEquals($expected, $domResponse->getHeader('Set-Cookie', false));
84+
try {
85+
$this->assertEquals($expected31[0], $domResponse->getHeader('Set-Cookie'));
86+
} catch (\PHPUnit_Framework_ExpectationFailedException $e) {
87+
$this->assertEquals($expected33[0], $domResponse->getHeader('Set-Cookie'));
88+
}
89+
try {
90+
$this->assertEquals($expected31, $domResponse->getHeader('Set-Cookie', false));
91+
} catch (\PHPUnit_Framework_ExpectationFailedException $e) {
92+
$this->assertEquals($expected33, $domResponse->getHeader('Set-Cookie', false));
93+
}
7594
}
7695

7796
public function testFilterResponseSupportsStreamedResponses()

0 commit comments

Comments
 (0)