From d056a8de3d7315726b652fb1057d47e9791413e0 Mon Sep 17 00:00:00 2001 From: Matthew Grasmick Date: Tue, 2 Nov 2021 13:32:28 -0400 Subject: [PATCH 1/7] Fixes #711: Adding ide:list-mine command. --- src/Command/Ide/IdeListMineCommand.php | 68 ++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/Command/Ide/IdeListMineCommand.php diff --git a/src/Command/Ide/IdeListMineCommand.php b/src/Command/Ide/IdeListMineCommand.php new file mode 100644 index 000000000..44916cbb8 --- /dev/null +++ b/src/Command/Ide/IdeListMineCommand.php @@ -0,0 +1,68 @@ +setDescription('List available Cloud IDEs belong to you, across all applications'); + $this->acceptApplicationUuid(); + } + + /** + * @param \Symfony\Component\Console\Input\InputInterface $input + * @param \Symfony\Component\Console\Output\OutputInterface $output + * + * @return int 0 if everything went fine, or an exit code + * @throws \Exception + */ + protected function execute(InputInterface $input, OutputInterface $output) { + $acquia_cloud_client = $this->cloudApiClientService->getClient(); + $account_ides = $acquia_cloud_client->request('get', '/account/ides'); + $application_resource = new Applications($acquia_cloud_client); + + if (count($account_ides)) { + $table = new Table($output); + $table->setStyle('borderless'); + $table->setHeaders(['IDEs']); + foreach ($account_ides as $ide) { + $app_url_parts = explode('/', $ide->_links->application->href); + $app_uuid = end($app_url_parts); + $application = $application_resource->get($app_uuid); + $application_url = str_replace('/api', '/a', $application->links->self->href); + + $table->addRows([ + ["{$ide->label} {$ide->uuid}"], + ["{$application->name} ({$application->subscription->name})"], + ["IDE URL: _links->ide->href}>{$ide->_links->ide->href}"], + ["Web URL: _links->web->href}>{$ide->_links->web->href}"], + new TableSeparator(), + ]); + } + $table->render(); + } + else { + $output->writeln('No IDE exists for this application.'); + } + + return 0; + } + +} From f54dbda5ed5d78e5dff2e4983c17ca22dd38a33f Mon Sep 17 00:00:00 2001 From: Matthew Grasmick Date: Tue, 2 Nov 2021 13:35:52 -0400 Subject: [PATCH 2/7] Fix text. --- src/Command/Ide/IdeListMineCommand.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Command/Ide/IdeListMineCommand.php b/src/Command/Ide/IdeListMineCommand.php index 44916cbb8..10767dec9 100644 --- a/src/Command/Ide/IdeListMineCommand.php +++ b/src/Command/Ide/IdeListMineCommand.php @@ -2,10 +2,7 @@ namespace Acquia\Cli\Command\Ide; -use AcquiaCloudApi\Endpoints\Account; use AcquiaCloudApi\Endpoints\Applications; -use AcquiaCloudApi\Endpoints\Ides; -use AcquiaCloudApi\Response\IdesResponse; use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Helper\TableSeparator; use Symfony\Component\Console\Input\InputInterface; @@ -59,7 +56,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { $table->render(); } else { - $output->writeln('No IDE exists for this application.'); + $output->writeln('No IDE exists for your account.'); } return 0; From 90024ad6456d10bea7595518c161f2fc4b079b09 Mon Sep 17 00:00:00 2001 From: Matthew Grasmick Date: Tue, 2 Nov 2021 14:26:55 -0400 Subject: [PATCH 3/7] Adding test. --- .../Commands/Ide/IdeListCommandMineTest.php | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 tests/phpunit/src/Commands/Ide/IdeListCommandMineTest.php diff --git a/tests/phpunit/src/Commands/Ide/IdeListCommandMineTest.php b/tests/phpunit/src/Commands/Ide/IdeListCommandMineTest.php new file mode 100644 index 000000000..1aee1608c --- /dev/null +++ b/tests/phpunit/src/Commands/Ide/IdeListCommandMineTest.php @@ -0,0 +1,81 @@ +injectCommand(IdeListMineCommand::class); + } + + /** + * Tests the 'ide:list-mine' commands. + * + * @throws \Psr\Cache\InvalidArgumentException + */ + public function testIdeListMineCommand(): void { + $applications_response = $this->getMockResponseFromSpec('/applications', 'get', '200'); + $ides_response = $this->mockAccountIdeListRequest(); + foreach ($ides_response->{'_embedded'}->items as $key => $ide) { + $application_response = $applications_response->{'_embedded'}->items[$key]; + $app_url_parts = explode('/', $ide->_links->application->href); + $app_uuid = end($app_url_parts); + $application_response->uuid = $app_uuid; + $this->clientProphecy->request('get', '/applications/' . $app_uuid) + ->willReturn($application_response) + ->shouldBeCalled(); + } + + $inputs = [ + // Would you like Acquia CLI to search for a Cloud application that matches your local git config? + 'n', + // Please select the application. + 0, + // Would you like to link the project at ... ? + 'y', + ]; + $this->executeCommand([], $inputs); + + // Assert. + $this->prophet->checkPredictions(); + $output = $this->getDisplay(); + $this->assertStringContainsString('IDE Label 1 9a83c081-ef78-4dbd-8852-11cc3eb248f7', $output); + $this->assertStringContainsString('Sample application 1 (Sample subscription)', $output); + $this->assertStringContainsString('IDE URL: https://9a83c081-ef78-4dbd-8852-11cc3eb248f7.ide.ahdev.cloud', $output); + $this->assertStringContainsString('Web URL: https://9a83c081-ef78-4dbd-8852-11cc3eb248f7.web.ahdev.cloud', $output); + $this->assertStringContainsString('IDE Label 2 feea197a-9503-4441-9f49-b4d420b0ecf8', $output); + $this->assertStringContainsString('Sample application 1 (Sample subscription)', $output); + $this->assertStringContainsString('IDE URL: https://feea197a-9503-4441-9f49-b4d420b0ecf8.ide.ahdev.cloud', $output); + $this->assertStringContainsString('Web URL: https://feea197a-9503-4441-9f49-b4d420b0ecf8.web.ahdev.cloud', $output); + } + + /** + * @return object + * @throws \Psr\Cache\InvalidArgumentException + */ + protected function mockAccountIdeListRequest() { + $response = $this->getMockResponseFromSpec('/account/ides', + 'get', '200'); + $this->clientProphecy->request('get', + '/account/ides') + ->willReturn($response->{'_embedded'}->items) + ->shouldBeCalled(); + + return $response; + } + +} From 841ff03272a9a6b17b509373838268c8a37bebd7 Mon Sep 17 00:00:00 2001 From: Matthew Grasmick Date: Tue, 2 Nov 2021 19:46:27 -0400 Subject: [PATCH 4/7] More verbose. --- src/Command/Ide/IdeListMineCommand.php | 6 ++++-- .../src/Commands/Ide/IdeListCommandMineTest.php | 13 +++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Command/Ide/IdeListMineCommand.php b/src/Command/Ide/IdeListMineCommand.php index 10767dec9..8bfac2ddb 100644 --- a/src/Command/Ide/IdeListMineCommand.php +++ b/src/Command/Ide/IdeListMineCommand.php @@ -46,8 +46,10 @@ protected function execute(InputInterface $input, OutputInterface $output) { $application_url = str_replace('/api', '/a', $application->links->self->href); $table->addRows([ - ["{$ide->label} {$ide->uuid}"], - ["{$application->name} ({$application->subscription->name})"], + ["{$ide->label}"], + ["UUID: {$ide->uuid}"], + ["Application: {$application->name}"], + ["Subscription: {$application->subscription->name}"], ["IDE URL: _links->ide->href}>{$ide->_links->ide->href}"], ["Web URL: _links->web->href}>{$ide->_links->web->href}"], new TableSeparator(), diff --git a/tests/phpunit/src/Commands/Ide/IdeListCommandMineTest.php b/tests/phpunit/src/Commands/Ide/IdeListCommandMineTest.php index 1aee1608c..eba7f07e0 100644 --- a/tests/phpunit/src/Commands/Ide/IdeListCommandMineTest.php +++ b/tests/phpunit/src/Commands/Ide/IdeListCommandMineTest.php @@ -53,12 +53,17 @@ public function testIdeListMineCommand(): void { // Assert. $this->prophet->checkPredictions(); $output = $this->getDisplay(); - $this->assertStringContainsString('IDE Label 1 9a83c081-ef78-4dbd-8852-11cc3eb248f7', $output); - $this->assertStringContainsString('Sample application 1 (Sample subscription)', $output); + $this->assertStringContainsString('IDE Label 1', $output); + $this->assertStringContainsString('UUID: 9a83c081-ef78-4dbd-8852-11cc3eb248f7', $output); + $this->assertStringContainsString('Application: Sample application 1', $output); + $this->assertStringContainsString('Subscription: Sample subscription', $output); $this->assertStringContainsString('IDE URL: https://9a83c081-ef78-4dbd-8852-11cc3eb248f7.ide.ahdev.cloud', $output); $this->assertStringContainsString('Web URL: https://9a83c081-ef78-4dbd-8852-11cc3eb248f7.web.ahdev.cloud', $output); - $this->assertStringContainsString('IDE Label 2 feea197a-9503-4441-9f49-b4d420b0ecf8', $output); - $this->assertStringContainsString('Sample application 1 (Sample subscription)', $output); + + $this->assertStringContainsString('IDE Label 2', $output); + $this->assertStringContainsString('UUID: 9a83c081-ef78-4dbd-8852-11cc3eb248f7', $output); + $this->assertStringContainsString('Application: Sample application 2', $output); + $this->assertStringContainsString('Subscription: Sample subscription', $output); $this->assertStringContainsString('IDE URL: https://feea197a-9503-4441-9f49-b4d420b0ecf8.ide.ahdev.cloud', $output); $this->assertStringContainsString('Web URL: https://feea197a-9503-4441-9f49-b4d420b0ecf8.web.ahdev.cloud', $output); } From 38814c68f5b033e15b2a253eff654a60bdfe75e0 Mon Sep 17 00:00:00 2001 From: Matthew Grasmick Date: Tue, 2 Nov 2021 19:48:38 -0400 Subject: [PATCH 5/7] Rename ide:list to ide:list-app --- src/Command/Ide/IdeCreateCommand.php | 2 +- src/Command/Ide/IdeListCommand.php | 5 +++-- src/Command/Ide/IdeListMineCommand.php | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Command/Ide/IdeCreateCommand.php b/src/Command/Ide/IdeCreateCommand.php index 02f97c04a..4d7ff5f59 100644 --- a/src/Command/Ide/IdeCreateCommand.php +++ b/src/Command/Ide/IdeCreateCommand.php @@ -46,7 +46,7 @@ class IdeCreateCommand extends IdeCommandBase { * {inheritdoc}. */ protected function configure() { - $this->setDescription('Create a Cloud IDE for development'); + $this->setDescription('Create a Cloud IDE'); $this->acceptApplicationUuid(); $this->addOption('label', NULL, InputOption::VALUE_REQUIRED, 'The label for the IDE'); } diff --git a/src/Command/Ide/IdeListCommand.php b/src/Command/Ide/IdeListCommand.php index b475a87d3..75f620a75 100644 --- a/src/Command/Ide/IdeListCommand.php +++ b/src/Command/Ide/IdeListCommand.php @@ -13,13 +13,14 @@ */ class IdeListCommand extends IdeCommandBase { - protected static $defaultName = 'ide:list'; + protected static $defaultName = 'ide:list-app'; /** * {inheritdoc}. */ protected function configure() { - $this->setDescription('List available Cloud IDEs'); + $this->setDescription('List available Cloud IDEs belonging to a given application'); + $this->setAliases(['ide:list']); $this->acceptApplicationUuid(); } diff --git a/src/Command/Ide/IdeListMineCommand.php b/src/Command/Ide/IdeListMineCommand.php index 8bfac2ddb..5906db53b 100644 --- a/src/Command/Ide/IdeListMineCommand.php +++ b/src/Command/Ide/IdeListMineCommand.php @@ -19,7 +19,7 @@ class IdeListMineCommand extends IdeCommandBase { * {inheritdoc}. */ protected function configure() { - $this->setDescription('List available Cloud IDEs belong to you, across all applications'); + $this->setDescription('List available Cloud IDEs belonging to you'); $this->acceptApplicationUuid(); } From 69795ea54b6951acdd1da1654c31fe34a229cd4c Mon Sep 17 00:00:00 2001 From: Matthew Grasmick Date: Wed, 3 Nov 2021 13:18:41 -0400 Subject: [PATCH 6/7] Update src/Command/Ide/IdeListMineCommand.php Co-authored-by: Dane Powell --- src/Command/Ide/IdeListMineCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Command/Ide/IdeListMineCommand.php b/src/Command/Ide/IdeListMineCommand.php index 5906db53b..d9ea50798 100644 --- a/src/Command/Ide/IdeListMineCommand.php +++ b/src/Command/Ide/IdeListMineCommand.php @@ -19,7 +19,7 @@ class IdeListMineCommand extends IdeCommandBase { * {inheritdoc}. */ protected function configure() { - $this->setDescription('List available Cloud IDEs belonging to you'); + $this->setDescription('List Cloud IDEs belonging to you'); $this->acceptApplicationUuid(); } From 769975f56f0ab5a171870a200768da58894e7c6d Mon Sep 17 00:00:00 2001 From: Matthew Grasmick Date: Wed, 3 Nov 2021 13:30:03 -0400 Subject: [PATCH 7/7] Quick rename. --- src/Command/Ide/IdeListCommand.php | 2 +- src/Command/Ide/IdeListMineCommand.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Command/Ide/IdeListCommand.php b/src/Command/Ide/IdeListCommand.php index 75f620a75..357a192c7 100644 --- a/src/Command/Ide/IdeListCommand.php +++ b/src/Command/Ide/IdeListCommand.php @@ -13,7 +13,7 @@ */ class IdeListCommand extends IdeCommandBase { - protected static $defaultName = 'ide:list-app'; + protected static $defaultName = 'ide:list:app'; /** * {inheritdoc}. diff --git a/src/Command/Ide/IdeListMineCommand.php b/src/Command/Ide/IdeListMineCommand.php index d9ea50798..9cedc7661 100644 --- a/src/Command/Ide/IdeListMineCommand.php +++ b/src/Command/Ide/IdeListMineCommand.php @@ -13,7 +13,7 @@ */ class IdeListMineCommand extends IdeCommandBase { - protected static $defaultName = 'ide:list-mine'; + protected static $defaultName = 'ide:list:mine'; /** * {inheritdoc}.