Passed
Push — master ( 9447a1...d83ffa )
by Dan
01:28
created

getMockWithExpectations()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
declare (strict_types=1);
3
4
namespace Nopolabs\Test;
5
6
use PHPUnit_Framework_MockObject_MockObject;
7
8
/**
9
 * This trait expects to be used in a sub-class of PHPUnit\Framework\TestCase
10
 */
11
trait MockWithExpectationsTrait
12
{
13
    private $mockWithExpectations;
14
15
    protected function mockWithExpectations(
16
        $className,
17
        array $expectations = [],
18
        array $constructorArgs = null): PHPUnit_Framework_MockObject_MockObject
19
    {
20
        return $this->getMockWithExpectations()->mockWithExpectations(
21
            $className,
22
            $expectations,
23
            $constructorArgs
24
        );
25
    }
26
27
    protected function setExpectation(
28
        PHPUnit_Framework_MockObject_MockObject $mock,
29
        $expectation) : void
30
    {
31
        $this->getMockWithExpectations()->setExpectation($mock, $expectation);
32
    }
33
34
    protected function setExpectations(
35
        PHPUnit_Framework_MockObject_MockObject $mock,
36
        array $expectations) : void
37
    {
38
        $this->getMockWithExpectations()->setExpectations($mock, $expectations);
39
    }
40
41
    protected function getMockWithExpectations() : MockWithExpectations
42
    {
43
        if ($this->mockWithExpectations === null) {
44
            $this->mockWithExpectations = new MockWithExpectations($this);
0 ignored issues
show
Bug introduced by
$this of type Nopolabs\Test\MockWithExpectationsTrait is incompatible with the type PHPUnit\Framework\TestCase expected by parameter $testCase of Nopolabs\Test\MockWithExpectations::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

44
            $this->mockWithExpectations = new MockWithExpectations(/** @scrutinizer ignore-type */ $this);
Loading history...
45
        }
46
47
        return $this->mockWithExpectations;
48
    }
49
}
50