diff --git a/tests/Commands/AccountCommandTest.php b/tests/Commands/AccountCommandTest.php index 18055fd..24f6ee1 100644 --- a/tests/Commands/AccountCommandTest.php +++ b/tests/Commands/AccountCommandTest.php @@ -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); } @@ -53,8 +67,8 @@ public function accountProvider() return [ [ - ['account'], - $infoResponse . PHP_EOL + 'account', + $infoResponse ] ]; } diff --git a/tests/Commands/ApplicationCommandTest.php b/tests/Commands/ApplicationCommandTest.php index c4935a1..09c2722 100644 --- a/tests/Commands/ApplicationCommandTest.php +++ b/tests/Commands/ApplicationCommandTest.php @@ -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); } @@ -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' ] ]; } diff --git a/tests/Commands/CacheClearCommandTest.php b/tests/Commands/CacheClearCommandTest.php index fc374cc..98e0631 100644 --- a/tests/Commands/CacheClearCommandTest.php +++ b/tests/Commands/CacheClearCommandTest.php @@ -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'); @@ -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')); diff --git a/tests/Commands/CodeCommandTest.php b/tests/Commands/CodeCommandTest.php index ce08e6c..e5c15db 100644 --- a/tests/Commands/CodeCommandTest.php +++ b/tests/Commands/CodeCommandTest.php @@ -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); } @@ -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 ] ]; } diff --git a/tests/Commands/CronCommandTest.php b/tests/Commands/CronCommandTest.php index 006fbbc..01e5288 100644 --- a/tests/Commands/CronCommandTest.php +++ b/tests/Commands/CronCommandTest.php @@ -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); } @@ -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 ] ]; } diff --git a/tests/Commands/DbBackupCommandTest.php b/tests/Commands/DbBackupCommandTest.php index ef9a72e..2ca0908 100644 --- a/tests/Commands/DbBackupCommandTest.php +++ b/tests/Commands/DbBackupCommandTest.php @@ -3,14 +3,23 @@ namespace AcquiaCli\Tests\Commands; use AcquiaCli\Tests\AcquiaCliTestCase; +use AcquiaCli\Tests\Traits\CommandTesterTrait; +use AcquiaCli\Commands\DbBackupCommand; class DbBackupCommandTest extends AcquiaCliTestCase { + use CommandTesterTrait; + + public function setUp(): void + { + $this->setupCommandTester(DbBackupCommand::class); + } public function testDownloadDatabaseBackupsCommands() { - $command = ['database:backup:download', 'devcloud:devcloud2', 'dev', 'database2']; - $actualResponse = $this->execute($command); + $command = 'database:backup:download'; + $arguments = ['uuid' => 'devcloud:devcloud2', 'environment' => 'dev', 'dbName' => 'database2']; + list($actualResponse, $statusCode) = $this->executeCommand($command, $arguments); $this->assertEquals( preg_match( @@ -27,16 +36,16 @@ public function testDownloadDatabaseBackupsCommands() public function testDownloadDatabaseBackupsCommandsWithOptions() { - $command = [ - 'database:backup:download', - 'devcloud:devcloud2', - 'dev', - 'database2', - '--backup=1', - '--filename=foo', - '--path=/tmp' + $command = 'database:backup:download'; + $arguments = [ + 'uuid' => 'devcloud:devcloud2', + 'environment' => 'dev', + 'dbName' => 'database2', + '--backup' => '1', + '--filename' => 'foo', + '--path' => '/tmp' ]; - $actualResponse = $this->execute($command); + list($actualResponse, $statusCode) = $this->executeCommand($command, $arguments); $this->assertEquals( preg_match( @@ -54,9 +63,9 @@ public function testDownloadDatabaseBackupsCommandsWithOptions() /** * @dataProvider dbBackupProvider */ - public function testDbBackupCommands($command, $expected) + public function testDbBackupCommands($command, $arguments, $expected) { - $actualResponse = $this->execute($command); + list($actualResponse, $statusCode) = $this->executeCommand($command, $arguments); $this->assertSame($expected, $actualResponse); } @@ -97,32 +106,39 @@ public function dbBackupProvider() return [ [ - ['database:backup:restore', 'devcloud:devcloud2', 'dev', 'dbName', '1234'], - '> Restoring backup 1234 to dbName on Dev' . PHP_EOL + 'database:backup:restore', + ['uuid' => 'devcloud:devcloud2', 'environment' => 'dev', 'dbName' => 'dbName', 'backupId' => '1234'], + '> Restoring backup 1234 to dbName on Dev' ], [ - ['database:backup:all', 'devcloud:devcloud2', 'dev'], - $createBackupAllText . PHP_EOL + 'database:backup:all', + ['uuid' => 'devcloud:devcloud2', 'environment' => 'dev'], + $createBackupAllText ], [ - ['database:backup', 'devcloud:devcloud2', 'dev', 'database1'], - $createBackupText . PHP_EOL + 'database:backup', + ['uuid' => 'devcloud:devcloud2', 'environment' => 'dev', 'dbName' => 'database1'], + $createBackupText ], [ - ['database:backup:list', 'devcloud:devcloud2', 'dev'], - $dbBackupList . PHP_EOL + 'database:backup:list', + ['uuid' => 'devcloud:devcloud2', 'environment' => 'dev'], + $dbBackupList ], [ - ['database:backup:list', 'devcloud:devcloud2', 'dev', 'dbName'], - $dbBackupList . PHP_EOL + 'database:backup:list', + ['uuid' => 'devcloud:devcloud2', 'environment' => 'dev', 'dbName' => 'dbName'], + $dbBackupList ], [ - ['database:backup:link', 'devcloud:devcloud2', 'dev', 'dbName', '1234'], - $dbLink . PHP_EOL + 'database:backup:link', + ['uuid' => 'devcloud:devcloud2', 'environment' => 'dev', 'dbName' => 'dbName', 'backupId' => '1234'], + $dbLink ], [ - ['database:backup:delete', 'devcloud:devcloud2', 'dev', 'dbName', '1234'], - '> Deleting backup 1234 to dbName on Dev' . PHP_EOL + 'database:backup:delete', + ['uuid' => 'devcloud:devcloud2', 'environment' => 'dev', 'dbName' => 'dbName', 'backupId' => '1234'], + '> Deleting backup 1234 to dbName on Dev' ], ]; } diff --git a/tests/Commands/DbCommandTest.php b/tests/Commands/DbCommandTest.php index 26aab13..bba152d 100644 --- a/tests/Commands/DbCommandTest.php +++ b/tests/Commands/DbCommandTest.php @@ -3,16 +3,24 @@ namespace AcquiaCli\Tests\Commands; use AcquiaCli\Tests\AcquiaCliTestCase; +use AcquiaCli\Tests\Traits\CommandTesterTrait; +use AcquiaCli\Commands\DbCommand; class DbCommandTest extends AcquiaCliTestCase { + use CommandTesterTrait; + + public function setUp(): void + { + $this->setupCommandTester(DbCommand::class); + } /** * @dataProvider dbProvider */ - public function testDbCommands($command, $expected) + public function testDbCommands($command, $arguments, $expected) { - $actualResponse = $this->execute($command); + list($actualResponse, $statusCode) = $this->executeCommand($command, $arguments); $this->assertSame($expected, $actualResponse); } @@ -42,36 +50,44 @@ public function dbProvider() return [ [ - ['database:create', 'devcloud:devcloud2', 'dbName'], - '> Creating database (dbName)' . PHP_EOL + 'database:create', + ['uuid' => 'devcloud:devcloud2', 'dbName' => 'dbName'], + '> Creating database (dbName)' ], [ - ['database:delete', 'devcloud:devcloud2', 'dbName'], - '> Deleting database (dbName)' . PHP_EOL + 'database:delete', + ['uuid' => 'devcloud:devcloud2', 'dbName' => 'dbName'], + '> Deleting database (dbName)' ], [ - ['database:list', 'devcloud:devcloud2'], - $dbTable . PHP_EOL + 'database:list', + ['uuid' => 'devcloud:devcloud2'], + $dbTable ], [ - ['database:truncate', 'devcloud:devcloud2', 'dbName'], - '> Truncate database (dbName)' . PHP_EOL + 'database:truncate', + ['uuid' => 'devcloud:devcloud2', 'dbName' => 'dbName'], + '> Truncate database (dbName)' ], [ - ['database:copy', 'devcloud:devcloud2', 'test', 'dev', 'dbName'], - $dbCopy . PHP_EOL + 'database:copy', + ['uuid' => 'devcloud:devcloud2', 'environmentFrom' => 'test', 'environmentTo' => 'dev', 'dbName' => 'dbName'], + $dbCopy ], [ - ['database:copy:all', 'devcloud:devcloud2', 'test', 'dev'], - $dbCopy . PHP_EOL + 'database:copy:all', + ['uuid' => 'devcloud:devcloud2', 'environmentFrom' => 'test', 'environmentTo' => 'dev'], + $dbCopy ], [ - ['database:copy', 'devcloud:devcloud2', 'test', 'dev', 'dbName', '--no-backup'], - $dbCopyNoBackup . PHP_EOL + 'database:copy', + ['uuid' => 'devcloud:devcloud2', 'environmentFrom' => 'test', 'environmentTo' => 'dev', 'dbName' => 'dbName', '--no-backup' => true], + $dbCopyNoBackup ], [ - ['database:copy:all', 'devcloud:devcloud2', 'test', 'dev', '--no-backup'], - $dbCopyNoBackup . PHP_EOL + 'database:copy:all', + ['uuid' => 'devcloud:devcloud2', 'environmentFrom' => 'test', 'environmentTo' => 'dev', '--no-backup' => true], + $dbCopyNoBackup ] ]; } diff --git a/tests/Commands/DeployCommandTest.php b/tests/Commands/DeployCommandTest.php index 50d6c04..a28f984 100644 --- a/tests/Commands/DeployCommandTest.php +++ b/tests/Commands/DeployCommandTest.php @@ -3,16 +3,24 @@ namespace AcquiaCli\Tests\Commands; use AcquiaCli\Tests\AcquiaCliTestCase; +use AcquiaCli\Tests\Traits\CommandTesterTrait; +use AcquiaCli\Commands\DeployCommand; class DeployCommandTest extends AcquiaCliTestCase { + use CommandTesterTrait; + + public function setUp(): void + { + $this->setupCommandTester(DeployCommand::class); + } /** * @dataProvider deployProvider */ - public function testDeployInfo($command, $expected) + public function testDeployInfo($command, $arguments, $expected) { - $actualResponse = $this->execute($command); + list($actualResponse, $statusCode) = $this->executeCommand($command, $arguments); $this->assertSame($expected, $actualResponse); } @@ -41,16 +49,19 @@ public function deployProvider() return [ [ - ['deploy:prepare', 'devcloud:devcloud2', 'dev', 'prod'], - $deployResponseDev . PHP_EOL + 'deploy:prepare', + ['uuid' => 'devcloud:devcloud2', 'environmentTo' => 'dev', 'environmentFrom' => 'prod'], + $deployResponseDev ], [ - ['deploy:prepare', 'devcloud:devcloud2', 'test'], - $deployResponseTest . PHP_EOL + 'deploy:prepare', + ['uuid' => 'devcloud:devcloud2', 'environmentTo' => 'test'], + $deployResponseTest ], [ - ['deploy:prepare', 'devcloud:devcloud2', 'prod'], - $deployResponseProd . PHP_EOL + 'deploy:prepare', + ['uuid' => 'devcloud:devcloud2', 'environmentTo' => 'prod'], + $deployResponseProd ] ]; } diff --git a/tests/Commands/DomainsCommandTest.php b/tests/Commands/DomainsCommandTest.php index 4f7f8ca..28e868d 100644 --- a/tests/Commands/DomainsCommandTest.php +++ b/tests/Commands/DomainsCommandTest.php @@ -3,16 +3,24 @@ namespace AcquiaCli\Tests\Commands; use AcquiaCli\Tests\AcquiaCliTestCase; +use AcquiaCli\Tests\Traits\CommandTesterTrait; +use AcquiaCli\Commands\DomainCommand; class DomainsCommandTest extends AcquiaCliTestCase { + use CommandTesterTrait; + + public function setUp(): void + { + $this->setupCommandTester(DomainCommand::class); + } /** * @dataProvider domainsProvider */ - public function testDomainsCommands($command, $expected) + public function testDomainsCommands($command, $arguments, $expected) { - $actualResponse = $this->execute($command); + list($actualResponse, $statusCode) = $this->executeCommand($command, $arguments); $this->assertSame($expected, $actualResponse); } @@ -45,32 +53,39 @@ public function domainsProvider() return [ [ - ['domain:create', 'devcloud:devcloud2', 'dev', 'domain'], - '> Adding domain to environment Dev' . PHP_EOL + 'domain:create', + ['uuid' => 'devcloud:devcloud2', 'environment' => 'dev', 'domain' => 'domain'], + '> Adding domain to environment Dev' ], [ - ['domain:delete', 'devcloud:devcloud2', 'test', 'domain'], - '> Removing domain from environment Stage' . PHP_EOL + 'domain:delete', + ['uuid' => 'devcloud:devcloud2', 'environment' => 'test', 'domain' => 'domain'], + '> Removing domain from environment Stage' ], [ - ['domain:info', 'devcloud:devcloud2', 'prod', 'domain'], - $domainInfo . PHP_EOL + 'domain:info', + ['uuid' => 'devcloud:devcloud2', 'environment' => 'prod', 'domain' => 'domain'], + $domainInfo ], [ - ['domain:list', 'devcloud:devcloud2', 'dev'], - $domainsList . PHP_EOL + 'domain:list', + ['uuid' => 'devcloud:devcloud2', 'environment' => 'dev'], + $domainsList ], [ - ['domain:move', 'devcloud:devcloud2', 'domain', 'dev', 'test'], - '> Moving domain from Dev to Stage' . PHP_EOL + 'domain:move', + ['uuid' => 'devcloud:devcloud2', 'domain' => 'domain', 'environmentFrom' => 'dev', 'environmentTo' => 'test'], + '> Moving domain from Dev to Stage' ], [ - ['domain:purge', 'devcloud:devcloud2', 'dev'], - $domainPurge . PHP_EOL + 'domain:purge', + ['uuid' => 'devcloud:devcloud2', 'environment' => 'dev'], + $domainPurge ], [ - ['domain:purge', 'devcloud:devcloud2', 'dev', 'www.domain1.com'], - '> Purging domain: www.domain1.com' . PHP_EOL + 'domain:purge', + ['uuid' => 'devcloud:devcloud2', 'environment' => 'dev', 'domain' => 'www.domain1.com'], + '> Purging domain: www.domain1.com' ] ]; } diff --git a/tests/Commands/EnvironmentCommandTest.php b/tests/Commands/EnvironmentCommandTest.php index d513462..a320a9e 100644 --- a/tests/Commands/EnvironmentCommandTest.php +++ b/tests/Commands/EnvironmentCommandTest.php @@ -3,16 +3,24 @@ namespace AcquiaCli\Tests\Commands; use AcquiaCli\Tests\AcquiaCliTestCase; +use AcquiaCli\Tests\Traits\CommandTesterTrait; +use AcquiaCli\Commands\EnvironmentsCommand; class EnvironmentCommandTest extends AcquiaCliTestCase { + use CommandTesterTrait; + + public function setUp(): void + { + $this->setupCommandTester(EnvironmentsCommand::class); + } /** * @dataProvider environmentProvider */ - public function testEnvironmentCommands($command, $expected) + public function testEnvironmentCommands($command, $arguments, $expected) { - $actualResponse = $this->execute($command); + list($actualResponse, $statusCode) = $this->executeCommand($command, $arguments); $this->assertSame($expected, $actualResponse); } @@ -32,8 +40,7 @@ public function environmentProvider() TABLE; $getEnvironmentInfo = << Environment ID: 24-a47ac10b-58cc-4372-a567-0e02b2c3d470 +---------+-------+--------------------------+-----------+-----------+----------+----------+--------+---------+-----+ @@ -85,28 +92,34 @@ public function environmentProvider() return [ [ - ['environment:list', 'devcloud:devcloud2'], - $getAllEnvironments . PHP_EOL + 'environment:list', + ['uuid' => 'devcloud:devcloud2'], + $getAllEnvironments ], [ - ['environment:info', 'devcloud:devcloud2', 'dev'], - $getEnvironmentInfo . PHP_EOL + 'environment:info', + ['uuid' => 'devcloud:devcloud2', 'env' => 'dev'], + $getEnvironmentInfo ], [ - ['environment:branch', 'devcloud:devcloud2', 'dev'], - '> master' . PHP_EOL + 'environment:branch', + ['uuid' => 'devcloud:devcloud2', 'environment' => 'dev'], + '> master' ], [ - ['environment:rename', 'devcloud:devcloud2', 'dev', 'name'], - '> Renaming Dev to name' . PHP_EOL + 'environment:rename', + ['uuid' => 'devcloud:devcloud2', 'environment' => 'dev', 'name' => 'name'], + '> Renaming Dev to name' ], [ - ['environment:delete', 'devcloud:devcloud2', 'dev'], - '> Deleting Dev environment' . PHP_EOL + 'environment:delete', + ['uuid' => 'devcloud:devcloud2', 'environment' => 'dev'], + '> Deleting Dev environment' ], [ - ['environment:configure', 'devcloud:devcloud2', 'dev', 'version', '7.4'], - '> Configuring Dev with [version => 7.4]' . PHP_EOL + 'environment:configure', + ['uuid' => 'devcloud:devcloud2', 'environment' => 'dev', 'key' => 'version', 'value' => '7.4'], + '> Configuring Dev with [version => 7.4]' ] ]; } diff --git a/tests/Commands/FilesCommandTest.php b/tests/Commands/FilesCommandTest.php index 5dff0fc..9d2f7a4 100644 --- a/tests/Commands/FilesCommandTest.php +++ b/tests/Commands/FilesCommandTest.php @@ -3,16 +3,24 @@ namespace AcquiaCli\Tests\Commands; use AcquiaCli\Tests\AcquiaCliTestCase; +use AcquiaCli\Tests\Traits\CommandTesterTrait; +use AcquiaCli\Commands\FilesCommand; class FilesCommandTest extends AcquiaCliTestCase { + use CommandTesterTrait; + + public function setUp(): void + { + $this->setupCommandTester(FilesCommand::class); + } /** * @dataProvider filesProvider */ - public function testFilesCommands($command, $expected) + public function testFilesCommands($command, $arguments, $expected) { - $actualResponse = $this->execute($command); + list($actualResponse, $statusCode) = $this->executeCommand($command, $arguments); $this->assertSame($expected, $actualResponse); } @@ -21,8 +29,9 @@ public function filesProvider() return [ [ - ['files:copy', 'devcloud:devcloud2', 'dev', 'test'], - '> Copying files from Dev to Stage' . PHP_EOL + 'files:copy', + ['uuid' => 'devcloud:devcloud2', 'environmentFrom' => 'dev', 'environmentTo' => 'test'], + '> Copying files from Dev to Stage' ] ]; } diff --git a/tests/Commands/IdesCommandTest.php b/tests/Commands/IdesCommandTest.php index e0f24c8..447be38 100644 --- a/tests/Commands/IdesCommandTest.php +++ b/tests/Commands/IdesCommandTest.php @@ -3,16 +3,24 @@ namespace AcquiaCli\Tests\Commands; use AcquiaCli\Tests\AcquiaCliTestCase; +use AcquiaCli\Tests\Traits\CommandTesterTrait; +use AcquiaCli\Commands\IdesCommand; class IdesCommandTest extends AcquiaCliTestCase { + use CommandTesterTrait; + + public function setUp(): void + { + $this->setupCommandTester(IdesCommand::class); + } /** * @dataProvider idesProvider */ - public function testIdesCommands($command, $expected) + public function testIdesCommands($command, $arguments, $expected) { - $actualResponse = $this->execute($command); + list($actualResponse, $statusCode) = $this->executeCommand($command, $arguments); $this->assertSame($expected, $actualResponse); } @@ -29,16 +37,19 @@ public function idesProvider() return [ [ - ['ide:create', 'devcloud:devcloud2', 'Example IDE'], - '> Creating IDE (Example IDE)' . PHP_EOL + 'ide:create', + ['uuid' => 'devcloud:devcloud2', 'label' => 'Example IDE'], + '> Creating IDE (Example IDE)' ], [ - ['ide:delete', '215824ff-272a-4a8c-9027-df32ed1d68a9'], - '> Deleting IDE (215824ff-272a-4a8c-9027-df32ed1d68a9)' . PHP_EOL + 'ide:delete', + ['ideUuid' => '215824ff-272a-4a8c-9027-df32ed1d68a9'], + '> Deleting IDE (215824ff-272a-4a8c-9027-df32ed1d68a9)' ], [ - ['ide:list', 'devcloud:devcloud2'], - $idesTable . PHP_EOL + 'ide:list', + ['uuid' => 'devcloud:devcloud2'], + $idesTable ] ]; } diff --git a/tests/Commands/InsightsCommandTest.php b/tests/Commands/InsightsCommandTest.php index f5da657..aa69f00 100644 --- a/tests/Commands/InsightsCommandTest.php +++ b/tests/Commands/InsightsCommandTest.php @@ -3,16 +3,24 @@ namespace AcquiaCli\Tests\Commands; use AcquiaCli\Tests\AcquiaCliTestCase; +use AcquiaCli\Tests\Traits\CommandTesterTrait; +use AcquiaCli\Commands\InsightsCommand; class InsightsCommandTest extends AcquiaCliTestCase { + use CommandTesterTrait; + + public function setUp(): void + { + $this->setupCommandTester(InsightsCommand::class); + } /** * @dataProvider insightsProvider */ - public function testInsightsCommands($command, $expected) + public function testInsightsCommands($command, $arguments, $expected) { - $actualResponse = $this->execute($command); + list($actualResponse, $statusCode) = $this->executeCommand($command, $arguments); $this->assertSame($expected, $actualResponse); } @@ -49,8 +57,7 @@ public function insightsProvider() ALERTS; $insightEnvironmentInfo = << Site ID: 50227ff0-2a53-11e9-b210-d663bd873d93 > Status: ok @@ -76,8 +83,7 @@ public function insightsProvider() INFO; $insightApplicationInfo = << Site ID: 1bc0b462-2665-11e9-ab14-d663bd873d93 > Status: ok @@ -105,24 +111,29 @@ public function insightsProvider() return [ [ - ['insights:alerts:get', 'siteId', 'alertUuid'], - $insightAlert . PHP_EOL + 'insights:alerts:get', + ['siteId' => 'siteId', 'alertUuid' => 'alertUuid'], + $insightAlert ], [ - ['insights:alerts:list', 'siteId'], - $insightAlerts . PHP_EOL + 'insights:alerts:list', + ['siteId' => 'siteId'], + $insightAlerts ], [ - ['insights:info', 'devcloud:devcloud2', 'dev'], - $insightEnvironmentInfo . PHP_EOL + 'insights:info', + ['uuid' => 'devcloud:devcloud2', 'environment' => 'dev'], + $insightEnvironmentInfo ], [ - ['insights:info', 'devcloud:devcloud2'], - $insightApplicationInfo . PHP_EOL + 'insights:info', + ['uuid' => 'devcloud:devcloud2'], + $insightApplicationInfo ], [ - ['insights:modules', 'siteId'], - $insightModules . PHP_EOL + 'insights:modules', + ['siteId' => 'siteId'], + $insightModules ] ]; } diff --git a/tests/Commands/LiveDevCommandTest.php b/tests/Commands/LiveDevCommandTest.php index cf4adbd..c475d22 100644 --- a/tests/Commands/LiveDevCommandTest.php +++ b/tests/Commands/LiveDevCommandTest.php @@ -3,16 +3,24 @@ namespace AcquiaCli\Tests\Commands; use AcquiaCli\Tests\AcquiaCliTestCase; +use AcquiaCli\Tests\Traits\CommandTesterTrait; +use AcquiaCli\Commands\LivedevCommand; class LiveDevCommandTest extends AcquiaCliTestCase { + use CommandTesterTrait; + + public function setUp(): void + { + $this->setupCommandTester(LivedevCommand::class); + } /** * @dataProvider liveDevProvider */ - public function testLiveDevInfo($command, $expected) + public function testLiveDevInfo($command, $arguments, $expected) { - $actualResponse = $this->execute($command); + list($actualResponse, $statusCode) = $this->executeCommand($command, $arguments); $this->assertSame($expected, $actualResponse); } @@ -21,12 +29,14 @@ public function liveDevProvider() return [ [ - ['livedev:enable', 'devcloud:devcloud2', 'dev'], - '> Enabling livedev for Dev environment' . PHP_EOL + 'livedev:enable', + ['uuid' => 'devcloud:devcloud2', 'environment' => 'dev'], + '> Enabling livedev for Dev environment' ], [ - ['livedev:disable', 'devcloud:devcloud2', 'dev'], - '> Disabling livedev for Dev environment' . PHP_EOL + 'livedev:disable', + ['uuid' => 'devcloud:devcloud2', 'environment' => 'dev'], + '> Disabling livedev for Dev environment' ] ]; } diff --git a/tests/Commands/LogForwardCommandTest.php b/tests/Commands/LogForwardCommandTest.php index 981fa54..2437b91 100644 --- a/tests/Commands/LogForwardCommandTest.php +++ b/tests/Commands/LogForwardCommandTest.php @@ -3,16 +3,24 @@ namespace AcquiaCli\Tests\Commands; use AcquiaCli\Tests\AcquiaCliTestCase; +use AcquiaCli\Tests\Traits\CommandTesterTrait; +use AcquiaCli\Commands\LogForwardCommand; class LogForwardCommandTest extends AcquiaCliTestCase { + use CommandTesterTrait; + + public function setUp(): void + { + $this->setupCommandTester(LogForwardCommand::class); + } /** * @dataProvider logForwardProvider */ - public function testLogForwardInfo($command, $expected) + public function testLogForwardInfo($command, $arguments, $expected) { - $actualResponse = $this->execute($command); + list($actualResponse, $statusCode) = $this->executeCommand($command, $arguments); $this->assertSame($expected, $actualResponse); } @@ -29,8 +37,7 @@ public function logForwardProvider() LIST; $infoResponse = << Certificate: -----BEGIN CERTIFICATE-----...-----END CERTIFICATE----- > Expires at: 2018-07-16T16:15:33+00:00 @@ -44,12 +51,14 @@ public function logForwardProvider() return [ [ - ['lf:list', 'devcloud:devcloud2', 'dev'], - $listResponse . PHP_EOL + 'lf:list', + ['uuid' => 'devcloud:devcloud2', 'environment' => 'dev'], + $listResponse ], [ - ['lf:info', 'devcloud:devcloud2', 'dev', '1234'], - $infoResponse . PHP_EOL, + 'lf:info', + ['uuid' => 'devcloud:devcloud2', 'environment' => 'dev', 'destinationId' => '1234'], + $infoResponse, ] ]; } diff --git a/tests/Commands/LogsCommandTest.php b/tests/Commands/LogsCommandTest.php index 0f6ddca..f325d51 100644 --- a/tests/Commands/LogsCommandTest.php +++ b/tests/Commands/LogsCommandTest.php @@ -3,14 +3,23 @@ namespace AcquiaCli\Tests\Commands; use AcquiaCli\Tests\AcquiaCliTestCase; +use AcquiaCli\Tests\Traits\CommandTesterTrait; +use AcquiaCli\Commands\LogsCommand; class LogsCommandTest extends AcquiaCliTestCase { + use CommandTesterTrait; + + public function setUp(): void + { + $this->setupCommandTester(LogsCommand::class); + } public function testDownloadLogsCommands() { - $command = ['log:download', 'devcloud:devcloud2', 'dev', 'apache-access']; - $actualResponse = $this->execute($command); + $command = 'log:download'; + $arguments = ['uuid' => 'devcloud:devcloud2', 'environment' => 'dev', 'logType' => 'apache-access']; + list($actualResponse, $statusCode) = $this->executeCommand($command, [], $arguments); $this->assertEquals( preg_match('@> Log downloaded to ((\S+)dev-apache-access(\w+).tar.gz)@', $actualResponse, $matches), @@ -34,16 +43,16 @@ public function testDownloadLogsCommands() public function testDownloadLogsCommandsWithOptions() { - $command = [ - 'log:download', - 'devcloud:devcloud2', - 'dev', - 'apache-access', - '--filename=bar', - '--path=/tmp' + $command = 'log:download'; + $arguments = [ + 'uuid' => 'devcloud:devcloud2', + 'environment' => 'dev', + 'logType' => 'apache-access', + '--filename' => 'bar', + '--path' => '/tmp' ]; - $actualResponse = $this->execute($command); + list($actualResponse, $statusCode) = $this->executeCommand($command, [], $arguments); $this->assertEquals( preg_match( @@ -61,16 +70,16 @@ public function testDownloadLogsCommandsWithOptions() public function testLogstream() { - $command = [ - 'log:stream', - 'devcloud:devcloud2', - 'dev', - '--colourise', - '--logtypes=apache-access', - '--servers=web-1234' + $command = 'log:stream'; + $arguments = [ + 'uuid' => 'devcloud:devcloud2', + 'environment' => 'dev', + '--colourise' => true, + '--logtypes' => ['apache-access'], + '--servers' => ['web-1234'] ]; - $this->execute($command); + list($actualResponse, $statusCode) = $this->executeCommand($command, [], $arguments); $authArray = [ 'site' => 'clouduidev:qa4', @@ -96,9 +105,9 @@ public function testLogstream() /** * @dataProvider logsProvider */ - public function testLogsCommands($command, $expected) + public function testLogsCommands($command, $arguments, $expected) { - $actualResponse = $this->execute($command); + list($actualResponse, $statusCode) = $this->executeCommand($command, $arguments); $this->assertSame($expected, $actualResponse); } @@ -120,12 +129,14 @@ public function logsProvider() return [ [ - ['log:list', 'devcloud:devcloud2', 'dev'], - $logsList . PHP_EOL + 'log:list', + ['uuid' => 'devcloud:devcloud2', 'environment' => 'dev'], + $logsList ], [ - ['log:snapshot', 'devcloud:devcloud2', 'dev', 'apache-access'], - '> Creating snapshot for apache-access in Dev environment' . PHP_EOL + 'log:snapshot', + ['uuid' => 'devcloud:devcloud2', 'environment' => 'dev', 'logType' => 'apache-access'], + '> Creating snapshot for apache-access in Dev environment' ], ]; } diff --git a/tests/Commands/NotificationCommandTest.php b/tests/Commands/NotificationCommandTest.php index 3987450..a05eba7 100644 --- a/tests/Commands/NotificationCommandTest.php +++ b/tests/Commands/NotificationCommandTest.php @@ -3,16 +3,24 @@ namespace AcquiaCli\Tests\Commands; use AcquiaCli\Tests\AcquiaCliTestCase; +use AcquiaCli\Tests\Traits\CommandTesterTrait; +use AcquiaCli\Commands\NotificationsCommand; class NotificationCommandTest extends AcquiaCliTestCase { + use CommandTesterTrait; + + public function setUp(): void + { + $this->setupCommandTester(NotificationsCommand::class); + } /** * @dataProvider notificationProvider */ - public function testNotificationCommands($command, $expected) + public function testNotificationCommands($command, $arguments, $expected) { - $actualResponse = $this->execute($command); + list($actualResponse, $statusCode) = $this->executeCommand($command, $arguments); $this->assertSame($expected, $actualResponse); } @@ -46,16 +54,19 @@ public function notificationProvider() return [ [ - ['notification:list', 'devcloud:devcloud2'], - $getAllNotifictions . PHP_EOL + 'notification:list', + ['uuid' => 'devcloud:devcloud2'], + $getAllNotifictions ], [ - ['notification:list', 'devcloud:devcloud2', '--details'], - $getAllNotifictionsDetails . PHP_EOL + 'notification:list', + ['uuid' => 'devcloud:devcloud2', '--details' => true], + $getAllNotifictionsDetails ], [ - ['notification:info', 'devcloud:devcloud2', 'f4b37e3c-1g96-4ed4-ad20-3081fe0f9545'], - $getNotification . PHP_EOL + 'notification:info', + ['uuid' => 'devcloud:devcloud2', 'notificationUuid' => 'f4b37e3c-1g96-4ed4-ad20-3081fe0f9545'], + $getNotification ] ]; } diff --git a/tests/Commands/OrganizationsCommandTest.php b/tests/Commands/OrganizationsCommandTest.php index 93fc88c..52e00ed 100644 --- a/tests/Commands/OrganizationsCommandTest.php +++ b/tests/Commands/OrganizationsCommandTest.php @@ -3,16 +3,24 @@ namespace AcquiaCli\Tests\Commands; use AcquiaCli\Tests\AcquiaCliTestCase; +use AcquiaCli\Tests\Traits\CommandTesterTrait; +use AcquiaCli\Commands\OrganizationsCommand; class OrganizationsCommandTest extends AcquiaCliTestCase { + use CommandTesterTrait; + + public function setUp(): void + { + $this->setupCommandTester(OrganizationsCommand::class); + } /** * @dataProvider organizationsProvider */ - public function testOrganizationsCommands($command, $expected) + public function testOrganizationsCommands($command, $arguments, $expected) { - $actualResponse = $this->execute($command); + list($actualResponse, $statusCode) = $this->executeCommand($command, $arguments); $this->assertSame($expected, $actualResponse); } @@ -69,20 +77,24 @@ public function organizationsProvider() return [ [ - ['organization:applications', 'Sample organization'], - $organizationApplications . PHP_EOL + 'organization:applications', + ['organization' => 'Sample organization'], + $organizationApplications ], [ - ['organization:list'], - $getOrganizations . PHP_EOL + 'organization:list', + [], + $getOrganizations ], [ - ['organization:members', 'Sample organization'], - $organizationMembers . PHP_EOL + 'organization:members', + ['organization' => 'Sample organization'], + $organizationMembers ], [ - ['organization:teams', 'Sample organization'], - $organizationTeams . PHP_EOL + 'organization:teams', + ['organization' => 'Sample organization'], + $organizationTeams ] ]; } diff --git a/tests/Commands/PermissionsCommandTest.php b/tests/Commands/PermissionsCommandTest.php index e2cdcdc..f40c8d1 100644 --- a/tests/Commands/PermissionsCommandTest.php +++ b/tests/Commands/PermissionsCommandTest.php @@ -3,16 +3,24 @@ namespace AcquiaCli\Tests\Commands; use AcquiaCli\Tests\AcquiaCliTestCase; +use AcquiaCli\Tests\Traits\CommandTesterTrait; +use AcquiaCli\Commands\TeamsCommand; class PermissionsCommandTest extends AcquiaCliTestCase { + use CommandTesterTrait; + + public function setUp(): void + { + $this->setupCommandTester(TeamsCommand::class); + } /** * @dataProvider permissionsProvider */ - public function testPermissionsCommands($command, $expected) + public function testPermissionsCommands($command, $arguments, $expected) { - $actualResponse = $this->execute($command); + list($actualResponse, $statusCode) = $this->executeCommand($command, $arguments); $this->assertSame($expected, $actualResponse); } @@ -79,8 +87,9 @@ public function permissionsProvider() return [ [ - ['permissions:list'], - $permissions . PHP_EOL + 'permissions:list', + [], + $permissions ] ]; } diff --git a/tests/Commands/ProductionModeCommandTest.php b/tests/Commands/ProductionModeCommandTest.php index 638a3f6..41d7126 100644 --- a/tests/Commands/ProductionModeCommandTest.php +++ b/tests/Commands/ProductionModeCommandTest.php @@ -3,16 +3,24 @@ namespace AcquiaCli\Tests\Commands; use AcquiaCli\Tests\AcquiaCliTestCase; +use AcquiaCli\Tests\Traits\CommandTesterTrait; +use AcquiaCli\Commands\ProductionModeCommand; class ProductionModeCommandTest extends AcquiaCliTestCase { + use CommandTesterTrait; + + public function setUp(): void + { + $this->setupCommandTester(ProductionModeCommand::class); + } /** * @dataProvider productionModeProvider */ - public function testProductionModeCommands($command, $expected) + public function testProductionModeCommands($command, $arguments, $expected) { - $actualResponse = $this->execute($command); + list($actualResponse, $statusCode) = $this->executeCommand($command, $arguments); $this->assertSame($expected, $actualResponse); } @@ -26,20 +34,24 @@ public function productionModeProvider() INFO; return [ [ - ['productionmode:enable', 'devcloud:devcloud2', 'dev'], - ' [error] Production mode may only be enabled/disabled on the prod environment. ' . PHP_EOL + 'productionmode:enable', + ['uuid' => 'devcloud:devcloud2', 'environment' => 'dev'], + ' [error] Production mode may only be enabled/disabled on the prod environment. ' ], [ - ['productionmode:disable', 'devcloud:devcloud2', 'dev'], - ' [error] Production mode may only be enabled/disabled on the prod environment. ' . PHP_EOL + 'productionmode:disable', + ['uuid' => 'devcloud:devcloud2', 'environment' => 'dev'], + ' [error] Production mode may only be enabled/disabled on the prod environment. ' ], [ - ['productionmode:enable', 'devcloud:devcloud2', 'prod'], - '> Enabling production mode for Production environment' . PHP_EOL + 'productionmode:enable', + ['uuid' => 'devcloud:devcloud2', 'environment' => 'prod'], + '> Enabling production mode for Production environment' ], [ - ['productionmode:disable', 'devcloud:devcloud2', 'prod'], - '> Disabling production mode for Production environment' . PHP_EOL + 'productionmode:disable', + ['uuid' => 'devcloud:devcloud2', 'environment' => 'prod'], + '> Disabling production mode for Production environment' ] ]; } diff --git a/tests/Commands/RolesCommandTest.php b/tests/Commands/RolesCommandTest.php index cfb260b..46c82da 100644 --- a/tests/Commands/RolesCommandTest.php +++ b/tests/Commands/RolesCommandTest.php @@ -3,16 +3,24 @@ namespace AcquiaCli\Tests\Commands; use AcquiaCli\Tests\AcquiaCliTestCase; +use AcquiaCli\Tests\Traits\CommandTesterTrait; +use AcquiaCli\Commands\TeamsCommand; class RolesCommandTest extends AcquiaCliTestCase { + use CommandTesterTrait; + + public function setUp(): void + { + $this->setupCommandTester(TeamsCommand::class); + } /** * @dataProvider roleProvider */ - public function testRoleCommands($command, $expected) + public function testRoleCommands($command, $arguments, $expected) { - $actualResponse = $this->execute($command); + list($actualResponse, $statusCode) = $this->executeCommand($command, $arguments); $this->assertSame($expected, $actualResponse); } @@ -82,20 +90,24 @@ public function roleProvider() return [ [ - ['role:add', 'Sample organization', 'name', 'permissions'], - '> Creating new role (name) and adding it to organisation.' . PHP_EOL + 'role:add', + ['organization' => 'Sample organization', 'name' => 'name', 'permissions' => 'permissions'], + '> Creating new role (name) and adding it to organisation.' ], [ - ['role:delete', 'roleUuid'], - '> Deleting role' . PHP_EOL + 'role:delete', + ['roleUuid' => 'roleUuid'], + '> Deleting role' ], [ - ['role:list', 'Sample organization'], - $roleList . PHP_EOL + 'role:list', + ['organization' => 'Sample organization'], + $roleList ], [ - ['role:update:permissions', 'roleUuid', 'permissions'], - '> Updating role permissions' . PHP_EOL + 'role:update:permissions', + ['roleUuid' => 'roleUuid', 'permissions' => 'permissions'], + '> Updating role permissions' ] ]; } diff --git a/tests/Commands/SetupCommandTest.php b/tests/Commands/SetupCommandTest.php index abd5f4f..b37f1a0 100644 --- a/tests/Commands/SetupCommandTest.php +++ b/tests/Commands/SetupCommandTest.php @@ -10,16 +10,23 @@ use Consolidation\Config\Loader\ConfigProcessor; use Consolidation\Config\Loader\YamlConfigLoader; use Symfony\Component\Console\Output\BufferedOutput; +use AcquiaCli\Tests\Traits\CommandTesterTrait; +use AcquiaCli\Commands\SetupCommand; class SetupCommandTest extends AcquiaCliTestCase { + use CommandTesterTrait; + + public function setUp(): void + { + $this->setupCommandTester(SetupCommand::class); + } public function testSetupConfigViewDefault() { - $command = ['setup:config:view']; + $command = 'setup:config:view'; $defaultConfiguration = <<< DEFAULT - - Default configuration +Default configuration acquia: key: 'd0697bfc-7f56-4942-9205-b5686bf5b3f5' @@ -41,20 +48,17 @@ public function testSetupConfigViewDefault() format: 'Y-m-d H:i:s' taskwait: 5 timeout: 300 - - DEFAULT; - $actualResponse = $this->execute($command); + list($actualResponse, $statusCode) = $this->executeCommand($command); $this->assertSame($defaultConfiguration, $actualResponse); } public function testSetupConfigViewOverwritten() { - $command = ['setup:config:view']; + $command = 'setup:config:view'; $overwrittenConfiguration = <<< OVERWRITTEN - - Default configuration +Default configuration acquia: key: 'd0697bfc-7f56-4942-9205-b5686bf5b3f5' @@ -83,14 +87,12 @@ public function testSetupConfigViewOverwritten() format: U taskwait: 5 timeout: 300 - - OVERWRITTEN; putenv('ACQUIACLI_TIMEZONE=Australia/Melbourne'); putenv('ACQUIACLI_FORMAT=U'); - $actualResponse = $this->execute($command); + list($actualResponse, $statusCode) = $this->executeCommand($command); $this->assertSame($overwrittenConfiguration, $actualResponse); putenv('ACQUIACLI_TIMEZONE='); diff --git a/tests/Commands/SshCommandTest.php b/tests/Commands/SshCommandTest.php index 60341ac..a0d376d 100644 --- a/tests/Commands/SshCommandTest.php +++ b/tests/Commands/SshCommandTest.php @@ -3,16 +3,24 @@ namespace AcquiaCli\Tests\Commands; use AcquiaCli\Tests\AcquiaCliTestCase; +use AcquiaCli\Tests\Traits\CommandTesterTrait; +use AcquiaCli\Commands\SshCommand; class SshCommandTest extends AcquiaCliTestCase { + use CommandTesterTrait; + + public function setUp(): void + { + $this->setupCommandTester(SshCommand::class); + } /** * @dataProvider sshProvider */ - public function testSshInfo($command, $expected) + public function testSshInfo($command, $arguments, $expected) { - $actualResponse = $this->execute($command); + list($actualResponse, $statusCode) = $this->executeCommand($command, $arguments); $this->assertSame($expected, $actualResponse); } @@ -22,17 +30,19 @@ public function sshProvider() $infoResponse = << dev: ssh > prod: ssh -> test: ssh +> test: ssh INFO; return [ [ - ['ssh:info', 'devcloud:devcloud2'], - $infoResponse . PHP_EOL + 'ssh:info', + ['uuid' => 'devcloud:devcloud2'], + $infoResponse ], [ - ['ssh:info', 'devcloud:devcloud2', 'dev'], - $infoResponse . PHP_EOL, + 'ssh:info', + ['uuid' => 'devcloud:devcloud2', 'env' => 'dev'], + $infoResponse, ] ]; } diff --git a/tests/Commands/SslCertificateCommandTest.php b/tests/Commands/SslCertificateCommandTest.php index d9e0c44..41766e5 100644 --- a/tests/Commands/SslCertificateCommandTest.php +++ b/tests/Commands/SslCertificateCommandTest.php @@ -3,16 +3,24 @@ namespace AcquiaCli\Tests\Commands; use AcquiaCli\Tests\AcquiaCliTestCase; +use AcquiaCli\Tests\Traits\CommandTesterTrait; +use AcquiaCli\Commands\SslCertificateCommand; class SslCertificateCommandTest extends AcquiaCliTestCase { + use CommandTesterTrait; + + public function setUp(): void + { + $this->setupCommandTester(SslCertificateCommand::class); + } /** * @dataProvider sslCertificateProvider */ - public function testSslCertificateInfo($command, $expected) + public function testSslCertificateInfo($command, $arguments, $expected) { - $actualResponse = $this->execute($command); + list($actualResponse, $statusCode) = $this->executeCommand($command, $arguments); $this->assertSame($expected, $actualResponse); } @@ -34,8 +42,7 @@ public function sslCertificateProvider() LIST; $infoResponse = << 'devcloud:devcloud2', 'environment' => 'dev'], + $listResponse ], [ - ['ssl:info', 'devcloud:devcloud2', 'dev', '1234'], - $infoResponse . PHP_EOL, + 'ssl:info', + ['uuid' => 'devcloud:devcloud2', 'environment' => 'dev', 'certificateId' => '1234'], + $infoResponse, ], [ - ['ssl:enable', 'devcloud:devcloud2', 'dev', '1234'], - '> Activating certificate on Dev environment.' . PHP_EOL, + 'ssl:enable', + ['uuid' => 'devcloud:devcloud2', 'environment' => 'dev', 'certificateId' => '1234'], + '> Activating certificate on Dev environment.', ], [ - ['ssl:disable', 'devcloud:devcloud2', 'dev', '1234'], - '> Disabling certificate on Dev environment.' . PHP_EOL, + 'ssl:disable', + ['uuid' => 'devcloud:devcloud2', 'environment' => 'dev', 'certificateId' => '1234'], + '> Disabling certificate on Dev environment.', ], [ - ['ssl:create', - 'devcloud:devcloud2', - 'dev', - 'Test Certificate 2', - $sslCertificatesPath . '/cert.pem', - $sslCertificatesPath . '/key.pem', - $sslCertificatesPath . '/ca.pem', - '--activate'], + 'ssl:create', + [ + 'uuid' => 'devcloud:devcloud2', + 'environment' => 'dev', + 'label' => 'Test Certificate 2', + 'certificate' => $sslCertificatesPath . '/cert.pem', + 'key' => $sslCertificatesPath . '/key.pem', + 'ca' => $sslCertificatesPath . '/ca.pem', + '--activate' => true + ], '> Installing new certificate Test Certificate 2 on Dev environment.' . PHP_EOL . - '> Activating certificate Test Certificate 2 on Dev environment.' . PHP_EOL + '> Activating certificate Test Certificate 2 on Dev environment.' ], [ - ['ssl:create', - 'devcloud:devcloud2', - 'dev', - 'Test Certificate 2', - $sslCertificatesPath . '/cert.pem', - $sslCertificatesPath . '/key.pem'], - '> Installing new certificate Test Certificate 2 on Dev environment.' . PHP_EOL, + 'ssl:create', + [ + 'uuid' => 'devcloud:devcloud2', + 'environment' => 'dev', + 'label' => 'Test Certificate 2', + 'certificate' => $sslCertificatesPath . '/cert.pem', + 'key' => $sslCertificatesPath . '/key.pem' + ], + '> Installing new certificate Test Certificate 2 on Dev environment.', ], [ - ['ssl:create', - 'devcloud:devcloud2', - 'dev', - 'Test Certificate 2', - '/nopath/cert.pem', - $sslCertificatesPath . '/key.pem'], - ' [error] Cannot open certificate file at /nopath/cert.pem. ' . PHP_EOL, + 'ssl:create', + [ + 'uuid' => 'devcloud:devcloud2', + 'environment' => 'dev', + 'label' => 'Test Certificate 2', + 'certificate' => '/nopath/cert.pem', + 'key' => $sslCertificatesPath . '/key.pem' + ], + ' [error] Cannot open certificate file at /nopath/cert.pem. ', ], [ - ['ssl:create', - 'devcloud:devcloud2', - 'dev', - 'Test Certificate 2', - $sslCertificatesPath . '/cert.pem', - '/nopath/key.pem'], - ' [error] Cannot open key file at /nopath/key.pem. ' . PHP_EOL, + 'ssl:create', + [ + 'uuid' => 'devcloud:devcloud2', + 'environment' => 'dev', + 'label' => 'Test Certificate 2', + 'certificate' => $sslCertificatesPath . '/cert.pem', + 'key' => '/nopath/key.pem' + ], + ' [error] Cannot open key file at /nopath/key.pem. ', ], [ - ['ssl:create', - 'devcloud:devcloud2', - 'dev', - 'Test Certificate 2', - $sslCertificatesPath . '/cert.pem', - $sslCertificatesPath . '/key.pem', - '/nopath/ca.pem'], - ' [error] Cannot open ca file at /nopath/ca.pem. ' . PHP_EOL, + 'ssl:create', + [ + 'uuid' => 'devcloud:devcloud2', + 'environment' => 'dev', + 'label' => 'Test Certificate 2', + 'certificate' => $sslCertificatesPath . '/cert.pem', + 'key' => $sslCertificatesPath . '/key.pem', + 'ca' => '/nopath/ca.pem' + ], + ' [error] Cannot open ca file at /nopath/ca.pem. ', ] ]; } diff --git a/tests/Commands/TeamsCommandTest.php b/tests/Commands/TeamsCommandTest.php index 93ea08d..2bc37bf 100644 --- a/tests/Commands/TeamsCommandTest.php +++ b/tests/Commands/TeamsCommandTest.php @@ -3,16 +3,24 @@ namespace AcquiaCli\Tests\Commands; use AcquiaCli\Tests\AcquiaCliTestCase; +use AcquiaCli\Tests\Traits\CommandTesterTrait; +use AcquiaCli\Commands\TeamsCommand; class TeamsCommandTest extends AcquiaCliTestCase { + use CommandTesterTrait; + + public function setUp(): void + { + $this->setupCommandTester(TeamsCommand::class); + } /** * @dataProvider teamsProvider */ - public function testTeamsCommands($command, $expected) + public function testTeamsCommands($command, $arguments, $expected) { - $actualResponse = $this->execute($command); + list($actualResponse, $statusCode) = $this->executeCommand($command, $arguments); $this->assertSame($expected, $actualResponse); } @@ -21,16 +29,19 @@ public function teamsProvider() return [ [ - ['team:addapplication', 'devcloud:devcloud2', 'teamUuid'], - '> Adding application to team.' . PHP_EOL + 'team:addapplication', + ['uuid' => 'devcloud:devcloud2', 'teamUuid' => 'teamUuid'], + '> Adding application to team.' ], [ - ['team:create', 'Sample organization', 'name'], - '> Creating new team.' . PHP_EOL + 'team:create', + ['organization' => 'Sample organization', 'name' => 'name'], + '> Creating new team.' ], [ - ['team:invite', 'teamUuid', 'email', 'roles'], - '> Inviting email to team.' . PHP_EOL + 'team:invite', + ['teamUuid' => 'teamUuid', 'email' => 'email', 'roleUuids' => 'roles'], + '> Inviting email to team.' ] ]; } diff --git a/tests/Commands/VariablesCommandTest.php b/tests/Commands/VariablesCommandTest.php index 02e445e..b3e9013 100644 --- a/tests/Commands/VariablesCommandTest.php +++ b/tests/Commands/VariablesCommandTest.php @@ -3,16 +3,24 @@ namespace AcquiaCli\Tests\Commands; use AcquiaCli\Tests\AcquiaCliTestCase; +use AcquiaCli\Tests\Traits\CommandTesterTrait; +use AcquiaCli\Commands\VariablesCommand; class VariablesCommandTest extends AcquiaCliTestCase { + use CommandTesterTrait; + + public function setUp(): void + { + $this->setupCommandTester(VariablesCommand::class); + } /** * @dataProvider variablesProvider */ - public function testVariablesCommands($command, $expected) + public function testVariablesCommands($command, $arguments, $expected) { - $actualResponse = $this->execute($command); + list($actualResponse, $statusCode) = $this->executeCommand($command, $arguments); $this->assertSame($expected, $actualResponse); } @@ -31,24 +39,29 @@ public function variablesProvider() return [ [ - ['variable:create', 'devcloud:devcloud2', 'dev', 'variable_one', 'Sample Value One'], - '> Adding variable variable_one:Sample Value One to Dev environment' . PHP_EOL + 'variable:create', + ['uuid' => 'devcloud:devcloud2', 'environment' => 'dev', 'name' => 'variable_one', 'value' => 'Sample Value One'], + '> Adding variable variable_one:Sample Value One to Dev environment' ], [ - ['variable:delete', 'devcloud:devcloud2', 'dev', 'variable_one'], - '> Removing variable variable_one from Dev environment' . PHP_EOL + 'variable:delete', + ['uuid' => 'devcloud:devcloud2', 'environment' => 'dev', 'name' => 'variable_one'], + '> Removing variable variable_one from Dev environment' ], [ - ['variable:info', 'devcloud:devcloud2', 'dev', 'variable_one'], - '> Sample Value One' . PHP_EOL + 'variable:info', + ['uuid' => 'devcloud:devcloud2', 'environment' => 'dev', 'name' => 'variable_one'], + '> Sample Value One' ], [ - ['variable:list', 'devcloud:devcloud2', 'dev'], - $variablesList . PHP_EOL + 'variable:list', + ['uuid' => 'devcloud:devcloud2', 'environment' => 'dev'], + $variablesList ], [ - ['variable:update', 'devcloud:devcloud2', 'dev', 'variable_one', 'Sample Value One'], - '> Updating variable variable_one:Sample Value One on Dev environment' . PHP_EOL + 'variable:update', + ['uuid' => 'devcloud:devcloud2', 'environment' => 'dev', 'name' => 'variable_one', 'value' => 'Sample Value One'], + '> Updating variable variable_one:Sample Value One on Dev environment' ] ]; } diff --git a/tests/Traits/CommandTesterTrait.php b/tests/Traits/CommandTesterTrait.php new file mode 100644 index 0000000..728e712 --- /dev/null +++ b/tests/Traits/CommandTesterTrait.php @@ -0,0 +1,175 @@ +runner = new Runner(); + if (!is_null($commandClasses)) { + $this->commandClasses = $commandClasses; + } + } + + /** + * @param string $commandString + * @param array $command_extra + * @param array $inputs + * @param string|array|null $commandClasses + * @return array + */ + protected function executeCommand($commandString, $command_extra = [], $inputs = [], $commandClasses = null) + { + $commandClasses = $commandClasses ?? $this->commandClasses; + + $app = $this->getAppForTesting($this->appName, $this->appVersion, $commandClasses); + $command = $app->get($commandString); + $tester = new CommandTester($command); + $tester->setInputs($inputs); + $command_extra['--no-wait'] = true; + $command_extra['--yes'] = true; + $options = ['capture_stderr_separately' => false]; + $status_code = $tester->execute(array_merge(['command' => $commandString], $command_extra), $options); + Robo::unsetContainer(); + return [trim($tester->getDisplay()), $status_code]; + } + + public function getAppForTesting($appName = null, $appVersion = null, $commandFile = null, $config = null, $classLoader = null) + { + // Create an instance of the application and use some default parameters. + $root = dirname(dirname(dirname(__DIR__))); + $config = new Config($root); + + $input = new ArgvInput(); + $output = new BufferedOutput(); + $acquiaCli = new AcquiaCli($config, $this->getMockClient(), $input, $output); + + // Override the LogstreamManager with a mock in the container. + $container = Robo::getContainer(); + $container->add('logstream', $this->getMockLogstream()); + $parameterInjection = $container->get('parameterInjection'); + $parameterInjection->register('AcquiaLogstream\LogstreamManager', new AcquiaCliInjector()); + Robo::setContainer($container); + + $app = $container->get('application'); + + if (!is_null($commandFile) && (is_array($commandFile) || is_string($commandFile))) { + if (is_string($commandFile)) { + $commandFile = [$commandFile]; + } + $this->registerCommandClasses($app, $commandFile); + } + return $app; + } + + public function registerCommandClasses($app, $commandClasses) + { + foreach ((array)$commandClasses as $commandClass) { + $this->registerCommandClass($app, $commandClass); + } + } + + public function registerCommandClass($app, $commandClass) + { + $container = Robo::getContainer(); + $roboCommandFileInstance = $this->instantiateCommandClass($commandClass); + if (!$roboCommandFileInstance) { + return; + } + + // Register commands for all of the public methods in the RoboFile. + $commandFactory = $container->get('commandFactory'); + $commandList = $commandFactory->createCommandsFromClass($roboCommandFileInstance); + foreach ($commandList as $command) { + $app->add($command); + } + return $roboCommandFileInstance; + } + + protected function instantiateCommandClass($commandClass) + { + $container = Robo::getContainer(); + + // Register the RoboFile with the container and then immediately + // fetch it; this ensures that all of the inflectors will run. + // If the command class is already an instantiated object, then + // just use it exactly as it was provided to us. + + if (is_string($commandClass)) { + if (!class_exists($commandClass)) { + return; + } + $reflectionClass = new \ReflectionClass($commandClass); + if ($reflectionClass->isAbstract()) { + return; + } + + $container->share($commandClass, $commandClass); + $commandClass = $container->get($commandClass); + } + + return $commandClass; + } + + protected function getMockClient() + { + $connector = $this + ->getMockBuilder('AcquiaCloudApi\Connector\Connector') + ->disableOriginalConstructor() + ->setMethods(['sendRequest']) + ->getMock(); + + $connector + ->expects($this->any()) + ->method('sendRequest') + ->will($this->returnCallback(array($this, 'sendRequestCallback'))); + + return Client::factory($connector); + } + + protected function getMockLogstream() + { + $logstream = $this + ->getMockBuilder('AcquiaLogstream\LogstreamManager') + ->disableOriginalConstructor() + ->setMethods(['stream']) + ->getMock(); + + $logstream + ->expects($this->any()) + ->method('stream') + ->willReturn(''); + + return $logstream; + } +}