Passed
Push — bugfix/allow-gacela-anon-class... ( 98e2e1 )
by Chema
09:04
created

FeatureTest.php$0 ➔ createDomainService()   A

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
dl 0
loc 4
rs 10
c 1
b 0
f 0
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
final class FeatureTest extends TestCase
14
{
15
    public function setUp(): void
16
    {
17
        Gacela::bootstrap(__DIR__, GacelaConfig::withDefaults());
18
    }
19
20
    public function test_override_existing_resolved_class_when_config_method_is_called(): void
21
    {
22
        AnonymousGlobal::overrideExistingResolvedClass(
23
            '\module-name@anonymous\FeatureTest\Config',
24
            new Module\Config()
25
        );
26
27
        AnonymousGlobal::overrideExistingResolvedClass(
28
            Module\Factory::class,
29
            new class() extends Module\Factory {
30
                public function createDomainService(): StringValue
31
                {
32
                    $this->getConfigValue();
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