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

MockeryMockingStrategy   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 4
dl 0
loc 46
c 0
b 0
f 0
rs 10

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\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