Passed
Pull Request — master (#179)
by Chema
06:30 queued 03:13
created

FeatureTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 8
rs 10
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 DependencyProvider.
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
    public function setUp(): void
23
    {
24
        Gacela::bootstrap(__DIR__, static function (GacelaConfig $config): void {
25
            $config->addAppConfig('config/default.php');
26
27
            $config->setProjectNamespaces([
28
                'GacelaTest\Feature\Framework\ResolveDifferentProjectNamespaces\src\Main',
29
                'GacelaTest\Feature\Framework\ResolveDifferentProjectNamespaces\src\Secondary',
30
            ]);
31
        });
32
    }
33
34
    public function test_override_factory_from_highest_prio_namespace(): void
35
    {
36
        $facade = new ThirdPartyModuleAFacade();
37
38
        self::assertSame('Overridden, from src\CompanyA\ModuleA::StringA', $facade->stringValueA1());
39
    }
40
41
    public function test_non_overridden_factory_method_from_vendor(): void
42
    {
43
        $facade = new ThirdPartyModuleAFacade();
44
45
        self::assertSame('Hi, from vendor\ThirdParty\ModuleA::StringA2', $facade->stringValueA2());
46
    }
47
48
    public function test_override_factory_from_second_highest_prio_namespace(): void
49
    {
50
        $facade = new ThirdPartyModuleBFacade();
51
52
        self::assertSame('Overridden, from src\CompanyB\ModuleB', $facade->stringValueB1());
53
    }
54
}
55