Completed
Pull Request — master (#12)
by Angelo
08:49
created

MockeryMockingStrategy::doBuild()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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