1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace AbterPhp\Framework\Environments; |
6
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
|
9
|
|
|
class EnvironmentTest extends TestCase |
10
|
|
|
{ |
11
|
|
|
private const KEY = "FOOBAR001"; |
12
|
|
|
|
13
|
|
|
public function tearDown(): void |
14
|
|
|
{ |
15
|
|
|
Environment::unsetVar(static::KEY); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
public function testUnset(): void |
19
|
|
|
{ |
20
|
|
|
$value = static::KEY; |
21
|
|
|
|
22
|
|
|
Environment::setVar(static::KEY, $value); |
23
|
|
|
$this->assertEquals($value, Environment::getVar(static::KEY)); |
24
|
|
|
|
25
|
|
|
Environment::unsetVar(static::KEY); |
26
|
|
|
|
27
|
|
|
$this->assertNull(Environment::getVar(static::KEY)); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testMustGetVarGetsDefaultIfEnvironmentVariableIsMissing(): void |
31
|
|
|
{ |
32
|
|
|
$value = static::KEY; |
33
|
|
|
|
34
|
|
|
$this->assertEquals($value, Environment::mustGetVar(static::KEY, $value)); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function testMustGetVarGetsEnvironmentVariableValueByDefault(): void |
38
|
|
|
{ |
39
|
|
|
$value = static::KEY; |
40
|
|
|
$wrong = "BARBAZ002"; |
41
|
|
|
|
42
|
|
|
Environment::setVar(static::KEY, $value); |
43
|
|
|
|
44
|
|
|
$this->assertEquals($value, Environment::mustGetVar(static::KEY, $wrong)); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testMustGetVarThrowsExceptionIfEnvironmentVariableAndDefaultAreMissing(): void |
48
|
|
|
{ |
49
|
|
|
$this->expectException(\RuntimeException::class); |
50
|
|
|
|
51
|
|
|
Environment::mustGetVar(static::KEY); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testIsStagingIsFalse(): void |
55
|
|
|
{ |
56
|
|
|
|
57
|
|
|
$this->assertFalse(Environment::isStaging()); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function testIsTestingIsTrue(): void |
61
|
|
|
{ |
62
|
|
|
|
63
|
|
|
$this->assertTrue(Environment::isTesting()); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function testIsDevelopmentIsFalse(): void |
67
|
|
|
{ |
68
|
|
|
|
69
|
|
|
$this->assertFalse(Environment::isDevelopment()); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function testIsProductionIsFalse(): void |
73
|
|
|
{ |
74
|
|
|
|
75
|
|
|
$this->assertFalse(Environment::isProduction()); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|