Passed
Push — master ( e045e9...e425e2 )
by Chema
02:48
created

ConfigTest::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GacelaTest\Unit\Framework;
6
7
use Gacela\Framework\Config;
8
use Gacela\Framework\Config\ConfigReaderInterface;
9
use PHPUnit\Framework\TestCase;
10
11
final class ConfigTest extends TestCase
12
{
13
    private Config $config;
14
15
    public function setUp(): void
16
    {
17
        Config::resetInstance();
18
        $this->config = Config::getInstance();
19
    }
20
21
    public function tearDown(): void
22
    {
23
        Config::resetInstance();
24
    }
25
26
    public function test_get_undefined_key(): void
27
    {
28
        $this->expectExceptionMessageMatches('/Could not find config key "key"/');
29
        $this->config->get('key');
30
    }
31
32
    public function test_get_default_value_from_undefined_key(): void
33
    {
34
        self::assertSame('default', $this->config->get('key', 'default'));
35
    }
36
37
    public function test_get_using_custom_reader(): void
38
    {
39
        $this->config->setConfigReaders([
40
            Config\GacelaJsonConfigItem::DEFAULT_TYPE => new class() implements ConfigReaderInterface {
41
                public function read(string $absolutePath): array
42
                {
43
                    return ['key' => 'value'];
44
                }
45
46
                public function canRead(string $absolutePath): bool
47
                {
48
                    return true;
49
                }
50
            },
51
        ]);
52
53
        $this->config->init();
54
55
        self::assertSame('value', $this->config->get('key'));
56
    }
57
}
58