Completed
Pull Request — master (#552)
by Greg
02:57
created

RunnerTest::testWithConfigurationAndOptionOverride()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
dl 11
loc 11
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
use Robo\Robo;
3
4
use Robo\Config\ConfigProcessor;
5
use Robo\Config\YamlConfigLoader;
6
7
class RunnerTest extends \Codeception\TestCase\Test
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
8
{
9
    /**
10
     * @var \Robo\Runner
11
     */
12
    private $runner;
13
14
    /**
15
     * @var \CodeGuy
16
     */
17
    protected $guy;
18
19
    public function _before()
20
    {
21
        $this->runner = new \Robo\Runner('\Robo\RoboFileFixture');
22
    }
23
24
    public function testHandleError()
25
    {
26
        $tmpLevel = error_reporting();
27
28
        $this->assertFalse($this->runner->handleError());
29
        error_reporting(0);
30
        $this->assertTrue($this->runner->handleError());
31
32
        error_reporting($tmpLevel);
33
    }
34
35
    public function testErrorIsHandled()
36
    {
37
        $tmpLevel = error_reporting();
38
39
        // Set error_get_last to a known state.  Note that it can never be
40
        // reset; see http://php.net/manual/en/function.error-get-last.php
41
        @trigger_error('control');
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
42
        $error_description = error_get_last();
43
        $this->assertEquals('control', $error_description['message']);
44
        @trigger_error('');
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
45
        $error_description = error_get_last();
46
        $this->assertEquals('', $error_description['message']);
47
48
        // Set error_reporting to a non-zero value.  In this instance,
49
        // 'trigger_error' would abort our test script, so we use
50
        // @trigger_error so that execution will continue.  With our
51
        // error handler in place, the value of error_get_last() does
52
        // not change.
53
        error_reporting(E_USER_ERROR);
54
        set_error_handler(array($this->runner, 'handleError'));
55
        @trigger_error('test error', E_USER_ERROR);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
56
        $error_description = error_get_last();
57
        $this->assertEquals('', $error_description['message']);
58
59
        // Set error_reporting to zero.  Now, even 'trigger_error'
60
        // does not abort execution.  The value of error_get_last()
61
        // still does not change.
62
        error_reporting(0);
63
        trigger_error('test error 2', E_USER_ERROR);
64
        $error_description = error_get_last();
65
        $this->assertEquals('', $error_description['message']);
66
67
        error_reporting($tmpLevel);
68
    }
69
70
    public function testThrowsExceptionWhenNoContainerAvailable()
71
    {
72
        \PHPUnit_Framework_TestCase::setExpectedExceptionRegExp(
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCa...pectedExceptionRegExp() has been deprecated with message: Method deprecated since Release 5.6.0; use expectExceptionMessageRegExp() instead

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

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

Loading history...
73
            '\RuntimeException',
74
            '/container is not initialized yet.*/'
75
        );
76
        Robo::unsetContainer();
77
        Robo::getContainer();
78
    }
79
80
    public function testRunnerNoSuchCommand()
81
    {
82
        $argv = ['placeholder', 'no-such-command'];
83
        $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
84
        $this->guy->seeInOutput('Command "no-such-command" is not defined.');
85
    }
86
87
    public function testRunnerList()
88
    {
89
        $argv = ['placeholder', 'list'];
90
        $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
91
        $this->guy->seeInOutput('test:array-args');
92
    }
93
94
    public function testRunnerTryArgs()
95
    {
96
        $argv = ['placeholder', 'test:array-args', 'a', 'b', 'c'];
97
        $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
98
99
        $expected = <<<EOT
100
>  The parameters passed are:
101
array (
102
  0 => 'a',
103
  1 => 'b',
104
  2 => 'c',
105
)
106
107
EOT;
108
        $this->guy->seeOutputEquals($expected);
109
    }
110
111
    public function testSymfonyStyle()
112
    {
113
        $argv = ['placeholder', 'test:symfony-style'];
114
        $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
115
        $this->guy->seeInOutput('Some text in section one.');
116
    }
117
118 View Code Duplication
    public function testCommandEventHook()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
119
    {
120
        $argv = ['placeholder', 'test:command-event'];
121
        $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
122
123
        $expected = <<<EOT
124
 This is the command-event hook for the test:command-event command.
125
 This is the main method for the test:command-event command.
126
 This is the post-command hook for the test:command-event command.
127
EOT;
128
        $this->guy->seeInOutput($expected);
129
    }
130
131 View Code Duplication
    public function testCustomEventHook()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
132
    {
133
        $argv = ['placeholder', 'test:custom-event'];
134
        $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
135
136
        $expected = 'one,two';
137
        $this->guy->seeInOutput($expected);
138
    }
139
140
    public function testRoboStaticRunMethod()
141
    {
142
        $argv = ['placeholder', 'test:symfony-style'];
143
        $commandFiles = ['\Robo\RoboFileFixture'];
144
        Robo::run($argv, $commandFiles, 'MyApp', '1.2.3', $this->guy->capturedOutputStream());
0 ignored issues
show
Documentation introduced by
$commandFiles is of type array<integer,string,{"0":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
145
        $this->guy->seeInOutput('Some text in section one.');
146
    }
147
148 View Code Duplication
    public function testDeploy()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
149
    {
150
        $argv = ['placeholder', 'test:deploy', '--simulate'];
151
        $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
152
        $this->guy->seeInOutput('[Simulator] Simulating Remote\\Ssh(\'mysite.com\', null)');
153
        $this->guy->seeInOutput('[Simulator] Running ssh mysite.com \'cd "/var/www/somesite" && git pull\'');
154
    }
155
156 View Code Duplication
    public function testRunnerTryError()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
157
    {
158
        $argv = ['placeholder', 'test:error'];
159
        $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
160
161
        $this->guy->seeInOutput('[Exec] Running ls xyzzy');
162
        $this->assertTrue($result > 0);
163
    }
164
165 View Code Duplication
    public function testRunnerTrySimulatedError()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
166
    {
167
        $argv = ['placeholder', 'test:error', '--simulate'];
168
        $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
169
170
        $this->guy->seeInOutput('Simulating Exec');
171
        $this->assertEquals(0, $result);
172
    }
173
174 View Code Duplication
    public function testRunnerTryException()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
175
    {
176
        $argv = ['placeholder', 'test:exception', '--task'];
177
        $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
178
179
        $this->guy->seeInOutput('Task failed with an exception');
180
        $this->assertEquals(1, $result);
181
    }
182
183
    public function testInitCommand()
184
    {
185
        $container = \Robo\Robo::getContainer();
186
        $app = $container->get('application');
187
        $app->addInitRoboFileCommand(getcwd() . '/testRoboFile.php', 'RoboTestClass');
188
189
        $argv = ['placeholder', 'init'];
190
        $status = $this->runner->run($argv, $this->guy->capturedOutputStream(), $app);
0 ignored issues
show
Documentation introduced by
$argv is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a null|object<Symfony\Comp...e\Input\InputInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
191
        $this->guy->seeInOutput('testRoboFile.php will be created in the current directory');
192
        $this->assertEquals(0, $status);
193
194
        $this->assertTrue(file_exists('testRoboFile.php'));
195
        $commandContents = file_get_contents('testRoboFile.php');
196
        unlink('testRoboFile.php');
197
        $this->assertContains('class RoboTestClass', $commandContents);
198
    }
199
200 View Code Duplication
    public function testTasksStopOnFail()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
201
    {
202
        $argv = ['placeholder', 'test:stop-on-fail'];
203
        $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
204
205
        $this->guy->seeInOutput('[');
206
        $this->assertTrue($result > 0);
207
    }
208
209 View Code Duplication
    public function testInvalidRoboDirectory()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
210
    {
211
        $runnerWithNoRoboFile = new \Robo\Runner();
212
213
        $argv = ['placeholder', 'list', '-f', 'no-such-directory'];
214
        $result = $runnerWithNoRoboFile->execute($argv, null, null, $this->guy->capturedOutputStream());
0 ignored issues
show
Unused Code introduced by
$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 $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.

Loading history...
215
216
        $this->guy->seeInOutput('Path `no-such-directory` is invalid; please provide a valid absolute path to the Robofile to load.');
217
    }
218
219 View Code Duplication
    public function testUnloadableRoboFile()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
220
    {
221
        $runnerWithNoRoboFile = new \Robo\Runner();
222
223
        $argv = ['placeholder', 'list', '-f', dirname(__DIR__) . '/src/RoboFileFixture.php'];
224
        $result = $runnerWithNoRoboFile->execute($argv, null, null, $this->guy->capturedOutputStream());
0 ignored issues
show
Unused Code introduced by
$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 $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.

Loading history...
225
226
        // We cannot load RoboFileFixture.php via -f / --load-from because
227
        // it has a namespace, and --load-from does not support that.
228
        $this->guy->seeInOutput('Class RoboFileFixture was not loaded');
229
    }
230
231 View Code Duplication
    public function testRunnerQuietOutput()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
232
    {
233
        $argv = ['placeholder', 'test:verbosity', '--quiet'];
234
        $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
235
236
        $this->guy->doNotSeeInOutput('This command will print more information at higher verbosity levels');
237
        $this->guy->doNotSeeInOutput('This is a verbose message (-v).');
238
        $this->guy->doNotSeeInOutput('This is a very verbose message (-vv).');
239
        $this->guy->doNotSeeInOutput('This is a debug message (-vvv).');
240
        $this->guy->doNotSeeInOutput(' [warning] This is a warning log message.');
241
        $this->guy->doNotSeeInOutput(' [notice] This is a notice log message.');
242
        $this->guy->doNotSeeInOutput(' [debug] This is a debug log message.');
243
        $this->assertEquals(0, $result);
244
    }
245
246 View Code Duplication
    public function testRunnerVerboseOutput()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
247
    {
248
        $argv = ['placeholder', 'test:verbosity', '-v'];
249
        $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
250
251
        $this->guy->seeInOutput('This command will print more information at higher verbosity levels');
252
        $this->guy->seeInOutput('This is a verbose message (-v).');
253
        $this->guy->doNotSeeInOutput('This is a very verbose message (-vv).');
254
        $this->guy->doNotSeeInOutput('This is a debug message (-vvv).');
255
        $this->guy->seeInOutput(' [warning] This is a warning log message.');
256
        $this->guy->seeInOutput(' [notice] This is a notice log message.');
257
        $this->guy->doNotSeeInOutput(' [debug] This is a debug log message.');
258
        $this->assertEquals(0, $result);
259
    }
260
261 View Code Duplication
    public function testRunnerVeryVerboseOutput()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
262
    {
263
        $argv = ['placeholder', 'test:verbosity', '-vv'];
264
        $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
265
266
        $this->guy->seeInOutput('This command will print more information at higher verbosity levels');
267
        $this->guy->seeInOutput('This is a verbose message (-v).');
268
        $this->guy->seeInOutput('This is a very verbose message (-vv).');
269
        $this->guy->doNotSeeInOutput('This is a debug message (-vvv).');
270
        $this->guy->seeInOutput(' [warning] This is a warning log message.');
271
        $this->guy->seeInOutput(' [notice] This is a notice log message.');
272
        $this->guy->doNotSeeInOutput(' [debug] This is a debug log message.');
273
        $this->assertEquals(0, $result);
274
    }
275
276 View Code Duplication
    public function testRunnerVerbosityThresholdVerbose()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
277
    {
278
        $argv = ['placeholder', 'test:verbosity-threshold', '-v'];
279
        $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
280
281
        $this->guy->seeInOutput('This command will print more information at higher verbosity levels');
282
        $this->guy->seeInOutput("Running echo verbose or higher\nverbose or higher");
283
        $this->guy->doNotSeeInOutput('very verbose or higher');
284
        $this->assertEquals(0, $result);
285
    }
286
287 View Code Duplication
    public function testRunnerVerbosityThresholdVeryVerbose()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
288
    {
289
        $argv = ['placeholder', 'test:verbosity-threshold', '-vv'];
290
        $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
291
292
        $this->guy->seeInOutput('This command will print more information at higher verbosity levels');
293
        $this->guy->seeInOutput("Running echo verbose or higher\nverbose or higher");
294
        $this->guy->seeInOutput("Running echo very verbose or higher\nvery verbose or higher");
295
        $this->assertEquals(0, $result);
296
    }
297
298 View Code Duplication
    public function testRunnerDebugOutput()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
299
    {
300
        $argv = ['placeholder', 'test:verbosity', '-vvv'];
301
        $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
302
303
        $this->guy->seeInOutput('This command will print more information at higher verbosity levels');
304
        $this->guy->seeInOutput('This is a verbose message (-v).');
305
        $this->guy->seeInOutput('This is a very verbose message (-vv).');
306
        $this->guy->seeInOutput('This is a debug message (-vvv).');
307
        $this->guy->seeInOutput(' [warning] This is a warning log message.');
308
        $this->guy->seeInOutput(' [notice] This is a notice log message.');
309
        $this->guy->seeInOutput(' [debug] This is a debug log message.');
310
        $this->assertEquals(0, $result);
311
    }
312
313 View Code Duplication
    public function testNoOptionsNoConfiguration()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
314
    {
315
        // Run without any config and without any options
316
        $argv = ['placeholder', 'test:simple-list'];
317
        $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
0 ignored issues
show
Unused Code introduced by
$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 $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.

Loading history...
318
319
        $this->guy->seeInOutput("a: '1'");
320
        $this->guy->seeInOutput("b: '2'");
321
    }
322
323 View Code Duplication
    public function testOptionsButNoConfiguration()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
324
    {
325
        // Set one option, but provide no config
326
        $argv = ['placeholder', 'test:simple-list', '--b=3'];
327
        $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
0 ignored issues
show
Unused Code introduced by
$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 $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.

Loading history...
328
329
        $this->guy->seeInOutput("a: '1'");
330
        $this->guy->seeInOutput("b: '3'");
331
    }
332
333 View Code Duplication
    public function testWithConfigurationButNoOptions()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
334
    {
335
        \Robo\Robo::config()->set('command.test.simple-list.options.a', '4');
336
        \Robo\Robo::config()->set('command.test.simple-list.options.b', '5');
337
338
        $argv = ['placeholder', 'test:simple-list'];
339
        $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
0 ignored issues
show
Unused Code introduced by
$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 $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.

Loading history...
340
341
        $this->guy->seeInOutput("a: '4'");
342
        $this->guy->seeInOutput("b: '5'");
343
    }
344
345 View Code Duplication
    public function testWithConfigurationAndOptionOverride()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
346
    {
347
        \Robo\Robo::config()->set('command.test.simple-list.options.a', '4');
348
        \Robo\Robo::config()->set('command.test.simple-list.options.b', '5');
349
350
        $argv = ['placeholder', 'test:simple-list', '--b=6'];
351
        $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
0 ignored issues
show
Unused Code introduced by
$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 $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.

Loading history...
352
353
        $this->guy->seeInOutput("a: '4'");
354
        $this->guy->seeInOutput("b: '6'");
355
    }
356
357 View Code Duplication
    public function testSettingConfigurationFromCommandOptions()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
358
    {
359
        $argv = ['placeholder', 'test:simple-list', '-D', 'config.key=value'];
360
        $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
0 ignored issues
show
Unused Code introduced by
$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 $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.

Loading history...
361
362
        $this->guy->seeInOutput("a: '1'");
363
        $this->guy->seeInOutput("b: '2'");
364
365
        $actual = \Robo\Robo::config()->get('config.key');
366
        $this->assertEquals('value', $actual);
367
    }
368
369 View Code Duplication
    public function testWithConfigLoader()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
370
    {
371
        $loader = new YamlConfigLoader();
372
        $loader->load(dirname(__DIR__) . '/_data/robo.yml');
373
374
        \Robo\Robo::config()->extend($loader->export());
375
376
        $argv = ['placeholder', 'test:simple-list'];
377
        $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
0 ignored issues
show
Unused Code introduced by
$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 $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.

Loading history...
378
379
        $this->guy->seeInOutput("a: '12'");
380
        $this->guy->seeInOutput("b: '13'");
381
    }
382
383 View Code Duplication
    public function testWithConfigLoaderAndCliOverride()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
384
    {
385
        $loader = new YamlConfigLoader();
386
        $loader->load(dirname(__DIR__) . '/_data/robo.yml');
387
388
        \Robo\Robo::config()->extend($loader->export());
389
390
        $argv = ['placeholder', 'test:simple-list', '--b=3'];
391
        $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
0 ignored issues
show
Unused Code introduced by
$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 $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.

Loading history...
392
393
        $this->guy->seeInOutput("a: '12'");
394
        $this->guy->seeInOutput("b: '3'");
395
    }
396
397
    public function testWithConfigProcessor()
398
    {
399
        $processor = new ConfigProcessor();
400
        $loader = new YamlConfigLoader();
401
        $processor->extend($loader->load(dirname(__DIR__) . '/_data/robo.yml'));
402
        $processor->extend($loader->load(dirname(__DIR__) . '/_data/robo2.yml'));
403
        \Robo\Robo::config()->import($processor->export());
404
405
        $argv = ['placeholder', 'test:simple-list'];
406
        $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
0 ignored issues
show
Unused Code introduced by
$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 $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.

Loading history...
407
408
        $this->guy->seeInOutput("a: '112'");
409
        $this->guy->seeInOutput("b: '13'");
410
    }
411
412 View Code Duplication
    public function testCommandWithTaskConfiguration()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
413
    {
414
        $loader = new YamlConfigLoader();
415
        $loader->load(dirname(__DIR__) . '/_data/robo.yml');
416
417
        \Robo\Robo::config()->extend($loader->export());
418
419
        $argv = ['placeholder', 'test:exec', '--simulate'];
420
        $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
0 ignored issues
show
Unused Code introduced by
$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 $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.

Loading history...
421
422
        // `task.Exec.settings.dir` is defined in loaded robo.yml configuration file.
423
        $this->guy->seeInOutput("->dir('/some/dir')");
424
    }
425
}
426