Completed
Push — master ( aea954...9f22d1 )
by Iman
1312:51 queued 1306:32
created

CheckExpectations::checkResponses()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Imanghafoori\HeyMan\MakeSure;
4
5
class CheckExpectations
6
{
7
    private $last;
8
9
    /**
10
     * CheckExpectations constructor.
11
     *
12
     * @param $last
13
     */
14 26
    public function __construct($last)
15
    {
16 26
        $this->last = $last;
17 26
    }
18
19 26
    public function check()
20
    {
21 26
        $this->expectExceptions();
22 26
        $this->fireEvents();
23 25
        $this->checkResponse();
24 25
    }
25
26 25
    private function checkResponse()
27
    {
28 25
        if (!$this->last->http) {
29
            return;
30
        }
31 25
        $this->checkResponses($this->sendRequest());
32 25
    }
33
34
    /**
35
     * @return mixed
36
     */
37 25
    private function sendRequest()
38
    {
39 25
        $method = $this->last->http['method'];
40
41 25
        $response = $this->last->app->$method($this->last->http['url'], $this->last->http['data']);
42
43 25
        return $response;
44
    }
45
46
    /**
47
     * @param $response
48
     */
49 25
    private function checkResponses($response)
50
    {
51 25
        foreach ($this->last->assertion as $assertion) {
52 25
            $type = $assertion['type'];
53 25
            $response->$type($assertion['value']);
54
        }
55 25
    }
56
57 26
    private function fireEvents()
58
    {
59 26
        if ($this->last->event) {
60 1
            event($this->last->event);
61
        }
62 25
    }
63
64 26
    private function expectExceptions()
65
    {
66 26
        if ($this->last->exception) {
67 1
            $this->last->app->expectException($this->last->exception);
68
        }
69 26
    }
70
}
71