These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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
|
|||
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 | View Code Duplication | public function testCommandEventHook() |
|
70 | { |
||
71 | $argv = ['placeholder', 'test:command-event']; |
||
72 | $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream()); |
||
73 | |||
74 | $expected = <<<EOT |
||
75 | This is the command-event hook for the test:command-event command. |
||
76 | This is the main method for the test:command-event command. |
||
77 | This is the post-command hook for the test:command-event command. |
||
78 | EOT; |
||
79 | $this->guy->seeInOutput($expected); |
||
80 | } |
||
81 | |||
82 | View Code Duplication | public function testCustomEventHook() |
|
83 | { |
||
84 | $argv = ['placeholder', 'test:custom-event']; |
||
85 | $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream()); |
||
86 | |||
87 | $expected = 'one,two'; |
||
88 | $this->guy->seeInOutput($expected); |
||
89 | } |
||
90 | |||
91 | public function testRoboStaticRunMethod() |
||
92 | { |
||
93 | $argv = ['placeholder', 'test:symfony-style']; |
||
94 | $commandFiles = ['\Robo\RoboFileFixture']; |
||
95 | Robo::run($argv, $commandFiles, 'MyApp', '1.2.3', $this->guy->capturedOutputStream()); |
||
96 | $this->guy->seeInOutput('Some text in section one.'); |
||
97 | } |
||
98 | |||
99 | View Code Duplication | public function testDeploy() |
|
100 | { |
||
101 | $argv = ['placeholder', 'test:deploy', '--simulate']; |
||
102 | $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream()); |
||
103 | $this->guy->seeInOutput('[Simulator] Simulating Remote\\Ssh(\'mysite.com\', null)'); |
||
104 | $this->guy->seeInOutput('[Simulator] Running ssh mysite.com \'cd "/var/www/somesite" && git pull\''); |
||
105 | } |
||
106 | |||
107 | View Code Duplication | public function testRunnerTryError() |
|
108 | { |
||
109 | $argv = ['placeholder', 'test:error']; |
||
110 | $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream()); |
||
111 | |||
112 | $this->guy->seeInOutput('[Exec] Running ls xyzzy'); |
||
113 | $this->assertTrue($result > 0); |
||
114 | } |
||
115 | |||
116 | View Code Duplication | public function testRunnerTrySimulatedError() |
|
117 | { |
||
118 | $argv = ['placeholder', 'test:error', '--simulate']; |
||
119 | $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream()); |
||
120 | |||
121 | $this->guy->seeInOutput('Simulating Exec'); |
||
122 | $this->assertEquals(0, $result); |
||
123 | } |
||
124 | |||
125 | View Code Duplication | public function testRunnerTryException() |
|
126 | { |
||
127 | $argv = ['placeholder', 'test:exception', '--task']; |
||
128 | $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream()); |
||
129 | |||
130 | $this->guy->seeInOutput('Task failed with an exception'); |
||
131 | $this->assertEquals(1, $result); |
||
132 | } |
||
133 | |||
134 | public function testInitCommand() |
||
135 | { |
||
136 | $container = \Robo\Robo::getContainer(); |
||
137 | $app = $container->get('application'); |
||
138 | $app->addInitRoboFileCommand(getcwd() . '/testRoboFile.php', 'RoboTestClass'); |
||
139 | |||
140 | $argv = ['placeholder', 'init']; |
||
141 | $status = $this->runner->run($argv, $this->guy->capturedOutputStream(), $app); |
||
142 | $this->guy->seeInOutput('testRoboFile.php will be created in the current directory'); |
||
143 | $this->assertEquals(0, $status); |
||
144 | |||
145 | $this->assertTrue(file_exists('testRoboFile.php')); |
||
146 | $commandContents = file_get_contents('testRoboFile.php'); |
||
147 | unlink('testRoboFile.php'); |
||
148 | $this->assertContains('class RoboTestClass', $commandContents); |
||
149 | } |
||
150 | |||
151 | View Code Duplication | public function testTasksStopOnFail() |
|
152 | { |
||
153 | $argv = ['placeholder', 'test:stop-on-fail']; |
||
154 | $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream()); |
||
155 | |||
156 | $this->guy->seeInOutput('['); |
||
157 | $this->assertTrue($result > 0); |
||
158 | } |
||
159 | |||
160 | View Code Duplication | public function testInvalidRoboDirectory() |
|
161 | { |
||
162 | $runnerWithNoRoboFile = new \Robo\Runner(); |
||
163 | |||
164 | $argv = ['placeholder', 'no-such-command', '-f', 'no-such-directory']; |
||
165 | $result = $runnerWithNoRoboFile->execute($argv, null, null, $this->guy->capturedOutputStream()); |
||
166 | |||
167 | $this->guy->seeInOutput('Path `no-such-directory` is invalid; please provide a valid absolute path to the Robofile to load.'); |
||
168 | } |
||
169 | |||
170 | View Code Duplication | public function testUnloadableRoboFile() |
|
171 | { |
||
172 | $runnerWithNoRoboFile = new \Robo\Runner(); |
||
173 | |||
174 | $argv = ['placeholder', 'help', 'test:custom-event', '-f', dirname(__DIR__) . '/src/RoboFileFixture.php']; |
||
175 | $result = $runnerWithNoRoboFile->execute($argv, null, null, $this->guy->capturedOutputStream()); |
||
176 | |||
177 | // We cannot load RoboFileFixture.php via -f / --load-from because |
||
178 | // it has a namespace, and --load-from does not support that. |
||
179 | $this->guy->seeInOutput('Class RoboFileFixture was not loaded'); |
||
180 | } |
||
181 | |||
182 | View Code Duplication | public function testRunnerQuietOutput() |
|
183 | { |
||
184 | $argv = ['placeholder', 'test:verbosity', '--quiet']; |
||
185 | $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream()); |
||
186 | |||
187 | $this->guy->doNotSeeInOutput('This command will print more information at higher verbosity levels'); |
||
188 | $this->guy->doNotSeeInOutput('This is a verbose message (-v).'); |
||
189 | $this->guy->doNotSeeInOutput('This is a very verbose message (-vv).'); |
||
190 | $this->guy->doNotSeeInOutput('This is a debug message (-vvv).'); |
||
191 | $this->guy->doNotSeeInOutput(' [warning] This is a warning log message.'); |
||
192 | $this->guy->doNotSeeInOutput(' [notice] This is a notice log message.'); |
||
193 | $this->guy->doNotSeeInOutput(' [debug] This is a debug log message.'); |
||
194 | $this->assertEquals(0, $result); |
||
195 | } |
||
196 | |||
197 | View Code Duplication | public function testRunnerVerboseOutput() |
|
198 | { |
||
199 | $argv = ['placeholder', 'test:verbosity', '-v']; |
||
200 | $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream()); |
||
201 | |||
202 | $this->guy->seeInOutput('This command will print more information at higher verbosity levels'); |
||
203 | $this->guy->seeInOutput('This is a verbose message (-v).'); |
||
204 | $this->guy->doNotSeeInOutput('This is a very verbose message (-vv).'); |
||
205 | $this->guy->doNotSeeInOutput('This is a debug message (-vvv).'); |
||
206 | $this->guy->seeInOutput(' [warning] This is a warning log message.'); |
||
207 | $this->guy->seeInOutput(' [notice] This is a notice log message.'); |
||
208 | $this->guy->doNotSeeInOutput(' [debug] This is a debug log message.'); |
||
209 | $this->assertEquals(0, $result); |
||
210 | } |
||
211 | |||
212 | View Code Duplication | public function testRunnerVeryVerboseOutput() |
|
213 | { |
||
214 | $argv = ['placeholder', 'test:verbosity', '-vv']; |
||
215 | $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream()); |
||
216 | |||
217 | $this->guy->seeInOutput('This command will print more information at higher verbosity levels'); |
||
218 | $this->guy->seeInOutput('This is a verbose message (-v).'); |
||
219 | $this->guy->seeInOutput('This is a very verbose message (-vv).'); |
||
220 | $this->guy->doNotSeeInOutput('This is a debug message (-vvv).'); |
||
221 | $this->guy->seeInOutput(' [warning] This is a warning log message.'); |
||
222 | $this->guy->seeInOutput(' [notice] This is a notice log message.'); |
||
223 | $this->guy->doNotSeeInOutput(' [debug] This is a debug log message.'); |
||
224 | $this->assertEquals(0, $result); |
||
225 | } |
||
226 | |||
227 | View Code Duplication | public function testRunnerVerbosityThresholdVerbose() |
|
228 | { |
||
229 | $argv = ['placeholder', 'test:verbosity-threshold', '-v']; |
||
230 | $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream()); |
||
231 | |||
232 | $this->guy->seeInOutput('This command will print more information at higher verbosity levels'); |
||
233 | $this->guy->seeInOutput("Running echo verbose or higher\nverbose or higher"); |
||
234 | $this->guy->doNotSeeInOutput('very verbose or higher'); |
||
235 | $this->assertEquals(0, $result); |
||
236 | } |
||
237 | |||
238 | View Code Duplication | public function testRunnerVerbosityThresholdVeryVerbose() |
|
239 | { |
||
240 | $argv = ['placeholder', 'test:verbosity-threshold', '-vv']; |
||
241 | $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream()); |
||
242 | |||
243 | $this->guy->seeInOutput('This command will print more information at higher verbosity levels'); |
||
244 | $this->guy->seeInOutput("Running echo verbose or higher\nverbose or higher"); |
||
245 | $this->guy->seeInOutput("Running echo very verbose or higher\nvery verbose or higher"); |
||
246 | $this->assertEquals(0, $result); |
||
247 | } |
||
248 | |||
249 | View Code Duplication | public function testRunnerDebugOutput() |
|
250 | { |
||
251 | $argv = ['placeholder', 'test:verbosity', '-vvv']; |
||
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('This is a verbose message (-v).'); |
||
256 | $this->guy->seeInOutput('This is a very verbose message (-vv).'); |
||
257 | $this->guy->seeInOutput('This is a debug message (-vvv).'); |
||
258 | $this->guy->seeInOutput(' [warning] This is a warning log message.'); |
||
259 | $this->guy->seeInOutput(' [notice] This is a notice log message.'); |
||
260 | $this->guy->seeInOutput(' [debug] This is a debug log message.'); |
||
261 | $this->assertEquals(0, $result); |
||
262 | } |
||
263 | } |
||
264 |
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.