Completed
Push — master ( d44a4d...4aa695 )
by Iman
09:02
created

CheckExpectations::check()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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
    public function __construct($last)
15
    {
16
        $this->last = $last;
17
    }
18
19
    public function check()
20
    {
21
        $this->checkExceptions();
22
        $this->fireEvents();
23
        $this->checkResponse();
24
    }
25
26
    private function checkResponse()
27
    {
28
        if (! $this->last->http) {
29
            return;
30
        }
31
        $method = $this->last->http['method'];
32
33
        $response = $this->last->app->$method($this->last->http['url'], $this->last->http['data']);
34
35
        foreach ($this->last->assertion as $assertion) {
36
            $type = $assertion['type'];
37
            $response->$type($assertion['value']);
38
        }
39
    }
40
41
    private function fireEvents()
42
    {
43
        if ($this->last->event) {
44
            event($this->last->event);
45
        }
46
    }
47
48
    private function checkExceptions()
49
    {
50
        if ($this->last->exception) {
51
            $this->last->app->expectException($this->last->exception);
52
        }
53
    }
54
}