Skip to content

Commit 15ea05e

Browse files
committed
Merge pull request #41 from php-http/cookie
Update dependencies and cookie plugin
2 parents 3fdf49f + d796ade commit 15ea05e

File tree

3 files changed

+30
-33
lines changed

3 files changed

+30
-33
lines changed

composer.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@
1818
"psr/log": "^1.0",
1919
"psr/cache": "^1.0",
2020
"php-http/client-common": "^0.1.1",
21-
"php-http/message": "^0.1.1",
21+
"php-http/message": "^0.2",
2222
"symfony/options-resolver": "^2.6|^3.0"
2323
},
2424
"require-dev": {
25-
"php-http/cookie": "^0.1@dev",
2625
"symfony/stopwatch": "^2.3",
2726
"phpspec/phpspec": "^2.4",
2827
"henrikbjorn/phpspec-code-coverage" : "^1.0"
@@ -38,7 +37,6 @@
3837
}
3938
},
4039
"suggest": {
41-
"php-http/cookie": "Allow to use CookiePlugin",
4240
"symfony/stopwatch": "Allow to use the StopwatchPlugin",
4341
"psr/log-implementation": "Allow to use the LoggerPlugin",
4442
"psr/cache-implementation": "Allow to use the CachePlugin"

spec/CookiePluginSpec.php

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
namespace spec\Http\Client\Plugin;
44

55
use Http\Promise\FulfilledPromise;
6-
use Http\Cookie\Cookie;
7-
use Http\Cookie\CookieJar;
6+
use Http\Message\Cookie;
7+
use Http\Message\CookieJar;
88
use Http\Promise\Promise;
99
use Psr\Http\Message\RequestInterface;
1010
use Psr\Http\Message\ResponseInterface;
@@ -14,9 +14,13 @@
1414

1515
class CookiePluginSpec extends ObjectBehavior
1616
{
17-
function let(CookieJar $cookieJar)
17+
private $cookieJar;
18+
19+
function let()
1820
{
19-
$this->beConstructedWith($cookieJar);
21+
$this->cookieJar = new CookieJar();
22+
23+
$this->beConstructedWith($this->cookieJar);
2024
}
2125

2226
function it_is_initializable()
@@ -29,11 +33,11 @@ function it_is_a_plugin()
2933
$this->shouldImplement('Http\Client\Plugin\Plugin');
3034
}
3135

32-
function it_loads_cookie(CookieJar $cookieJar, RequestInterface $request, UriInterface $uri, Promise $promise)
36+
function it_loads_cookie(RequestInterface $request, UriInterface $uri, Promise $promise)
3337
{
34-
$cookie = new Cookie('name', 'value', (new \DateTime())->modify('+1day'), 'test.com');
38+
$cookie = new Cookie('name', 'value', 86400, 'test.com');
39+
$this->cookieJar->addCookie($cookie);
3540

36-
$cookieJar->getCookies()->willReturn([$cookie]);
3741
$request->getUri()->willReturn($uri);
3842
$uri->getHost()->willReturn('test.com');
3943
$uri->getPath()->willReturn('/');
@@ -47,11 +51,11 @@ function it_loads_cookie(CookieJar $cookieJar, RequestInterface $request, UriInt
4751
}, function () {});
4852
}
4953

50-
function it_does_not_load_cookie_if_expired(CookieJar $cookieJar, RequestInterface $request, UriInterface $uri, Promise $promise)
54+
function it_does_not_load_cookie_if_expired(RequestInterface $request, UriInterface $uri, Promise $promise)
5155
{
52-
$cookie = new Cookie('name', 'value', (new \DateTime())->modify('-1day'), 'test.com');
56+
$cookie = new Cookie('name', 'value', null, 'test.com', false, false, null, (new \DateTime())->modify('-1 day'));
57+
$this->cookieJar->addCookie($cookie);
5358

54-
$cookieJar->getCookies()->willReturn([$cookie]);
5559
$request->withAddedHeader('Cookie', 'name=value')->shouldNotBeCalled();
5660

5761
$this->handleRequest($request, function (RequestInterface $requestReceived) use ($request, $promise) {
@@ -61,11 +65,11 @@ function it_does_not_load_cookie_if_expired(CookieJar $cookieJar, RequestInterfa
6165
}, function () {});
6266
}
6367

64-
function it_does_not_load_cookie_if_domain_does_not_match(CookieJar $cookieJar, RequestInterface $request, UriInterface $uri, Promise $promise)
68+
function it_does_not_load_cookie_if_domain_does_not_match(RequestInterface $request, UriInterface $uri, Promise $promise)
6569
{
66-
$cookie = new Cookie('name', 'value', (new \DateTime())->modify('+1day'), 'test2.com');
70+
$cookie = new Cookie('name', 'value', 86400, 'test2.com');
71+
$this->cookieJar->addCookie($cookie);
6772

68-
$cookieJar->getCookies()->willReturn([$cookie]);
6973
$request->getUri()->willReturn($uri);
7074
$uri->getHost()->willReturn('test.com');
7175

@@ -78,11 +82,11 @@ function it_does_not_load_cookie_if_domain_does_not_match(CookieJar $cookieJar,
7882
}, function () {});
7983
}
8084

81-
function it_does_not_load_cookie_if_path_does_not_match(CookieJar $cookieJar, RequestInterface $request, UriInterface $uri, Promise $promise)
85+
function it_does_not_load_cookie_if_path_does_not_match(RequestInterface $request, UriInterface $uri, Promise $promise)
8286
{
83-
$cookie = new Cookie('name', 'value', (new \DateTime())->modify('+1day'), 'test.com', '/sub');
87+
$cookie = new Cookie('name', 'value', 86400, 'test.com', '/sub');
88+
$this->cookieJar->addCookie($cookie);
8489

85-
$cookieJar->getCookies()->willReturn([$cookie]);
8690
$request->getUri()->willReturn($uri);
8791
$uri->getHost()->willReturn('test.com');
8892
$uri->getPath()->willReturn('/');
@@ -96,11 +100,11 @@ function it_does_not_load_cookie_if_path_does_not_match(CookieJar $cookieJar, Re
96100
}, function () {});
97101
}
98102

99-
function it_does_not_load_cookie_when_cookie_is_secure(CookieJar $cookieJar, RequestInterface $request, UriInterface $uri, Promise $promise)
103+
function it_does_not_load_cookie_when_cookie_is_secure(RequestInterface $request, UriInterface $uri, Promise $promise)
100104
{
101-
$cookie = new Cookie('name', 'value', (new \DateTime())->modify('+1day'), 'test.com', null, true);
105+
$cookie = new Cookie('name', 'value', 86400, 'test.com', null, true);
106+
$this->cookieJar->addCookie($cookie);
102107

103-
$cookieJar->getCookies()->willReturn([$cookie]);
104108
$request->getUri()->willReturn($uri);
105109
$uri->getHost()->willReturn('test.com');
106110
$uri->getPath()->willReturn('/');
@@ -115,11 +119,11 @@ function it_does_not_load_cookie_when_cookie_is_secure(CookieJar $cookieJar, Req
115119
}, function () {});
116120
}
117121

118-
function it_loads_cookie_when_cookie_is_secure(CookieJar $cookieJar, RequestInterface $request, UriInterface $uri, Promise $promise)
122+
function it_loads_cookie_when_cookie_is_secure(RequestInterface $request, UriInterface $uri, Promise $promise)
119123
{
120-
$cookie = new Cookie('name', 'value', (new \DateTime())->modify('+1day'), 'test.com', null, true);
124+
$cookie = new Cookie('name', 'value', 86400, 'test.com', null, true);
125+
$this->cookieJar->addCookie($cookie);
121126

122-
$cookieJar->getCookies()->willReturn([$cookie]);
123127
$request->getUri()->willReturn($uri);
124128
$uri->getHost()->willReturn('test.com');
125129
$uri->getPath()->willReturn('/');
@@ -134,10 +138,8 @@ function it_loads_cookie_when_cookie_is_secure(CookieJar $cookieJar, RequestInte
134138
}, function () {});
135139
}
136140

137-
function it_saves_cookie(CookieJar $cookieJar, RequestInterface $request, ResponseInterface $response, UriInterface $uri)
141+
function it_saves_cookie(RequestInterface $request, ResponseInterface $response, UriInterface $uri)
138142
{
139-
$cookieJar->getCookies()->willReturn([]);
140-
141143
$next = function () use ($response) {
142144
return new FulfilledPromise($response->getWrappedObject());
143145
};
@@ -147,9 +149,6 @@ function it_saves_cookie(CookieJar $cookieJar, RequestInterface $request, Respon
147149
'cookie=value',
148150
]);
149151

150-
$cookie = new Cookie('cookie', 'value', 0, 'test.com');
151-
$cookieJar->addCookie($cookie)->shouldBeCalled();
152-
153152
$request->getUri()->willReturn($uri);
154153
$uri->getHost()->willReturn('test.com');
155154
$uri->getPath()->willReturn('/');

src/CookiePlugin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace Http\Client\Plugin;
44

5-
use Http\Cookie\Cookie;
6-
use Http\Cookie\CookieJar;
5+
use Http\Message\Cookie;
6+
use Http\Message\CookieJar;
77
use Psr\Http\Message\RequestInterface;
88
use Psr\Http\Message\ResponseInterface;
99

0 commit comments

Comments
 (0)