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

FeatureTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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