1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the box project. |
7
|
|
|
* |
8
|
|
|
* (c) Kevin Herrera <[email protected]> |
9
|
|
|
* Théo Fidry <[email protected]> |
10
|
|
|
* |
11
|
|
|
* This source file is subject to the MIT license that is bundled |
12
|
|
|
* with this source code in the file LICENSE. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace KevinGH\RequirementChecker; |
16
|
|
|
|
17
|
|
|
use PHPUnit\Framework\TestCase; |
18
|
|
|
use function putenv; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @covers \KevinGH\RequirementChecker\IO |
22
|
|
|
*/ |
23
|
|
|
class IOTest extends TestCase |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @dataProvider provideOptions |
27
|
|
|
*/ |
28
|
|
|
public function test_it_can_parse_the_options(array $argv, bool $interactive, int $verbosity): void |
29
|
|
|
{ |
30
|
|
|
$_SERVER['argv'] = $argv; |
31
|
|
|
|
32
|
|
|
$io = new IO(); |
33
|
|
|
|
34
|
|
|
$this->assertSame($interactive, $io->isInteractive()); |
35
|
|
|
$this->assertSame($verbosity, $io->getVerbosity()); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @dataProvider provideOptionsWithShellVerbosity |
40
|
|
|
*/ |
41
|
|
|
public function test_it_uses_the_shell_verbosity_environment_variable_over_the_options(array $argv, string $putenv, bool $interactive, int $verbosity): void |
42
|
|
|
{ |
43
|
|
|
$_SERVER['argv'] = $argv; |
44
|
|
|
putenv($putenv); |
45
|
|
|
|
46
|
|
|
$io = new IO(); |
47
|
|
|
|
48
|
|
|
$this->assertSame($interactive, $io->isInteractive()); |
49
|
|
|
$this->assertSame($verbosity, $io->getVerbosity()); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function provideOptions() |
53
|
|
|
{ |
54
|
|
|
yield [ |
55
|
|
|
['cli.php', '--foo'], |
56
|
|
|
true, |
57
|
|
|
IO::VERBOSITY_NORMAL, |
58
|
|
|
]; |
59
|
|
|
|
60
|
|
|
yield [ |
61
|
|
|
['cli.php', '--foo', '--verbose=0'], |
62
|
|
|
true, |
63
|
|
|
IO::VERBOSITY_VERBOSE, |
64
|
|
|
]; |
65
|
|
|
|
66
|
|
|
yield [ |
67
|
|
|
['cli.php', '--foo', '--quiet'], |
68
|
|
|
false, |
69
|
|
|
IO::VERBOSITY_QUIET, |
70
|
|
|
]; |
71
|
|
|
|
72
|
|
|
yield [ |
73
|
|
|
['cli.php', '--foo', '-q'], |
74
|
|
|
false, |
75
|
|
|
IO::VERBOSITY_QUIET, |
76
|
|
|
]; |
77
|
|
|
|
78
|
|
|
yield [ |
79
|
|
|
['cli.php', '--foo', '-vvv'], |
80
|
|
|
true, |
81
|
|
|
IO::VERBOSITY_DEBUG, |
82
|
|
|
]; |
83
|
|
|
|
84
|
|
|
yield [ |
85
|
|
|
['cli.php', '--foo', '--verbose=3'], |
86
|
|
|
true, |
87
|
|
|
IO::VERBOSITY_DEBUG, |
88
|
|
|
]; |
89
|
|
|
|
90
|
|
|
yield [ |
91
|
|
|
['cli.php', '--foo', '--verbose 3'], |
92
|
|
|
true, |
93
|
|
|
IO::VERBOSITY_DEBUG, |
94
|
|
|
]; |
95
|
|
|
|
96
|
|
|
yield [ |
97
|
|
|
['cli.php', '--foo', '-vv'], |
98
|
|
|
true, |
99
|
|
|
IO::VERBOSITY_VERY_VERBOSE, |
100
|
|
|
]; |
101
|
|
|
|
102
|
|
|
yield [ |
103
|
|
|
['cli.php', '--foo', '--verbose=2'], |
104
|
|
|
true, |
105
|
|
|
IO::VERBOSITY_VERY_VERBOSE, |
106
|
|
|
]; |
107
|
|
|
|
108
|
|
|
yield [ |
109
|
|
|
['cli.php', '--foo', '--verbose 2'], |
110
|
|
|
true, |
111
|
|
|
IO::VERBOSITY_VERY_VERBOSE, |
112
|
|
|
]; |
113
|
|
|
|
114
|
|
|
yield [ |
115
|
|
|
['cli.php', '--foo', '-v'], |
116
|
|
|
true, |
117
|
|
|
IO::VERBOSITY_VERBOSE, |
118
|
|
|
]; |
119
|
|
|
|
120
|
|
|
yield [ |
121
|
|
|
['cli.php', '--foo', '--verbose=1'], |
122
|
|
|
true, |
123
|
|
|
IO::VERBOSITY_VERBOSE, |
124
|
|
|
]; |
125
|
|
|
|
126
|
|
|
yield [ |
127
|
|
|
['cli.php', '--foo', '--verbose '], |
128
|
|
|
true, |
129
|
|
|
IO::VERBOSITY_VERBOSE, |
130
|
|
|
]; |
131
|
|
|
|
132
|
|
|
yield [ |
133
|
|
|
['cli.php', '--no-interaction'], |
134
|
|
|
false, |
135
|
|
|
IO::VERBOSITY_NORMAL, |
136
|
|
|
]; |
137
|
|
|
|
138
|
|
|
yield [ |
139
|
|
|
['cli.php', '-n'], |
140
|
|
|
false, |
141
|
|
|
IO::VERBOSITY_NORMAL, |
142
|
|
|
]; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
public function provideOptionsWithShellVerbosity() |
146
|
|
|
{ |
147
|
|
|
yield [ |
148
|
|
|
['cli.php', '--foo'], |
149
|
|
|
'SHELL_VERBOSITY=-1', |
150
|
|
|
false, |
151
|
|
|
IO::VERBOSITY_QUIET, |
152
|
|
|
]; |
153
|
|
|
|
154
|
|
|
yield [ |
155
|
|
|
['cli.php', '--foo'], |
156
|
|
|
'SHELL_VERBOSITY=0', |
157
|
|
|
true, |
158
|
|
|
IO::VERBOSITY_NORMAL, |
159
|
|
|
]; |
160
|
|
|
|
161
|
|
|
yield [ |
162
|
|
|
['cli.php', '--foo'], |
163
|
|
|
'SHELL_VERBOSITY=1', |
164
|
|
|
true, |
165
|
|
|
IO::VERBOSITY_VERBOSE, |
166
|
|
|
]; |
167
|
|
|
|
168
|
|
|
yield [ |
169
|
|
|
['cli.php', '--foo'], |
170
|
|
|
'SHELL_VERBOSITY=2', |
171
|
|
|
true, |
172
|
|
|
IO::VERBOSITY_VERY_VERBOSE, |
173
|
|
|
]; |
174
|
|
|
|
175
|
|
|
yield [ |
176
|
|
|
['cli.php', '--foo'], |
177
|
|
|
'SHELL_VERBOSITY=3', |
178
|
|
|
true, |
179
|
|
|
IO::VERBOSITY_DEBUG, |
180
|
|
|
]; |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
|