[HttpFoundation] included cookie headers in string representation

This commit is contained in:
jsor 2011-05-19 09:49:34 +02:00
parent e6d929aa71
commit f9b6c8b74a
2 changed files with 28 additions and 0 deletions

View File

@ -33,6 +33,21 @@ class ResponseHeaderBag extends HeaderBag
$this->set('cache-control', '');
}
}
/**
* {@inheritdoc}
*/
public function __toString()
{
$cookies = '';
foreach ($this->cookies as $cookie) {
$cookies .= 'Set-Cookie: '.$cookie."\r\n";
}
return
parent::__toString().
$cookies;
}
/**
* {@inheritdoc}

View File

@ -12,6 +12,7 @@
namespace Symfony\Tests\Component\HttpFoundation;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Symfony\Component\HttpFoundation\Cookie;
class ResponseHeaderBagTest extends \PHPUnit_Framework_TestCase
{
@ -62,4 +63,16 @@ class ResponseHeaderBagTest extends \PHPUnit_Framework_TestCase
$bag->set('Last-Modified', 'abcde');
$this->assertEquals('private, must-revalidate', $bag->get('Cache-Control'));
}
public function testToStringIncludesCookieHeaders()
{
$bag = new ResponseHeaderBag(array());
$bag->setCookie(new Cookie('foo', 'bar'));
$this->assertContains("Set-Cookie: foo=bar; path=/; httponly", explode("\r\n", $bag->__toString()));
$bag->clearCookie('foo');
$this->assertContains("Set-Cookie: foo=deleted; expires=Thu, 01 Jan 1970 00:00:00 GMT; httponly", explode("\r\n", $bag->__toString()));
}
}