/** * @group testCookie */ public function testCookie() { $test_cookie_data = array('name' => 'name', 'value' => 'value', 'expiration' => null, 'path' => '/path', 'domain' => 'whatever.com', 'secure' => true, 'httponly' => true); $test_cookie = new ResponseCookie($test_cookie_data['name'], $test_cookie_data['value'], $test_cookie_data['expiration'], $test_cookie_data['path'], $test_cookie_data['domain'], $test_cookie_data['secure'], $test_cookie_data['httponly']); $response = new Response(); // Make sure the cookies are initially empty $this->assertEmpty($response->cookies()->all()); // Set a cookies $response->cookies()->set($test_cookie_data['name'], $test_cookie); $this->assertNotEmpty($response->cookies()->all()); $the_cookie = $response->cookies()->get($test_cookie_data['name']); $this->assertNotNull($the_cookie); $this->assertTrue($the_cookie instanceof ResponseCookie); $this->assertSame($test_cookie_data['name'], $the_cookie->getName()); $this->assertSame($test_cookie_data['value'], $the_cookie->getValue()); $this->assertSame($test_cookie_data['path'], $the_cookie->getPath()); $this->assertSame($test_cookie_data['domain'], $the_cookie->getDomain()); $this->assertSame($test_cookie_data['secure'], $the_cookie->getSecure()); $this->assertSame($test_cookie_data['httponly'], $the_cookie->getHttpOnly()); $this->assertNull($the_cookie->getExpiration()); }
/** * @param Cookie $cookie * * @return mixed */ public function addCookie(Cookie $cookie) { $cookie = new ResponseCookie($cookie->getName(), $cookie->getValue(), $cookie->getExpiration(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly()); $this->response->cookies()->set($cookie->getName(), $cookie); }