Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 40 additions & 26 deletions tests/Commands/AccountCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,54 @@
namespace AcquiaCli\Tests\Commands;

use AcquiaCli\Tests\AcquiaCliTestCase;
use Symfony\Component\Console\Tester\CommandTester;
use AcquiaCli\Tests\Traits\CommandTesterTrait;
use AcquiaCli\Commands\AccountCommand;

class AccountCommandTest extends AcquiaCliTestCase
{
use CommandTesterTrait;

// public function testDownloadDrushCommands()
// {
// $command = ['drush:aliases'];
// $actualResponse = $this->execute($command);

// $this->assertEquals(
// preg_match(
// '@> Acquia Cloud Drush Aliases archive downloaded to ((\S+)AcquiaDrushAliases(\w+).sql.gz)@',
// $actualResponse, $matches),
// 1
// );

// $this->assertStringStartsWith('> Acquia Cloud Drush Aliases archive downloaded to ', $actualResponse);
// $this->assertStringContainsString(sys_get_temp_dir(), $matches[2]);

// $path = sprintf(
// '%s/vendor/typhonius/acquia-php-sdk-v2/tests/Fixtures/Endpoints/%s',
// dirname(dirname(__DIR__)),
// 'Account/getDrushAliases.dat'
// );
// $this->assertFileExists($path);
// $contents = file_get_contents($path);
// }
public function setUp(): void
{
$this->setupCommandTester(AccountCommand::class);
}

public function testDownloadDrushCommands()
{

list($actualResponse, $statusCode) = $this->executeCommand('drush:aliases');

$this->assertEquals(
preg_match(
'@> Acquia Cloud Drush Aliases archive downloaded to ((\S+)AcquiaDrushAliases\w+\.tar\.gz).*@',
$actualResponse,
$matches
),
1
);

$this->assertStringStartsWith('> Acquia Cloud Drush Aliases archive downloaded to ', $actualResponse);
$this->assertStringContainsString(sys_get_temp_dir(), $matches[2]);

$testFilePath = sprintf(
'%s/vendor/typhonius/acquia-php-sdk-v2/tests/Fixtures/Endpoints/%s',
dirname(dirname(__DIR__)),
'Account/getDrushAliases.dat'
);
$this->assertFileExists($testFilePath);
$testFileContents = file_get_contents($testFilePath);
$downloadedFile = $matches[1];
$downloadedFileContents = file_get_contents($downloadedFile);
$this->assertEquals($testFileContents, $downloadedFileContents);
}

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

Expand All @@ -53,8 +67,8 @@ public function accountProvider()

return [
[
['account'],
$infoResponse . PHP_EOL
'account',
$infoResponse
]
];
}
Expand Down
42 changes: 28 additions & 14 deletions tests/Commands/ApplicationCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,24 @@
namespace AcquiaCli\Tests\Commands;

use AcquiaCli\Tests\AcquiaCliTestCase;
use AcquiaCli\Tests\Traits\CommandTesterTrait;
use AcquiaCli\Commands\ApplicationsCommand;

class ApplicationCommandTest extends AcquiaCliTestCase
{
use CommandTesterTrait;

public function setUp(): void
{
$this->setupCommandTester(ApplicationsCommand::class);
}

/**
* @dataProvider applicationProvider
*/
public function testApplicationCommands($command, $expected)
public function testApplicationCommands($command, $arguments, $expected)
{
$actualResponse = $this->execute($command);
list($actualResponse, $statusCode) = $this->executeCommand($command, $arguments);
$this->assertSame($expected, $actualResponse);
}

Expand Down Expand Up @@ -55,28 +63,34 @@ public function applicationProvider()

return [
[
['application:list'],
$getAllApplications . PHP_EOL
'application:list',
[],
$getAllApplications
],
[
['application:info', 'devcloud:devcloud2'],
$applicationInfo . PHP_EOL
'application:info',
['uuid' => 'devcloud:devcloud2'],
$applicationInfo
],
[
['application:tags', 'devcloud:devcloud2'],
$getTags . PHP_EOL
'application:tags',
['uuid' => 'devcloud:devcloud2'],
$getTags
],
[
['application:tag:create', 'devcloud:devcloud2', 'name', 'color'],
'> Creating application tag name:color' . PHP_EOL
'application:tag:create',
['uuid' => 'devcloud:devcloud2', 'name' => 'name', 'color' => 'color'],
'> Creating application tag name:color'
],
[
['application:tag:delete', 'devcloud:devcloud2', 'name'],
'> Deleting application tag name' . PHP_EOL
'application:tag:delete',
['uuid' => 'devcloud:devcloud2', 'name' => 'name'],
'> Deleting application tag name'
],
[
['application:rename', 'devcloud:devcloud2', 'foobar'],
'> Renaming application to foobar' . PHP_EOL
'application:rename',
['uuid' => 'devcloud:devcloud2', 'name' => 'foobar'],
'> Renaming application to foobar'
]
];
}
Expand Down
17 changes: 13 additions & 4 deletions tests/Commands/CacheClearCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,24 @@

use AcquiaCli\Tests\AcquiaCliTestCase;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use AcquiaCli\Tests\Traits\CommandTesterTrait;
use AcquiaCli\Commands\CacheClearCommand;

class CacheClearCommandTest extends AcquiaCliTestCase
{
use CommandTesterTrait;

public function setUp(): void
{
$this->setupCommandTester(CacheClearCommand::class);
}

public function testClearCache()
{
// Run a basic command to fill the cache.
$command = ['database:backup:list', 'devcloud:devcloud2', 'dev'];
$this->execute($command);
$command = 'database:backup:list';
$arguments = ['uuid' => 'devcloud:devcloud2', 'environment' => 'dev'];
list($actualResponse, $statusCode) = $this->executeCommand($command, $arguments);

// Ensure the items exist in the cache before we attempt a clear.
$cache = new FilesystemAdapter('acquiacli');
Expand All @@ -21,8 +30,8 @@ public function testClearCache()
$this->assertTrue($cache->hasItem('environment.a47ac10b-58cc-4372-a567-0e02b2c3d470.dev'));

// Clear the cache.
$command = ['cache:clear'];
$this->execute($command);
$command = 'cache:clear';
list($actualResponse, $statusCode) = $this->executeCommand($command);

$this->assertFalse($cache->hasItem('application.devcloud.devcloud2'));
$this->assertFalse($cache->hasItem('environment.a47ac10b-58cc-4372-a567-0e02b2c3d470.dev'));
Expand Down
37 changes: 25 additions & 12 deletions tests/Commands/CodeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,24 @@
namespace AcquiaCli\Tests\Commands;

use AcquiaCli\Tests\AcquiaCliTestCase;
use AcquiaCli\Tests\Traits\CommandTesterTrait;
use AcquiaCli\Commands\CodeCommand;

class CodeCommandTest extends AcquiaCliTestCase
{
use CommandTesterTrait;

public function setUp(): void
{
$this->setupCommandTester(CodeCommand::class);
}

/**
* @dataProvider codeProvider
*/
public function testCodeCommands($command, $expected)
public function testCodeCommands($command, $arguments, $expected)
{
$actualResponse = $this->execute($command);
list($actualResponse, $statusCode) = $this->executeCommand($command, $arguments);
$this->assertSame($expected, $actualResponse);
}

Expand Down Expand Up @@ -44,24 +52,29 @@ public function codeProvider()

return [
[
['code:deploy', 'devcloud:devcloud2', 'dev', 'test'],
$codeDeploy . PHP_EOL
'code:deploy',
['uuid' => 'devcloud:devcloud2', 'environmentFrom' => 'dev', 'environmentTo' => 'test'],
$codeDeploy
],
[
['code:deploy', 'devcloud:devcloud2', 'dev', 'test', '--no-backup'],
$codeDeployNoBackup . PHP_EOL
'code:deploy',
['uuid' => 'devcloud:devcloud2', 'environmentFrom' => 'dev', 'environmentTo' => 'test', '--no-backup' => true],
$codeDeployNoBackup
],
[
['code:list', 'devcloud:devcloud2'],
$codeList . PHP_EOL
'code:list',
['uuid' => 'devcloud:devcloud2'],
$codeList
],
[
['code:switch', 'devcloud:devcloud2', 'prod', 'master'],
$codeSwitch . PHP_EOL
'code:switch',
['uuid' => 'devcloud:devcloud2', 'environment' => 'prod', 'branch' => 'master'],
$codeSwitch
],
[
['code:switch', 'devcloud:devcloud2', 'prod', 'master', '--no-backup'],
$codeSwitchNoBackup . PHP_EOL
'code:switch',
['uuid' => 'devcloud:devcloud2', 'environment' => 'prod', 'branch' => 'master', '--no-backup' => true],
$codeSwitchNoBackup
]
];
}
Expand Down
42 changes: 28 additions & 14 deletions tests/Commands/CronCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,24 @@
namespace AcquiaCli\Tests\Commands;

use AcquiaCli\Tests\AcquiaCliTestCase;
use AcquiaCli\Tests\Traits\CommandTesterTrait;
use AcquiaCli\Commands\CronCommand;

class CronCommandTest extends AcquiaCliTestCase
{
use CommandTesterTrait;

public function setUp(): void
{
$this->setupCommandTester(CronCommand::class);
}

/**
* @dataProvider cronProvider
*/
public function testCronCommands($command, $expected)
public function testCronCommands($command, $arguments, $expected)
{
$actualResponse = $this->execute($command);
list($actualResponse, $statusCode) = $this->executeCommand($command, $arguments);
$this->assertSame($expected, $actualResponse);
}

Expand Down Expand Up @@ -42,28 +50,34 @@ public function cronProvider()

return [
[
['cron:create', 'devcloud:devcloud2', 'dev', 'commandString', 'frequency', 'label'],
'> Adding new cron task on dev environment' . PHP_EOL
'cron:create',
['uuid' => 'devcloud:devcloud2', 'environment' => 'dev', 'commandString' => 'commandString', 'frequency' => 'frequency', 'label' => 'label'],
'> Adding new cron task on dev environment'
],
[
['cron:delete', 'devcloud:devcloud2', 'dev', 'cronId'],
'> Deleting cron task cronId from Dev' . PHP_EOL
'cron:delete',
['uuid' => 'devcloud:devcloud2', 'environment' => 'dev', 'cronId' => 'cronId'],
'> Deleting cron task cronId from Dev'
],
[
['cron:disable', 'devcloud:devcloud2', 'dev', 'cronId'],
'> Disabling cron task cronId on dev environment' . PHP_EOL
'cron:disable',
['uuid' => 'devcloud:devcloud2', 'environment' => 'dev', 'cronId' => 'cronId'],
'> Disabling cron task cronId on dev environment'
],
[
['cron:enable', 'devcloud:devcloud2', 'dev', 'cronId'],
'> Enabling cron task cronId on dev environment' . PHP_EOL
'cron:enable',
['uuid' => 'devcloud:devcloud2', 'environment' => 'dev', 'cronId' => 'cronId'],
'> Enabling cron task cronId on dev environment'
],
[
['cron:info', 'devcloud:devcloud2', 'dev', 'cronId'],
$cronInfo . PHP_EOL
'cron:info',
['uuid' => 'devcloud:devcloud2', 'environment' => 'dev', 'cronId' => 'cronId'],
$cronInfo
],
[
['cron:list', 'devcloud:devcloud2', 'dev'],
$cronList . PHP_EOL
'cron:list',
['uuid' => 'devcloud:devcloud2', 'environment' => 'dev'],
$cronList
]
];
}
Expand Down
Loading