From 30424b2fb1ac3fcd216f95e41f9986f39d10dacf Mon Sep 17 00:00:00 2001 From: Dane Powell Date: Thu, 18 Apr 2024 10:12:59 -0700 Subject: [PATCH 1/2] CLI-1317: api:base is not a valid command --- src/Command/Api/ApiBaseCommand.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Command/Api/ApiBaseCommand.php b/src/Command/Api/ApiBaseCommand.php index 8baebf8fe..c4d5d5992 100644 --- a/src/Command/Api/ApiBaseCommand.php +++ b/src/Command/Api/ApiBaseCommand.php @@ -6,6 +6,7 @@ use Acquia\Cli\Attribute\RequireAuth; use Acquia\Cli\Command\CommandBase; +use Acquia\Cli\Exception\AcquiaCliException; use AcquiaCloudApi\Connector\Client; use AcquiaCloudApi\Exception\ApiErrorException; use Closure; @@ -87,6 +88,9 @@ protected function interact(InputInterface $input, OutputInterface $output): voi } protected function execute(InputInterface $input, OutputInterface $output): int { + if ($this->getName() === 'api:base') { + throw new AcquiaCliException('api:base is not a valid command'); + } // Build query from non-null options. $acquiaCloudClient = $this->cloudApiClientService->getClient(); $this->addQueryParamsToClient($input, $acquiaCloudClient); From 8b2c3c72381b3d63c525c3d27e6bd9cbfcb7c859 Mon Sep 17 00:00:00 2001 From: Dane Powell Date: Thu, 18 Apr 2024 10:45:32 -0700 Subject: [PATCH 2/2] fix test case --- src/Command/Api/ApiBaseCommand.php | 2 ++ .../src/Commands/Api/ApiBaseCommandTest.php | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 tests/phpunit/src/Commands/Api/ApiBaseCommandTest.php diff --git a/src/Command/Api/ApiBaseCommand.php b/src/Command/Api/ApiBaseCommand.php index c4d5d5992..1a9a743e6 100644 --- a/src/Command/Api/ApiBaseCommand.php +++ b/src/Command/Api/ApiBaseCommand.php @@ -110,6 +110,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int $response = $acquiaCloudClient->request($this->method, $path); $exitCode = 0; } + // Ignore PhpStorm warning here. + // @see https://youtrack.jetbrains.com/issue/WI-77190/Exception-is-never-thrown-when-thrown-from-submethod catch (ApiErrorException $exception) { $response = $exception->getResponseBody(); $exitCode = 1; diff --git a/tests/phpunit/src/Commands/Api/ApiBaseCommandTest.php b/tests/phpunit/src/Commands/Api/ApiBaseCommandTest.php new file mode 100644 index 000000000..6cf4a8f5f --- /dev/null +++ b/tests/phpunit/src/Commands/Api/ApiBaseCommandTest.php @@ -0,0 +1,24 @@ +injectCommand(ApiBaseCommand::class); + } + + public function testApiBaseCommand(): void { + $this->expectException(AcquiaCliException::class); + $this->expectExceptionMessage('api:base is not a valid command'); + $this->executeCommand(); + } + +}