Completed
Pull Request — master (#769)
by
unknown
03:19
created

ExecCest::testInheritEnv()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 9.568
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, count how many environment
36
        // variables are present.
37
        $task = $I->taskExec('env | wc -l')->interactive(false);
38
        $result = $task->run();
39
        $start_count = (int) $result->getMessage();
40
        verify($start_count)->greaterThan(0);
41
42
        // Verify that we get the same amount of environment variables with
43
        // another exec call.
44
        $task = $I->taskExec('env | wc -l')->interactive(false);
45
        $result = $task->run();
46
        verify((int) $result->getMessage())->equals($start_count);
47
48
        // Now run the same command, but this time add another environment
49
        // variable, and see if our count increases by one.
50
        $task = $I->taskExec('env | wc -l')->interactive(false);
51
        $task->env('FOO', 'BAR');
52
        $result = $task->run();
53
        verify((int) $result->getMessage())->equals($start_count + 1);
54
    }
55
}
56