Completed
Push — master ( 9f22d1...f046fa )
by Iman
06:44
created

HttpClient::whenYouReachCheckPoint()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Imanghafoori\HeyMan\MakeSure;
4
5
class HttpClient
6
{
7
    public $http = [];
8
9
    public $assertion;
10
11
    public $app;
12
13
    public $event;
14
15
    public $exception;
16
17
    /**
18
     * HttpClient constructor.
19
     *
20
     * @param $app
21
     */
22 26
    public function __construct($app)
23
    {
24 26
        $this->app = $app;
25 26
    }
26
27 2
    public function sendingPostRequest($uri, array $data = [], array $headers = []): IsRespondedWith
28
    {
29 2
        $this->http = [
30 2
            'method'  => 'post',
31 2
            'url'     => $uri,
32 2
            'data'    => $data,
33 2
            'headers' => $headers,
34
        ];
35
36 2
        return new IsRespondedWith($this);
37
    }
38
39
    public function sendingDeleteRequest($uri, array $data = [], array $headers = [])
40
    {
41
        $this->http = [
42
            'method'  => 'delete',
43
            'url'     => $uri,
44
            'data'    => $data,
45
            'headers' => $headers,
46
        ];
47
48
        return new IsRespondedWith($this);
49
    }
50
51
    public function sendingPutRequest($uri, array $data = [], array $headers = [])
52
    {
53
        $this->http = [
54
            'method'  => 'put',
55
            'url'     => $uri,
56
            'data'    => $data,
57
            'headers' => $headers,
58
        ];
59
60
        return new IsRespondedWith($this);
61
    }
62
63
    public function sendingPatchRequest($uri, array $data = [], array $headers = [])
64
    {
65
        $this->http = [
66
            'method'  => 'patch',
67
            'url'     => $uri,
68
            'data'    => $data,
69
            'headers' => $headers,
70
        ];
71
72
        return new IsRespondedWith($this);
73
    }
74
75 23
    public function sendingGetRequest($url): IsRespondedWith
76
    {
77 23
        $this->http = [
78 23
            'method' => 'get',
79 23
            'url'    => $url,
80
            'data'   => [],
81
        ];
82
83 23
        return new IsRespondedWith($this);
84
    }
85
86 1
    public function exceptionIsThrown($type)
87
    {
88 1
        $this->exception = $type;
89 1
    }
90
91 1
    public function whenEventHappens($event)
92
    {
93 1
        $this->event = $event;
94
95 1
        return $this;
96
    }
97
98 26
    public function whenYouReachCheckPoint($name)
99
    {
100 26
        return $this->whenEventHappens('heyman_checkpoint_'.$name);
101 25
    }
102
103
    public function __destruct()
104
    {
105
        (new CheckExpectations($this))->check();
106
    }
107
}
108