From 3cf28e5336e2f15fc91ffaeef07971d85c2c9765 Mon Sep 17 00:00:00 2001 From: Adam Malone Date: Sat, 7 Mar 2020 17:38:20 +1100 Subject: [PATCH] Fixes tests/stan. --- src/AcquiaCli.php | 25 ++++++++++++++++++++----- src/CloudApi.php | 6 +++--- src/Commands/AccountCommand.php | 5 +++-- src/Commands/AcquiaCommand.php | 1 - src/Commands/CodeCommand.php | 7 ++++--- src/Commands/DbCommand.php | 5 ----- src/Commands/DeployCommand.php | 2 +- src/Commands/EnvironmentsCommand.php | 10 ++++++---- src/Commands/LivedevCommand.php | 2 ++ src/Commands/NotificationsCommand.php | 11 +++++++---- src/Commands/ProductionModeCommand.php | 12 ++++++++---- src/Config.php | 4 +--- src/Injector/AcquiaCliInjector.php | 7 +++++++ tests/Commands/DbBackupCommandTest.php | 10 +++++++++- 14 files changed, 71 insertions(+), 36 deletions(-) diff --git a/src/AcquiaCli.php b/src/AcquiaCli.php index 6a4fc3f..a26fc2a 100644 --- a/src/AcquiaCli.php +++ b/src/AcquiaCli.php @@ -34,9 +34,17 @@ class AcquiaCli * @param InputInterface|null $input * @param OutputInterface|null $output */ - public function __construct(Config $config, Client $client, InputInterface $input = null, OutputInterface $output = null) - { - $version = trim(file_get_contents(dirname(__DIR__) . '/VERSION')); + public function __construct( + Config $config, + Client $client, + InputInterface $input = null, + OutputInterface $output = null + ) { + if ($file = file_get_contents(dirname(__DIR__) . '/VERSION')) { + $version = trim($file); + } else { + throw new \Exception('No VERSION file'); + } // Create application. $this->setConfig($config); @@ -88,11 +96,18 @@ public function getContainer($input, $output, $application, $config, $client) $parameterInjection = $container->get('parameterInjection'); $parameterInjection->register('AcquiaCli\CloudApi', new \AcquiaCli\Injector\AcquiaCliInjector); - $parameterInjection->register('AcquiaCloudApi\Endpoints\Applications', new \AcquiaCli\Injector\AcquiaCliInjector); - $parameterInjection->register('AcquiaCloudApi\Endpoints\Environments', new \AcquiaCli\Injector\AcquiaCliInjector); + $parameterInjection->register( + 'AcquiaCloudApi\Endpoints\Applications', + new \AcquiaCli\Injector\AcquiaCliInjector + ); + $parameterInjection->register( + 'AcquiaCloudApi\Endpoints\Environments', + new \AcquiaCli\Injector\AcquiaCliInjector + ); $parameterInjection->register('AcquiaCloudApi\Endpoints\Databases', new \AcquiaCli\Injector\AcquiaCliInjector); $parameterInjection->register('AcquiaCloudApi\Endpoints\Servers', new \AcquiaCli\Injector\AcquiaCliInjector); $parameterInjection->register('AcquiaCloudApi\Endpoints\Domains', new \AcquiaCli\Injector\AcquiaCliInjector); + $parameterInjection->register('AcquiaCloudApi\Endpoints\Code', new \AcquiaCli\Injector\AcquiaCliInjector); return $container; } diff --git a/src/CloudApi.php b/src/CloudApi.php index 79e6e40..4a5c8c7 100644 --- a/src/CloudApi.php +++ b/src/CloudApi.php @@ -6,9 +6,9 @@ use AcquiaCloudApi\Connector\Connector; use AcquiaCloudApi\Endpoints\Applications; use AcquiaCloudApi\Endpoints\Environments; +use AcquiaCloudApi\Response\EnvironmentResponse; use Robo\Config\Config; - /** * Class CloudApi * @package AcquiaCli @@ -51,7 +51,7 @@ public function createClient() * @param string $uuid * @param string $environment * @return EnvironmentResponse - * @throws Exception + * @throws \Exception */ public function getEnvironment($uuid, $environment) { @@ -64,7 +64,7 @@ public function getEnvironment($uuid, $environment) } } - throw new Exception('Unable to find ID for environment'); + throw new \Exception('Unable to find ID for environment'); } public function getClient() diff --git a/src/Commands/AccountCommand.php b/src/Commands/AccountCommand.php index 5dadd99..842a471 100644 --- a/src/Commands/AccountCommand.php +++ b/src/Commands/AccountCommand.php @@ -27,8 +27,9 @@ public function __construct() */ public function account() { - $tz = $this->extraConfig['timezone']; - $format = $this->extraConfig['format']; + $extraConfig = $this->cloudapiService->getExtraConfig(); + $tz = $extraConfig['timezone']; + $format = $extraConfig['format']; $timezone = new \DateTimeZone($tz); $account = $this->accountAdapter->get(); diff --git a/src/Commands/AcquiaCommand.php b/src/Commands/AcquiaCommand.php index b009c21..f14dbaa 100644 --- a/src/Commands/AcquiaCommand.php +++ b/src/Commands/AcquiaCommand.php @@ -22,7 +22,6 @@ use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Helper\TableStyle; - /** * Class AcquiaCommand * @package AcquiaCli\Commands diff --git a/src/Commands/CodeCommand.php b/src/Commands/CodeCommand.php index 50ce14a..e63122f 100644 --- a/src/Commands/CodeCommand.php +++ b/src/Commands/CodeCommand.php @@ -61,6 +61,7 @@ public function code(Code $codeAdapter, $uuid, $match = null) * @aliases c:d */ public function codeDeploy( + Code $codeAdapter, $uuid, $environmentFrom, $environmentTo @@ -85,7 +86,7 @@ public function codeDeploy( ) ); - $response = $this->codeAdapter->deploy($environmentFrom->uuid, $environmentTo->uuid); + $response = $codeAdapter->deploy($environmentFrom->uuid, $environmentTo->uuid); $this->waitForNotification($response); } @@ -99,7 +100,7 @@ public function codeDeploy( * @command code:switch * @aliases c:s */ - public function codeSwitch($uuid, $environment, $branch) + public function codeSwitch(Code $codeAdapter, $uuid, $environment, $branch) { if (!$this->confirm( sprintf( @@ -115,7 +116,7 @@ public function codeSwitch($uuid, $environment, $branch) $this->say(sprintf('Switching %s enviroment to %s branch', $environment->label, $branch)); - $response = $this->codeAdapter->switch($environment->uuid, $branch); + $response = $codeAdapter->switch($environment->uuid, $branch); $this->waitForNotification($response); } } diff --git a/src/Commands/DbCommand.php b/src/Commands/DbCommand.php index c1c1f7f..48e7ef5 100644 --- a/src/Commands/DbCommand.php +++ b/src/Commands/DbCommand.php @@ -128,11 +128,6 @@ public function dbCopy($uuid, $environmentFrom, $environmentTo, $dbName) ) )) { $this->backupAndMoveDbs($uuid, $environmentFrom, $environmentTo, $dbName); - - // $this->backupDb($uuid, $environmentTo, $database); - // $this->say(sprintf('Copying database (%s) from %s to %s', $dbName, $environmentFrom->label, $environmentTo->label)); - // $response = $this->databaseAdapter->copy($environmentFrom->uuid, $dbName, $environmentTo->uuid); - // $this->waitForNotification($response); } } diff --git a/src/Commands/DeployCommand.php b/src/Commands/DeployCommand.php index 6554149..7861259 100644 --- a/src/Commands/DeployCommand.php +++ b/src/Commands/DeployCommand.php @@ -27,7 +27,7 @@ public function deployPrepare($uuid, $environmentTo, $environmentFrom = null) } if ($environmentFrom === null) { - $environmentFrom = $this->getEnvironmentFromEnvironmentName($uuid, 'prod'); + $environmentFrom = $this->cloudapiService->getEnvironment($uuid, 'prod'); } $this->backupAndMoveDbs($uuid, $environmentFrom, $environmentTo); diff --git a/src/Commands/EnvironmentsCommand.php b/src/Commands/EnvironmentsCommand.php index e2b95a3..b359dde 100644 --- a/src/Commands/EnvironmentsCommand.php +++ b/src/Commands/EnvironmentsCommand.php @@ -176,10 +176,11 @@ protected function renderEnvironmentInfo(EnvironmentResponse $environment, Serve * @command environment:rename * @alias env:rename,e:rename */ - public function environmentRename($uuid, $environment, $name) + public function environmentRename(Environments $environmentsAdapter, $uuid, $environment, $name) { + $environment = $this->cloudapiService->getEnvironment($uuid, $environment); $this->say(sprintf('Renaming %s to %s', $environment->label, $name)); - $environments = $this->environmentsAdapter->rename($environment->uuid, $name); + $environments = $environmentsAdapter->rename($environment->uuid, $name); } /** @@ -191,10 +192,11 @@ public function environmentRename($uuid, $environment, $name) * @command environment:delete * @alias env:delete,e:d,environment:remove,env:remove */ - public function environmentDelete($uuid, $environment) + public function environmentDelete(Environments $environmentsAdapter, $uuid, $environment) { + $environment = $this->cloudapiService->getEnvironment($uuid, $environment); if ($this->confirm("Are you sure you want to delete this environment?")) { - $response = $this->environmentsAdapter->delete($environment->uuid); + $response = $environmentsAdapter->delete($environment->uuid); $this->waitForNotification($response); } } diff --git a/src/Commands/LivedevCommand.php b/src/Commands/LivedevCommand.php index 746858b..98fae2c 100644 --- a/src/Commands/LivedevCommand.php +++ b/src/Commands/LivedevCommand.php @@ -22,6 +22,7 @@ class LivedevCommand extends EnvironmentsCommand */ public function acquiaLivedevEnable(Environments $environmentsAdapter, $uuid, $environment) { + $environment = $this->cloudapiService->getEnvironment($uuid, $environment); $this->say(sprintf('Enabling livedev for %s environment', $environment->label)); $environmentsAdapter->enableLiveDev($environment->uuid); } @@ -36,6 +37,7 @@ public function acquiaLivedevEnable(Environments $environmentsAdapter, $uuid, $e */ public function acquiaLivedevDisable(Environments $environmentsAdapter, $uuid, $environment) { + $environment = $this->cloudapiService->getEnvironment($uuid, $environment); if ($this->confirm('Are you sure you want to disable livedev? Uncommitted work will be lost.')) { $this->say(sprintf('Disabling livedev for %s environment', $environment->label)); $environmentsAdapter->disableLiveDev($environment->uuid); diff --git a/src/Commands/NotificationsCommand.php b/src/Commands/NotificationsCommand.php index 9afb16a..293db9d 100644 --- a/src/Commands/NotificationsCommand.php +++ b/src/Commands/NotificationsCommand.php @@ -52,8 +52,10 @@ public function notificationList($uuid, $limit = 50, $filter = null, $sort = '~c $table = new Table($output); $table->setHeaders(['UUID', 'Created', 'Name', 'Status']); - $tz = $this->extraConfig['timezone']; - $format = $this->extraConfig['format']; + $extraConfig = $this->cloudapiService->getExtraConfig(); + + $tz = $extraConfig['timezone']; + $format = $extraConfig['format']; $timezone = new \DateTimeZone($tz); foreach ($notifications as $notification) { @@ -87,8 +89,9 @@ public function notificationList($uuid, $limit = 50, $filter = null, $sort = '~c public function notificationInfo($uuid, $notificationUuid) { - $tz = $this->extraConfig['timezone']; - $format = $this->extraConfig['format']; + $extraConfig = $this->cloudapiService->getExtraConfig(); + $tz = $extraConfig['timezone']; + $format = $extraConfig['format']; $timezone = new \DateTimeZone($tz); $notification = $this->notificationsAdapter->get($notificationUuid); diff --git a/src/Commands/ProductionModeCommand.php b/src/Commands/ProductionModeCommand.php index 528b61a..4d4492b 100644 --- a/src/Commands/ProductionModeCommand.php +++ b/src/Commands/ProductionModeCommand.php @@ -22,13 +22,15 @@ class ProductionModeCommand extends EnvironmentsCommand * @command productionmode:enable * @aliases pm:enable */ - public function productionModeEnable($uuid, $environment) + public function productionModeEnable(Environments $environmentsAdapter, $uuid, $environment) { + $environment = $this->cloudapiService->getEnvironment($uuid, $environment); + if ('prod' !== $environment->name) { throw new \Exception('Production mode may only be enabled/disabled on the prod environment.'); } $this->say(sprintf('Enabling production mode for %s environment', $environment->label)); - $this->environmentsAdapter->enableProductionMode($environment->uuid); + $environmentsAdapter->enableProductionMode($environment->uuid); } /** @@ -41,15 +43,17 @@ public function productionModeEnable($uuid, $environment) * @command productionmode:disable * @aliases pm:disable */ - public function productionModeDisable($uuid, $environment) + public function productionModeDisable(Environments $environmentsAdapter, $uuid, $environment) { + $environment = $this->cloudapiService->getEnvironment($uuid, $environment); + if ('prod' !== $environment->name) { throw new \Exception('Production mode may only be enabled/disabled on the prod environment.'); } if ($this->confirm('Are you sure you want to disable production mode?')) { $this->say(sprintf('Disabling production mode for %s environment', $environment->label)); - $this->environmentsAdapter->disableProductionMode($environment->uuid); + $environmentsAdapter->disableProductionMode($environment->uuid); } } } diff --git a/src/Config.php b/src/Config.php index 729f299..ac795e5 100644 --- a/src/Config.php +++ b/src/Config.php @@ -2,7 +2,6 @@ namespace AcquiaCli; - use Consolidation\Config\ConfigInterface; use Robo\Config\Config as RoboConfig; use Robo\Config\GlobalOptionDefaultValuesInterface; @@ -10,7 +9,6 @@ use Consolidation\Config\Loader\ConfigProcessor; use Consolidation\Config\Loader\YamlConfigLoader; - /** * Class Config * @package AcquiaCli @@ -36,6 +34,6 @@ public function __construct($root) $this->set('config.global', $globalConfig); // $this->set('config.root', $root); - return $this; + // return $this; } } diff --git a/src/Injector/AcquiaCliInjector.php b/src/Injector/AcquiaCliInjector.php index d88b72e..3749c0c 100644 --- a/src/Injector/AcquiaCliInjector.php +++ b/src/Injector/AcquiaCliInjector.php @@ -10,10 +10,15 @@ use AcquiaCloudApi\Endpoints\Databases; use AcquiaCloudApi\Endpoints\Servers; use AcquiaCloudApi\Endpoints\Domains; +use AcquiaCloudApi\Endpoints\Code; class AcquiaCliInjector implements ParameterInjector { + protected $config; + protected $cloudapi; + protected $client; + public function __construct() { $this->config = \Robo\Robo::config(); @@ -38,6 +43,8 @@ public function get(CommandData $commandData, $interfaceName) return new Servers($this->client); case 'AcquiaCloudApi\Endpoints\Domains': return new Domains($this->client); + case 'AcquiaCloudApi\Endpoints\Code': + return new Code($this->client); } return null; diff --git a/tests/Commands/DbBackupCommandTest.php b/tests/Commands/DbBackupCommandTest.php index b11a52b..78c2a25 100644 --- a/tests/Commands/DbBackupCommandTest.php +++ b/tests/Commands/DbBackupCommandTest.php @@ -41,6 +41,14 @@ public function dbBackupProvider() $createBackupText = '> Backing up DB (database1) on Mock Env > Backing up DB (database2) on Mock Env'; + $dbLink = sprintf( + '%s/environments/%s/databases/%s/backups/%s/actions/download', + '> https://cloud.acquia.com/api', + 'bfcc7ad1-f987-41b8-9ea5-f26f0ef3838a', + 'dbName', + 1234 + ); + return [ [ ['database:backup:restore', 'uuid', 'environment', 'dbName', 1234], @@ -59,7 +67,7 @@ public function dbBackupProvider() [ ['database:backup:link', 'uuid', 'environment', 'dbName', 1234], 'DatabaseBackups/restoreDatabaseBackup.json', - '> https://cloud.acquia.com/api/environments/bfcc7ad1-f987-41b8-9ea5-f26f0ef3838a/databases/dbName/backups/1234/actions/download' . PHP_EOL + $dbLink . PHP_EOL ], ]; }