Passed
Push — rename-prePlugins-to-plugins ( 9e4707...211e7b )
by Chema
04:27 queued 01:13
created

FeatureTest::test_multiple_plugins_latest_win()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 13
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GacelaTest\Feature\Framework\Plugins;
6
7
use Gacela\Framework\Bootstrap\GacelaConfig;
8
use Gacela\Framework\Gacela;
9
use GacelaTest\Feature\Framework\Plugins\Module\Infrastructure\ExamplePluginWithConstructor;
10
use GacelaTest\Feature\Framework\Plugins\Module\Infrastructure\ExamplePluginWithoutConstructor;
11
use GacelaTest\Fixtures\StringValue;
12
use PHPUnit\Framework\TestCase;
13
14
final class FeatureTest extends TestCase
15
{
16
    public function test_singleton_altered_via_plugin_with_constructor(): void
17
    {
18
        Gacela::bootstrap(__DIR__, static function (GacelaConfig $config): void {
19
            $config->addPlugin(ExamplePluginWithConstructor::class);
20
        });
21
22
        /** @var StringValue $singleton */
23
        $singleton = Gacela::get(StringValue::class);
24
25
        self::assertSame('Set from plugin ExamplePluginWithConstructor', $singleton->value());
26
    }
27
28
    public function test_singleton_altered_via_plugin_without_constructor(): void
29
    {
30
        Gacela::bootstrap(__DIR__, static function (GacelaConfig $config): void {
31
            $config->addPlugin(ExamplePluginWithoutConstructor::class);
32
        });
33
34
        /** @var StringValue $singleton */
35
        $singleton = Gacela::get(StringValue::class);
36
37
        self::assertSame('Set from plugin ExamplePluginWithoutConstructor', $singleton->value());
38
    }
39
40
    public function test_multiple_plugins_latest_win(): void
41
    {
42
        Gacela::bootstrap(__DIR__, static function (GacelaConfig $config): void {
43
            $config->addPlugins([
44
                ExamplePluginWithoutConstructor::class,
45
                ExamplePluginWithConstructor::class,
46
            ]);
47
        });
48
49
        /** @var StringValue $singleton */
50
        $singleton = Gacela::get(StringValue::class);
51
52
        self::assertSame('Set from plugin ExamplePluginWithConstructor', $singleton->value());
53
    }
54
}
55