|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Behat\Gherkin\Node\PyStringNode; |
|
4
|
|
|
|
|
5
|
|
|
class RestContext extends \Behatch\Context\RestContext |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* @Given I send a :method request to the entity :entityId with body: |
|
9
|
|
|
* @param $method |
|
10
|
|
|
* @param string $entityId |
|
11
|
|
|
* @param PyStringNode $body |
|
12
|
|
|
* @throws Exception |
|
13
|
|
|
*/ |
|
14
|
|
|
public function iSendARequestToEntityWithBody($method, string $entityId, PyStringNode $body) |
|
15
|
|
|
{ |
|
16
|
|
|
$this->iSendARequestTo($method, JsonContext::getVar($entityId), $body); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Sends a HTTP request |
|
21
|
|
|
* |
|
22
|
|
|
* @Given I send a :method request to the entity :entity |
|
23
|
|
|
* @param $method |
|
24
|
|
|
* @param string $entity |
|
25
|
|
|
* @throws Exception |
|
26
|
|
|
*/ |
|
27
|
|
|
public function iSendARequestToEntity($method, string $entity) |
|
28
|
|
|
{ |
|
29
|
|
|
$this->iSendARequestTo($method, JsonContext::getVar($entity), null, []); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Sends a HTTP request |
|
34
|
|
|
* |
|
35
|
|
|
* @Given I send a :method request to the sub-resource :resource of :entity with body: |
|
36
|
|
|
* @param $method |
|
37
|
|
|
* @param string $entity |
|
38
|
|
|
* @param PyStringNode|null $body |
|
39
|
|
|
* @param array $files |
|
40
|
|
|
* @throws Exception |
|
41
|
|
|
*/ |
|
42
|
|
|
public function iSendARequestToSubresourceOfEntity($method, string $url, string $entity, PyStringNode $body = null, $files = []) |
|
43
|
|
|
{ |
|
44
|
|
|
$this->iSendARequestTo($method, JsonContext::getVar($entity) . '/' . $url, $body, $files); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @Given I send a :method request to :url with the json variable :var as the body |
|
49
|
|
|
* @throws Exception |
|
50
|
|
|
*/ |
|
51
|
|
|
public function iSendARequestToWithBodyFromJsonVar($method, $url, $var) |
|
52
|
|
|
{ |
|
53
|
|
|
$this->iSendARequestTo($method, $url, new PyStringNode([JsonContext::getJsonVar($var)->encode()], 1), []); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|