Skip to content

Commit f89b80c

Browse files
Add tests
1 parent d34d3ea commit f89b80c

File tree

1 file changed

+152
-0
lines changed

1 file changed

+152
-0
lines changed

tests/unit/Util/PHP/PhpJobTest.php

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace PHPUnit\Util\PHP;
11+
12+
use PHPUnit\Framework\Attributes\CoversClass;
13+
use PHPUnit\Framework\Attributes\Small;
14+
use PHPUnit\Framework\TestCase;
15+
16+
#[CoversClass(PhpJob::class)]
17+
#[Small]
18+
final class PhpJobTest extends TestCase
19+
{
20+
public function testHasCode(): void
21+
{
22+
$code = 'the-code';
23+
24+
$job = new PhpJob(
25+
$code,
26+
[],
27+
[],
28+
[],
29+
null,
30+
false,
31+
);
32+
33+
$this->assertSame($code, $job->code());
34+
35+
$this->assertFalse($job->hasEnvironmentVariables());
36+
$this->assertFalse($job->hasInput());
37+
$this->assertFalse($job->redirectErrors());
38+
}
39+
40+
public function testMayHavePhpSettings(): void
41+
{
42+
$phpSettings = ['foo' => 'bar'];
43+
44+
$job = new PhpJob(
45+
'the-code',
46+
$phpSettings,
47+
[],
48+
[],
49+
null,
50+
false,
51+
);
52+
53+
$this->assertSame($phpSettings, $job->phpSettings());
54+
55+
$this->assertFalse($job->hasEnvironmentVariables());
56+
$this->assertFalse($job->hasInput());
57+
$this->assertFalse($job->redirectErrors());
58+
}
59+
60+
public function testMayHaveEnvironmentVariables(): void
61+
{
62+
$environmentVariables = ['foo' => 'bar'];
63+
64+
$job = new PhpJob(
65+
'the-code',
66+
[],
67+
$environmentVariables,
68+
[],
69+
null,
70+
false,
71+
);
72+
73+
$this->assertTrue($job->hasEnvironmentVariables());
74+
$this->assertSame($environmentVariables, $job->environmentVariables());
75+
76+
$this->assertFalse($job->hasInput());
77+
$this->assertFalse($job->redirectErrors());
78+
}
79+
80+
public function testMayHaveArguments(): void
81+
{
82+
$arguments = ['foo', 'bar'];
83+
84+
$job = new PhpJob(
85+
'the-code',
86+
[],
87+
[],
88+
$arguments,
89+
null,
90+
false,
91+
);
92+
93+
$this->assertTrue($job->hasArguments());
94+
$this->assertSame($arguments, $job->arguments());
95+
96+
$this->assertFalse($job->hasEnvironmentVariables());
97+
$this->assertFalse($job->hasInput());
98+
$this->assertFalse($job->redirectErrors());
99+
}
100+
101+
public function testMayHaveInput(): void
102+
{
103+
$input = 'the-input';
104+
105+
$job = new PhpJob(
106+
'the-code',
107+
[],
108+
[],
109+
[],
110+
$input,
111+
false,
112+
);
113+
114+
$this->assertTrue($job->hasInput());
115+
$this->assertSame($input, $job->input());
116+
117+
$this->assertFalse($job->hasEnvironmentVariables());
118+
$this->assertFalse($job->redirectErrors());
119+
}
120+
121+
public function testMayNotHaveInput(): void
122+
{
123+
$job = new PhpJob(
124+
'the-code',
125+
[],
126+
[],
127+
[],
128+
null,
129+
false,
130+
);
131+
132+
$this->assertFalse($job->hasInput());
133+
134+
$this->expectException(PhpProcessException::class);
135+
136+
$job->input();
137+
}
138+
139+
public function testMayRedirectErrors(): void
140+
{
141+
$job = new PhpJob(
142+
'the-code',
143+
[],
144+
[],
145+
[],
146+
null,
147+
true,
148+
);
149+
150+
$this->assertTrue($job->redirectErrors());
151+
}
152+
}

0 commit comments

Comments
 (0)