Passed
Push — feature/remove-config-default-... ( a334bc )
by Chema
09:13
created

ConfigBuilderTest::test_empty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GacelaTest\Unit\Framework\Config\GacelaConfigBuilder;
6
7
use Gacela\Framework\Config\ConfigReaderInterface;
8
use Gacela\Framework\Config\GacelaConfigBuilder\ConfigBuilder;
9
use Gacela\Framework\Config\GacelaFileConfig\GacelaConfigItem;
10
use GacelaTest\Fixtures\SimpleEnvConfigReader;
11
use PHPUnit\Framework\TestCase;
12
13
final class ConfigBuilderTest extends TestCase
14
{
15
    public function test_empty(): void
16
    {
17
        $builder = new ConfigBuilder();
18
19
        self::assertEquals([], $builder->build());
20
    }
21
22
    public function test_custom_path(): void
23
    {
24
        $builder = new ConfigBuilder();
25
        $builder->add('custom/*.php');
26
27
        self::assertEquals(
28
            [new GacelaConfigItem('custom/*.php', '')],
29
            $builder->build()
30
        );
31
    }
32
33
    public function test_custom_path_local(): void
34
    {
35
        $builder = new ConfigBuilder();
36
        $builder->add('', 'custom/local.php');
37
38
        self::assertEquals(
39
            [new GacelaConfigItem('', 'custom/local.php')],
40
            $builder->build()
41
        );
42
    }
43
44
    public function test_custom_reader(): void
45
    {
46
        $reader = new class() implements ConfigReaderInterface {
47
            public function read(string $absolutePath): array
48
            {
49
                return ['key' => 'value'];
50
            }
51
        };
52
53
        $builder = new ConfigBuilder();
54
        $builder->add('custom/*.php', 'custom/local.php', $reader);
55
56
        self::assertEquals(
57
            [new GacelaConfigItem('custom/*.php', 'custom/local.php', $reader)],
58
            $builder->build()
59
        );
60
    }
61
62
    public function test_custom_reader_by_class_name(): void
63
    {
64
        $builder = new ConfigBuilder();
65
        $builder->add('custom/*.php', 'custom/local.php', SimpleEnvConfigReader::class);
66
67
        self::assertEquals(
68
            [new GacelaConfigItem('custom/*.php', 'custom/local.php', new SimpleEnvConfigReader())],
69
            $builder->build()
70
        );
71
    }
72
}
73