Skip to content

Commit

Permalink
Adds tests for pm, account, environments
Browse files Browse the repository at this point in the history
  • Loading branch information
typhonius committed Mar 8, 2020
1 parent 9e62a20 commit 557aef3
Show file tree
Hide file tree
Showing 14 changed files with 310 additions and 21 deletions.
4 changes: 4 additions & 0 deletions src/AcquiaCli.php
Expand Up @@ -48,6 +48,7 @@ public function __construct(

// Create application.
$this->setConfig($config);

$application = new Application(self::NAME, $version);

$application->getDefinition()->addOptions([
Expand Down Expand Up @@ -112,6 +113,9 @@ public function getContainer($input, $output, $application, $config, $client)
'AcquiaCloudApi\Endpoints\DatabaseBackups',
new \AcquiaCli\Injector\AcquiaCliInjector
);
$parameterInjection->register('AcquiaCloudApi\Endpoints\Crons', new \AcquiaCli\Injector\AcquiaCliInjector);
$parameterInjection->register('AcquiaCloudApi\Endpoints\Account', new \AcquiaCli\Injector\AcquiaCliInjector);


return $container;
}
Expand Down
13 changes: 2 additions & 11 deletions src/Commands/AccountCommand.php
Expand Up @@ -11,28 +11,19 @@
class AccountCommand extends AcquiaCommand
{

protected $accountAdapter;

public function __construct()
{
parent::__construct();

$this->accountAdapter = new Account($this->cloudapi);
}

/**
* Gets information about the user's account.
*
* @command account
*/
public function account()
public function account(Account $accountAdapter)
{
$extraConfig = $this->cloudapiService->getExtraConfig();
$tz = $extraConfig['timezone'];
$format = $extraConfig['format'];
$timezone = new \DateTimeZone($tz);

$account = $this->accountAdapter->get();
$account = $accountAdapter->get();

$lastLogin = new \DateTime($account->last_login_at);
$lastLogin->setTimezone($timezone);
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/DrushAliasesCommand.php
Expand Up @@ -17,9 +17,9 @@ class DrushAliasesCommand extends AccountCommand
*
* @command drush:aliases
*/
public function downloadDrushAliases($options = ['install' => false])
public function downloadDrushAliases(Account $accountAdapter, $options = ['install' => false])
{
$aliases = $this->accountAdapter->getDrushAliases();
$aliases = $accountAdapter->getDrushAliases();
$drushArchive = tempnam(sys_get_temp_dir(), 'AcquiaDrushAliases') . '.tar.gz';
$this->say(sprintf('Acquia Cloud Drush Aliases archive downloaded to %s', $drushArchive));
if (file_put_contents($drushArchive, $aliases, LOCK_EX)) {
Expand Down
11 changes: 11 additions & 0 deletions src/Commands/EnvironmentsCommand.php
Expand Up @@ -151,6 +151,16 @@ protected function renderEnvironmentInfo(EnvironmentResponse $environment, Serve
'APCu',
'Sendmail Path'
]);

if (!isset($environment->configuration->php)) {
$environment->configuration = new \stdClass();
$environment->configuration->php = new \stdClass();
$environment->configuration->php->version = ' ';
$environment->configuration->php->memory_limit = ' ';
$environment->configuration->php->opcache = ' ';
$environment->configuration->php->apcu = ' ';
$environment->configuration->php->sendmail_path = ' ';
}
$environmentTable
->addRows([
[
Expand Down Expand Up @@ -196,6 +206,7 @@ public function environmentDelete(Environments $environmentsAdapter, $uuid, $env
{
$environment = $this->cloudapiService->getEnvironment($uuid, $environment);
if ($this->confirm("Are you sure you want to delete this environment?")) {
$this->say(sprintf('Deleting %s environment', $environment->label));
$response = $environmentsAdapter->delete($environment->uuid);
$this->waitForNotification($response);
}
Expand Down
11 changes: 7 additions & 4 deletions src/Commands/ProductionModeCommand.php
Expand Up @@ -24,11 +24,13 @@ class ProductionModeCommand extends EnvironmentsCommand
*/
public function productionModeEnable(Environments $environmentsAdapter, $uuid, $environment)
{
$environment = $this->cloudapiService->getEnvironment($uuid, $environment);

if ('prod' !== $environment->name) {
if ('prod' !== $environment) {
throw new \Exception('Production mode may only be enabled/disabled on the prod environment.');
}

$environment = $this->cloudapiService->getEnvironment($uuid, $environment);

$this->say(sprintf('Enabling production mode for %s environment', $environment->label));
$environmentsAdapter->enableProductionMode($environment->uuid);
}
Expand All @@ -45,12 +47,13 @@ public function productionModeEnable(Environments $environmentsAdapter, $uuid, $
*/
public function productionModeDisable(Environments $environmentsAdapter, $uuid, $environment)
{
$environment = $this->cloudapiService->getEnvironment($uuid, $environment);

if ('prod' !== $environment->name) {
if ('prod' !== $environment) {
throw new \Exception('Production mode may only be enabled/disabled on the prod environment.');
}

$environment = $this->cloudapiService->getEnvironment($uuid, $environment);

if ($this->confirm('Are you sure you want to disable production mode?')) {
$this->say(sprintf('Disabling production mode for %s environment', $environment->label));
$environmentsAdapter->disableProductionMode($environment->uuid);
Expand Down
3 changes: 3 additions & 0 deletions src/Injector/AcquiaCliInjector.php
Expand Up @@ -13,6 +13,7 @@
use AcquiaCloudApi\Endpoints\Code;
use AcquiaCloudApi\Endpoints\DatabaseBackups;
use AcquiaCloudApi\Endpoints\Crons;
use AcquiaCloudApi\Endpoints\Account;

class AcquiaCliInjector implements ParameterInjector
{
Expand Down Expand Up @@ -51,6 +52,8 @@ public function get(CommandData $commandData, $interfaceName)
return new DatabaseBackups($this->client);
case 'AcquiaCloudApi\Endpoints\Crons':
return new Crons($this->client);
case 'AcquiaCloudApi\Endpoints\Account':
return new Account($this->client);
}

return null;
Expand Down
4 changes: 3 additions & 1 deletion tests/AcquiaCliTest.php
Expand Up @@ -32,7 +32,7 @@ class AcquiaCliTest extends AcquiaCli

public function getContainer($input, $output, $application, $config, $client)
{
$container = Robo::createDefaultContainer($input, $output, $application);
$container = Robo::createDefaultContainer($input, $output, $application, $config);
$container->add('client', $client);

$container->add('cloudApi', \AcquiaCli\Tests\CloudApiTest::class)
Expand All @@ -50,13 +50,15 @@ public function getContainer($input, $output, $application, $config, $client)
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);
$parameterInjection->register(
'AcquiaCloudApi\Endpoints\DatabaseBackups',
new \AcquiaCli\Injector\AcquiaCliInjector
);
$parameterInjection->register('AcquiaCloudApi\Endpoints\Crons', new \AcquiaCli\Injector\AcquiaCliInjector);
$parameterInjection->register('AcquiaCloudApi\Endpoints\Account', new \AcquiaCli\Injector\AcquiaCliInjector);

return $container;
}
Expand Down
34 changes: 33 additions & 1 deletion tests/AcquiaCliTestCase.php
Expand Up @@ -132,6 +132,9 @@ public function sendRequestCallback($verb, $path)
public static function getFixtureMap()
{
return [
'/account' => [
'get' => 'Account/getAccount.json'
],
'/applications' => [
'get' => 'Applications/getAllApplications.json',
],
Expand Down Expand Up @@ -162,6 +165,12 @@ public static function getFixtureMap()
'/organizations/organisation/roles' => [
'post' => 'Roles/createRole.json'
],
'/applications/uuid/environments' => [
'get' => 'Environments/getAllEnvironments.json'
],
'/environments/bfcc7ad1-f987-41b8-9ea5-f26f0ef3838a' => [
'delete' => 'Environments/deleteCDEnvironment.json'
],
'/environments/bfcc7ad1-f987-41b8-9ea5-f26f0ef3838a/databases/database2/backups' => [
'get' => 'DatabaseBackups/getAllDatabaseBackups.json',
'post' => 'DatabaseBackups/createDatabaseBackup.json'
Expand Down Expand Up @@ -214,8 +223,31 @@ public static function getFixtureMap()
],
'/applications/uuid/code' => [
'get' => 'Code/getAllCode.json'
],
'/environments/bfcc7ad1-f987-41b8-9ea5-f26f0ef3838a/livedev/actions/disable' => [
'post' => 'Environments/disableLiveDev.json'
],
'/environments/bfcc7ad1-f987-41b8-9ea5-f26f0ef3838a/livedev/actions/enable' => [
'post' => 'Environments/enableLiveDev.json'
],
'/environments/24-a47ac10b-58cc-4372-a567-0e02b2c3d470/servers' => [
'get' => 'Servers/getAllServers.json'
],
'/environments/15-a47ac10b-58cc-4372-a567-0e02b2c3d470/servers' => [
'get' => 'Servers/getAllServers.json'
],
'/environments/32-a47ac10b-58cc-4372-a567-0e02b2c3d470/servers' => [
'get' => 'Servers/getAllServers.json'
],
'/environments/bfcc7ad1-f987-41b8-9ea5-f26f0ef3838a/actions/change-label' => [
'post' => 'Environments/renameEnvironment.json'
],
'/environments/bfcc7ad1-f987-41b8-9ea5-f26f0ef3838a/production-mode/actions/disable' => [
'post' => 'Environments/disableProductionMode.json'
],
'/environments/bfcc7ad1-f987-41b8-9ea5-f26f0ef3838a/production-mode/actions/enable' => [
'post' => 'Environments/disableProductionMode.json'
]



];
Expand Down
3 changes: 2 additions & 1 deletion tests/CloudApiTest.php
Expand Up @@ -15,13 +15,14 @@
class CloudApiTest extends CloudApi
{


public function __construct(Config $config, Client $client)
{
parent::__construct($config);
$this->extraConfig = $config->get('extraconfig');
$this->acquia = $config->get('acquia');

$this->setClient($client);
parent::__construct($config);
}

public function getInstance()
Expand Down
37 changes: 37 additions & 0 deletions tests/Commands/AccountCommandTest.php
@@ -0,0 +1,37 @@
<?php

namespace AcquiaCli\Tests\Commands;

use AcquiaCli\Tests\AcquiaCliTestCase;

class AccountCommandTest extends AcquiaCliTestCase
{

/**
* @dataProvider accountProvider
*/
public function testAccountInfo($command, $expected)
{
$actualResponse = $this->execute($command);
$this->assertSame($expected, $actualResponse);
}

public function accountProvider()
{

$infoResponse = <<<INFO
> Name: jane.doe
> Last login: 2017-03-29 05:07:54
> Created at: 2017-03-29 05:07:54
> Status: ✓
> TFA: ✓
INFO;

return [
[
['account'],
$infoResponse . PHP_EOL
]
];
}
}
23 changes: 22 additions & 1 deletion tests/Commands/ApplicationCommandTest.php
Expand Up @@ -27,6 +27,24 @@ public function applicationProvider()
+----------------------+--------------------------------------+--------------------+
TABLE;

// phpcs:disable Generic.Files.LineLength.TooLong
$applicationInfo = <<<TABLE
+----------------------+-----------------------------------------+-----------------+----------------------------------+-------------+
| Environment | ID | Branch/Tag | Domain(s) | Database(s) |
+----------------------+-----------------------------------------+-----------------+----------------------------------+-------------+
| Dev (dev) | 24-a47ac10b-58cc-4372-a567-0e02b2c3d470 | master | sitedev.hosted.acquia-sites.com | database1 |
| | | | example.com | database2 |
| 🔒 Production (prod) | 15-a47ac10b-58cc-4372-a567-0e02b2c3d470 | tags/01-01-2015 | siteprod.hosted.acquia-sites.com | database1 |
| | | | example.com | database2 |
| Stage (test) | 32-a47ac10b-58cc-4372-a567-0e02b2c3d470 | | sitetest.hosted.acquia-sites.com | database1 |
| | | | test.example.com | database2 |
+----------------------+-----------------------------------------+-----------------+----------------------------------+-------------+
> 🔧 Git URL: qa10@svn-3.networkdev.ahserversdev.com:qa10.git
> 💻 indicates environment in livedev mode.
> 🔒 indicates environment in production mode.
TABLE;
// phpcs:enable

$getTags = <<<TABLE
+------+--------+
| Name | Color |
Expand All @@ -39,7 +57,10 @@ public function applicationProvider()
[
['application:list'],
$getAllApplications . PHP_EOL

],
[
['application:info', 'uuid'],
$applicationInfo . PHP_EOL
],
[
['application:tags', 'uuid'],
Expand Down

0 comments on commit 557aef3

Please sign in to comment.