Completed
Push — master ( dbd889...95c92d )
by Alberto
02:45
created

MockeryMockingStrategy::doDecorate()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 3
nop 2
crap 3
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