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