PortToMock   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 58
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
getMock() 0 1 ?
A expects() 0 4 1
A __phpunit_setOriginalObject() 0 6 1
A __phpunit_getInvocationMocker() 0 4 1
A __phpunit_verify() 0 4 1
A __phpunit_hasMatchers() 0 4 1
A __phpunit_setReturnValueGeneration() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ekvedaras\LaravelTestHelpers\Traits;
6
7
use PHPUnit\Framework\MockObject\Matcher\Invocation;
8
use PHPUnit_Framework_MockObject_MockObject;
9
10
/**
11
 * Trait PortToMock.
12
 */
13
trait PortToMock
14
{
15
    /**
16
     * @return PHPUnit_Framework_MockObject_MockObject
17
     */
18
    abstract public function getMock(): PHPUnit_Framework_MockObject_MockObject;
19
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function expects(Invocation $matcher)
24
    {
25
        return $this->getMock()->expects($matcher);
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function __phpunit_setOriginalObject($originalObject)
32
    {
33
        $this->mock = $originalObject;
0 ignored issues
show
Bug introduced by
The property mock does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
34
35
        return $this->getMock();
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function __phpunit_getInvocationMocker()
42
    {
43
        return $this->getMock()->__phpunit_getInvocationMocker();
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function __phpunit_verify($unsetInvocationMocker = true)
50
    {
51
        return $this->getMock()->__phpunit_verify($unsetInvocationMocker);
0 ignored issues
show
Unused Code introduced by
The call to PHPUnit_Framework_MockOb...ect::__phpunit_verify() has too many arguments starting with $unsetInvocationMocker.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function __phpunit_hasMatchers()
58
    {
59
        return $this->getMock()->__phpunit_hasMatchers();
60
    }
61
62
    /**
63
     * @param bool $returnValueGeneration
64
     * @return mixed
65
     */
66
    public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration)
67
    {
68
        return $this->getMock()->__phpunit_setReturnValueGeneration($returnValueGeneration);
69
    }
70
}
71