1 | <?php |
||
10 | class RestContext extends BaseContext |
||
11 | { |
||
12 | /** |
||
13 | * @var Request |
||
14 | */ |
||
15 | protected $request; |
||
16 | |||
17 | public function __construct(Request $request) |
||
21 | |||
22 | /** |
||
23 | * Sends a HTTP request |
||
24 | * |
||
25 | * @Given I send a :method request to :url |
||
26 | */ |
||
27 | public function iSendARequestTo($method, $url, PyStringNode $body = null, $files = []) |
||
37 | |||
38 | /** |
||
39 | * Sends a HTTP request with a some parameters |
||
40 | * |
||
41 | * @Given I send a :method request to :url with parameters: |
||
42 | */ |
||
43 | public function iSendARequestToWithParameters($method, $url, TableNode $data) |
||
68 | |||
69 | /** |
||
70 | * Sends a HTTP request with a body |
||
71 | * |
||
72 | * @Given I send a :method request to :url with body: |
||
73 | */ |
||
74 | public function iSendARequestToWithBody($method, $url, PyStringNode $body) |
||
78 | |||
79 | /** |
||
80 | * Checks, whether the response content is equal to given text |
||
81 | * |
||
82 | * @Then the response should be equal to |
||
83 | * @Then the response should be equal to: |
||
84 | */ |
||
85 | public function theResponseShouldBeEqualTo(PyStringNode $expected) |
||
92 | |||
93 | /** |
||
94 | * Checks, whether the response content is null or empty string |
||
95 | * |
||
96 | * @Then the response should be empty |
||
97 | */ |
||
98 | public function theResponseShouldBeEmpty() |
||
104 | |||
105 | /** |
||
106 | * Checks, whether the header name is equal to given text |
||
107 | * |
||
108 | * @Then the header :name should be equal to :value |
||
109 | */ |
||
110 | public function theHeaderShouldBeEqualTo($name, $value) |
||
117 | |||
118 | /** |
||
119 | * Checks, whether the header name is not equal to given text |
||
120 | * |
||
121 | * @Then the header :name should not be equal to :value |
||
122 | */ |
||
123 | public function theHeaderShouldNotBeEqualTo($name, $value) { |
||
132 | |||
133 | public function theHeaderShouldBeContains($name, $value) |
||
141 | |||
142 | /** |
||
143 | * Checks, whether the header name contains the given text |
||
144 | * |
||
145 | * @Then the header :name should contain :value |
||
146 | */ |
||
147 | public function theHeaderShouldContain($name, $value) |
||
154 | |||
155 | /** |
||
156 | * Checks, whether the header name doesn't contain the given text |
||
157 | * |
||
158 | * @Then the header :name should not contain :value |
||
159 | */ |
||
160 | public function theHeaderShouldNotContain($name, $value) |
||
166 | |||
167 | /** |
||
168 | * Checks, whether the header not exist |
||
169 | * |
||
170 | * @Then the header :name should not exist |
||
171 | */ |
||
172 | public function theHeaderShouldNotExist($name) |
||
178 | |||
179 | protected function theHeaderShouldExist($name) |
||
183 | |||
184 | /** |
||
185 | * @Then the header :name should match :regex |
||
186 | */ |
||
187 | public function theHeaderShouldMatch($name, $regex) |
||
197 | |||
198 | /** |
||
199 | * @Then the header :name should not match :regex |
||
200 | */ |
||
201 | public function theHeaderShouldNotMatch($name, $regex) |
||
210 | |||
211 | /** |
||
212 | * Checks, that the response header expire is in the future |
||
213 | * |
||
214 | * @Then the response should expire in the future |
||
215 | */ |
||
216 | public function theResponseShouldExpireInTheFuture() |
||
225 | |||
226 | /** |
||
227 | * Add an header element in a request |
||
228 | * |
||
229 | * @Then I add :name header equal to :value |
||
230 | */ |
||
231 | public function iAddHeaderEqualTo($name, $value) |
||
235 | |||
236 | /** |
||
237 | * @Then the response should be encoded in :encoding |
||
238 | */ |
||
239 | public function theResponseShouldBeEncodedIn($encoding) |
||
248 | |||
249 | /** |
||
250 | * @Then print last response headers |
||
251 | */ |
||
252 | public function printLastResponseHeaders() |
||
262 | |||
263 | |||
264 | /** |
||
265 | * @Then print the corresponding curl command |
||
266 | */ |
||
267 | public function printTheCorrespondingCurlCommand() |
||
288 | } |
||
289 |
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: