test_load_config_from_custom_env_prod()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 15
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GacelaTest\Feature\Framework\UsingConfigFromCustomEnv;
6
7
use Gacela\Framework\Bootstrap\GacelaConfig;
8
use Gacela\Framework\Gacela;
9
use PHPUnit\Framework\TestCase;
10
11
final class FeatureTest extends TestCase
12
{
13
    protected function tearDown(): void
14
    {
15
        # Remove the APP_ENV
16
        putenv('APP_ENV');
17
    }
18
19
    public function test_load_config_from_custom_env_default(): void
20
    {
21
        $this->bootstrapGacela();
22
23
        $facade = new LocalConfig\Facade();
24
25
        self::assertSame(
26
            [
27
                'from-default' => 1,
28
                'from-default-env-override' => 1,
29
                'from-local-override' => 4,
30
            ],
31
            $facade->doSomething(),
32
        );
33
    }
34
35
    public function test_load_config_from_custom_env_dev(): void
36
    {
37
        putenv('APP_ENV=dev');
38
39
        $this->bootstrapGacela();
40
41
        $facade = new LocalConfig\Facade();
42
43
        self::assertSame(
44
            [
45
                'from-default' => 1,
46
                'from-default-env-override' => 2,
47
                'from-local-override' => 4,
48
            ],
49
            $facade->doSomething(),
50
        );
51
    }
52
53
    public function test_load_config_from_custom_env_prod(): void
54
    {
55
        putenv('APP_ENV=prod');
56
57
        $this->bootstrapGacela();
58
59
        $facade = new LocalConfig\Facade();
60
61
        self::assertSame(
62
            [
63
                'from-default' => 1,
64
                'from-default-env-override' => 3,
65
                'from-local-override' => 4,
66
            ],
67
            $facade->doSomething(),
68
        );
69
    }
70
71
    private function bootstrapGacela(): void
72
    {
73
        Gacela::bootstrap(__DIR__, static function (GacelaConfig $config): void {
74
            $config->resetInMemoryCache();
75
            $config->addAppConfig('config/*.php', 'config/local.php');
76
        });
77
    }
78
}
79