|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class ExecCest |
|
|
|
|
|
|
4
|
|
|
{ |
|
5
|
|
|
// tests |
|
6
|
|
|
public function toExecLsCommand(CliGuy $I) |
|
7
|
|
|
{ |
|
8
|
|
|
$command = strncasecmp(PHP_OS, 'WIN', 3) == 0 ? 'dir' : 'ls'; |
|
9
|
|
|
$res = $I->taskExec($command)->interactive(false)->run(); |
|
10
|
|
|
verify($res->getMessage())->contains('src'); |
|
11
|
|
|
verify($res->getMessage())->contains('codeception.yml'); |
|
12
|
|
|
} |
|
13
|
|
|
|
|
14
|
|
|
public function testMultipleEnvVars(CliGuy $I) |
|
15
|
|
|
{ |
|
16
|
|
|
$task = $I->taskExec('env')->interactive(false); |
|
17
|
|
|
$task->env('FOO', 'BAR'); |
|
18
|
|
|
$task->env('BAR', 'BAZ'); |
|
19
|
|
|
$result = $task->run(); |
|
20
|
|
|
// Verify that the text contains our environment variable. |
|
21
|
|
|
verify($result->getMessage())->contains('FOO=BAR'); |
|
22
|
|
|
verify($result->getMessage())->contains('BAR=BAZ'); |
|
23
|
|
|
|
|
24
|
|
|
// Now verify that we can reset a value that was previously set. |
|
25
|
|
|
$task = $I->taskExec('env')->interactive(false); |
|
26
|
|
|
$task->env('FOO', 'BAR'); |
|
27
|
|
|
$task->env('FOO', 'BAZ'); |
|
28
|
|
|
$result = $task->run(); |
|
29
|
|
|
// Verify that the text contains the most recent environment variable. |
|
30
|
|
|
verify($result->getMessage())->contains('FOO=BAZ'); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function testInheritEnv(CliGuy $I) |
|
34
|
|
|
{ |
|
35
|
|
|
// With no environment variables set, test that we have a known variable |
|
36
|
|
|
// such as PATH. |
|
37
|
|
|
$task = $I->taskExec('env | grep -E "^PATH="')->interactive(false); |
|
38
|
|
|
$result = $task->run(); |
|
39
|
|
|
verify($result->getExitCode())->equals(\Robo\Result::EXITCODE_OK); |
|
40
|
|
|
|
|
41
|
|
|
// Now run the same command, but this time set an environment variable |
|
42
|
|
|
// on the task using ->env(). |
|
43
|
|
|
$task = $I->taskExec('env | grep -E "^PATH="')->interactive(false); |
|
44
|
|
|
$task->env('FOO', 'BAR'); |
|
45
|
|
|
$result = $task->run(); |
|
46
|
|
|
verify($result->getExitCode())->equals(\Robo\Result::EXITCODE_OK); |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.