Completed
Push — master ( 4848aa...64d9da )
by Dmitry
03:44
created

Mock   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
wmc 7
lcom 2
cbo 1
dl 0
loc 46
ccs 15
cts 20
cp 0.75
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A withParams() 0 5 1
A handler() 0 14 3
A willDo() 0 4 1
A willReturn() 0 4 1
1
<?php
2
3
namespace Basis\Test;
4
5
use Basis\Converter;
6
use Basis\Test;
7
use Exception;
8
9
class Mock
10
{
11
    private $converter;
12
    private $test;
13
14
    public $params;
15
    public $result;
16
    public $calls = 0;
17
18 4
    public function __construct(Converter $converter, Test $test)
19
    {
20 4
        $this->converter = $converter;
21 4
        $this->test = $test;
22 4
    }
23
24
    public function withParams($params)
25
    {
26
        $this->params = $params;
27
        return $this;
28
    }
29
30 4
    public function handler($result)
31
    {
32 4
        $this->result = $result;
33 4
        if (is_string($result)) {
34
            if (!method_exists($this->test, $result)) {
35
                throw new Exception("Invalid method ".get_class($this->test)."::$result");
36
            }
37 1
            $this->result = function($params) use ($result) {
38 1
                $params = $this->converter->toObject($params);
39 1
                return $this->test->$result($params);
40
            };
41
        }
42 4
        return $this;
43
    }
44
45 1
    public function willDo($result)
46
    {
47 1
        return $this->handler($result);
48
    }
49
50 4
    public function willReturn($result)
51
    {
52 4
        return $this->handler($result);
53
    }
54
}
55