Passed
Push — master ( a4cb77...4b52d2 )
by Stanislau
01:29 queued 13s
created

KernelTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 9
eloc 39
c 2
b 0
f 0
dl 0
loc 81
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 29 3
A testContainer() 0 3 1
A testRunAgain() 0 22 1
A testExceptionWhenTryBootloaderInstallAfterKernelRun() 0 4 1
A testKernelPlugins() 0 8 3
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 *  This file is part of the Micro framework package.
7
 *
8
 *  (c) Stanislau Komar <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace Micro\Framework\Kernel\Test\Unit;
15
16
use Micro\Component\DependencyInjection\Container;
17
use Micro\Framework\Kernel\Kernel;
18
use Micro\Framework\Kernel\KernelInterface;
19
use Micro\Framework\Kernel\Plugin\PluginBootLoaderInterface;
20
use PHPUnit\Framework\TestCase;
21
22
class KernelTest extends TestCase
23
{
24
    private KernelInterface $kernel;
25
26
    private Container $container;
27
28
    protected function setUp(): void
29
    {
30
        $plugins = [];
31
        for ($i = 0; $i < 3; ++$i) {
32
            $plugins[] = \stdClass::class;
33
        }
34
35
        $bootLoaders = [];
36
        for ($i = 0; $i < 3; ++$i) {
37
            $bootLoader = $this->createMock(PluginBootLoaderInterface::class);
38
            $bootLoader
39
                ->expects($this->any())
40
                ->method('boot');
41
42
            $bootLoaders[] = $bootLoader;
43
        }
44
45
        $this->container = new Container();
46
47
        $this->kernel = new Kernel(
48
            $plugins,
49
            [],
50
            $this->container,
51
        );
52
53
        $this->kernel->setBootLoaders($bootLoaders);
54
        $this->kernel->addBootLoader($this->createMock(PluginBootLoaderInterface::class));
55
56
        $this->kernel->run();
57
    }
58
59
    public function testExceptionWhenTryBootloaderInstallAfterKernelRun()
60
    {
61
        $this->expectException(\LogicException::class);
62
        $this->kernel->addBootLoader($this->createMock(PluginBootLoaderInterface::class));
63
    }
64
65
    public function testKernelPlugins()
66
    {
67
        foreach ($this->kernel->plugins(\stdClass::class) as $plugin) {
68
            $this->assertInstanceOf(\stdClass::class, $plugin);
69
        }
70
71
        foreach ($this->kernel->plugins() as $plugin) {
72
            $this->assertInstanceOf(\stdClass::class, $plugin);
73
        }
74
    }
75
76
    public function testRunAgain()
77
    {
78
        $kernel = $this->getMockBuilder(Kernel::class)
79
            ->enableOriginalConstructor()
80
            ->setConstructorArgs(
81
                [
82
                    [],
83
                    [],
84
                    new Container(),
85
                ]
86
            )
87
            ->onlyMethods([
88
                'loadPlugins',
89
            ])
90
        ->getMock();
91
92
        $kernel
93
            ->expects($this->once())
94
            ->method('loadPlugins');
95
96
        $kernel->run();
97
        $kernel->run();
98
    }
99
100
    public function testContainer()
101
    {
102
        $this->assertEquals($this->container, $this->kernel->container());
103
    }
104
}
105