Skip to content

Commit

Permalink
Fixes tests/stan.
Browse files Browse the repository at this point in the history
  • Loading branch information
typhonius committed Mar 21, 2020
1 parent cc475f0 commit 3cf28e5
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 36 deletions.
25 changes: 20 additions & 5 deletions src/AcquiaCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions src/CloudApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -51,7 +51,7 @@ public function createClient()
* @param string $uuid
* @param string $environment
* @return EnvironmentResponse
* @throws Exception
* @throws \Exception
*/
public function getEnvironment($uuid, $environment)
{
Expand All @@ -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()
Expand Down
5 changes: 3 additions & 2 deletions src/Commands/AccountCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion src/Commands/AcquiaCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Helper\TableStyle;


/**
* Class AcquiaCommand
* @package AcquiaCli\Commands
Expand Down
7 changes: 4 additions & 3 deletions src/Commands/CodeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function code(Code $codeAdapter, $uuid, $match = null)
* @aliases c:d
*/
public function codeDeploy(
Code $codeAdapter,
$uuid,
$environmentFrom,
$environmentTo
Expand All @@ -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);
}
Expand All @@ -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(
Expand All @@ -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);
}
}
5 changes: 0 additions & 5 deletions src/Commands/DbCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Commands/DeployCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 6 additions & 4 deletions src/Commands/EnvironmentsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/Commands/LivedevCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
Expand Down
11 changes: 7 additions & 4 deletions src/Commands/NotificationsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 8 additions & 4 deletions src/Commands/ProductionModeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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);
}
}
}
4 changes: 1 addition & 3 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

namespace AcquiaCli;


use Consolidation\Config\ConfigInterface;
use Robo\Config\Config as RoboConfig;
use Robo\Config\GlobalOptionDefaultValuesInterface;

use Consolidation\Config\Loader\ConfigProcessor;
use Consolidation\Config\Loader\YamlConfigLoader;


/**
* Class Config
* @package AcquiaCli
Expand All @@ -36,6 +34,6 @@ public function __construct($root)
$this->set('config.global', $globalConfig);
// $this->set('config.root', $root);

return $this;
// return $this;
}
}
7 changes: 7 additions & 0 deletions src/Injector/AcquiaCliInjector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand Down
10 changes: 9 additions & 1 deletion tests/Commands/DbBackupCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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
],
];
}
Expand Down

0 comments on commit 3cf28e5

Please sign in to comment.