Passed
Push — attributes ( b566ac...704868 )
by Peter
03:02
created

ConfigTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 29
rs 10
c 1
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testMustGetThrowsExceptionIfEnvironmentVariableAndDefaultAreMissing() 0 7 1
A testMustGetGetsEnvironmentVariableValueByDefault() 0 8 1
A testMustGetGetsDefaultIfEnvironmentVariableIsMissing() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Framework\Config;
6
7
use PHPUnit\Framework\TestCase;
8
9
class ConfigTest extends TestCase
10
{
11
    private const CATEGORY = "FOO";
12
    private const SETTING  = "BAR01";
13
14
    public function testMustGetGetsDefaultIfEnvironmentVariableIsMissing(): void
15
    {
16
        $value = 17;
17
18
        $this->assertEquals($value, Config::mustGet(static::CATEGORY, static::SETTING, $value));
19
    }
20
21
    public function testMustGetGetsEnvironmentVariableValueByDefault(): void
22
    {
23
        $value = 17;
24
        $wrong = "BARBAZ002";
25
26
        Config::set(static::CATEGORY, static::SETTING, $value);
27
28
        $this->assertEquals($value, Config::mustGet(static::CATEGORY, static::SETTING, $wrong));
29
    }
30
31
    public function testMustGetThrowsExceptionIfEnvironmentVariableAndDefaultAreMissing(): void
32
    {
33
        Config::set(static::CATEGORY, static::SETTING, null);
34
35
        $this->expectException(\RuntimeException::class);
36
37
        Config::mustGet(static::CATEGORY, static::SETTING);
38
    }
39
}
40