1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace GacelaTest\Feature\Console\ListModules; |
6
|
|
|
|
7
|
|
|
use Gacela\Console\Infrastructure\Command\ListModulesCommand; |
8
|
|
|
use Gacela\Framework\Bootstrap\GacelaConfig; |
9
|
|
|
use Gacela\Framework\Gacela; |
10
|
|
|
use PHPUnit\Framework\Attributes\DataProvider; |
11
|
|
|
use PHPUnit\Framework\TestCase; |
12
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
13
|
|
|
|
14
|
|
|
final class ListModulesCommandTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
private CommandTester $command; |
17
|
|
|
|
18
|
|
|
protected function setUp(): void |
19
|
|
|
{ |
20
|
|
|
Gacela::bootstrap(__DIR__, static function (GacelaConfig $config): void { |
21
|
|
|
$config->resetInMemoryCache(); |
22
|
|
|
}); |
23
|
|
|
|
24
|
|
|
$this->command = new CommandTester(new ListModulesCommand()); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function test_list_modules_simple(): void |
28
|
|
|
{ |
29
|
|
|
$this->command->execute([]); |
30
|
|
|
|
31
|
|
|
$expected = <<<TXT |
32
|
|
|
┌────────────────────────────────────────────────────────────┬────────┬─────────┬────────┬──────────┐ |
33
|
|
|
│ Module namespace │ Facade │ Factory │ Config │ Provider │ |
34
|
|
|
├────────────────────────────────────────────────────────────┼────────┼─────────┼────────┼──────────┤ |
35
|
|
|
│ GacelaTest\Feature\Console\ListModules\LevelUp\TestModule3 │ x │ x │ x │ │ |
36
|
|
|
│ GacelaTest\Feature\Console\ListModules\TestModule1 │ x │ x │ │ x │ |
37
|
|
|
│ GacelaTest\Feature\Console\ListModules\TestModule2 │ x │ │ │ │ |
38
|
|
|
└────────────────────────────────────────────────────────────┴────────┴─────────┴────────┴──────────┘ |
39
|
|
|
|
40
|
|
|
TXT; |
41
|
|
|
self::assertSame($expected, $this->command->getDisplay()); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function test_list_modules_detailed(): void |
45
|
|
|
{ |
46
|
|
|
$this->command->execute(['--detailed' => true]); |
47
|
|
|
|
48
|
|
|
$output = $this->command->getDisplay(); |
49
|
|
|
|
50
|
|
|
// Verify this is the detailed view (not the table view) |
51
|
|
|
self::assertStringNotContainsString('┌────', $output, 'Should not contain table borders'); |
52
|
|
|
self::assertStringContainsString('============================', $output, 'Should contain detailed view separators'); |
53
|
|
|
self::assertStringContainsString('TestModule3Facade', $output); |
54
|
|
|
self::assertStringContainsString('TestModule1Factory', $output); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function test_list_modules_not_detailed(): void |
58
|
|
|
{ |
59
|
|
|
$this->command->execute(['--detailed' => false]); |
60
|
|
|
|
61
|
|
|
$output = $this->command->getDisplay(); |
62
|
|
|
|
63
|
|
|
// Verify this is the simple table view (not detailed view) |
64
|
|
|
self::assertStringContainsString('┌────', $output, 'Should contain table borders'); |
65
|
|
|
self::assertStringNotContainsString('============================', $output, 'Should not contain detailed view separators'); |
66
|
|
|
self::assertStringContainsString('TestModule3', $output); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
#[DataProvider('commandInputProvider')] |
70
|
|
|
public function test_list_modules_with_filter(string $input): void |
71
|
|
|
{ |
72
|
|
|
$this->command->execute(['filter' => $input]); |
73
|
|
|
|
74
|
|
|
$out = $this->command->getDisplay(); |
75
|
|
|
|
76
|
|
|
self::assertStringContainsString('TestModule1', $out); |
77
|
|
|
self::assertStringNotContainsString('TestModule2', $out); |
78
|
|
|
self::assertStringNotContainsString('TestModule3', $out); |
79
|
|
|
self::assertStringNotContainsString('vendor', $out); |
80
|
|
|
self::assertStringNotContainsString('ToBeIgnored', $out); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public static function commandInputProvider(): iterable |
84
|
|
|
{ |
85
|
|
|
yield 'slashes' => ['ListModules/TestModule1']; |
86
|
|
|
yield 'backward slashes' => ['ListModules\\TestModule1']; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|