Skip to content

Commit

Permalink
CLI-1317: api:base is not a valid command (#1730)
Browse files Browse the repository at this point in the history
* CLI-1317: api:base is not a valid command

* fix test case
  • Loading branch information
danepowell authored Apr 18, 2024
1 parent cf14e26 commit b6673f4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Command/Api/ApiBaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down
24 changes: 24 additions & 0 deletions tests/phpunit/src/Commands/Api/ApiBaseCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types = 1);

namespace Acquia\Cli\Tests\Commands\Api;

use Acquia\Cli\Command\Api\ApiBaseCommand;
use Acquia\Cli\Command\CommandBase;
use Acquia\Cli\Exception\AcquiaCliException;
use Acquia\Cli\Tests\CommandTestBase;

class ApiBaseCommandTest extends CommandTestBase {

protected function createCommand(): CommandBase {
return $this->injectCommand(ApiBaseCommand::class);
}

public function testApiBaseCommand(): void {
$this->expectException(AcquiaCliException::class);
$this->expectExceptionMessage('api:base is not a valid command');
$this->executeCommand();
}

}

0 comments on commit b6673f4

Please sign in to comment.