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\AppModeEnum; |
18
|
|
|
use Micro\Framework\Kernel\Kernel; |
19
|
|
|
use Micro\Framework\Kernel\KernelInterface; |
20
|
|
|
use Micro\Framework\Kernel\Plugin\PluginBootLoaderInterface; |
21
|
|
|
use PHPUnit\Framework\TestCase; |
22
|
|
|
|
23
|
|
|
require_once __DIR__.'/PluginClasses.php'; |
24
|
|
|
|
25
|
|
|
class KernelTest extends TestCase |
26
|
|
|
{ |
27
|
|
|
private KernelInterface $kernel; |
28
|
|
|
|
29
|
|
|
private Container $container; |
|
|
|
|
30
|
|
|
|
31
|
|
|
protected function setUp(): void |
32
|
|
|
{ |
33
|
|
|
$plugins = [ |
34
|
|
|
\PluginClassHasDependencies::class, |
35
|
|
|
\PluginClassDefault::class, |
36
|
|
|
]; |
37
|
|
|
|
38
|
|
|
$bootLoaders = []; |
39
|
|
|
for ($i = 0; $i < 3; ++$i) { |
40
|
|
|
$bootLoader = $this->createMock(PluginBootLoaderInterface::class); |
41
|
|
|
$bootLoader |
42
|
|
|
->expects($this->any()) |
43
|
|
|
->method('boot'); |
44
|
|
|
|
45
|
|
|
$bootLoaders[] = $bootLoader; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
$this->kernel = new Kernel( |
49
|
|
|
$plugins, |
50
|
|
|
[], |
51
|
|
|
AppModeEnum::TEST, |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
$this->kernel->setBootLoaders($bootLoaders); |
55
|
|
|
$this->kernel->addBootLoader($this->createMock(PluginBootLoaderInterface::class)); |
56
|
|
|
|
57
|
|
|
$this->kernel->run(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function testExceptionWhenTryBootloaderInstallAfterKernelRun() |
61
|
|
|
{ |
62
|
|
|
$this->expectException(\LogicException::class); |
63
|
|
|
$this->kernel->addBootLoader($this->createMock(PluginBootLoaderInterface::class)); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function testKernelPlugins() |
67
|
|
|
{ |
68
|
|
|
foreach ($this->kernel->plugins(\PluginClassDefault::class) as $plugin) { |
69
|
|
|
$this->assertInstanceOf(\PluginClassDefault::class, $plugin); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function testRunAgain() |
74
|
|
|
{ |
75
|
|
|
$kernel = $this->getMockBuilder(Kernel::class) |
76
|
|
|
->enableOriginalConstructor() |
77
|
|
|
->setConstructorArgs( |
78
|
|
|
[ |
79
|
|
|
[], |
80
|
|
|
[], |
81
|
|
|
AppModeEnum::TEST, |
82
|
|
|
] |
83
|
|
|
) |
84
|
|
|
->onlyMethods([ |
85
|
|
|
'loadPlugins', |
86
|
|
|
]) |
87
|
|
|
->getMock(); |
88
|
|
|
|
89
|
|
|
$kernel |
90
|
|
|
->expects($this->once()) |
91
|
|
|
->method('loadPlugins'); |
92
|
|
|
|
93
|
|
|
$kernel->run(); |
94
|
|
|
$kernel->run(); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|