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

AfterFeatureTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A test_singleton_altered_via_plugin_with_constructor() 0 10 1
A test_singleton_altered_via_plugin_without_constructor() 0 10 1
A test_multiple_plugins_latest_win() 0 13 1
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