Passed
Push — master ( fa1416...da5f2f )
by Jesús
04:02 queued 12s
created

ConfigTest::test_get_using_custom_reader()

Size

Total Lines 19
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
c 0
b 0
f 0
dl 0
loc 19
nc 1
nop 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A ConfigTest.php$0 ➔ canRead() 0 3 1
A ConfigTest.php$0 ➔ read() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GacelaTest\Integration\Framework\Config;
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
    protected function setUp(): void
14
    {
15
        Config::resetInstance();
16
    }
17
18
    public function test_get_undefined_key(): void
19
    {
20
        $this->expectExceptionMessageMatches('/Could not find config key "undefined-key"/');
21
        Config::getInstance()->get('undefined-key');
22
    }
23
24
    public function test_get_default_value_from_undefined_key(): void
25
    {
26
        self::assertSame('default', Config::getInstance()->get('undefined-key', 'default'));
27
    }
28
29
    public function test_null_as_default_value_from_undefined_key(): void
30
    {
31
        self::assertNull(Config::getInstance()->get('undefined-key', null));
32
    }
33
34
    public function test_get_using_custom_reader(): void
35
    {
36
        Config::getInstance()->setGlobalServices([
37
            'config-readers' => [
38
                Config\GacelaFileConfig\GacelaConfigItem::DEFAULT_TYPE => new class () implements ConfigReaderInterface {
39
                    public function read(string $absolutePath): array
40
                    {
41
                        return ['key' => 'value'];
42
                    }
43
44
                    public function canRead(string $absolutePath): bool
45
                    {
46
                        return true;
47
                    }
48
                },
49
            ],
50
        ]);
51
52
        self::assertSame('value', Config::getInstance()->get('key'));
53
    }
54
}
55