|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace EasyHttp\MockBuilder; |
|
4
|
|
|
|
|
5
|
|
|
use EasyHttp\MockBuilder\Contracts\HeaderAggregate; |
|
6
|
|
|
use EasyHttp\MockBuilder\Contracts\QueryParameterAggregate; |
|
7
|
|
|
use EasyHttp\MockBuilder\Contracts\ResponseBuilder; |
|
8
|
|
|
use EasyHttp\MockBuilder\Iterators\ArrayIterator; |
|
9
|
|
|
use EasyHttp\MockBuilder\Iterators\NotEmptyArrayValuesIterator; |
|
10
|
|
|
use EasyHttp\MockBuilder\Iterators\EmptyArrayValuesIterator; |
|
11
|
|
|
use EasyHttp\MockBuilder\ResponseBuilders\GuzzleResponseBuilder; |
|
12
|
|
|
|
|
13
|
|
|
class Expectation implements QueryParameterAggregate, HeaderAggregate |
|
14
|
|
|
{ |
|
15
|
|
|
protected ResponseBuilder $responseBuilder; |
|
16
|
|
|
|
|
17
|
|
|
private string $method; |
|
18
|
|
|
private string $path; |
|
19
|
|
|
private array $queryParams = []; |
|
20
|
|
|
private array $headers = []; |
|
21
|
|
|
|
|
22
|
|
|
private string $pathRegex; |
|
23
|
|
|
private array $missingQueryParams = []; |
|
24
|
|
|
private array $missingHeaders = []; |
|
25
|
|
|
|
|
26
|
|
|
private array $rejectedHeaders = []; |
|
27
|
|
|
|
|
28
|
107 |
|
public function then(): ResponseBuilder |
|
29
|
|
|
{ |
|
30
|
107 |
|
$this->responseBuilder = new GuzzleResponseBuilder(); |
|
31
|
|
|
|
|
32
|
107 |
|
return $this->responseBuilder; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
52 |
|
public function responseBuilder(): ResponseBuilder |
|
36
|
|
|
{ |
|
37
|
52 |
|
return $this->responseBuilder; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
107 |
|
public function getMethod(): ?string |
|
41
|
|
|
{ |
|
42
|
107 |
|
return $this->method ?? null; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
106 |
|
public function getPath(): ?string |
|
46
|
|
|
{ |
|
47
|
106 |
|
return $this->path ?? null; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
106 |
|
public function getPathRegex(): ?string |
|
51
|
|
|
{ |
|
52
|
106 |
|
return $this->pathRegex ?? null; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
8 |
|
public function methodIs(string $method): self |
|
56
|
|
|
{ |
|
57
|
8 |
|
$this->method = $method; |
|
58
|
|
|
|
|
59
|
8 |
|
return $this; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
3 |
|
public function pathIs(string $path): self |
|
63
|
|
|
{ |
|
64
|
3 |
|
$this->path = $path; |
|
65
|
|
|
|
|
66
|
3 |
|
return $this; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
1 |
|
public function pathMatch(string $regex): self |
|
70
|
|
|
{ |
|
71
|
1 |
|
$this->pathRegex = $regex; |
|
72
|
|
|
|
|
73
|
1 |
|
return $this; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
15 |
|
public function queryParamIs(string $key, string $value): self |
|
77
|
|
|
{ |
|
78
|
15 |
|
$this->queryParams[$key] = $value; |
|
79
|
|
|
|
|
80
|
15 |
|
return $this; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
14 |
|
public function queryParamExists(string $key): self |
|
84
|
|
|
{ |
|
85
|
14 |
|
$this->queryParams[$key] = null; |
|
86
|
|
|
|
|
87
|
14 |
|
return $this; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
12 |
|
public function queryParamNotExist(string $key): self |
|
91
|
|
|
{ |
|
92
|
12 |
|
$this->missingQueryParams[] = $key; |
|
93
|
|
|
|
|
94
|
12 |
|
return $this; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
7 |
|
public function queryParamsAre(array $params): self |
|
98
|
|
|
{ |
|
99
|
7 |
|
array_walk( |
|
100
|
7 |
|
$params, |
|
101
|
7 |
|
function ($value, $key) { |
|
102
|
6 |
|
$this->queryParamIs($key, $value); |
|
103
|
7 |
|
} |
|
104
|
|
|
); |
|
105
|
|
|
|
|
106
|
7 |
|
return $this; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
7 |
|
public function queryParamsExist(array $params): self |
|
110
|
|
|
{ |
|
111
|
7 |
|
array_walk( |
|
112
|
7 |
|
$params, |
|
113
|
7 |
|
function ($value) { |
|
114
|
6 |
|
$this->queryParamExists($value); |
|
115
|
7 |
|
} |
|
116
|
|
|
); |
|
117
|
|
|
|
|
118
|
7 |
|
return $this; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
7 |
|
public function queryParamsNotExist(array $params): self |
|
122
|
|
|
{ |
|
123
|
7 |
|
array_walk( |
|
124
|
7 |
|
$params, |
|
125
|
7 |
|
function ($value) { |
|
126
|
6 |
|
$this->queryParamNotExist($value); |
|
127
|
7 |
|
} |
|
128
|
|
|
); |
|
129
|
|
|
|
|
130
|
7 |
|
return $this; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
12 |
|
public function headerIs(string $key, string $value): self |
|
134
|
|
|
{ |
|
135
|
12 |
|
$this->headers[$key] = $value; |
|
136
|
|
|
|
|
137
|
12 |
|
return $this; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
8 |
|
public function headerIsNot(string $key, string $value): self |
|
141
|
|
|
{ |
|
142
|
8 |
|
$this->rejectedHeaders[$key] = $value; |
|
143
|
|
|
|
|
144
|
8 |
|
return $this; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
12 |
|
public function headerExists(string $key): self |
|
148
|
|
|
{ |
|
149
|
12 |
|
$this->headers[$key] = null; |
|
150
|
|
|
|
|
151
|
12 |
|
return $this; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
12 |
|
public function headerNotExist(string $key): self |
|
155
|
|
|
{ |
|
156
|
12 |
|
$this->missingHeaders[] = $key; |
|
157
|
|
|
|
|
158
|
12 |
|
return $this; |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
7 |
|
public function headersAre(array $headers): self |
|
162
|
|
|
{ |
|
163
|
7 |
|
array_walk( |
|
164
|
7 |
|
$headers, |
|
165
|
7 |
|
function ($value, $key) { |
|
166
|
6 |
|
$this->headerIs($key, $value); |
|
167
|
7 |
|
} |
|
168
|
|
|
); |
|
169
|
|
|
|
|
170
|
7 |
|
return $this; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
7 |
|
public function headersExist(array $headers): self |
|
174
|
|
|
{ |
|
175
|
7 |
|
array_walk( |
|
176
|
7 |
|
$headers, |
|
177
|
7 |
|
function ($value) { |
|
178
|
6 |
|
$this->headerExists($value); |
|
179
|
7 |
|
} |
|
180
|
|
|
); |
|
181
|
|
|
|
|
182
|
7 |
|
return $this; |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
7 |
|
public function headersNotExist(array $headers): self |
|
186
|
|
|
{ |
|
187
|
7 |
|
array_walk( |
|
188
|
7 |
|
$headers, |
|
189
|
7 |
|
function ($value) { |
|
190
|
6 |
|
$this->headerNotExist($value); |
|
191
|
7 |
|
} |
|
192
|
|
|
); |
|
193
|
|
|
|
|
194
|
7 |
|
return $this; |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
106 |
|
public function notEmptyQueryParamsIterator(): NotEmptyArrayValuesIterator |
|
198
|
|
|
{ |
|
199
|
106 |
|
return new NotEmptyArrayValuesIterator($this->queryParams); |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
97 |
|
public function emptyQueryParamsIterator(): EmptyArrayValuesIterator |
|
203
|
|
|
{ |
|
204
|
97 |
|
return new EmptyArrayValuesIterator($this->queryParams); |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
88 |
|
public function missingQueryParamsIterator(): ArrayIterator |
|
208
|
|
|
{ |
|
209
|
88 |
|
return new ArrayIterator($this->missingQueryParams); |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
80 |
|
public function notEmptyHeadersIterator(): NotEmptyArrayValuesIterator |
|
213
|
|
|
{ |
|
214
|
80 |
|
return new NotEmptyArrayValuesIterator($this->headers); |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
68 |
|
public function emptyHeadersIterator(): EmptyArrayValuesIterator |
|
218
|
|
|
{ |
|
219
|
68 |
|
return new EmptyArrayValuesIterator($this->headers); |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
60 |
|
public function missingHeadersIterator(): ArrayIterator |
|
223
|
|
|
{ |
|
224
|
60 |
|
return new ArrayIterator($this->missingHeaders); |
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
72 |
|
public function rejectedHeadersIterator(): ArrayIterator |
|
228
|
|
|
{ |
|
229
|
72 |
|
return new ArrayIterator($this->rejectedHeaders); |
|
230
|
|
|
} |
|
231
|
|
|
} |
|
232
|
|
|
|