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

PHPUnitMockingStrategy::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 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 PHPUnit_Framework_MockObject_Generator as MockGenerator;
9
use PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount as AnyInvokedCountMatcher;
10
use PHPUnit_Framework_MockObject_MockObject as MockObject;
11
12
/**
13
 * Class PHPUnitMockingStrategy
14
 * @package Moka\Strategy
15
 */
16
class PHPUnitMockingStrategy extends AbstractMockingStrategy
17
{
18
    /**
19
     * @var MockGenerator
20
     */
21
    private $generator;
22
23
    /**
24
     * PHPUnitMockingStrategy constructor.
25
     */
26 4
    public function __construct()
27
    {
28 4
        $this->generator = new MockGenerator();
29 4
        $this->setMockType(MockObject::class);
30
    }
31
32
    /**
33
     * @param string $fqcn
34
     * @return MockObject
35
     */
36 21
    protected function doBuild(string $fqcn)
37
    {
38 21
        return $this->generator->getMock(
39 21
            $fqcn,
40 21
            $methods = [],
41 21
            $arguments = [],
42 21
            $mockClassName = '',
43 21
            $callOriginalConstructor = false
44
        );
45
    }
46
47
    /**
48
     * @param MockObject $mock
49
     * @param Stub $stub
50
     * @return void
51
     */
52 21 View Code Duplication
    protected function doDecorate($mock, Stub $stub)
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...
53
    {
54 21
        $methodName = $stub->getMethodName();
55 21
        $methodValue = $stub->getMethodValue();
56
57 21
        $partial = $mock->expects(new AnyInvokedCountMatcher())->method($methodName);
58 21
        $methodValue instanceof \Throwable
59 21
            ? $partial->willThrowException($methodValue)
60 21
            : $partial->willReturn($methodValue);
61
    }
62
63
    /**
64
     * @param MockObject $mock
65
     * @return MockObject
66
     */
67 10
    protected function doGet($mock)
68
    {
69 10
        return $mock;
70
    }
71
}
72