Completed
Push — master ( 92cca6...dbd889 )
by Alberto
13s
created

MockeryMockingStrategy   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

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