CommandArgumentsTest::testArgs()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 3
nc 4
nop 3
1
<?php
2
3
use PHPUnit\Framework\TestCase;
4
use Robo\Traits\Common\CommandArgumentsHost;
5
6
/**
7
 * Class CommandArgumentsTest.
8
 *
9
 * @coversDefaultClass \Robo\Common\CommandArguments
10
 */
11
class CommandArgumentsTest extends TestCase
12
{
13
    public function casesArgs() {
14
        return [
15
            'no arguments' => [
16
                ' ',
17
                ' ',
18
                [],
19
            ],
20
            'empty string' => [
21
                " ''",
22
                ' ""',
23
                [''],
24
            ],
25
            'space' => [
26
                " ' '",
27
                ' " "',
28
                [' '],
29
            ],
30
            'no escape - a' => [
31
                " a",
32
                " a",
33
                ['a'],
34
            ],
35
            'no escape - A' => [
36
                " A",
37
                " A",
38
                ['A'],
39
            ],
40
            'no escape - 0' => [
41
                " 0",
42
                " 0",
43
                ['0'],
44
            ],
45
            'no escape - --' => [
46
                " --",
47
                " --",
48
                ['--'],
49
            ],
50
            'no escape - @_~.' => [
51
                " @_~.",
52
                " @_~.",
53
                ['@_~.'],
54
            ],
55
            '$' => [
56
                " 'a\$b'",
57
                ' "a$b"',
58
                ['a$b'],
59
            ],
60
            '*' => [
61
                " 'a*b'",
62
                ' "a*b"',
63
                ['a*b'],
64
            ],
65
            'multi' => [
66
                " '' a '\$PATH'",
67
                ' "" a "$PATH"',
68
                ['', 'a', '$PATH'],
69
            ],
70
        ];
71
    }
72
73
    /**
74
     * @dataProvider casesArgs
75
     *
76
     * @covers ::args
77
     *
78
     * @param string $expected
0 ignored issues
show
Documentation introduced by
There is no parameter named $expected. Did you maybe mean $expectedLinux?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
79
     * @param array $args
80
     */
81
    public function testArgs($expectedLinux, $expectedWindows, $args)
82
    {
83
        $expected = stripos(PHP_OS, 'WIN') === 0 ? $expectedWindows : $expectedLinux;
84
        $commandArguments = new CommandArgumentsHost();
85
        $commandArguments->args($args);
86
        $this->assertEquals($expected, $commandArguments->getArguments());
87
88
        if ($args) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $args of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
89
            $commandArguments = new CommandArgumentsHost();
90
            call_user_func_array([$commandArguments, 'args'], $args);
91
            $this->assertEquals($expected, $commandArguments->getArguments());
92
        }
93
    }
94
}
95