Passed
Push — rename-plugins-to-after-plugin... ( ebb4f8 )
by Chema
03:39
created

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 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 13
rs 10
c 0
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 AfterFeatureTest 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->addAfterPlugin(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->addAfterPlugin(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->addAfterPlugins([
44
                ExamplePluginWithConstructor::class,
45
                ExamplePluginWithoutConstructor::class,
46
            ]);
47
        });
48
49
        /** @var StringValue $singleton */
50
        $singleton = Gacela::get(StringValue::class);
51
52
        self::assertSame('Set from plugin ExamplePluginWithoutConstructor', $singleton->value());
53
    }
54
}
55