-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathCookieJarSpec.php
178 lines (134 loc) · 4.76 KB
/
CookieJarSpec.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php
namespace spec\Http\Message;
use Http\Message\Cookie;
use PhpSpec\ObjectBehavior;
class CookieJarSpec extends ObjectBehavior
{
public function it_is_initializable()
{
$this->shouldHaveType('Http\Message\CookieJar');
}
public function it_is_an_iterator_aggregate()
{
$this->getIterator()->shouldHaveType('Iterator');
}
public function it_has_a_cookie()
{
$cookie = new Cookie('name', 'value');
$this->addCookie($cookie);
$this->hasCookie($cookie)->shouldReturn(true);
$this->hasCookies()->shouldReturn(true);
}
public function it_accepts_a_cookie()
{
$cookie = new Cookie('name', 'value');
$cookie2 = new Cookie('name', 'value2');
$this->addCookie($cookie);
$this->addCookie($cookie2);
$this->hasCookie($cookie)->shouldReturn(false);
$this->hasCookie($cookie2)->shouldReturn(true);
}
public function it_removes_a_cookie_with_an_empty_value()
{
$cookie = new Cookie('name', 'value');
$cookie2 = new Cookie('name');
$this->addCookie($cookie);
$this->addCookie($cookie2);
$this->hasCookie($cookie)->shouldReturn(false);
$this->hasCookie($cookie2)->shouldReturn(false);
}
public function it_removes_a_cookie_with_a_lower_expiration_time()
{
$cookie = new Cookie('name', 'value', 100);
$cookie2 = new Cookie('name', 'value', 1000);
$this->addCookie($cookie);
$this->addCookie($cookie2);
$this->hasCookie($cookie)->shouldReturn(false);
$this->hasCookie($cookie2)->shouldReturn(true);
}
public function it_removes_a_cookie()
{
$cookie = new Cookie('name', 'value', 100);
$this->addCookie($cookie);
$this->removeCookie($cookie);
$this->hasCookie($cookie)->shouldReturn(false);
}
public function it_returns_all_cookies()
{
$cookie = new Cookie('name', 'value');
$cookie2 = new Cookie('name2', 'value');
$this->addCookie($cookie);
$this->addCookie($cookie2);
$this->getCookies()->shouldBeAnArrayOfInstance('Http\Message\Cookie');
}
public function it_returns_the_matching_cookies()
{
$cookie = new Cookie('name', 'value');
$cookie2 = new Cookie('name', 'value2');
$this->addCookie($cookie);
$this->getMatchingCookies($cookie2)->shouldBeAnArrayOfInstance('Http\Message\Cookie');
}
public function it_sets_cookies()
{
$cookie = new Cookie('name', 'value');
$this->setCookies([$cookie]);
$this->hasCookie($cookie)->shouldReturn(true);
$this->hasCookies()->shouldReturn(true);
$this->count()->shouldReturn(1);
}
public function it_accepts_cookies()
{
$cookie = new Cookie('name', 'value');
$cookie2 = new Cookie('name2', 'value');
$this->addCookie($cookie);
$this->addCookies([$cookie2]);
$this->hasCookie($cookie)->shouldReturn(true);
$this->hasCookie($cookie2)->shouldReturn(true);
$this->hasCookies()->shouldReturn(true);
$this->count()->shouldReturn(2);
}
public function it_removes_cookies()
{
$cookie = new Cookie('name', 'value');
$cookie2 = new Cookie('name2', 'value');
$this->addCookies([$cookie, $cookie2]);
$this->removeCookies([$cookie2]);
$this->hasCookie($cookie)->shouldReturn(true);
$this->hasCookie($cookie2)->shouldReturn(false);
$this->hasCookies()->shouldReturn(true);
$this->count()->shouldReturn(1);
}
public function it_removes_matching_cookies()
{
$cookie = new Cookie('name', 'value');
$cookie2 = new Cookie('name2', 'value', 0, 'php-http.org');
$this->addCookies([$cookie, $cookie2]);
$this->removeMatchingCookies('name2', 'php-http.org', '/');
$this->hasCookie($cookie)->shouldReturn(true);
$this->hasCookie($cookie2)->shouldReturn(false);
$this->hasCookies()->shouldReturn(true);
$this->count()->shouldReturn(1);
}
public function it_clears_cookies()
{
$cookie = new Cookie('name', 'value', 0, 'php-http.org');
$cookie2 = new Cookie('name2', 'value');
$this->addCookies([$cookie, $cookie2]);
$this->clear();
$this->hasCookies()->shouldReturn(false);
$this->count()->shouldReturn(0);
}
public function getMatchers(): array
{
return [
'beAnArrayOfInstance' => function ($subject, $instance) {
foreach ($subject as $element) {
if (!$element instanceof $instance) {
return false;
}
}
return true;
},
];
}
}