public function testSetRemoveCookie() { $response = new Response(); $foo = new Cookie('foo', 'bar'); $foo->setSecure(true); $this->assertSame($response, $response->setCookie($foo)); $this->assertSame([$foo], $response->getCookies()); $this->assertSame(['foo=bar; Secure'], $response->getHeaderAsArray('Set-Cookie')); $bar = new Cookie('bar', 'baz'); $bar->setHttpOnly(true); $this->assertSame($response, $response->setCookie($bar)); $this->assertSame([$foo, $bar], $response->getCookies()); $this->assertSame(['foo=bar; Secure', 'bar=baz; HttpOnly'], $response->getHeaderAsArray('Set-Cookie')); $this->assertSame($response, $response->removeCookies()); $this->assertSame([], $response->getCookies()); $this->assertSame([], $response->getHeaderAsArray('Set-Cookie')); }
public function testToString() { $cookie = new Cookie('foo', 'bar'); $this->assertSame('foo=bar', (string) $cookie); $cookie->setExpires(2000000000); $this->assertSame('foo=bar; Expires=Wed, 18 May 2033 03:33:20 +0000', (string) $cookie); $cookie->setExpires(0)->setDomain('example.com'); $this->assertSame('foo=bar; Domain=example.com', (string) $cookie); $cookie->setDomain(null)->setPath('/'); $this->assertSame('foo=bar; Path=/', (string) $cookie); $cookie->setPath(null)->setSecure(true); $this->assertSame('foo=bar; Secure', (string) $cookie); $cookie->setHttpOnly(true); $this->assertSame('foo=bar; Secure; HttpOnly', (string) $cookie); }