Skip to content

Commit

Permalink
Fixes #123: Infer applicationUuid argument for api:* commands. (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
grasmash authored Jun 9, 2020
1 parent a7e8837 commit 08df362
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
18 changes: 18 additions & 0 deletions src/Command/Api/ApiCommandBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,24 @@ class ApiCommandBase extends CommandBase {
/** @var array */
private $pathParams = [];

/**
* @param \Symfony\Component\Console\Input\InputInterface $input
* @param \Symfony\Component\Console\Output\OutputInterface $output
*
* @throws \Acquia\Cli\Exception\AcquiaCliException
*/
protected function initialize(InputInterface $input, OutputInterface $output) {
parent::initialize($input, $output);

if ($input->hasArgument('applicationUuid') && !$input->getArgument('applicationUuid')) {
$output->writeln('Inferring Cloud Application UUID for this command since none was provided...');
if ($application_uuid = $this->determineCloudApplication()) {
$output->writeln("Set application uuid to <comment>$application_uuid</comment>");
$input->setArgument('applicationUuid', $application_uuid);
}
}
}

/**
* @param \Symfony\Component\Console\Input\InputInterface $input
* @param \Symfony\Component\Console\Output\OutputInterface $output
Expand Down
2 changes: 1 addition & 1 deletion src/Command/CommandBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ protected function getAppUuidFromLocalProjectInfo() {
protected function promptLinkApplication(
?ApplicationResponse $cloud_application
): bool {
$question = new ConfirmationQuestion("<question>Would you like to link the Cloud application {$cloud_application->name} to this repository</question>? ");
$question = new ConfirmationQuestion("<question>Would you like to link the Cloud application <comment>{$cloud_application->name}</comment> to this repository</question>? ");
$helper = $this->getHelper('question');
$answer = $helper->ask($this->input, $this->output, $question);
if ($answer) {
Expand Down
24 changes: 23 additions & 1 deletion tests/phpunit/src/Commands/Api/ApiCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,28 @@ public function testApiCommandExecutionForHttpGet(): void {
$this->assertArrayHasKey('uuid', $contents[0]);
}

public function testInferApplicationUuidArgument() {
$mock_body = $this->getMockResponseFromSpec('/applications/{applicationUuid}', 'get', '200');
$this->clientProphecy->request('get', '/applications')->willReturn([$mock_body])->shouldBeCalled();
$this->clientProphecy->request('get', '/applications/' . $mock_body->uuid)->willReturn($mock_body)->shouldBeCalled();
$this->command = $this->getApiCommandByName('api:applications:find');
$this->executeCommand([], [
// Would you like Acquia CLI to search for a Cloud application that matches your local git config?
'n',
// Please select an Acquia Cloud application:
'0',
// Would you like to link the Cloud application Sample application to this repository?
'n'
]);

// Assert.
$this->prophet->checkPredictions();
$output = $this->getDisplay();
$this->assertStringContainsString('Inferring Cloud Application UUID for this command since none was provided...', $output);
$this->assertStringContainsString('Set application uuid to ' . $mock_body->uuid, $output);
$this->assertEquals(0, $this->getStatusCode());
}

public function testApiCommandExecutionForHttpPost(): void {
$mock_request_args = $this->getMockRequestBodyFromSpec('/account/ssh-keys');
$mock_response_body = $this->getMockResponseFromSpec('/account/ssh-keys', 'post', '202');
Expand Down Expand Up @@ -123,9 +145,9 @@ public function providerTestApiCommandDefinitionRequestBody(): array {
/**
* @dataProvider providerTestApiCommandDefinitionRequestBody
*
* @param $use_command_cache
* @param $command_name
* @param $method
* @param $usage
*
* @throws \Psr\Cache\InvalidArgumentException
*/
Expand Down

0 comments on commit 08df362

Please sign in to comment.