1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace GacelaTest\Feature\Framework\ResolveDifferentProjectNamespaces; |
6
|
|
|
|
7
|
|
|
use Gacela\Framework\Bootstrap\GacelaConfig; |
8
|
|
|
use Gacela\Framework\Gacela; |
9
|
|
|
use GacelaTest\Feature\Framework\ResolveDifferentProjectNamespaces\vendor\ThirdParty\ModuleA\Facade as ThirdPartyModuleAFacade; |
10
|
|
|
use GacelaTest\Feature\Framework\ResolveDifferentProjectNamespaces\vendor\ThirdParty\ModuleB\Facade as ThirdPartyModuleBFacade; |
11
|
|
|
use PHPUnit\Framework\TestCase; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* ProjectNamespaces is a list of namespaces sort by prio to resolve the Facade, Factory, Config or AbstractProvider. |
15
|
|
|
* |
16
|
|
|
* In this example, we are using the Facade from a third-party vendor's module (`vendor\ThirdParty\ModuleA\Facade`), |
17
|
|
|
* and when that Facade uses its Factory, gacela will resolve it from our `src\Main` namespace, because we have the same |
18
|
|
|
* module structure as that ThirdParty, and we have defined the `src\Main` as first thing in the GacelaConfig::setProjectNamespaces(). |
19
|
|
|
*/ |
20
|
|
|
final class FeatureTest extends TestCase |
21
|
|
|
{ |
22
|
|
|
protected function setUp(): void |
23
|
|
|
{ |
24
|
|
|
Gacela::bootstrap(__DIR__, static function (GacelaConfig $config): void { |
25
|
|
|
$config->resetInMemoryCache(); |
26
|
|
|
$config->setFileCache(false); |
27
|
|
|
|
28
|
|
|
$config->setProjectNamespaces([ |
29
|
|
|
'GacelaTest\Feature\Framework\ResolveDifferentProjectNamespaces\src\Main', |
30
|
|
|
'GacelaTest\Feature\Framework\ResolveDifferentProjectNamespaces\src\Secondary', |
31
|
|
|
]); |
32
|
|
|
}); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function test_override_factory_from_highest_prio_namespace(): void |
36
|
|
|
{ |
37
|
|
|
$facade = new ThirdPartyModuleAFacade(); |
38
|
|
|
|
39
|
|
|
self::assertSame('Overridden, from src\CompanyA\ModuleA::StringA', $facade->stringValueA1()); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function test_non_overridden_factory_method_from_vendor(): void |
43
|
|
|
{ |
44
|
|
|
$facade = new ThirdPartyModuleAFacade(); |
45
|
|
|
|
46
|
|
|
self::assertSame('Hi, from vendor\ThirdParty\ModuleA::StringA2', $facade->stringValueA2()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function test_override_factory_from_second_highest_prio_namespace(): void |
50
|
|
|
{ |
51
|
|
|
$facade = new ThirdPartyModuleBFacade(); |
52
|
|
|
|
53
|
|
|
self::assertSame('Overridden, from src\CompanyB\ModuleB', $facade->stringValueB1()); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|