Passed
Push — main ( 56d495...a6c8e7 )
by Chema
11:12
created

php$0 ➔ test_override_factory_as_anonymous_global()   A

Complexity

Conditions 1

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 17
rs 9.7
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A FeatureTest.php$0 ➔ createDomainService() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GacelaTest\Feature\Framework\AnonymousGlobalExtendsExistingClass;
6
7
use Gacela\Framework\Bootstrap\GacelaConfig;
8
use Gacela\Framework\ClassResolver\GlobalInstance\AnonymousGlobal;
9
use Gacela\Framework\Gacela;
10
use GacelaTest\Fixtures\StringValue;
11
use PHPUnit\Framework\TestCase;
12
13
use function assert;
14
15
final class FeatureTest extends TestCase
16
{
17
    public function setUp(): void
18
    {
19
        Gacela::bootstrap(__DIR__, static function (GacelaConfig $config): void {
20
            $config->resetInMemoryCache();
21
            $config->addAppConfig('config/*.php');
22
        });
23
    }
24
25
    public function test_override_factory_as_anonymous_global(): void
26
    {
27
        AnonymousGlobal::overrideExistingResolvedClass(
28
            Module\Factory::class,
29
            new class() extends Module\Factory {
30
                public function createDomainService(): StringValue
31
                {
32
                    assert($this->getConfigValue() === 'value');
33
                    return new StringValue('other');
34
                }
35
            },
36
        );
37
38
        $facade = new Module\Facade();
39
        $result = $facade->getSomething();
40
41
        self::assertSame('other', $result);
42
    }
43
44
    public function test_override_config_as_anonymous_global(): void
45
    {
46
        AnonymousGlobal::overrideExistingResolvedClass(
47
            Module\Config::class,
48
            new class() extends Module\Config {
49
                public function getValue(): string
50
                {
51
                    return 'other';
52
                }
53
            },
54
        );
55
56
        $facade = new Module\Facade();
57
        $result = $facade->getSomething();
58
59
        self::assertSame('other', $result);
60
    }
61
}
62