|
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
|
98 |
|
public function then(): ResponseBuilder |
|
27
|
|
|
{ |
|
28
|
98 |
|
$this->responseBuilder = new GuzzleResponseBuilder(); |
|
29
|
|
|
|
|
30
|
98 |
|
return $this->responseBuilder; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
47 |
|
public function responseBuilder(): ResponseBuilder |
|
34
|
|
|
{ |
|
35
|
47 |
|
return $this->responseBuilder; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
98 |
|
public function getMethod(): ?string |
|
39
|
|
|
{ |
|
40
|
98 |
|
return $this->method ?? null; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
97 |
|
public function getPath(): ?string |
|
44
|
|
|
{ |
|
45
|
97 |
|
return $this->path ?? null; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
97 |
|
public function getPathRegex(): ?string |
|
49
|
|
|
{ |
|
50
|
97 |
|
return $this->pathRegex ?? null; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
6 |
|
public function methodIs(string $method): self |
|
54
|
|
|
{ |
|
55
|
6 |
|
$this->method = $method; |
|
56
|
|
|
|
|
57
|
6 |
|
return $this; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
1 |
|
public function pathIs(string $path): self |
|
61
|
|
|
{ |
|
62
|
1 |
|
$this->path = $path; |
|
63
|
|
|
|
|
64
|
1 |
|
return $this; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
1 |
|
public function pathMatch(string $regex): self |
|
68
|
|
|
{ |
|
69
|
1 |
|
$this->pathRegex = $regex; |
|
70
|
|
|
|
|
71
|
1 |
|
return $this; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
15 |
|
public function queryParamIs(string $key, string $value): self |
|
75
|
|
|
{ |
|
76
|
15 |
|
$this->queryParams[$key] = $value; |
|
77
|
|
|
|
|
78
|
15 |
|
return $this; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
14 |
|
public function queryParamExists(string $key): self |
|
82
|
|
|
{ |
|
83
|
14 |
|
$this->queryParams[$key] = null; |
|
84
|
|
|
|
|
85
|
14 |
|
return $this; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
12 |
|
public function queryParamNotExists(string $key): self |
|
89
|
|
|
{ |
|
90
|
12 |
|
$this->missingQueryParams[] = $key; |
|
91
|
|
|
|
|
92
|
12 |
|
return $this; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
7 |
|
public function queryParamsAre(array $params): self |
|
96
|
|
|
{ |
|
97
|
7 |
|
array_walk( |
|
98
|
7 |
|
$params, |
|
99
|
7 |
|
function ($value, $key) { |
|
100
|
6 |
|
$this->queryParamIs($key, $value); |
|
101
|
7 |
|
} |
|
102
|
|
|
); |
|
103
|
|
|
|
|
104
|
7 |
|
return $this; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
7 |
|
public function queryParamsExists(array $params): self |
|
108
|
|
|
{ |
|
109
|
7 |
|
array_walk( |
|
110
|
7 |
|
$params, |
|
111
|
7 |
|
function ($value) { |
|
112
|
6 |
|
$this->queryParamExists($value); |
|
113
|
7 |
|
} |
|
114
|
|
|
); |
|
115
|
|
|
|
|
116
|
7 |
|
return $this; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
7 |
|
public function queryParamsNotExists(array $params): self |
|
120
|
|
|
{ |
|
121
|
7 |
|
array_walk( |
|
122
|
7 |
|
$params, |
|
123
|
7 |
|
function ($value) { |
|
124
|
6 |
|
$this->queryParamNotExists($value); |
|
125
|
7 |
|
} |
|
126
|
|
|
); |
|
127
|
|
|
|
|
128
|
7 |
|
return $this; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
12 |
|
public function headerIs(string $key, string $value): self |
|
132
|
|
|
{ |
|
133
|
12 |
|
$this->headers[$key] = $value; |
|
134
|
|
|
|
|
135
|
12 |
|
return $this; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
12 |
|
public function headerExists(string $key): self |
|
139
|
|
|
{ |
|
140
|
12 |
|
$this->headers[$key] = null; |
|
141
|
|
|
|
|
142
|
12 |
|
return $this; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
12 |
|
public function headerNotExists(string $key): self |
|
146
|
|
|
{ |
|
147
|
12 |
|
$this->missingHeaders[] = $key; |
|
148
|
|
|
|
|
149
|
12 |
|
return $this; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
7 |
|
public function headersAre(array $headers): self |
|
153
|
|
|
{ |
|
154
|
7 |
|
array_walk( |
|
155
|
7 |
|
$headers, |
|
156
|
7 |
|
function ($value, $key) { |
|
157
|
6 |
|
$this->headerIs($key, $value); |
|
158
|
7 |
|
} |
|
159
|
|
|
); |
|
160
|
|
|
|
|
161
|
7 |
|
return $this; |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
7 |
|
public function headersExists(array $headers): self |
|
165
|
|
|
{ |
|
166
|
7 |
|
array_walk( |
|
167
|
7 |
|
$headers, |
|
168
|
7 |
|
function ($value) { |
|
169
|
6 |
|
$this->headerExists($value); |
|
170
|
7 |
|
} |
|
171
|
|
|
); |
|
172
|
|
|
|
|
173
|
7 |
|
return $this; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
7 |
|
public function headersNotExists(array $headers): self |
|
177
|
|
|
{ |
|
178
|
7 |
|
array_walk( |
|
179
|
7 |
|
$headers, |
|
180
|
7 |
|
function ($value) { |
|
181
|
6 |
|
$this->headerNotExists($value); |
|
182
|
7 |
|
} |
|
183
|
|
|
); |
|
184
|
|
|
|
|
185
|
7 |
|
return $this; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
97 |
|
public function notEmptyQueryParamsIterator(): NotEmptyArrayValuesIterator |
|
189
|
|
|
{ |
|
190
|
97 |
|
return new NotEmptyArrayValuesIterator($this->queryParams); |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
88 |
|
public function emptyQueryParamsIterator(): EmptyArrayValuesIterator |
|
194
|
|
|
{ |
|
195
|
88 |
|
return new EmptyArrayValuesIterator($this->queryParams); |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
79 |
|
public function missingQueryParamsIterator(): ArrayIterator |
|
199
|
|
|
{ |
|
200
|
79 |
|
return new ArrayIterator($this->missingQueryParams); |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
71 |
|
public function notEmptyHeadersIterator(): NotEmptyArrayValuesIterator |
|
204
|
|
|
{ |
|
205
|
71 |
|
return new NotEmptyArrayValuesIterator($this->headers); |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
63 |
|
public function emptyHeadersIterator(): EmptyArrayValuesIterator |
|
209
|
|
|
{ |
|
210
|
63 |
|
return new EmptyArrayValuesIterator($this->headers); |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
55 |
|
public function missingHeadersIterator(): ArrayIterator |
|
214
|
|
|
{ |
|
215
|
55 |
|
return new ArrayIterator($this->missingHeaders); |
|
216
|
|
|
} |
|
217
|
|
|
} |
|
218
|
|
|
|