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