|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace GacelaTest\Unit\Framework\Config\GacelaFileConfig\Factory; |
|
6
|
|
|
|
|
7
|
|
|
use Gacela\Framework\Bootstrap\SetupGacela; |
|
8
|
|
|
use Gacela\Framework\Config\ConfigReader\PhpConfigReader; |
|
9
|
|
|
use Gacela\Framework\Config\GacelaConfigBuilder\AppConfigBuilder; |
|
10
|
|
|
use Gacela\Framework\Config\GacelaConfigBuilder\BindingsBuilder; |
|
11
|
|
|
use Gacela\Framework\Config\GacelaConfigBuilder\SuffixTypesBuilder; |
|
12
|
|
|
use Gacela\Framework\Config\GacelaFileConfig\Factory\GacelaConfigFromBootstrapFactory; |
|
13
|
|
|
use Gacela\Framework\Config\GacelaFileConfig\GacelaConfigFile; |
|
14
|
|
|
use Gacela\Framework\Config\GacelaFileConfig\GacelaConfigItem; |
|
15
|
|
|
use GacelaTest\Fixtures\CustomClass; |
|
16
|
|
|
use GacelaTest\Fixtures\CustomInterface; |
|
17
|
|
|
use PHPUnit\Framework\TestCase; |
|
18
|
|
|
|
|
19
|
|
|
final class GacelaConfigFromBootstrapFactoryTest extends TestCase |
|
20
|
|
|
{ |
|
21
|
|
|
public function test_no_global_services_then_default(): void |
|
22
|
|
|
{ |
|
23
|
|
|
$factory = new GacelaConfigFromBootstrapFactory(new SetupGacela()); |
|
24
|
|
|
|
|
25
|
|
|
self::assertEquals(new GacelaConfigFile(), $factory->createGacelaFileConfig()); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function test_no_special_global_services_then_default(): void |
|
29
|
|
|
{ |
|
30
|
|
|
$setupGacela = (new SetupGacela())->setExternalServices([ |
|
31
|
|
|
'randomKey' => static fn (): string => 'randomValue', |
|
32
|
|
|
]); |
|
33
|
|
|
|
|
34
|
|
|
$factory = new GacelaConfigFromBootstrapFactory($setupGacela); |
|
35
|
|
|
|
|
36
|
|
|
self::assertEquals(new GacelaConfigFile(), $factory->createGacelaFileConfig()); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function test_global_service_config(): void |
|
40
|
|
|
{ |
|
41
|
|
|
$factory = new GacelaConfigFromBootstrapFactory( |
|
42
|
|
|
(new SetupGacela())->setAppConfigFn( |
|
43
|
|
|
static function (AppConfigBuilder $configBuilder): void { |
|
44
|
|
|
$configBuilder->add('custom-path.php', 'custom-path_local.php'); |
|
45
|
|
|
}, |
|
46
|
|
|
), |
|
47
|
|
|
); |
|
48
|
|
|
|
|
49
|
|
|
$expected = (new GacelaConfigFile()) |
|
50
|
|
|
->setConfigItems([new GacelaConfigItem('custom-path.php', 'custom-path_local.php', new PhpConfigReader())]); |
|
51
|
|
|
|
|
52
|
|
|
self::assertEquals($expected, $factory->createGacelaFileConfig()); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function test_global_service_mapping_interfaces_with_global_services(): void |
|
56
|
|
|
{ |
|
57
|
|
|
$factory = new GacelaConfigFromBootstrapFactory( |
|
58
|
|
|
(new SetupGacela()) |
|
59
|
|
|
->setExternalServices(['externalServiceKey' => static fn (): string => 'externalServiceValue']) |
|
60
|
|
|
->setBindingsFn(static function ( |
|
61
|
|
|
BindingsBuilder $interfacesBuilder, |
|
62
|
|
|
array $externalServices, |
|
63
|
|
|
): void { |
|
64
|
|
|
self::assertSame('externalServiceValue', $externalServices['externalServiceKey']->__invoke()); |
|
65
|
|
|
$interfacesBuilder->bind(CustomInterface::class, CustomClass::class); |
|
66
|
|
|
}), |
|
67
|
|
|
); |
|
68
|
|
|
|
|
69
|
|
|
$expected = (new GacelaConfigFile()) |
|
70
|
|
|
->setBindings([CustomInterface::class => CustomClass::class]); |
|
71
|
|
|
|
|
72
|
|
|
self::assertEquals($expected, $factory->createGacelaFileConfig()); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function test_global_service_suffix_types(): void |
|
76
|
|
|
{ |
|
77
|
|
|
$factory = new GacelaConfigFromBootstrapFactory( |
|
78
|
|
|
(new SetupGacela()) |
|
79
|
|
|
->setSuffixTypesFn( |
|
80
|
|
|
static function (SuffixTypesBuilder $suffixTypesBuilder): void { |
|
81
|
|
|
$suffixTypesBuilder->addProvider('DPCustom'); |
|
82
|
|
|
}, |
|
83
|
|
|
), |
|
84
|
|
|
); |
|
85
|
|
|
|
|
86
|
|
|
$expected = (new GacelaConfigFile()) |
|
87
|
|
|
->setSuffixTypes([ |
|
88
|
|
|
'Provider' => ['Provider', 'DPCustom'], |
|
89
|
|
|
'Factory' => ['Factory'], |
|
90
|
|
|
'Config' => ['Config'], |
|
91
|
|
|
'Facade' => ['Facade'], |
|
92
|
|
|
]); |
|
93
|
|
|
|
|
94
|
|
|
self::assertEquals($expected, $factory->createGacelaFileConfig()); |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|