These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | use Robo\Traits\Common\CommandArgumentsHost; |
||
4 | |||
5 | /** |
||
6 | * Class CommandArgumentsTest. |
||
7 | * |
||
8 | * @coversDefaultClass \Robo\Common\CommandArguments |
||
9 | */ |
||
10 | class CommandArgumentsTest extends \Codeception\Test\Unit |
||
11 | { |
||
12 | /** |
||
13 | * @var \CodeGuy |
||
14 | */ |
||
15 | protected $guy; |
||
16 | |||
17 | public function casesArgs() { |
||
18 | return [ |
||
19 | 'no arguments' => [ |
||
20 | ' ', |
||
21 | ' ', |
||
22 | [], |
||
23 | ], |
||
24 | 'empty string' => [ |
||
25 | " ''", |
||
26 | ' ""', |
||
27 | [''], |
||
28 | ], |
||
29 | 'space' => [ |
||
30 | " ' '", |
||
31 | ' " "', |
||
32 | [' '], |
||
33 | ], |
||
34 | 'no escape - a' => [ |
||
35 | " a", |
||
36 | " a", |
||
37 | ['a'], |
||
38 | ], |
||
39 | 'no escape - A' => [ |
||
40 | " A", |
||
41 | " A", |
||
42 | ['A'], |
||
43 | ], |
||
44 | 'no escape - 0' => [ |
||
45 | " 0", |
||
46 | " 0", |
||
47 | ['0'], |
||
48 | ], |
||
49 | 'no escape - --' => [ |
||
50 | " --", |
||
51 | " --", |
||
52 | ['--'], |
||
53 | ], |
||
54 | 'no escape - @_~.' => [ |
||
55 | " @_~.", |
||
56 | " @_~.", |
||
57 | ['@_~.'], |
||
58 | ], |
||
59 | '$' => [ |
||
60 | " 'a\$b'", |
||
61 | ' "a$b"', |
||
62 | ['a$b'], |
||
63 | ], |
||
64 | '*' => [ |
||
65 | " 'a*b'", |
||
66 | ' "a*b"', |
||
67 | ['a*b'], |
||
68 | ], |
||
69 | 'multi' => [ |
||
70 | " '' a '\$PATH'", |
||
71 | ' "" a "$PATH"', |
||
72 | ['', 'a', '$PATH'], |
||
73 | ], |
||
74 | ]; |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * @dataProvider casesArgs |
||
79 | * |
||
80 | * @covers ::args |
||
81 | * |
||
82 | * @param string $expected |
||
83 | * @param array $args |
||
84 | */ |
||
85 | public function testArgs($expectedLinux, $expectedWindows, $args) |
||
86 | { |
||
87 | $expected = stripos(PHP_OS, 'WIN') === 0 ? $expectedWindows : $expectedLinux; |
||
88 | $commandArguments = new CommandArgumentsHost(); |
||
89 | $commandArguments->args($args); |
||
90 | $this->guy->assertEquals($expected, $commandArguments->getArguments()); |
||
91 | |||
92 | if ($args) { |
||
0 ignored issues
–
show
|
|||
93 | $commandArguments = new CommandArgumentsHost(); |
||
94 | call_user_func_array([$commandArguments, 'args'], $args); |
||
95 | $this->guy->assertEquals($expected, $commandArguments->getArguments()); |
||
96 | } |
||
97 | } |
||
98 | } |
||
99 |
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.