Completed
Push — master ( 92cca6...dbd889 )
by Alberto
13s
created

src/Moka/Strategy/PHPUnitMockingStrategy.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
declare(strict_types=1);
3
4
namespace Moka\Strategy;
5
6
use Moka\Stub\Stub;
7
use Moka\Stub\StubSet;
8
use PHPUnit_Framework_MockObject_Generator as MockGenerator;
9
use PHPUnit_Framework_MockObject_MockObject as MockObject;
10
use PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount as AnyInvokedCountMatcher;
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 5
    public function __construct()
27
    {
28 5
        $this->generator = new MockGenerator();
29 5
        $this->setMockType(MockObject::class);
30
    }
31
32
    /**
33
     * @param string $fqcn
34
     * @return MockObject
35
     */
36 6
    protected function doBuild(string $fqcn)
37
    {
38 6
        return $this->generator->getMock(
39 6
            $fqcn,
40 6
            $methods = [],
41 6
            $arguments = [],
42 6
            $mockClassName = '',
43 6
            $callOriginalConstructor = false
44
        );
45
    }
46
47
    /**
48
     * @param MockObject $mock
49
     * @param StubSet $stubs
50
     * @return void
51
     */
52 1 View Code Duplication
    protected function doDecorate($mock, StubSet $stubs)
1 ignored issue
show
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
        /** @var Stub $stub */
55 1
        foreach ($stubs as $stub) {
56 1
            $methodName = $stub->getMethodName();
57 1
            $methodValue = $stub->getMethodValue();
58
59 1
            $partial = $mock->expects(new AnyInvokedCountMatcher())->method($methodName);
60 1
            $methodValue instanceof \Throwable
61 1
                ? $partial->willThrowException($methodValue)
62 1
                : $partial->willReturn($methodValue);
63
        }
64
    }
65
66
    /**
67
     * @param MockObject $mock
68
     * @return MockObject
69
     */
70 3
    protected function doGet($mock)
71
    {
72 3
        return $mock;
73
    }
74
}
75