Passed
Push — master ( b31bae...4a6c69 )
by Jesús
01:27 queued 13s
created

ConfigTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
eloc 12
c 2
b 0
f 0
dl 0
loc 33
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A test_get_default_value_from_undefined_key() 0 3 1
A test_get_undefined_key() 0 4 1
A setUp() 0 4 1
A test_null_as_default_value_from_undefined_key() 0 3 1
A test_normalize_app_root_dir() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GacelaTest\Integration\Framework\Config;
6
7
use Gacela\Framework\Bootstrap\GacelaConfig;
8
use Gacela\Framework\Config\Config;
9
use Gacela\Framework\Gacela;
10
use PHPUnit\Framework\TestCase;
11
12
final class ConfigTest extends TestCase
13
{
14
    public function setUp(): void
15
    {
16
        Gacela::bootstrap(__DIR__, static function (GacelaConfig $config): void {
17
            $config->setCacheEnabled(false);
18
        });
19
    }
20
21
    public function test_get_undefined_key(): void
22
    {
23
        $this->expectExceptionMessageMatches('/Could not find config key "undefined-key"/');
24
        Config::getInstance()->get('undefined-key');
25
    }
26
27
    public function test_get_default_value_from_undefined_key(): void
28
    {
29
        self::assertSame('default', Config::getInstance()->get('undefined-key', 'default'));
30
    }
31
32
    public function test_null_as_default_value_from_undefined_key(): void
33
    {
34
        self::assertNull(Config::getInstance()->get('undefined-key', null));
35
    }
36
37
    public function test_normalize_app_root_dir(): void
38
    {
39
        $config = Config::getInstance();
40
        $config->setAppRootDir('/directory1');
41
        self::assertSame('/directory1', $config->getAppRootDir());
42
43
        $config->setAppRootDir('/directory2/');
44
        self::assertSame('/directory2', $config->getAppRootDir());
45
    }
46
}
47