diff --git a/src/N98/Magento/Command/Route/ListCommand.php b/src/N98/Magento/Command/Route/ListCommand.php index 4295d576..e8100905 100644 --- a/src/N98/Magento/Command/Route/ListCommand.php +++ b/src/N98/Magento/Command/Route/ListCommand.php @@ -2,6 +2,15 @@ namespace N98\Magento\Command\Route; +use Magento\Framework\App\Action\HttpConnectActionInterface; +use Magento\Framework\App\Action\HttpDeleteActionInterface; +use Magento\Framework\App\Action\HttpGetActionInterface; +use Magento\Framework\App\Action\HttpOptionsActionInterface; +use Magento\Framework\App\Action\HttpPatchActionInterface; +use Magento\Framework\App\Action\HttpPostActionInterface; +use Magento\Framework\App\Action\HttpPropfindActionInterface; +use Magento\Framework\App\Action\HttpPutActionInterface; +use Magento\Framework\App\Action\HttpTraceActionInterface; use Magento\Framework\App\ActionInterface; use Magento\Framework\App\AreaList; use Magento\Framework\App\Route\Config; @@ -125,7 +134,10 @@ protected function execute(InputInterface $input, OutputInterface $output) $actionClass = substr($actionClass, 0, -6); } - $moduleActions[$moduleName][$area][] = strtolower(implode('/', $actionPath) . '/' . $actionClass); + $moduleActions[$moduleName][$area][] = [ + 'file' => strtolower(implode('/', $actionPath) . '/' . $actionClass), + 'class' => $fullActionPath, + ]; } $areas = $input->getOption('area') ? [$input->getOption('area')] : $this->areaList->getCodes(); @@ -142,6 +154,7 @@ protected function execute(InputInterface $input, OutputInterface $output) 'Frontname', 'Module', 'Route', + 'Methods' ] ) ->renderByFormat($output, $table, $input->getOption('format')) @@ -195,7 +208,8 @@ protected function processSingleRoute($area, $route, $moduleOption, array $modul if (isset($moduleActions[$module][$area])) { foreach ($moduleActions[$module][$area] as $action) { $moduleRouteAction = $moduleRoute; - $moduleRouteAction[] = $route['frontName'] . '/' . ActionPathFormatter::format($action); + $moduleRouteAction[] = $route['frontName'] . '/' . ActionPathFormatter::format($action['file']); + $moduleRouteAction[] = implode(',', $this->getSupportedHttpVerbs($action['class'])); $table[] = $moduleRouteAction; } @@ -203,4 +217,57 @@ protected function processSingleRoute($area, $route, $moduleOption, array $modul } return $table; } + + /** + * Returns the HTTP verb of route by class of action + * + * @param string $actionClass + * @return string[] + */ + private function getSupportedHttpVerbs(string $actionClass): array + { + $verbs = []; + + if (is_a($actionClass, HttpConnectActionInterface::class, true)) { + $verbs[] = 'CONNECT'; + } + + if (is_a($actionClass, HttpDeleteActionInterface::class, true)) { + $verbs[] = 'DELETE'; + } + + if (is_a($actionClass, HttpGetActionInterface::class, true)) { + $verbs[] = 'GET'; + } + + if (is_a($actionClass, HttpOptionsActionInterface::class, true)) { + $verbs[] = 'OPTIONS'; + } + + if (is_a($actionClass, HttpPatchActionInterface::class, true)) { + $verbs[] = 'PATCH'; + } + + if (is_a($actionClass, HttpPostActionInterface::class, true)) { + $verbs[] = 'POST'; + } + + if (is_a($actionClass, HttpPropfindActionInterface::class, true)) { + $verbs[] = 'PROPFIND'; + } + + if (is_a($actionClass, HttpPutActionInterface::class, true)) { + $verbs[] = 'PUT'; + } + + if (is_a($actionClass, HttpTraceActionInterface::class, true)) { + $verbs[] = 'TRACE'; + } + + if (count($verbs) === 0) { + return ['GET', 'POST']; + } + + return $verbs; + } } diff --git a/tests/bats/functional_core_commands.bats b/tests/bats/functional_core_commands.bats index f5644686..51eadf00 100755 --- a/tests/bats/functional_core_commands.bats +++ b/tests/bats/functional_core_commands.bats @@ -278,12 +278,3 @@ setup() { assert_output --partial "vcl 4.0" } -@test "Command: route:list -m Magento_Backend -a adminhtml" { - run $BIN "route:list" -m Magento_Backend -a adminhtml - assert_output --partial "admin/dashboard/index" -} - -@test "Command: route:list -m Magento_Multishipping -a frontend" { - run $BIN "route:list" -m Magento_Multishipping -a frontend - assert_output --partial "multishipping/checkout_address/editaddress" -} diff --git a/tests/bats/functional_magerun_commands.bats b/tests/bats/functional_magerun_commands.bats index 4b3a3bed..f3dd68cf 100755 --- a/tests/bats/functional_magerun_commands.bats +++ b/tests/bats/functional_magerun_commands.bats @@ -439,6 +439,18 @@ function cleanup_files_in_magento() { assert_output --partial "Compress" } +@test "Command: route:list -m Magento_Backend -a adminhtml" { + run $BIN "route:list" -m Magento_Backend -a adminhtml + assert_output --partial "admin/dashboard/index" + assert_output --partial "GET,POST" +} + +@test "Command: route:list -m Magento_Multishipping -a frontend" { + run $BIN "route:list" -m Magento_Multishipping -a frontend + assert_output --partial "multishipping/checkout_address/editaddress" + assert_output --partial "GET,POST" +} + @test "Command: script:repo:list" { run $BIN "script:repo:list" assert_output --partial "Script"