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
|
|
|
|