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

MockeryMockingStrategy::doGet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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