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

PHPUnitMockingStrategy::doGet()   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\PHPUnit;
5
6
use Moka\Strategy\AbstractMockingStrategy;
7
use Moka\Stub\Stub;
8
use Moka\Stub\StubSet;
9
use PHPUnit_Framework_MockObject_Generator as MockGenerator;
10
use PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount as AnyInvokedCountMatcher;
11
use PHPUnit_Framework_MockObject_MockObject as MockObject;
12
13
/**
14
 * Class PHPUnitMockingStrategy
15
 * @package Moka\Strategy
16
 */
17
class PHPUnitMockingStrategy extends AbstractMockingStrategy
18
{
19
    /**
20
     * @var MockGenerator
21
     */
22
    private $generator;
23
24
    /**
25
     * PHPUnitMockingStrategy constructor.
26
     */
27
    public function __construct()
28
    {
29
        $this->generator = new MockGenerator();
30
        $this->setMockType(MockObject::class);
31
    }
32
33
    /**
34
     * @param string $fqcn
35
     * @return MockObject
36
     */
37
    protected function doBuild(string $fqcn)
38
    {
39
        return $this->generator->getMock(
40
            $fqcn,
41
            $methods = [],
42
            $arguments = [],
43
            $mockClassName = '',
44
            $callOriginalConstructor = false
45
        );
46
    }
47
48
    /**
49
     * @param MockObject $mock
50
     * @param StubSet $stubs
51
     * @return void
52
     */
53 View Code Duplication
    protected function doDecorate($mock, StubSet $stubs)
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
54
    {
55
        /** @var Stub $stub */
56
        foreach ($stubs as $stub) {
57
            $methodName = $stub->getMethodName();
58
            $methodValue = $stub->getMethodValue();
59
60
            $partial = $mock->expects(new AnyInvokedCountMatcher())->method($methodName);
61
            $methodValue instanceof \Throwable
62
                ? $partial->willThrowException($methodValue)
63
                : $partial->willReturn($methodValue);
64
        }
65
    }
66
67
    /**
68
     * @param MockObject $mock
69
     * @return MockObject
70
     */
71
    protected function doGet($mock)
72
    {
73
        return $mock;
74
    }
75
}
76