|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
use AspectMock\Test as test; |
|
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
class ExecTaskTest extends \Codeception\TestCase\Test |
|
|
|
|
|
|
5
|
|
|
{ |
|
6
|
|
|
/** |
|
7
|
|
|
* @var \AspectMock\Proxy\ClassProxy |
|
8
|
|
|
*/ |
|
9
|
|
|
protected $process; |
|
10
|
|
|
|
|
11
|
|
View Code Duplication |
protected function _before() |
|
|
|
|
|
|
12
|
|
|
{ |
|
13
|
|
|
$this->process = test::double('Symfony\Component\Process\Process', [ |
|
|
|
|
|
|
14
|
|
|
'run' => false, |
|
15
|
|
|
'start' => false, |
|
16
|
|
|
'getOutput' => 'Hello world', |
|
17
|
|
|
'getExitCode' => 0, |
|
18
|
|
|
'logger' => new \Psr\Log\NullLogger(), |
|
19
|
|
|
]); |
|
20
|
|
|
test::double('Robo\Task\Base\Exec', ['output' => new \Symfony\Component\Console\Output\NullOutput()]); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
View Code Duplication |
public function testExec() |
|
|
|
|
|
|
24
|
|
|
{ |
|
25
|
|
|
$task = new \Robo\Task\Base\Exec('ls'); |
|
26
|
|
|
$task->setLogger(new \Psr\Log\NullLogger()); |
|
27
|
|
|
|
|
28
|
|
|
$result = $task->run(); |
|
29
|
|
|
$this->process->verifyInvoked('run'); |
|
30
|
|
|
verify($result->getMessage())->equals('Hello world'); |
|
31
|
|
|
verify($result->getExitCode())->equals(0); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
View Code Duplication |
public function testExecInBackground() |
|
|
|
|
|
|
35
|
|
|
{ |
|
36
|
|
|
$task = new \Robo\Task\Base\Exec('ls'); |
|
37
|
|
|
$task->setLogger(new \Psr\Log\NullLogger()); |
|
38
|
|
|
|
|
39
|
|
|
$result = $task->background()->run(); |
|
40
|
|
|
$this->process->verifyInvoked('start'); |
|
41
|
|
|
$this->process->verifyNeverInvoked('run'); |
|
42
|
|
|
verify('exit code was not received', $result->getExitCode())->notEquals(100); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function testGetCommand() |
|
46
|
|
|
{ |
|
47
|
|
|
verify((new \Robo\Task\Base\Exec('ls'))->getCommand())->equals('ls'); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function testExecStack() |
|
51
|
|
|
{ |
|
52
|
|
|
$task = new \Robo\Task\Base\ExecStack(); |
|
53
|
|
|
$task->setLogger(new \Psr\Log\NullLogger()); |
|
54
|
|
|
|
|
55
|
|
|
$task |
|
56
|
|
|
->exec('ls') |
|
57
|
|
|
->exec('cd /') |
|
58
|
|
|
->exec('cd home') |
|
59
|
|
|
->run(); |
|
60
|
|
|
$this->process->verifyInvoked('run', 3); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function testExecStackCommand() |
|
64
|
|
|
{ |
|
65
|
|
|
verify((new \Robo\Task\Base\ExecStack()) |
|
66
|
|
|
->exec('ls') |
|
67
|
|
|
->exec('cd /') |
|
68
|
|
|
->exec('cd home') |
|
69
|
|
|
->getCommand() |
|
70
|
|
|
)->equals('ls && cd / && cd home'); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function testExecStackCommandInterface() |
|
74
|
|
|
{ |
|
75
|
|
|
verify((new \Robo\Task\Base\ExecStack()) |
|
76
|
|
|
->exec('ls') |
|
77
|
|
|
->exec((new \Robo\Task\Vcs\GitStack('git'))->add('-A')->pull()) |
|
78
|
|
|
->getCommand() |
|
79
|
|
|
)->equals('ls && git add -A && git pull'); |
|
80
|
|
|
} |
|
81
|
|
|
}; |
|
82
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.