This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | namespace Robo; |
||
3 | |||
4 | use PHPUnit\Framework\TestCase; |
||
5 | use Robo\Traits\TestTasksTrait; |
||
6 | |||
7 | class RunnerTest extends TestCase |
||
8 | { |
||
9 | use TestTasksTrait; |
||
10 | use Task\Base\loadTasks; |
||
11 | |||
12 | /** |
||
13 | * @var \Robo\Runner |
||
14 | */ |
||
15 | private $runner; |
||
16 | |||
17 | public function setup() |
||
18 | { |
||
19 | $container = $this->initTestTasksTrait(); |
||
20 | $this->runner = new \Robo\Runner('\Robo\RoboFileFixture'); |
||
21 | $this->runner->setContainer($container); |
||
22 | } |
||
23 | |||
24 | public function testThrowsExceptionWhenNoContainerAvailable() |
||
25 | { |
||
26 | $this->expectException('\RuntimeException'); |
||
27 | $this->expectExceptionMessageRegExp( |
||
28 | '/container is not initialized yet.*/' |
||
29 | ); |
||
30 | Robo::unsetContainer(); |
||
31 | Robo::getContainer(); |
||
32 | } |
||
33 | |||
34 | public function testRunnerNoSuchCommand() |
||
35 | { |
||
36 | $argv = ['placeholder', 'no-such-command']; |
||
37 | $this->runner->execute($argv, null, null, $this->capturedOutputStream()); |
||
38 | $this->assertOutputContains('Command "no-such-command" is not defined.'); |
||
39 | } |
||
40 | |||
41 | public function testRunnerList() |
||
42 | { |
||
43 | $argv = ['placeholder', 'list']; |
||
44 | $this->runner->execute($argv, null, null, $this->capturedOutputStream()); |
||
45 | $this->assertOutputContains('test:array-args'); |
||
46 | } |
||
47 | |||
48 | public function testRunnerTryArgs() |
||
49 | { |
||
50 | $argv = ['placeholder', 'test:array-args', 'a', 'b', 'c']; |
||
51 | $this->runner->execute($argv, null, null, $this->capturedOutputStream()); |
||
52 | |||
53 | $expected = <<<EOT |
||
54 | > The parameters passed are: |
||
55 | array ( |
||
56 | 0 => 'a', |
||
57 | 1 => 'b', |
||
58 | 2 => 'c', |
||
59 | ) |
||
60 | |||
61 | EOT; |
||
62 | $this->assertOutputEquals($expected); |
||
63 | } |
||
64 | |||
65 | public function testSymfonyStyle() |
||
66 | { |
||
67 | $argv = ['placeholder', 'test:symfony-style']; |
||
68 | $this->runner->execute($argv, null, null, $this->capturedOutputStream()); |
||
69 | $this->assertOutputContains('Some text in section one.'); |
||
70 | } |
||
71 | |||
72 | public function testStyleInjector() |
||
73 | { |
||
74 | $argv = ['placeholder', 'test:style-injector']; |
||
75 | $this->runner->execute($argv, null, null, $this->capturedOutputStream()); |
||
76 | $this->assertOutputContains('Some text in section one printed via injected io object.'); |
||
77 | } |
||
78 | |||
79 | public function testSymfony() |
||
80 | { |
||
81 | $argv = ['placeholder', 'test:symfony', 'a', 'b', 'c', '--foo=bar', '--foo=baz', '--foo=boz']; |
||
82 | $this->runner->execute($argv, null, null, $this->capturedOutputStream()); |
||
83 | $expected = <<<EOT |
||
84 | > The parameters passed are: |
||
85 | array ( |
||
86 | 0 => 'a', |
||
87 | 1 => 'b', |
||
88 | 2 => 'c', |
||
89 | ) |
||
90 | > The options passed via --foo are: |
||
91 | array ( |
||
92 | 0 => 'bar', |
||
93 | 1 => 'baz', |
||
94 | 2 => 'boz', |
||
95 | ) |
||
96 | |||
97 | EOT; |
||
98 | $this->assertOutputEquals($expected); |
||
99 | } |
||
100 | |||
101 | public function testCommandEventHook() |
||
102 | { |
||
103 | $argv = ['placeholder', 'test:command-event']; |
||
104 | $this->runner->execute($argv, null, null, $this->capturedOutputStream()); |
||
105 | |||
106 | $expected = <<<EOT |
||
107 | This is the command-event hook for the test:command-event command. |
||
108 | This is the main method for the test:command-event command. |
||
109 | This is the post-command hook for the test:command-event command. |
||
110 | EOT; |
||
111 | $this->assertOutputContains($expected); |
||
112 | } |
||
113 | |||
114 | public function testCustomEventHook() |
||
115 | { |
||
116 | $argv = ['placeholder', 'test:custom-event']; |
||
117 | $this->runner->execute($argv, null, null, $this->capturedOutputStream()); |
||
118 | |||
119 | $expected = 'one,two'; |
||
120 | $this->assertOutputContains($expected); |
||
121 | } |
||
122 | |||
123 | public function testRoboStaticRunMethod() |
||
124 | { |
||
125 | $argv = ['placeholder', 'test:symfony-style']; |
||
126 | $commandFiles = ['\Robo\RoboFileFixture']; |
||
127 | Robo::run($argv, $commandFiles, 'MyApp', '1.2.3', $this->capturedOutputStream()); |
||
128 | $this->assertOutputContains('Some text in section one.'); |
||
129 | } |
||
130 | |||
131 | View Code Duplication | public function testDeploy() |
|
132 | { |
||
133 | $argv = ['placeholder', 'test:deploy', '--simulate']; |
||
134 | $this->runner->execute($argv, null, null, $this->capturedOutputStream()); |
||
135 | $this->assertOutputContains('[Simulator] Simulating Remote\\Ssh(\'mysite.com\', null)'); |
||
136 | $this->assertOutputContains('[Simulator] Running ssh mysite.com \'cd "/var/www/somesite" && git pull\''); |
||
137 | } |
||
138 | |||
139 | View Code Duplication | public function testRunnerTryError() |
|
140 | { |
||
141 | $argv = ['placeholder', 'test:error']; |
||
142 | $result = $this->runner->execute($argv, null, null, $this->capturedOutputStream()); |
||
143 | |||
144 | $this->assertOutputContains('[Exec] Running ls xyzzy'); |
||
145 | $this->assertTrue($result > 0); |
||
146 | } |
||
147 | |||
148 | View Code Duplication | public function testRunnerTrySimulatedError() |
|
149 | { |
||
150 | $argv = ['placeholder', 'test:error', '--simulate']; |
||
151 | $result = $this->runner->execute($argv, null, null, $this->capturedOutputStream()); |
||
152 | |||
153 | $this->assertOutputContains('Simulating Exec'); |
||
154 | $this->assertEquals(0, $result); |
||
155 | } |
||
156 | |||
157 | View Code Duplication | public function testRunnerTryException() |
|
158 | { |
||
159 | $argv = ['placeholder', 'test:exception', '--task']; |
||
160 | $result = $this->runner->execute($argv, null, null, $this->capturedOutputStream()); |
||
161 | |||
162 | $this->assertOutputContains('Task failed with an exception'); |
||
163 | $this->assertEquals(1, $result); |
||
164 | } |
||
165 | |||
166 | public function testInitCommand() |
||
167 | { |
||
168 | $container = \Robo\Robo::getContainer(); |
||
169 | $app = $container->get('application'); |
||
170 | $app->addInitRoboFileCommand(getcwd() . '/testRoboFile.php', 'RoboTestClass'); |
||
171 | |||
172 | $argv = ['placeholder', 'init']; |
||
173 | $status = $this->runner->run($argv, $this->capturedOutputStream(), $app); |
||
174 | $this->assertOutputContains('testRoboFile.php will be created in the current directory'); |
||
175 | $this->assertEquals(0, $status); |
||
176 | |||
177 | $this->assertTrue(file_exists('testRoboFile.php')); |
||
178 | $commandContents = file_get_contents('testRoboFile.php'); |
||
179 | unlink('testRoboFile.php'); |
||
180 | $this->assertContains('class RoboTestClass', $commandContents); |
||
181 | } |
||
182 | |||
183 | View Code Duplication | public function testTasksStopOnFail() |
|
184 | { |
||
185 | $argv = ['placeholder', 'test:stop-on-fail']; |
||
186 | $result = $this->runner->execute($argv, null, null, $this->capturedOutputStream()); |
||
187 | |||
188 | $this->assertOutputContains('['); |
||
189 | $this->assertTrue($result > 0); |
||
190 | } |
||
191 | |||
192 | View Code Duplication | public function testInvalidRoboDirectory() |
|
193 | { |
||
194 | $runnerWithNoRoboFile = new \Robo\Runner(); |
||
195 | |||
196 | $argv = ['placeholder', 'no-such-command', '-f', 'no-such-directory']; |
||
197 | $result = $runnerWithNoRoboFile->execute($argv, null, null, $this->capturedOutputStream()); |
||
0 ignored issues
–
show
|
|||
198 | |||
199 | $this->assertOutputContains('Path `no-such-directory` is invalid; please provide a valid absolute path to the Robofile to load.'); |
||
200 | } |
||
201 | |||
202 | View Code Duplication | public function testUnloadableRoboFile() |
|
203 | { |
||
204 | $runnerWithNoRoboFile = new \Robo\Runner(); |
||
205 | |||
206 | $argv = ['placeholder', 'help', 'test:custom-event', '-f', dirname(__DIR__) . '/src/RoboFileFixture.php']; |
||
207 | $result = $runnerWithNoRoboFile->execute($argv, null, null, $this->capturedOutputStream()); |
||
0 ignored issues
–
show
$result is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the
Loading history...
|
|||
208 | |||
209 | // We cannot load RoboFileFixture.php via -f / --load-from because |
||
210 | // it has a namespace, and --load-from does not support that. |
||
211 | $this->assertOutputContains('Class RoboFileFixture was not loaded'); |
||
212 | } |
||
213 | |||
214 | View Code Duplication | public function testRunnerQuietOutput() |
|
215 | { |
||
216 | $argv = ['placeholder', 'test:verbosity', '--quiet']; |
||
217 | $result = $this->runner->execute($argv, null, null, $this->capturedOutputStream()); |
||
218 | |||
219 | $this->assertOutputNotContains('This command will print more information at higher verbosity levels'); |
||
220 | $this->assertOutputNotContains('This is a verbose message (-v).'); |
||
221 | $this->assertOutputNotContains('This is a very verbose message (-vv).'); |
||
222 | $this->assertOutputNotContains('This is a debug message (-vvv).'); |
||
223 | $this->assertOutputNotContains(' [warning] This is a warning log message.'); |
||
224 | $this->assertOutputNotContains(' [notice] This is a notice log message.'); |
||
225 | $this->assertOutputNotContains(' [debug] This is a debug log message.'); |
||
226 | $this->assertEquals(0, $result); |
||
227 | } |
||
228 | |||
229 | View Code Duplication | public function testRunnerVerboseOutput() |
|
230 | { |
||
231 | $argv = ['placeholder', 'test:verbosity', '-v']; |
||
232 | $result = $this->runner->execute($argv, null, null, $this->capturedOutputStream()); |
||
233 | |||
234 | $this->assertOutputContains('This command will print more information at higher verbosity levels'); |
||
235 | $this->assertOutputContains('This is a verbose message (-v).'); |
||
236 | $this->assertOutputNotContains('This is a very verbose message (-vv).'); |
||
237 | $this->assertOutputNotContains('This is a debug message (-vvv).'); |
||
238 | $this->assertOutputContains(' [warning] This is a warning log message.'); |
||
239 | $this->assertOutputContains(' [notice] This is a notice log message.'); |
||
240 | $this->assertOutputNotContains(' [debug] This is a debug log message.'); |
||
241 | $this->assertEquals(0, $result); |
||
242 | } |
||
243 | |||
244 | View Code Duplication | public function testRunnerVeryVerboseOutput() |
|
245 | { |
||
246 | $argv = ['placeholder', 'test:verbosity', '-vv']; |
||
247 | $result = $this->runner->execute($argv, null, null, $this->capturedOutputStream()); |
||
248 | |||
249 | $this->assertOutputContains('This command will print more information at higher verbosity levels'); |
||
250 | $this->assertOutputContains('This is a verbose message (-v).'); |
||
251 | $this->assertOutputContains('This is a very verbose message (-vv).'); |
||
252 | $this->assertOutputNotContains('This is a debug message (-vvv).'); |
||
253 | $this->assertOutputContains(' [warning] This is a warning log message.'); |
||
254 | $this->assertOutputContains(' [notice] This is a notice log message.'); |
||
255 | $this->assertOutputNotContains(' [debug] This is a debug log message.'); |
||
256 | $this->assertEquals(0, $result); |
||
257 | } |
||
258 | |||
259 | View Code Duplication | public function testRunnerVerbosityThresholdVerbose() |
|
260 | { |
||
261 | $argv = ['placeholder', 'test:verbosity-threshold', '-v']; |
||
262 | $result = $this->runner->execute($argv, null, null, $this->capturedOutputStream()); |
||
263 | |||
264 | $this->assertOutputContains('This command will print more information at higher verbosity levels'); |
||
265 | $this->assertOutputContains("Running echo verbose or higher\nverbose or higher"); |
||
266 | $this->assertOutputNotContains('very verbose or higher'); |
||
267 | $this->assertEquals(0, $result); |
||
268 | } |
||
269 | |||
270 | View Code Duplication | public function testRunnerVerbosityThresholdVeryVerbose() |
|
271 | { |
||
272 | $argv = ['placeholder', 'test:verbosity-threshold', '-vv']; |
||
273 | $result = $this->runner->execute($argv, null, null, $this->capturedOutputStream()); |
||
274 | |||
275 | $this->assertOutputContains('This command will print more information at higher verbosity levels'); |
||
276 | $this->assertOutputContains("Running echo verbose or higher\nverbose or higher"); |
||
277 | $this->assertOutputContains("Running echo very verbose or higher\nvery verbose or higher"); |
||
278 | $this->assertEquals(0, $result); |
||
279 | } |
||
280 | |||
281 | View Code Duplication | public function testRunnerDebugOutput() |
|
282 | { |
||
283 | $argv = ['placeholder', 'test:verbosity', '-vvv']; |
||
284 | $result = $this->runner->execute($argv, null, null, $this->capturedOutputStream()); |
||
285 | |||
286 | $this->assertOutputContains('This command will print more information at higher verbosity levels'); |
||
287 | $this->assertOutputContains('This is a verbose message (-v).'); |
||
288 | $this->assertOutputContains('This is a very verbose message (-vv).'); |
||
289 | $this->assertOutputContains('This is a debug message (-vvv).'); |
||
290 | $this->assertOutputContains(' [warning] This is a warning log message.'); |
||
291 | $this->assertOutputContains(' [notice] This is a notice log message.'); |
||
292 | $this->assertOutputContains(' [debug] This is a debug log message.'); |
||
293 | $this->assertEquals(0, $result); |
||
294 | } |
||
295 | } |
||
296 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.