Completed
Pull Request — master (#769)
by
unknown
04:52
created

ExecCest::testMultipleEnvVars()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
class ExecCest
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...
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