|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Imanghafoori\HeyMan\MakeSure; |
|
4
|
|
|
|
|
5
|
|
|
class HttpClient |
|
6
|
|
|
{ |
|
7
|
|
|
private $chain; |
|
8
|
|
|
|
|
9
|
|
|
private $methods = [ |
|
10
|
|
|
'sendingPostRequest' => 'post', |
|
11
|
|
|
'sendingJsonPostRequest' => 'postJson', |
|
12
|
|
|
'sendingDeleteRequest' => 'delete', |
|
13
|
|
|
'sendingJsonDeleteRequest' => 'deleteJson', |
|
14
|
|
|
'sendingPutRequest' => 'put', |
|
15
|
|
|
'sendingJsonPutRequest' => 'putJson', |
|
16
|
38 |
|
'sendingPatchRequest' => 'patch', |
|
17
|
|
|
'sendingJsonPatchRequest' => 'patchJson', |
|
18
|
38 |
|
'sendingGetRequest' => 'get', |
|
19
|
38 |
|
'sendingJsonGetRequest' => 'getJson', |
|
20
|
|
|
]; |
|
21
|
3 |
|
|
|
22
|
|
|
/** |
|
23
|
3 |
|
* HttpClient constructor. |
|
24
|
|
|
* |
|
25
|
3 |
|
* @param $phpunit |
|
26
|
|
|
*/ |
|
27
|
|
|
public function __construct($phpunit) |
|
28
|
1 |
|
{ |
|
29
|
|
|
$this->chain = new Chain($phpunit); |
|
30
|
1 |
|
} |
|
31
|
|
|
|
|
32
|
1 |
|
public function __call($method, $params) |
|
33
|
|
|
{ |
|
34
|
|
|
return $this->sendRequest($method, ...$params); |
|
35
|
2 |
|
} |
|
36
|
|
|
|
|
37
|
2 |
|
public function sendRequest($method, ...$data): IsRespondedWith |
|
38
|
|
|
{ |
|
39
|
2 |
|
$this->chain->http($this->methods[$method], ...$data); |
|
40
|
|
|
|
|
41
|
|
|
return new IsRespondedWith($this->chain); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function exceptionIsThrown($type) |
|
45
|
|
|
{ |
|
46
|
|
|
$this->chain->data['exception'] = $type; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
1 |
|
public function whenEventHappens($event) |
|
50
|
|
|
{ |
|
51
|
1 |
|
$this->chain->data['event'] = $event; |
|
52
|
|
|
|
|
53
|
1 |
|
return $this; |
|
54
|
|
|
} |
|
55
|
|
|
} |