Skip to content

Commit 7ff2e54

Browse files
committed
Test fallback to sys_get_temp_dir()
1 parent 89a3ba5 commit 7ff2e54

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

src/test/php/com/amazon/aws/lambda/unittest/EnvironmentTest.class.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,24 @@
55
use io\{Path, File, Files};
66
use lang\ElementNotFoundException;
77
use lang\Environment as System;
8-
use unittest\{Assert, Test};
8+
use unittest\{Assert, After, Before, Test};
99
use util\Properties;
1010

1111
class EnvironmentTest {
12+
private $temp= [];
13+
14+
#[Before]
15+
public function cleanTemp() {
16+
foreach (['TEMP', 'TMP', 'TMPDIR', 'TEMPDIR'] as $variable) {
17+
$this->temp[$variable]= $_ENV[$variable] ?? null;
18+
unset($_ENV[$variable]);
19+
}
20+
}
21+
22+
#[After]
23+
public function restoreTemp() {
24+
$_ENV += $this->temp;
25+
}
1226

1327
#[Test]
1428
public function can_create() {
@@ -26,8 +40,15 @@ public function path() {
2640
}
2741

2842
#[Test]
29-
public function tempDir() {
30-
Assert::instance(Path::class, (new Environment('.'))->tempDir());
43+
public function tempDir_prefers_using_environment() {
44+
$_ENV['TEMP']= 'tmp';
45+
Assert::equals(new Path('tmp'), (new Environment('.'))->tempDir());
46+
}
47+
48+
#[Test]
49+
public function tempDir_falls_back_to_sys_get_temp_dir() {
50+
unset($_ENV['TEMP']);
51+
Assert::equals(new Path(sys_get_temp_dir()), (new Environment('.'))->tempDir());
3152
}
3253

3354
#[Test]

0 commit comments

Comments
 (0)