1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace GacelaTest\Feature\Console\ListModules; |
6
|
|
|
|
7
|
|
|
use Gacela\Console\Infrastructure\ConsoleBootstrap; |
8
|
|
|
use Gacela\Framework\Bootstrap\GacelaConfig; |
9
|
|
|
use Gacela\Framework\Gacela; |
10
|
|
|
use PHPUnit\Framework\TestCase; |
11
|
|
|
use Symfony\Component\Console\Input\StringInput; |
12
|
|
|
use Symfony\Component\Console\Output\BufferedOutput; |
13
|
|
|
|
14
|
|
|
final class ListModulesCommandTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
public function test_list_modules(): void |
17
|
|
|
{ |
18
|
|
|
Gacela::bootstrap(__DIR__, static function (GacelaConfig $config): void { |
19
|
|
|
$config->resetInMemoryCache(); |
20
|
|
|
}); |
21
|
|
|
|
22
|
|
|
$input = new StringInput('list:modules'); |
23
|
|
|
$output = new BufferedOutput(); |
24
|
|
|
|
25
|
|
|
$bootstrap = new ConsoleBootstrap(); |
26
|
|
|
$bootstrap->setAutoExit(false); |
27
|
|
|
$bootstrap->run($input, $output); |
28
|
|
|
|
29
|
|
|
$expected = <<<TXT |
30
|
|
|
============== |
31
|
|
|
TestModule3 |
32
|
|
|
============== |
33
|
|
|
TestModule1 |
34
|
|
|
============== |
35
|
|
|
TestModule2 |
36
|
|
|
|
37
|
|
|
TXT; |
38
|
|
|
self::assertSame($expected, $output->fetch()); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function test_list_detailed_modules(): void |
42
|
|
|
{ |
43
|
|
|
Gacela::bootstrap(__DIR__, static function (GacelaConfig $config): void { |
44
|
|
|
$config->resetInMemoryCache(); |
45
|
|
|
}); |
46
|
|
|
|
47
|
|
|
$input = new StringInput('list:modules --detailed'); |
48
|
|
|
$output = new BufferedOutput(); |
49
|
|
|
|
50
|
|
|
$bootstrap = new ConsoleBootstrap(); |
51
|
|
|
$bootstrap->setAutoExit(false); |
52
|
|
|
$bootstrap->run($input, $output); |
53
|
|
|
|
54
|
|
|
$expected = <<<TXT |
55
|
|
|
============== |
56
|
|
|
TestModule3 |
57
|
|
|
-------------- |
58
|
|
|
Facade: GacelaTest\Feature\Console\ListModules\LevelUp\TestModule3\TestModule3Facade |
59
|
|
|
Factory: GacelaTest\Feature\Console\ListModules\LevelUp\TestModule3\TestModule3Factory |
60
|
|
|
Config: GacelaTest\Feature\Console\ListModules\LevelUp\TestModule3\TestModule3Config |
61
|
|
|
DependencyProvider: None |
62
|
|
|
============== |
63
|
|
|
TestModule1 |
64
|
|
|
-------------- |
65
|
|
|
Facade: GacelaTest\Feature\Console\ListModules\TestModule1\TestModule1Facade |
66
|
|
|
Factory: GacelaTest\Feature\Console\ListModules\TestModule1\TestModule1Factory |
67
|
|
|
Config: None |
68
|
|
|
DependencyProvider: GacelaTest\Feature\Console\ListModules\TestModule1\TestModule1DependencyProvider |
69
|
|
|
============== |
70
|
|
|
TestModule2 |
71
|
|
|
-------------- |
72
|
|
|
Facade: GacelaTest\Feature\Console\ListModules\TestModule2\TestModule2Facade |
73
|
|
|
Factory: None |
74
|
|
|
Config: None |
75
|
|
|
DependencyProvider: None |
76
|
|
|
|
77
|
|
|
TXT; |
78
|
|
|
self::assertSame($expected, $output->fetch()); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @dataProvider commandInputProvider |
83
|
|
|
*/ |
84
|
|
|
public function test_list_modules_with_filter(string $input): void |
85
|
|
|
{ |
86
|
|
|
Gacela::bootstrap(__DIR__); |
87
|
|
|
|
88
|
|
|
$input = new StringInput('list:modules ' . $input); |
89
|
|
|
$output = new BufferedOutput(); |
90
|
|
|
|
91
|
|
|
$bootstrap = new ConsoleBootstrap(); |
92
|
|
|
$bootstrap->setAutoExit(false); |
93
|
|
|
$bootstrap->run($input, $output); |
94
|
|
|
|
95
|
|
|
$out = $output->fetch(); |
96
|
|
|
|
97
|
|
|
self::assertStringContainsString('TestModule1', $out); |
98
|
|
|
self::assertStringNotContainsString('TestModule2', $out); |
99
|
|
|
self::assertStringNotContainsString('TestModule3', $out); |
100
|
|
|
self::assertStringNotContainsString('vendor', $out); |
101
|
|
|
self::assertStringNotContainsString('ToBeIgnored', $out); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function commandInputProvider(): iterable |
105
|
|
|
{ |
106
|
|
|
yield 'slashes' => ['ListModules/TestModule1']; |
107
|
|
|
yield 'backward slashes' => ['ListModules\\\TestModule1']; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|