GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

TaskTest::testGroupInvoke()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
nc 1
nop 0
dl 0
loc 13
c 0
b 0
f 0
cc 1
rs 10
1
<?php
2
/* (c) Anton Medvedev <[email protected]>
3
 *
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 */
7
8
namespace Deployer\Task;
9
10
use Deployer\Host\Host;
11
use PHPUnit\Framework\TestCase;
12
13
use function Deployer\invoke;
14
use function Deployer\task;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Deployer\Task\task. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
15
16
class TaskTest extends TestCase
17
{
18
    protected function tearDown(): void
19
    {
20
        StubTask::$runned = 0;
21
    }
22
23
    public function testTask()
24
    {
25
        $mock = self::getMockBuilder('stdClass')
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\TestCase::getMockBuilder() is not static, but was called statically. ( Ignorable by Annotation )

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

25
        $mock = self::/** @scrutinizer ignore-call */ getMockBuilder('stdClass')
Loading history...
Deprecated Code introduced by
The function PHPUnit\Framework\MockOb...ckBuilder::addMethods() has been deprecated: https://github.com/sebastianbergmann/phpunit/issues/5320 ( Ignorable by Annotation )

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

25
        $mock = /** @scrutinizer ignore-deprecated */ self::getMockBuilder('stdClass')

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
26
            ->addMethods(['callback'])
27
            ->getMock();
28
        $mock
29
            ->expects(self::exactly(1))
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\TestCase::exactly() is not static, but was called statically. ( Ignorable by Annotation )

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

29
            ->expects(self::/** @scrutinizer ignore-call */ exactly(1))
Loading history...
30
            ->method('callback');
31
32
        $task = new Task('task_name', function () use ($mock) {
33
            $mock->callback();
34
        });
35
36
        $context = self::getMockBuilder(Context::class)
37
            ->disableOriginalConstructor()
38
            ->getMock();
39
        $task->run($context);
40
41
        self::assertEquals('task_name', $task->getName());
42
43
        $task->desc('Task description.');
44
        self::assertEquals('Task description.', $task->getDescription());
45
46
        $task->hidden();
47
        self::assertTrue($task->isHidden());
48
49
        $task->once();
50
        self::assertTrue($task->isOnce());
51
52
        $task->oncePerNode();
53
        self::assertTrue($task->isOncePerNode());
54
    }
55
56
    public function testInit()
57
    {
58
        $context = self::getMockBuilder(Context::class)->disableOriginalConstructor()->getMock();
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\TestCase::getMockBuilder() is not static, but was called statically. ( Ignorable by Annotation )

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

58
        $context = self::/** @scrutinizer ignore-call */ getMockBuilder(Context::class)->disableOriginalConstructor()->getMock();
Loading history...
59
60
        // Test create task with [$object, 'method']
61
        $mock1 = self::getMockBuilder('stdClass')
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\MockOb...ckBuilder::addMethods() has been deprecated: https://github.com/sebastianbergmann/phpunit/issues/5320 ( Ignorable by Annotation )

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

61
        $mock1 = /** @scrutinizer ignore-deprecated */ self::getMockBuilder('stdClass')

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
62
            ->addMethods(['callback'])
63
            ->getMock();
64
        $mock1
65
            ->expects(self::once())
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\TestCase::once() is not static, but was called statically. ( Ignorable by Annotation )

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

65
            ->expects(self::/** @scrutinizer ignore-call */ once())
Loading history...
66
            ->method('callback');
67
        $task1 = new Task('task1', [$mock1, 'callback']);
68
        $task1->run($context);
69
70
        // Test create task with anonymous functions
71
        $mock2 = self::getMockBuilder('stdClass')
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\MockOb...ckBuilder::addMethods() has been deprecated: https://github.com/sebastianbergmann/phpunit/issues/5320 ( Ignorable by Annotation )

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

71
        $mock2 = /** @scrutinizer ignore-deprecated */ self::getMockBuilder('stdClass')

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
72
            ->addMethods(['callback'])
73
            ->getMock();
74
        $mock2
75
            ->expects(self::once())
76
            ->method('callback');
77
        $task2 = new Task('task2', function () use ($mock2) {
78
            $mock2->callback();
79
        });
80
        $task2->run($context);
81
82
        self::assertEquals(0, StubTask::$runned);
83
        $task3 = new Task('task3', new StubTask());
84
        $task3->run($context);
85
        self::assertEquals(1, StubTask::$runned);
86
    }
87
88
    public function testGroupInvoke(): void
89
    {
90
        $spy = new StubTask();
91
92
        task('foo', $spy);
93
        task('bar', $spy);
94
        task('group', ['foo', 'bar']);
95
96
        (new Task('group:invoke', function () {
97
            invoke('group');
98
        }))->run(new Context(new Host('localhost')));
99
100
        $this->assertSame(2, StubTask::$runned);
101
    }
102
}
103
104
/**
105
 * Stub class for task callable by __invoke()
106
 */
107
class StubTask
108
{
109
    public static $runned = 0;
110
111
    public function __invoke()
112
    {
113
        self::$runned++;
114
    }
115
}
116