-
Notifications
You must be signed in to change notification settings - Fork 305
/
Copy pathExecTest.php
95 lines (85 loc) · 3.35 KB
/
ExecTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
namespace Robo;
use Yoast\PHPUnitPolyfills\TestCases\TestCase;
use Robo\Traits\TestTasksTrait;
class ExecTest extends TestCase
{
use TestTasksTrait;
use Task\Base\Tasks;
public function setUp(): void
{
$this->initTestTasksTrait();
}
public function testExecLsCommand()
{
$command = strncasecmp(PHP_OS, 'WIN', 3) == 0 ? 'dir' : 'ls';
$res = $this->taskExec($command)->interactive(false)->run();
$this->assertTrue($res->wasSuccessful());
$this->assertStringContainsString(
'src',
$res->getMessage());
$this->assertStringContainsString(
'codeception.yml',
$res->getMessage());
}
public function testMultipleEnvVars()
{
if (strncasecmp(PHP_OS, 'WIN', 3) == 0) {
$this->markTestSkipped('Environment variables is not supported on Windows.');
}
$task = $this->taskExec('env')->interactive(false);
$task->env('FOO', 'BAR');
$task->env('BAR', 'BAZ');
$result = $task->run();
$this->assertTrue($result->wasSuccessful(), $result->getMessage());
// Verify that the text contains our environment variable.
$this->assertStringContainsString(
'FOO=BAR',
$result->getMessage());
$this->assertStringContainsString(
'BAR=BAZ',
$result->getMessage());
// Now verify that we can reset a value that was previously set.
$task = $this->taskExec('env')->interactive(false);
$task->env('FOO', 'BAR');
$task->env('FOO', 'BAZ');
$result = $task->run();
$this->assertTrue($result->wasSuccessful());
// Verify that the text contains the most recent environment variable.
$this->assertStringContainsString(
'FOO=BAZ',
$result->getMessage());
}
public function testInheritEnv()
{
// Symfony < 3.2.1 does not inherit environment variables, so there's
// nothing to test if the function doesn't exist.
if (!method_exists('Symfony\Component\Process\Process', 'inheritEnvironmentVariables')) {
$this->markTestSkipped(
'Inheriting of environment variables is not supported.'
);
}
// With no environment variables set, count how many environment
// variables are present.
$task = $this->taskExec('env | wc -l')->interactive(false);
$result = $task->run();
$this->assertTrue($result->wasSuccessful());
$start_count = (int) $result->getMessage();
$this->assertGreaterThan(0, $start_count);
// Verify that we get the same amount of environment variables with
// another exec call.
$task = $this->taskExec('env | wc -l')->interactive(false);
$result = $task->run();
$this->assertTrue($result->wasSuccessful());
$this->assertEquals(
$start_count,
(int) $result->getMessage());
// Now run the same command, but this time add another environment
// variable, and see if our count increases by one.
$task = $this->taskExec('env | wc -l')->interactive(false);
$task->env('FOO', 'BAR');
$result = $task->run();
$this->assertTrue($result->wasSuccessful());
$this->assertEquals($start_count + 1, (int) $result->getMessage());
}
}