Passed
Push — main ( 06ee14...a96829 )
by Chema
03:58
created

ListModulesCommandTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Importance

Changes 9
Bugs 1 Features 0
Metric Value
eloc 38
c 9
b 1
f 0
dl 0
loc 73
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
A test_list_modules_simple() 0 15 1
A test_list_modules_not_detailed() 0 10 1
A test_list_modules_with_filter() 0 12 1
A commandInputProvider() 0 4 1
A test_list_modules_detailed() 0 11 1
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