Skip to content

Commit

Permalink
[HttpFoundation] included cookie headers in string representation
Browse files Browse the repository at this point in the history
  • Loading branch information
jsor committed May 19, 2011
1 parent e6d929a commit f9b6c8b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php
Expand Up @@ -33,6 +33,21 @@ public function __construct(array $headers = array())
$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}
Expand Down
Expand Up @@ -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
{
Expand Down Expand Up @@ -62,4 +63,16 @@ public function testCacheControlHeader()
$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()));
}
}

0 comments on commit f9b6c8b

Please sign in to comment.