Completed
Push — master ( d3a073...5737c8 )
by Greg
02:21
created

tests/unit/Task/WatchTest.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
3
namespace Tests\Unit\Task;
4
5
use AspectMock\Test as test;
6
7
class WatchTest extends \Codeception\TestCase\Test
8
{
9
    /**
10
     * @var \AspectMock\Proxy\AnythingClassProxy
11
     */
12
    protected $resourceWatcher;
13
14
    public function _before()
15
    {
16
        if (!class_exists('Lurker\\ResourceWatcher')) {
17
            $this->resourceWatcher = test::spec(
0 ignored issues
show
The method make does only exist in AspectMock\Proxy\ClassProxy, but not in AspectMock\Proxy\InstanceProxy.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
18
                'Lurker\ResourceWatcher',
19
                [
20
                    'start' => true,
21
                    'track' => true,
22
                    'addListener' => true
23
                ]
24
            )->make();
25
        } else {
26
            $this->resourceWatcher = test::double(
27
                'Lurker\ResourceWatcher',
28
                [
29
                    'start' => true,
30
                    'track' => true,
31
                    'addListener' => true
32
                ]
33
            );
34
        }
35
    }
36
37
    public function testMonitorWithOneEvent()
38
    {
39
        $task = new \Robo\Task\Base\Watch($this);
40
41
        $task->monitor(
42
            'src',
43
            function () {
44
                //do nothing
45
            },
46
            1 // CREATE
47
        )->run();
48
49
        $this->resourceWatcher->verifyInvokedOnce('track');
50
    }
51
52
    public function testMonitorWithTwoEvents()
53
    {
54
        $task = new \Robo\Task\Base\Watch($this);
55
56
        $task->monitor(
57
            'src',
58
            function () {
59
                //do nothing
60
            },
61
            [
62
                1, //CREATE
63
                4, //DELETE
64
            ]
65
        )->run();
66
67
        $this->resourceWatcher->verifyInvokedMultipleTimes('track', 2);
68
    }
69
}
70