[HttpKernel] Fix ClientTest cookie format assertions

This commit is contained in:
Nicolas Grekas 2016-12-18 21:52:30 +01:00
parent f4b3b87ef7
commit 20190c3861

View File

@ -18,6 +18,9 @@ use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpKernel\Tests\Fixtures\TestClient;
/**
* @group time-sensitive
*/
class ClientTest extends \PHPUnit_Framework_TestCase
{
public function testDoRequest()
@ -56,22 +59,38 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$m = $r->getMethod('filterResponse');
$m->setAccessible(true);
$expected = array(
$expected31 = array(
'foo=bar; expires=Sun, 15 Feb 2009 20:00:00 GMT; domain=http://example.com; path=/foo; secure; httponly',
'foo1=bar1; expires=Sun, 15 Feb 2009 20:00:00 GMT; domain=http://example.com; path=/foo; secure; httponly',
);
$expected33 = array(
'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',
'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',
);
$response = new Response();
$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));
$domResponse = $m->invoke($client, $response);
$this->assertEquals($expected[0], $domResponse->getHeader('Set-Cookie'));
try {
$this->assertEquals($expected31[0], $domResponse->getHeader('Set-Cookie'));
} catch (\PHPUnit_Framework_ExpectationFailedException $e) {
$this->assertEquals($expected33[0], $domResponse->getHeader('Set-Cookie'));
}
$response = new Response();
$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));
$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));
$domResponse = $m->invoke($client, $response);
$this->assertEquals($expected[0], $domResponse->getHeader('Set-Cookie'));
$this->assertEquals($expected, $domResponse->getHeader('Set-Cookie', false));
try {
$this->assertEquals($expected31[0], $domResponse->getHeader('Set-Cookie'));
} catch (\PHPUnit_Framework_ExpectationFailedException $e) {
$this->assertEquals($expected33[0], $domResponse->getHeader('Set-Cookie'));
}
try {
$this->assertEquals($expected31, $domResponse->getHeader('Set-Cookie', false));
} catch (\PHPUnit_Framework_ExpectationFailedException $e) {
$this->assertEquals($expected33, $domResponse->getHeader('Set-Cookie', false));
}
}
public function testFilterResponseSupportsStreamedResponses()