Completed
Push — master ( b72f37...0c7d03 )
by Alberto
15s
created

MockeryMockingStrategy   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 5
dl 0
loc 44
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A doBuild() 0 4 1
A doDecorate() 0 10 2
A doGet() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Moka\Plugin\Mockery;
5
6
use Mockery;
7
use Mockery\MockInterface;
8
use Moka\Strategy\AbstractMockingStrategy;
9
use Moka\Stub\Stub;
10
11
/**
12
 * Class MockeryMockingStrategy
13
 * @package Moka\Strategy
14
 */
15
class MockeryMockingStrategy extends AbstractMockingStrategy
16
{
17
    /**
18
     * MockeryMockingStrategy constructor.
19
     */
20 3
    public function __construct()
21
    {
22 3
        $this->setMockType(MockInterface::class);
23
    }
24
25
    /**
26
     * @param string $fqcn
27
     * @return MockInterface
28
     */
29 24
    protected function doBuild(string $fqcn)
30
    {
31 24
        return Mockery::mock($fqcn);
32
    }
33
34
    /**
35
     * @param MockInterface $mock
36
     * @param Stub $stub
37
     * @return void
38
     */
39 24
    protected function doDecorate($mock, Stub $stub)
40
    {
41 24
        $methodName = $stub->getMethodName();
42 24
        $methodValue = $stub->getMethodValue();
43
44 24
        $partial = $mock->shouldReceive($methodName)->zeroOrMoreTimes();
45 24
        $methodValue instanceof \Throwable
46 24
            ? $partial->andThrow($methodValue)
47 24
            : $partial->andReturn($methodValue);
48
    }
49
50
    /**
51
     * @param MockInterface $mock
52
     * @return MockInterface
53
     */
54 13
    protected function doGet($mock)
55
    {
56 13
        return $mock;
57
    }
58
}
59