Passed
Push — attributes ( d4959e...6cfdd6 )
by Peter
03:00
created

EnvironmentTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 43
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testMustGetVarThrowsExceptionIfEnvironmentVariableAndDefaultAreMissing() 0 5 1
A testUnset() 0 10 1
A testMustGetVarGetsDefaultIfEnvironmentVariableIsMissing() 0 5 1
A testMustGetVarGetsEnvironmentVariableValueByDefault() 0 8 1
A tearDown() 0 3 1
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