Passed
Push — feature/refactor-code-generato... ( 368fc0 )
by Chema
04:13
created

ConfigTest::test_normalize_app_root_dir()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 8
rs 10
cc 1
nc 1
nop 0
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