Completed
Push — master ( 287957...33dce2 )
by Iman
14:01 queued 09:52
created

HttpClient::sendingPatchRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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