Completed
Push — master ( 061d1e...31cfb3 )
by Greg
02:26
created

RunnerTest::testSymfony()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.584
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
use Robo\Robo;
3
4
class RunnerTest extends \Codeception\TestCase\Test
5
{
6
    /**
7
     * @var \Robo\Runner
8
     */
9
    private $runner;
10
11
    /**
12
     * @var \CodeGuy
13
     */
14
    protected $guy;
15
16
    public function _before()
17
    {
18
        $this->runner = new \Robo\Runner('\Robo\RoboFileFixture');
19
    }
20
21
    public function testThrowsExceptionWhenNoContainerAvailable()
22
    {
23
        \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...
24
            '\RuntimeException',
25
            '/container is not initialized yet.*/'
26
        );
27
        Robo::unsetContainer();
28
        Robo::getContainer();
29
    }
30
31
    public function testRunnerNoSuchCommand()
32
    {
33
        $argv = ['placeholder', 'no-such-command'];
34
        $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
35
        $this->guy->seeInOutput('Command "no-such-command" is not defined.');
36
    }
37
38
    public function testRunnerList()
39
    {
40
        $argv = ['placeholder', 'list'];
41
        $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
42
        $this->guy->seeInOutput('test:array-args');
43
    }
44
45
    public function testRunnerTryArgs()
46
    {
47
        $argv = ['placeholder', 'test:array-args', 'a', 'b', 'c'];
48
        $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
49
50
        $expected = <<<EOT
51
>  The parameters passed are:
52
array (
53
  0 => 'a',
54
  1 => 'b',
55
  2 => 'c',
56
)
57
58
EOT;
59
        $this->guy->seeOutputEquals($expected);
60
    }
61
62
    public function testSymfonyStyle()
63
    {
64
        $argv = ['placeholder', 'test:symfony-style'];
65
        $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
66
        $this->guy->seeInOutput('Some text in section one.');
67
    }
68
69
    public function testSymfony()
70
    {
71
        $argv = ['placeholder', 'test:symfony', 'a', 'b', 'c', '--foo=bar', '--foo=baz', '--foo=boz'];
72
        $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
73
        $expected = <<<EOT
74
>  The parameters passed are:
75
array (
76
  0 => 'a',
77
  1 => 'b',
78
  2 => 'c',
79
)
80
>  The options passed via --foo are:
81
array (
82
  0 => 'bar',
83
  1 => 'baz',
84
  2 => 'boz',
85
)
86
87
EOT;
88
        $this->guy->seeOutputEquals($expected);
89
    }
90
91 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...
92
    {
93
        $argv = ['placeholder', 'test:command-event'];
94
        $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
95
96
        $expected = <<<EOT
97
 This is the command-event hook for the test:command-event command.
98
 This is the main method for the test:command-event command.
99
 This is the post-command hook for the test:command-event command.
100
EOT;
101
        $this->guy->seeInOutput($expected);
102
    }
103
104 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...
105
    {
106
        $argv = ['placeholder', 'test:custom-event'];
107
        $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
108
109
        $expected = 'one,two';
110
        $this->guy->seeInOutput($expected);
111
    }
112
113
    public function testRoboStaticRunMethod()
114
    {
115
        $argv = ['placeholder', 'test:symfony-style'];
116
        $commandFiles = ['\Robo\RoboFileFixture'];
117
        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...
118
        $this->guy->seeInOutput('Some text in section one.');
119
    }
120
121 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...
122
    {
123
        $argv = ['placeholder', 'test:deploy', '--simulate'];
124
        $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
125
        $this->guy->seeInOutput('[Simulator] Simulating Remote\\Ssh(\'mysite.com\', null)');
126
        $this->guy->seeInOutput('[Simulator] Running ssh mysite.com \'cd "/var/www/somesite" && git pull\'');
127
    }
128
129 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...
130
    {
131
        $argv = ['placeholder', 'test:error'];
132
        $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
133
134
        $this->guy->seeInOutput('[Exec] Running ls xyzzy');
135
        $this->assertTrue($result > 0);
136
    }
137
138 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...
139
    {
140
        $argv = ['placeholder', 'test:error', '--simulate'];
141
        $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
142
143
        $this->guy->seeInOutput('Simulating Exec');
144
        $this->assertEquals(0, $result);
145
    }
146
147 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...
148
    {
149
        $argv = ['placeholder', 'test:exception', '--task'];
150
        $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
151
152
        $this->guy->seeInOutput('Task failed with an exception');
153
        $this->assertEquals(1, $result);
154
    }
155
156
    public function testInitCommand()
157
    {
158
        $container = \Robo\Robo::getContainer();
159
        $app = $container->get('application');
160
        $app->addInitRoboFileCommand(getcwd() . '/testRoboFile.php', 'RoboTestClass');
161
162
        $argv = ['placeholder', 'init'];
163
        $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...
164
        $this->guy->seeInOutput('testRoboFile.php will be created in the current directory');
165
        $this->assertEquals(0, $status);
166
167
        $this->assertTrue(file_exists('testRoboFile.php'));
168
        $commandContents = file_get_contents('testRoboFile.php');
169
        unlink('testRoboFile.php');
170
        $this->assertContains('class RoboTestClass', $commandContents);
171
    }
172
173 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...
174
    {
175
        $argv = ['placeholder', 'test:stop-on-fail'];
176
        $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
177
178
        $this->guy->seeInOutput('[');
179
        $this->assertTrue($result > 0);
180
    }
181
182 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...
183
    {
184
        $runnerWithNoRoboFile = new \Robo\Runner();
185
186
        $argv = ['placeholder', 'no-such-command', '-f', 'no-such-directory'];
187
        $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...
188
189
        $this->guy->seeInOutput('Path `no-such-directory` is invalid; please provide a valid absolute path to the Robofile to load.');
190
    }
191
192 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...
193
    {
194
        $runnerWithNoRoboFile = new \Robo\Runner();
195
196
        $argv = ['placeholder', 'help', 'test:custom-event', '-f', dirname(__DIR__) . '/src/RoboFileFixture.php'];
197
        $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...
198
199
        // We cannot load RoboFileFixture.php via -f / --load-from because
200
        // it has a namespace, and --load-from does not support that.
201
        $this->guy->seeInOutput('Class RoboFileFixture was not loaded');
202
    }
203
204 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...
205
    {
206
        $argv = ['placeholder', 'test:verbosity', '--quiet'];
207
        $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
208
209
        $this->guy->doNotSeeInOutput('This command will print more information at higher verbosity levels');
210
        $this->guy->doNotSeeInOutput('This is a verbose message (-v).');
211
        $this->guy->doNotSeeInOutput('This is a very verbose message (-vv).');
212
        $this->guy->doNotSeeInOutput('This is a debug message (-vvv).');
213
        $this->guy->doNotSeeInOutput(' [warning] This is a warning log message.');
214
        $this->guy->doNotSeeInOutput(' [notice] This is a notice log message.');
215
        $this->guy->doNotSeeInOutput(' [debug] This is a debug log message.');
216
        $this->assertEquals(0, $result);
217
    }
218
219 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...
220
    {
221
        $argv = ['placeholder', 'test:verbosity', '-v'];
222
        $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
223
224
        $this->guy->seeInOutput('This command will print more information at higher verbosity levels');
225
        $this->guy->seeInOutput('This is a verbose message (-v).');
226
        $this->guy->doNotSeeInOutput('This is a very verbose message (-vv).');
227
        $this->guy->doNotSeeInOutput('This is a debug message (-vvv).');
228
        $this->guy->seeInOutput(' [warning] This is a warning log message.');
229
        $this->guy->seeInOutput(' [notice] This is a notice log message.');
230
        $this->guy->doNotSeeInOutput(' [debug] This is a debug log message.');
231
        $this->assertEquals(0, $result);
232
    }
233
234 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...
235
    {
236
        $argv = ['placeholder', 'test:verbosity', '-vv'];
237
        $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
238
239
        $this->guy->seeInOutput('This command will print more information at higher verbosity levels');
240
        $this->guy->seeInOutput('This is a verbose message (-v).');
241
        $this->guy->seeInOutput('This is a very verbose message (-vv).');
242
        $this->guy->doNotSeeInOutput('This is a debug message (-vvv).');
243
        $this->guy->seeInOutput(' [warning] This is a warning log message.');
244
        $this->guy->seeInOutput(' [notice] This is a notice log message.');
245
        $this->guy->doNotSeeInOutput(' [debug] This is a debug log message.');
246
        $this->assertEquals(0, $result);
247
    }
248
249 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...
250
    {
251
        $argv = ['placeholder', 'test:verbosity-threshold', '-v'];
252
        $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
253
254
        $this->guy->seeInOutput('This command will print more information at higher verbosity levels');
255
        $this->guy->seeInOutput("Running echo verbose or higher\nverbose or higher");
256
        $this->guy->doNotSeeInOutput('very verbose or higher');
257
        $this->assertEquals(0, $result);
258
    }
259
260 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...
261
    {
262
        $argv = ['placeholder', 'test:verbosity-threshold', '-vv'];
263
        $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
264
265
        $this->guy->seeInOutput('This command will print more information at higher verbosity levels');
266
        $this->guy->seeInOutput("Running echo verbose or higher\nverbose or higher");
267
        $this->guy->seeInOutput("Running echo very verbose or higher\nvery verbose or higher");
268
        $this->assertEquals(0, $result);
269
    }
270
271 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...
272
    {
273
        $argv = ['placeholder', 'test:verbosity', '-vvv'];
274
        $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
275
276
        $this->guy->seeInOutput('This command will print more information at higher verbosity levels');
277
        $this->guy->seeInOutput('This is a verbose message (-v).');
278
        $this->guy->seeInOutput('This is a very verbose message (-vv).');
279
        $this->guy->seeInOutput('This is a debug message (-vvv).');
280
        $this->guy->seeInOutput(' [warning] This is a warning log message.');
281
        $this->guy->seeInOutput(' [notice] This is a notice log message.');
282
        $this->guy->seeInOutput(' [debug] This is a debug log message.');
283
        $this->assertEquals(0, $result);
284
    }
285
}
286