From b6673f4d82126aa5d4aa0ad98f0bfdc4d8114fb4 Mon Sep 17 00:00:00 2001 From: Dane Powell Date: Thu, 18 Apr 2024 11:00:01 -0700 Subject: [PATCH] CLI-1317: api:base is not a valid command (#1730) * CLI-1317: api:base is not a valid command * fix test case --- src/Command/Api/ApiBaseCommand.php | 6 +++++ .../src/Commands/Api/ApiBaseCommandTest.php | 24 +++++++++++++++++++ 2 files changed, 30 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 8baebf8fe..1a9a743e6 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); @@ -106,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(); + } + +}