|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Imanghafoori\HeyMan\MakeSure; |
|
4
|
|
|
|
|
5
|
|
|
class HttpClient |
|
6
|
|
|
{ |
|
7
|
|
|
public $app; |
|
8
|
|
|
|
|
9
|
|
|
private $chain; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* HttpClient constructor. |
|
13
|
|
|
* |
|
14
|
|
|
* @param $phpunit |
|
15
|
|
|
*/ |
|
16
|
33 |
|
public function __construct($phpunit) |
|
17
|
|
|
{ |
|
18
|
33 |
|
$this->chain = new Chain($phpunit); |
|
19
|
33 |
|
} |
|
20
|
|
|
|
|
21
|
3 |
|
public function sendingPostRequest($uri, array $data = [], array $headers = []): IsRespondedWith |
|
22
|
|
|
{ |
|
23
|
3 |
|
$this->chain->http($uri, $data, $headers, 'post'); |
|
24
|
|
|
|
|
25
|
3 |
|
return new IsRespondedWith($this->chain); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
1 |
|
public function sendingJsonPostRequest($uri, array $data = [], array $headers = []): IsRespondedWith |
|
29
|
|
|
{ |
|
30
|
1 |
|
$this->chain->http($uri, $data, $headers, 'postJson'); |
|
31
|
|
|
|
|
32
|
1 |
|
return new IsRespondedWith($this->chain); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
1 |
|
public function sendingDeleteRequest($uri, array $data = [], array $headers = []) : IsRespondedWith |
|
36
|
|
|
{ |
|
37
|
1 |
|
$this->chain->http($uri, $data, $headers, 'delete'); |
|
38
|
|
|
|
|
39
|
1 |
|
return new IsRespondedWith($this->chain); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
1 |
|
public function sendingJsonDeleteRequest($uri, array $data = [], array $headers = []) : IsRespondedWith |
|
43
|
|
|
{ |
|
44
|
1 |
|
$this->chain->http($uri, $data, $headers, 'deleteJson'); |
|
45
|
|
|
|
|
46
|
1 |
|
return new IsRespondedWith($this->chain); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
26 |
|
public function sendingPutRequest($uri, array $data = [], array $headers = []) : IsRespondedWith |
|
50
|
|
|
{ |
|
51
|
26 |
|
$this->chain->http($uri, $data, $headers, 'put'); |
|
52
|
26 |
|
|
|
53
|
26 |
|
return new IsRespondedWith($this->chain); |
|
54
|
|
|
} |
|
55
|
26 |
|
|
|
56
|
|
|
public function sendingJsonPutRequest($uri, array $data = [], array $headers = []) : IsRespondedWith |
|
57
|
|
|
{ |
|
58
|
26 |
|
$this->chain->http($uri, $data, $headers, 'putJson'); |
|
59
|
|
|
|
|
60
|
|
|
return new IsRespondedWith($this->chain); |
|
61
|
1 |
|
} |
|
62
|
|
|
|
|
63
|
1 |
|
public function sendingPatchRequest($uri, array $data = [], array $headers = []) : IsRespondedWith |
|
64
|
1 |
|
{ |
|
65
|
|
|
$this->chain->http($uri, $data, $headers, 'patch'); |
|
66
|
1 |
|
|
|
67
|
|
|
return new IsRespondedWith($this->chain); |
|
68
|
1 |
|
} |
|
69
|
|
|
|
|
70
|
1 |
|
public function sendingJsonPatchRequest($uri, array $data = [], array $headers = []) : IsRespondedWith |
|
71
|
|
|
{ |
|
72
|
|
|
$this->chain->http($uri, $data, $headers, 'patchJson'); |
|
73
|
|
|
|
|
74
|
|
|
return new IsRespondedWith($this->chain); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function sendingGetRequest($uri, array $headers = []): IsRespondedWith |
|
78
|
|
|
{ |
|
79
|
|
|
$this->chain->http($uri, [], $headers, 'get'); |
|
80
|
|
|
|
|
81
|
|
|
return new IsRespondedWith($this->chain); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function sendingJsonGetRequest($uri, array $headers = []): IsRespondedWith |
|
85
|
|
|
{ |
|
86
|
|
|
$this->chain->http($uri, [], $headers, 'getJson'); |
|
87
|
|
|
|
|
88
|
|
|
return new IsRespondedWith($this->chain); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function exceptionIsThrown($type) |
|
92
|
|
|
{ |
|
93
|
|
|
$this->chain->exception = $type; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function whenEventHappens($event) |
|
97
|
|
|
{ |
|
98
|
|
|
$this->chain->event = $event; |
|
99
|
|
|
|
|
100
|
|
|
return $this; |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|