3
3
namespace spec \Http \Client \Plugin ;
4
4
5
5
use Http \Promise \FulfilledPromise ;
6
- use Http \Cookie \Cookie ;
7
- use Http \Cookie \CookieJar ;
6
+ use Http \Message \Cookie ;
7
+ use Http \Message \CookieJar ;
8
8
use Http \Promise \Promise ;
9
9
use Psr \Http \Message \RequestInterface ;
10
10
use Psr \Http \Message \ResponseInterface ;
14
14
15
15
class CookiePluginSpec extends ObjectBehavior
16
16
{
17
- function let (CookieJar $ cookieJar )
17
+ private $ cookieJar ;
18
+
19
+ function let ()
18
20
{
19
- $ this ->beConstructedWith ($ cookieJar );
21
+ $ this ->cookieJar = new CookieJar ();
22
+
23
+ $ this ->beConstructedWith ($ this ->cookieJar );
20
24
}
21
25
22
26
function it_is_initializable ()
@@ -29,11 +33,11 @@ function it_is_a_plugin()
29
33
$ this ->shouldImplement ('Http\Client\Plugin\Plugin ' );
30
34
}
31
35
32
- function it_loads_cookie (CookieJar $ cookieJar , RequestInterface $ request , UriInterface $ uri , Promise $ promise )
36
+ function it_loads_cookie (RequestInterface $ request , UriInterface $ uri , Promise $ promise )
33
37
{
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 );
35
40
36
- $ cookieJar ->getCookies ()->willReturn ([$ cookie ]);
37
41
$ request ->getUri ()->willReturn ($ uri );
38
42
$ uri ->getHost ()->willReturn ('test.com ' );
39
43
$ uri ->getPath ()->willReturn ('/ ' );
@@ -47,11 +51,11 @@ function it_loads_cookie(CookieJar $cookieJar, RequestInterface $request, UriInt
47
51
}, function () {});
48
52
}
49
53
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 )
51
55
{
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 );
53
58
54
- $ cookieJar ->getCookies ()->willReturn ([$ cookie ]);
55
59
$ request ->withAddedHeader ('Cookie ' , 'name=value ' )->shouldNotBeCalled ();
56
60
57
61
$ this ->handleRequest ($ request , function (RequestInterface $ requestReceived ) use ($ request , $ promise ) {
@@ -61,11 +65,11 @@ function it_does_not_load_cookie_if_expired(CookieJar $cookieJar, RequestInterfa
61
65
}, function () {});
62
66
}
63
67
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 )
65
69
{
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 );
67
72
68
- $ cookieJar ->getCookies ()->willReturn ([$ cookie ]);
69
73
$ request ->getUri ()->willReturn ($ uri );
70
74
$ uri ->getHost ()->willReturn ('test.com ' );
71
75
@@ -78,11 +82,11 @@ function it_does_not_load_cookie_if_domain_does_not_match(CookieJar $cookieJar,
78
82
}, function () {});
79
83
}
80
84
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 )
82
86
{
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 );
84
89
85
- $ cookieJar ->getCookies ()->willReturn ([$ cookie ]);
86
90
$ request ->getUri ()->willReturn ($ uri );
87
91
$ uri ->getHost ()->willReturn ('test.com ' );
88
92
$ uri ->getPath ()->willReturn ('/ ' );
@@ -96,11 +100,11 @@ function it_does_not_load_cookie_if_path_does_not_match(CookieJar $cookieJar, Re
96
100
}, function () {});
97
101
}
98
102
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 )
100
104
{
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 );
102
107
103
- $ cookieJar ->getCookies ()->willReturn ([$ cookie ]);
104
108
$ request ->getUri ()->willReturn ($ uri );
105
109
$ uri ->getHost ()->willReturn ('test.com ' );
106
110
$ uri ->getPath ()->willReturn ('/ ' );
@@ -115,11 +119,11 @@ function it_does_not_load_cookie_when_cookie_is_secure(CookieJar $cookieJar, Req
115
119
}, function () {});
116
120
}
117
121
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 )
119
123
{
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 );
121
126
122
- $ cookieJar ->getCookies ()->willReturn ([$ cookie ]);
123
127
$ request ->getUri ()->willReturn ($ uri );
124
128
$ uri ->getHost ()->willReturn ('test.com ' );
125
129
$ uri ->getPath ()->willReturn ('/ ' );
@@ -134,10 +138,8 @@ function it_loads_cookie_when_cookie_is_secure(CookieJar $cookieJar, RequestInte
134
138
}, function () {});
135
139
}
136
140
137
- function it_saves_cookie (CookieJar $ cookieJar , RequestInterface $ request , ResponseInterface $ response , UriInterface $ uri )
141
+ function it_saves_cookie (RequestInterface $ request , ResponseInterface $ response , UriInterface $ uri )
138
142
{
139
- $ cookieJar ->getCookies ()->willReturn ([]);
140
-
141
143
$ next = function () use ($ response ) {
142
144
return new FulfilledPromise ($ response ->getWrappedObject ());
143
145
};
@@ -147,9 +149,6 @@ function it_saves_cookie(CookieJar $cookieJar, RequestInterface $request, Respon
147
149
'cookie=value ' ,
148
150
]);
149
151
150
- $ cookie = new Cookie ('cookie ' , 'value ' , 0 , 'test.com ' );
151
- $ cookieJar ->addCookie ($ cookie )->shouldBeCalled ();
152
-
153
152
$ request ->getUri ()->willReturn ($ uri );
154
153
$ uri ->getHost ()->willReturn ('test.com ' );
155
154
$ uri ->getPath ()->willReturn ('/ ' );
0 commit comments