21 $mock = $this->getMockBuilder(
'Guzzle\Plugin\Cookie\CookieJar\ArrayCookieJar')
22 ->setMethods(array(
'addCookiesFromResponse'))
25 $mock->expects($this->exactly(1))
26 ->method(
'addCookiesFromResponse')
30 $plugin->onRequestSent(
new Event(array(
31 'response' => $response
37 $cookie =
new Cookie(array(
42 $mock = $this->getMockBuilder(
'Guzzle\Plugin\Cookie\CookieJar\ArrayCookieJar')
43 ->setMethods(array(
'getMatchingCookies'))
46 $mock->expects($this->once())
47 ->method(
'getMatchingCookies')
48 ->will($this->returnValue(array($cookie)));
53 $client->getEventDispatcher()->addSubscriber($plugin);
55 $request = $client->get(
'http://www.example.com');
56 $plugin->onRequestBeforeSend(
new Event(array(
60 $this->assertEquals(
'bar', $request->getCookie(
'foo'));
68 "HTTP/1.1 302 Moved Temporarily\r\n" .
69 "Set-Cookie: test=583551; expires=Wednesday, 23-Mar-2050 19:49:45 GMT; path=/\r\n" .
70 "Location: /redirect\r\n\r\n",
71 "HTTP/1.1 200 OK\r\n" .
72 "Content-Length: 0\r\n\r\n",
73 "HTTP/1.1 200 OK\r\n" .
74 "Content-Length: 0\r\n\r\n"
78 $client->getEventDispatcher()->addSubscriber($plugin);
80 $client->get()->send();
81 $request = $client->get();
83 $this->assertEquals(
'test=583551', $request->getHeader(
'Cookie'));
85 $requests = $this->
getServer()->getReceivedRequests(
true);
87 $this->assertEquals(
'test=583551', $requests[2]->getHeader(
'Cookie'));
89 $this->assertEquals(
'test=583551', $requests[1]->getHeader(
'Cookie'));
97 $jar->add(
new Cookie(array(
98 'domain' =>
'example.com',
102 'expires' => time() + 3600
105 $client =
new Client(
'http://example.com');
106 $client->getEventDispatcher()->addSubscriber($plugin);
109 $request = $client->get();
110 $request->setResponse(
new Response(200),
true);
112 $this->assertEquals(
'hi', $request->getCookie(
'test'));
115 $request = $client->get();
116 $request->getParams()->set(
'cookies.disable',
true);
117 $request->setResponse(
new Response(200),
true);
119 $this->assertNull($request->getCookie(
'test'));
126 $this->assertSame($jar, $plugin->getCookieJar());
131 $cookie =
new Cookie(array(
'domain' =>
'/foo/^$[A-Z]+/'));
132 $this->assertFalse($cookie->matchesDomain(
'foo'));