diff --git a/CHANGELOG.md b/CHANGELOG.md index ee8ce651..43cb6e28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ### Unreleased -- Added command `gacela list:modules [--detailed|-d]` +- Added command `gacela list:modules [--simple|-s]` - Fixed Windows support ### 1.4.0 diff --git a/src/Console/Infrastructure/Command/ListModulesCommand.php b/src/Console/Infrastructure/Command/ListModulesCommand.php index 1ae68ca8..cd07f44b 100644 --- a/src/Console/Infrastructure/Command/ListModulesCommand.php +++ b/src/Console/Infrastructure/Command/ListModulesCommand.php @@ -25,7 +25,7 @@ protected function configure(): void $this->setName('list:modules') ->setDescription('Render all modules found') ->addArgument('filter', InputArgument::OPTIONAL, 'Any filter to simplify the output') - ->addOption('detailed', 'd', InputOption::VALUE_NONE, 'Display a detailed information of each module'); + ->addOption('simple', 's', InputOption::VALUE_NONE, 'Display just the module names'); } protected function execute(InputInterface $input, OutputInterface $output): int @@ -33,7 +33,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $filter = (string)$input->getArgument('filter'); $listOfModules = $this->generateListOfModules( - (bool)$input->getOption('detailed'), + (bool)$input->getOption('simple'), $this->getFacade()->findAllAppModules($filter), ); @@ -45,56 +45,54 @@ protected function execute(InputInterface $input, OutputInterface $output): int /** * @param list $modules */ - private function generateListOfModules(bool $isDetailed, array $modules): string + private function generateListOfModules(bool $isSimple, array $modules): string { - if ($isDetailed) { - return $this->generateDetailedView($modules); - } - - return $this->generateNonDetailedView($modules); + return ($isSimple) + ? $this->generateSimpleView($modules) + : $this->generateDetailedView($modules); } /** * @param list $modules */ - private function generateDetailedView(array $modules): string + private function generateSimpleView(array $modules): string { $result = ''; + foreach ($modules as $i => $module) { $n = $i + 1; - $factory = $module->factoryClass() ?? 'None'; - $config = $module->configClass() ?? 'None'; - $dependencyProviderClass = $module->dependencyProviderClass() ?? 'None'; - $result .= <<{$module->moduleName()} ----------------------------- -Facade: {$module->facadeClass()} -Factory: {$factory} -Config: {$config} -DependencyProvider: {$dependencyProviderClass} TXT; } + return $result; } /** * @param list $modules */ - private function generateNonDetailedView(array $modules): string + private function generateDetailedView(array $modules): string { $result = ''; - foreach ($modules as $i => $module) { $n = $i + 1; + $factory = $module->factoryClass() ?? 'None'; + $config = $module->configClass() ?? 'None'; + $dependencyProviderClass = $module->dependencyProviderClass() ?? 'None'; + $result .= <<{$module->moduleName()} +---------------------------- +Facade: {$module->facadeClass()} +Factory: {$factory} +Config: {$config} +DependencyProvider: {$dependencyProviderClass} TXT; } - return $result; } } diff --git a/tests/Feature/Console/ListModules/ListModulesCommandTest.php b/tests/Feature/Console/ListModules/ListModulesCommandTest.php index 2907a9bf..53e388d7 100644 --- a/tests/Feature/Console/ListModules/ListModulesCommandTest.php +++ b/tests/Feature/Console/ListModules/ListModulesCommandTest.php @@ -4,27 +4,28 @@ namespace GacelaTest\Feature\Console\ListModules; -use Gacela\Console\Infrastructure\ConsoleBootstrap; +use Gacela\Console\Infrastructure\Command\ListModulesCommand; use Gacela\Framework\Bootstrap\GacelaConfig; use Gacela\Framework\Gacela; use PHPUnit\Framework\TestCase; -use Symfony\Component\Console\Input\StringInput; -use Symfony\Component\Console\Output\BufferedOutput; +use Symfony\Component\Console\Tester\CommandTester; final class ListModulesCommandTest extends TestCase { - public function test_list_modules(): void + private CommandTester $command; + + protected function setUp(): void { Gacela::bootstrap(__DIR__, static function (GacelaConfig $config): void { $config->resetInMemoryCache(); }); - $input = new StringInput('list:modules'); - $output = new BufferedOutput(); + $this->command = new CommandTester(new ListModulesCommand()); + } - $bootstrap = new ConsoleBootstrap(); - $bootstrap->setAutoExit(false); - $bootstrap->run($input, $output); + public function test_list_modules_simple(): void + { + $this->command->execute(['--simple' => null]); $expected = <<fetch()); + self::assertSame($expected, $this->command->getDisplay()); } - public function test_list_detailed_modules(): void + public function test_list_modules(): void { - Gacela::bootstrap(__DIR__, static function (GacelaConfig $config): void { - $config->resetInMemoryCache(); - }); - - $input = new StringInput('list:modules --detailed'); - $output = new BufferedOutput(); - - $bootstrap = new ConsoleBootstrap(); - $bootstrap->setAutoExit(false); - $bootstrap->run($input, $output); + $this->command->execute([]); $expected = <<fetch()); + self::assertSame($expected, $this->command->getDisplay()); } /** @@ -80,16 +72,9 @@ public function test_list_detailed_modules(): void */ public function test_list_modules_with_filter(string $input): void { - Gacela::bootstrap(__DIR__); - - $input = new StringInput('list:modules ' . $input); - $output = new BufferedOutput(); - - $bootstrap = new ConsoleBootstrap(); - $bootstrap->setAutoExit(false); - $bootstrap->run($input, $output); + $this->command->execute(['filter' => $input]); - $out = $output->fetch(); + $out = $this->command->getDisplay(); self::assertStringContainsString('TestModule1', $out); self::assertStringNotContainsString('TestModule2', $out); @@ -101,6 +86,6 @@ public function test_list_modules_with_filter(string $input): void public function commandInputProvider(): iterable { yield 'slashes' => ['ListModules/TestModule1']; - yield 'backward slashes' => ['ListModules\\\TestModule1']; + yield 'backward slashes' => ['ListModules\\TestModule1']; } }