-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #711: Adding ide:list-mine command. #712
Changes from 6 commits
d056a8d
f54dbda
90024ad
841ff03
38814c6
69795ea
769975f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
namespace Acquia\Cli\Command\Ide; | ||
|
||
use AcquiaCloudApi\Endpoints\Applications; | ||
use Symfony\Component\Console\Helper\Table; | ||
use Symfony\Component\Console\Helper\TableSeparator; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Class IdeListMineCommand. | ||
*/ | ||
class IdeListMineCommand extends IdeCommandBase { | ||
|
||
protected static $defaultName = 'ide:list-mine'; | ||
|
||
/** | ||
* {inheritdoc}. | ||
*/ | ||
protected function configure() { | ||
$this->setDescription('List Cloud IDEs belonging to you'); | ||
$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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like it should use the same output format as Maybe even use it for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Filed CLI-530 so your feedback is not lost. |
||
$app_uuid = end($app_url_parts); | ||
$application = $application_resource->get($app_uuid); | ||
$application_url = str_replace('/api', '/a', $application->links->self->href); | ||
|
||
$table->addRows([ | ||
["<comment>{$ide->label}</comment>"], | ||
["UUID: {$ide->uuid}"], | ||
["Application: <href={$application_url}>{$application->name}</>"], | ||
["Subscription: {$application->subscription->name}"], | ||
["IDE URL: <href={$ide->_links->ide->href}>{$ide->_links->ide->href}</>"], | ||
["Web URL: <href={$ide->_links->web->href}>{$ide->_links->web->href}</>"], | ||
new TableSeparator(), | ||
]); | ||
} | ||
$table->render(); | ||
} | ||
else { | ||
$output->writeln('No IDE exists for your account.'); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
namespace Acquia\Cli\Tests\Commands\Ide; | ||
|
||
use Acquia\Cli\Command\Ide\IdeListCommand; | ||
use Acquia\Cli\Command\Ide\IdeListMineCommand; | ||
use Acquia\Cli\Tests\CommandTestBase; | ||
use Symfony\Component\Console\Command\Command; | ||
|
||
/** | ||
* Class IdeListCommandMineTest. | ||
* | ||
* @property \Acquia\Cli\Command\Ide\IdeListMineCommand $command | ||
* @package Acquia\Cli\Tests\Ide | ||
*/ | ||
class IdeListCommandMineTest extends CommandTestBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function createCommand(): Command { | ||
return $this->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', $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', $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); | ||
} | ||
|
||
/** | ||
* @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; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened an upstream issue to add this endpoint: typhonius/acquia-php-sdk-v2#208
Not a blocker for this PR, but feel free to weigh in there.