Passed
Push — feat/gacela-add-global ( e9b838...6f717f )
by Chema
03:44
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\OverrideExistingResolvedClass;
6
7
use Gacela\Framework\Bootstrap\GacelaConfig;
8
use Gacela\Framework\Gacela;
9
use GacelaTest\Fixtures\StringValue;
10
use PHPUnit\Framework\TestCase;
11
12
use function assert;
13
14
final class FeatureTest extends TestCase
15
{
16
    protected function setUp(): void
17
    {
18
        Gacela::bootstrap(__DIR__, static function (GacelaConfig $config): void {
19
            $config->resetInMemoryCache();
20
            $config->addAppConfig('config/*.php');
21
        });
22
    }
23
24
    public function test_override_factory_as_anonymous_global(): void
25
    {
26
        Gacela::overrideExistingResolvedClass(
27
            Module\Factory::class,
28
            new class() extends Module\Factory {
29
                public function createDomainService(): StringValue
30
                {
31
                    assert($this->getConfigValue() === 'value');
32
                    return new StringValue('other');
33
                }
34
            },
35
        );
36
37
        $facade = new Module\Facade();
38
        $result = $facade->getSomething();
39
40
        self::assertSame('other', $result);
41
    }
42
43
    public function test_override_config_as_anonymous_global(): void
44
    {
45
        Gacela::overrideExistingResolvedClass(
46
            Module\Config::class,
47
            new class() extends Module\Config {
48
                public function getValue(): string
49
                {
50
                    return 'other';
51
                }
52
            },
53
        );
54
55
        $facade = new Module\Facade();
56
        $result = $facade->getSomething();
57
58
        self::assertSame('other', $result);
59
    }
60
}
61