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

CheckExpectations   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 9
eloc 17
dl 0
loc 47
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A checkExceptions() 0 4 2
A check() 0 5 1
A fireEvents() 0 4 2
A checkResponse() 0 12 3
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
}