From 348e9c395995cb6cfd15c3eb025118c782462d30 Mon Sep 17 00:00:00 2001 From: Dane Powell Date: Thu, 16 May 2024 15:58:28 -0700 Subject: [PATCH] noserial --- .../ComposerScriptsListenerTest.php | 97 ---- .../Application/ExceptionApplicationTest.php | 34 -- .../src/Application/HelpApplicationTest.php | 57 -- tests/phpunit/src/Application/KernelTest.php | 119 ---- .../src/Commands/Api/ApiCommandTest.php | 528 ------------------ .../src/Commands/ClearCacheCommandTest.php | 67 --- .../src/Commands/Remote/DrushCommandTest.php | 72 --- .../src/Commands/Remote/SshCommandTest.php | 55 -- 8 files changed, 1029 deletions(-) delete mode 100644 tests/phpunit/src/Application/ComposerScriptsListenerTest.php delete mode 100644 tests/phpunit/src/Application/ExceptionApplicationTest.php delete mode 100644 tests/phpunit/src/Application/HelpApplicationTest.php delete mode 100644 tests/phpunit/src/Application/KernelTest.php delete mode 100644 tests/phpunit/src/Commands/Api/ApiCommandTest.php delete mode 100644 tests/phpunit/src/Commands/ClearCacheCommandTest.php delete mode 100644 tests/phpunit/src/Commands/Remote/DrushCommandTest.php delete mode 100644 tests/phpunit/src/Commands/Remote/SshCommandTest.php diff --git a/tests/phpunit/src/Application/ComposerScriptsListenerTest.php b/tests/phpunit/src/Application/ComposerScriptsListenerTest.php deleted file mode 100644 index f330bc415..000000000 --- a/tests/phpunit/src/Application/ComposerScriptsListenerTest.php +++ /dev/null @@ -1,97 +0,0 @@ - [ - 'pre-acli-hello-world' => [ - 'echo "good morning world"', - ], - ], - ]; - file_put_contents( - Path::join($this->projectDir, 'composer.json'), - json_encode($json, JSON_THROW_ON_ERROR) - ); - $this->mockRequest('getAccount'); - $this->setInput([ - 'command' => 'hello-world', - ]); - $buffer = $this->runApp(); - self::assertStringContainsString('pre-acli-hello-world', $buffer); - } - - /** - * @group serial - */ - public function testPostScripts(): void { - $json = [ - 'scripts' => [ - 'post-acli-hello-world' => [ - 'echo "goodbye world"', - ], - ], - ]; - file_put_contents( - Path::join($this->projectDir, 'composer.json'), - json_encode($json, JSON_THROW_ON_ERROR) - ); - $this->mockRequest('getAccount'); - $this->setInput([ - 'command' => 'hello-world', - ]); - $buffer = $this->runApp(); - self::assertStringContainsString('post-acli-hello-world', $buffer); - } - - public function testNoScripts(): void { - $json = [ - 'scripts' => [ - 'pre-acli-pull-code' => [ - 'echo "goodbye world"', - ], - ], - ]; - file_put_contents( - Path::join($this->projectDir, 'composer.json'), - json_encode($json, JSON_THROW_ON_ERROR) - ); - $this->setInput([ - '--no-scripts' => TRUE, - 'command' => 'pull:code', - ]); - $buffer = $this->runApp(); - self::assertStringNotContainsString('pre-acli-pull-code', $buffer); - } - - // Hack to ensure listener methods are recognized as used. - // If we were unit testing properly, we'd make meaningful assertions here instead of the integration tests above. - public function testApi(): void { - $listener = new ComposerScriptsListener(); - $listener->onConsoleCommand(new ConsoleCommandEvent($this->injectCommand(HelloWorldCommand::class), $this->input, $this->output)); - $listener->onConsoleTerminate(new ConsoleTerminateEvent($this->injectCommand(HelloWorldCommand::class), $this->input, $this->output, 0)); - self::assertTrue(TRUE); - } - -} diff --git a/tests/phpunit/src/Application/ExceptionApplicationTest.php b/tests/phpunit/src/Application/ExceptionApplicationTest.php deleted file mode 100644 index 6b6229481..000000000 --- a/tests/phpunit/src/Application/ExceptionApplicationTest.php +++ /dev/null @@ -1,34 +0,0 @@ -setInput([ - 'applicationUuid' => '2ed281d4-9dec-4cc3-ac63-691c3ba002c2', - 'command' => 'aliases', - ]); - $this->mockUnauthorizedRequest(); - $buffer = $this->runApp(); - // This is sensitive to the display width of the test environment, so that's fun. - self::assertStringContainsString('Your Cloud Platform API credentials are invalid.', $buffer); - } - -} diff --git a/tests/phpunit/src/Application/HelpApplicationTest.php b/tests/phpunit/src/Application/HelpApplicationTest.php deleted file mode 100644 index ffdec56b4..000000000 --- a/tests/phpunit/src/Application/HelpApplicationTest.php +++ /dev/null @@ -1,57 +0,0 @@ -setInput([ - 'command' => 'help', - 'command_name' => 'app:link', - ]); - $buffer = $this->runApp(); - $this->assertStringContainsString('The Cloud Platform application UUID or alias (i.e. an application name optionally prefixed with the realm)', $buffer); - $this->assertStringContainsString('Usage: - app:link [] - link - app:link [] - app:link myapp - app:link prod:myapp - app:link abcd1234-1111-2222-3333-0e02b2c3d470', $buffer); - } - - /** - * @group serial - */ - public function testEnvironmentAliasHelp(): void { - $this->setInput([ - 'command' => 'help', - 'command_name' => 'log:tail', - ]); - $buffer = $this->runApp(); - $this->assertStringContainsString('The Cloud Platform environment ID or alias (i.e. an application and environment name optionally prefixed with the realm)', $buffer); - $this->assertStringContainsString('Usage: - app:log:tail [] - tail - log:tail - app:log:tail [] - app:log:tail myapp.dev - app:log:tail prod:myapp.dev - app:log:tail 12345-abcd1234-1111-2222-3333-0e02b2c3d470', $buffer); - } - -} diff --git a/tests/phpunit/src/Application/KernelTest.php b/tests/phpunit/src/Application/KernelTest.php deleted file mode 100644 index 2b458cd4a..000000000 --- a/tests/phpunit/src/Application/KernelTest.php +++ /dev/null @@ -1,119 +0,0 @@ -setInput([ - 'command' => 'list', - ]); - $buffer = $this->runApp(); - // A bit dumb that we need to break these up, but the available commands vary based on whether a browser is available or the session is interactive. - // Could probably handle that more intelligently... - $this->assertStringStartsWith($this->getStart(), $buffer); - $this->assertStringEndsWith($this->getEnd(), $buffer); - } - - private function getStart(): string { - return <<injectCommand(ApiBaseCommand::class); - } - - /** - * @group brokenProphecy - */ - public function testArgumentsInteraction(): void { - $this->command = $this->getApiCommandByName('api:environments:log-download'); - $this->executeCommand([], [ - '289576-53785bca-1946-4adc-a022-e50d24686c20', - 'apache-access', - ]); - $output = $this->getDisplay(); - $this->assertStringContainsString('Enter a value for environmentId', $output); - $this->assertStringContainsString('logType is a required argument', $output); - $this->assertStringContainsString('An ID that uniquely identifies a log type.', $output); - $this->assertStringContainsString('apache-access', $output); - $this->assertStringContainsString('Select a value for logType', $output); - } - - public function testArgumentsInteractionValidation(): void { - $this->command = $this->getApiCommandByName('api:environments:variable-update'); - try { - $this->executeCommand([], [ - '289576-53785bca-1946-4adc-a022-e50d24686c20', - 'AH_SOMETHING', - 'AH_SOMETHING', - ]); - } - catch (MissingInputException) { - } - $output = $this->getDisplay(); - $this->assertStringContainsString('It must match the pattern', $output); - } - - public function testArgumentsInteractionValidationFormat(): void { - $this->command = $this->getApiCommandByName('api:notifications:find'); - try { - $this->executeCommand([], [ - 'test', - ]); - } - catch (MissingInputException) { - } - $output = $this->getDisplay(); - $this->assertStringContainsString('This is not a valid UUID', $output); - } - - /** - * Tests invalid UUID. - */ - public function testApiCommandErrorResponse(): void { - $invalidUuid = '257a5440-22c3-49d1-894d-29497a1cf3b9'; - $this->clientProphecy->addOption('headers', ['Accept' => 'application/hal+json, version=2'])->shouldBeCalled(); - $this->command = $this->getApiCommandByName('api:applications:find'); - $mockBody = $this->getMockResponseFromSpec($this->command->getPath(), $this->command->getMethod(), '404'); - $this->clientProphecy->request('get', '/applications/' . $invalidUuid)->willThrow(new ApiErrorException($mockBody))->shouldBeCalled(); - - // ApiCommandBase::convertApplicationAliastoUuid() will try to convert the invalid string to a uuid: - $this->clientProphecy->addQuery('filter', 'hosting=@*:' . $invalidUuid); - $this->clientProphecy->request('get', '/applications')->willReturn([]); - - $this->executeCommand(['applicationUuid' => $invalidUuid], [ - // Would you like Acquia CLI to search for a Cloud application that matches your local git config? - 'n', - // Select a Cloud Platform application: - '0', - // Would you like to link the Cloud application Sample application to this repository? - 'n', - ]); - - // Assert. - $output = $this->getDisplay(); - $this->assertJson($output); - $this->assertStringContainsString($mockBody->message, $output); - $this->assertEquals(1, $this->getStatusCode()); - } - - public function testApiCommandExecutionForHttpGet(): void { - $this->clientProphecy->addOption('headers', ['Accept' => 'application/hal+json, version=2'])->shouldBeCalled(); - $mockBody = $this->getMockResponseFromSpec('/account/ssh-keys', 'get', '200'); - $this->clientProphecy->addQuery('limit', '1')->shouldBeCalled(); - $this->clientProphecy->request('get', '/account/ssh-keys')->willReturn($mockBody->{'_embedded'}->items)->shouldBeCalled(); - $this->command = $this->getApiCommandByName('api:accounts:ssh-keys-list'); - // Our mock Client doesn't actually return a limited dataset, but we still assert it was passed added to the - // client's query correctly. - $this->executeCommand(['--limit' => '1']); - - // Assert. - $output = $this->getDisplay(); - $this->assertNotNull($output); - $this->assertJson($output); - $contents = json_decode($output, TRUE); - $this->assertArrayHasKey(0, $contents); - $this->assertArrayHasKey('uuid', $contents[0]); - } - - /** - * @group brokenProphecy - */ - public function testObjectParam(): void { - $this->mockRequest('putEnvironmentCloudActions', '24-a47ac10b-58cc-4372-a567-0e02b2c3d470'); - $this->command = $this->getApiCommandByName('api:environments:cloud-actions-update'); - $this->executeCommand([ - 'cloud-actions' => '{"fb4aa87a-8be2-42c6-bdf0-ef9d09a3de70":true}', - 'environmentId' => '24-a47ac10b-58cc-4372-a567-0e02b2c3d470', - ]); - $output = $this->getDisplay(); - $this->assertStringContainsString('Cloud Actions have been updated.', $output); - } - - public function testInferApplicationUuidArgument(): void { - $this->clientProphecy->addOption('headers', ['Accept' => 'application/hal+json, version=2'])->shouldBeCalled(); - $applications = $this->mockRequest('getApplications'); - $application = $this->mockRequest('getApplicationByUuid', $applications[0]->uuid); - $this->command = $this->getApiCommandByName('api:applications:find'); - $this->executeCommand([], [ - // Would you like Acquia CLI to search for a Cloud application that matches your local git config? - 'n', - // Select a Cloud Platform application: - '0', - // Would you like to link the Cloud application Sample application to this repository? - 'n', - ]); - - // Assert. - $output = $this->getDisplay(); - $this->assertStringContainsString('Inferring Cloud Application UUID for this command since none was provided...', $output); - $this->assertStringContainsString('Set application uuid to ' . $application->uuid, $output); - $this->assertEquals(0, $this->getStatusCode()); - } - - /** - * @return bool[][] - */ - public function providerTestConvertApplicationAliasToUuidArgument(): array { - return [ - [FALSE], - [TRUE], - ]; - } - - /** - * @dataProvider providerTestConvertApplicationAliasToUuidArgument - * @group serial - */ - public function testConvertApplicationAliasToUuidArgument(bool $support): void { - ClearCacheCommand::clearCaches(); - $this->clientProphecy->addOption('headers', ['Accept' => 'application/hal+json, version=2'])->shouldBeCalled(); - $tamper = function (&$response): void { - unset($response[1]); - }; - $applications = $this->mockRequest('getApplications', NULL, NULL, NULL, $tamper); - $this->mockRequest('getApplicationByUuid', $applications[self::$INPUT_DEFAULT_CHOICE]->uuid); - $this->clientProphecy->addQuery('filter', 'hosting=@*:devcloud2')->shouldBeCalled(); - $this->command = $this->getApiCommandByName('api:applications:find'); - $alias = 'devcloud2'; - $tamper = NULL; - if ($support) { - $this->clientProphecy->addQuery('all', 'true')->shouldBeCalled(); - $tamper = function (mixed $response): void { - $response->flags->support = TRUE; - }; - } - $this->mockRequest('getAccount', NULL, NULL, NULL, $tamper); - - $this->executeCommand(['applicationUuid' => $alias], [ - // Would you like Acquia CLI to search for a Cloud application that matches your local git config? - 'n', - // Select a Cloud Platform application: - self::$INPUT_DEFAULT_CHOICE, - // Would you like to link the Cloud application Sample application to this repository? - 'n', - ]); - - // Assert. - $this->getDisplay(); - $this->assertEquals(0, $this->getStatusCode()); - } - - public function testConvertInvalidApplicationAliasToUuidArgument(): void { - $this->mockApplicationsRequest(0); - $this->clientProphecy->addQuery('filter', 'hosting=@*:invalidalias')->shouldBeCalled(); - $this->mockRequest('getAccount'); - $this->command = $this->getApiCommandByName('api:applications:find'); - $alias = 'invalidalias'; - $this->expectException(AcquiaCliException::class); - $this->expectExceptionMessage('No applications match the alias *:invalidalias'); - $this->executeCommand(['applicationUuid' => $alias], []); - - } - - /** - * @serial - */ - public function testConvertNonUniqueApplicationAliasToUuidArgument(): void { - ClearCacheCommand::clearCaches(); - $this->mockApplicationsRequest(2, FALSE); - $this->clientProphecy->addQuery('filter', 'hosting=@*:devcloud2')->shouldBeCalled(); - $this->mockRequest('getAccount'); - $this->command = $this->getApiCommandByName('api:applications:find'); - $alias = 'devcloud2'; - $this->expectException(AcquiaCliException::class); - $this->expectExceptionMessage('Multiple applications match the alias *:devcloud2'); - $this->executeCommand(['applicationUuid' => $alias], []); - $output = $this->getDisplay(); - $this->assertStringContainsString('Use a unique application alias: devcloud:devcloud2, devcloud:devcloud2', $output); - - } - - /** - * @serial - */ - public function testConvertApplicationAliasWithRealmToUuidArgument(): void { - $this->clientProphecy->addOption('headers', ['Accept' => 'application/hal+json, version=2'])->shouldBeCalled(); - $this->mockApplicationsRequest(1, FALSE); - $this->clientProphecy->addQuery('filter', 'hosting=@devcloud:devcloud2')->shouldBeCalled(); - $this->mockApplicationRequest(); - $this->mockRequest('getAccount'); - $this->command = $this->getApiCommandByName('api:applications:find'); - $alias = 'devcloud:devcloud2'; - $this->executeCommand(['applicationUuid' => $alias], []); - - } - - /** - * @serial - */ - public function testConvertEnvironmentAliasToUuidArgument(): void { - ClearCacheCommand::clearCaches(); - $this->clientProphecy->addOption('headers', ['Accept' => 'application/hal+json, version=2'])->shouldBeCalled(); - $applicationsResponse = $this->mockApplicationsRequest(1); - $this->clientProphecy->addQuery('filter', 'hosting=@*:devcloud2')->shouldBeCalled(); - $this->mockEnvironmentsRequest($applicationsResponse); - $this->mockRequest('getAccount'); - - $response = $this->getMockEnvironmentResponse(); - $this->clientProphecy->request('get', '/environments/24-a47ac10b-58cc-4372-a567-0e02b2c3d470')->willReturn($response)->shouldBeCalled(); - - $this->command = $this->getApiCommandByName('api:environments:find'); - $alias = 'devcloud2.dev'; - - $this->executeCommand(['environmentId' => $alias], [ - // Would you like Acquia CLI to search for a Cloud application that matches your local git config? - 'n', - // Select a Cloud Platform application: - '0', - // Would you like to link the Cloud application Sample application to this repository? - 'n', - ]); - - // Assert. - $this->getDisplay(); - $this->assertEquals(0, $this->getStatusCode()); - } - - /** - * @group serial - */ - public function testConvertInvalidEnvironmentAliasToUuidArgument(): void { - ClearCacheCommand::clearCaches(); - $applicationsResponse = $this->mockApplicationsRequest(1); - $this->clientProphecy->addQuery('filter', 'hosting=@*:devcloud2')->shouldBeCalled(); - $this->mockEnvironmentsRequest($applicationsResponse); - $this->mockRequest('getAccount'); - $this->command = $this->getApiCommandByName('api:environments:find'); - $alias = 'devcloud2.invalid'; - $this->expectException(AcquiaCliException::class); - $this->expectExceptionMessage('{environmentId} must be a valid UUID or site alias.'); - $this->executeCommand(['environmentId' => $alias], []); - - } - - public function testApiCommandExecutionForHttpPost(): void { - $this->clientProphecy->addOption('headers', ['Accept' => 'application/hal+json, version=2'])->shouldBeCalled(); - $mockRequestArgs = $this->getMockRequestBodyFromSpec('/account/ssh-keys'); - $mockResponseBody = $this->getMockResponseFromSpec('/account/ssh-keys', 'post', '202'); - foreach ($mockRequestArgs as $name => $value) { - $this->clientProphecy->addOption('json', [$name => $value])->shouldBeCalled(); - } - $this->clientProphecy->request('post', '/account/ssh-keys')->willReturn($mockResponseBody)->shouldBeCalled(); - $this->command = $this->getApiCommandByName('api:accounts:ssh-key-create'); - $this->executeCommand($mockRequestArgs); - - // Assert. - $output = $this->getDisplay(); - $this->assertNotNull($output); - $this->assertJson($output); - $this->assertStringContainsString('Adding SSH key.', $output); - } - - public function testApiCommandExecutionForHttpPut(): void { - $this->clientProphecy->addOption('headers', ['Accept' => 'application/hal+json, version=2'])->shouldBeCalled(); - $mockRequestOptions = $this->getMockRequestBodyFromSpec('/environments/{environmentId}', 'put'); - $mockRequestOptions['max_input_vars'] = 1001; - $mockResponseBody = $this->getMockEnvironmentResponse('put', '202'); - - foreach ($mockRequestOptions as $name => $value) { - $this->clientProphecy->addOption('json', [$name => $value])->shouldBeCalled(); - } - $this->clientProphecy->request('put', '/environments/24-a47ac10b-58cc-4372-a567-0e02b2c3d470')->willReturn($mockResponseBody)->shouldBeCalled(); - $this->command = $this->getApiCommandByName('api:environments:update'); - - $options = []; - foreach ($mockRequestOptions as $key => $value) { - $options['--' . $key] = $value; - } - $options['--lang_version'] = $options['--version']; - unset($options['--version']); - $args = ['environmentId' => '24-a47ac10b-58cc-4372-a567-0e02b2c3d470'] + $options; - $this->executeCommand($args); - - // Assert. - $output = $this->getDisplay(); - $this->assertNotNull($output); - $this->assertJson($output); - $this->assertStringContainsString('The environment configuration is being updated.', $output); - } - - /** - * @return array - */ - public function providerTestApiCommandDefinitionParameters(): array { - $apiAccountsSshKeysListUsage = '--from="-7d" --to="-1d" --sort="field1,-field2" --limit="10" --offset="10"'; - return [ - ['0', 'api:accounts:ssh-keys-list', 'get', $apiAccountsSshKeysListUsage], - ['1', 'api:accounts:ssh-keys-list', 'get', $apiAccountsSshKeysListUsage], - ['1', 'api:accounts:ssh-keys-list', 'get', $apiAccountsSshKeysListUsage], - ['1', 'api:environments:domain-clear-caches', 'post', '12-d314739e-296f-11e9-b210-d663bd873d93 example.com'], - ['1', 'api:applications:find', 'get', 'da1c0a8e-ff69-45db-88fc-acd6d2affbb7'], - ['1', 'api:applications:find', 'get', 'myapp'], - ]; - } - - /** - * @dataProvider providerTestApiCommandDefinitionParameters - */ - public function testApiCommandDefinitionParameters(string $useSpecCache, string $commandName, string $method, string $usage): void { - putenv('ACQUIA_CLI_USE_CLOUD_API_SPEC_CACHE=' . $useSpecCache); - - $this->command = $this->getApiCommandByName($commandName); - $resource = $this->getResourceFromSpec($this->command->getPath(), $method); - $this->assertEquals($resource['summary'], $this->command->getDescription()); - - $expectedCommandName = 'api:' . $resource['x-cli-name']; - $this->assertEquals($expectedCommandName, $this->command->getName()); - - foreach ($resource['parameters'] as $parameter) { - $paramKey = str_replace('#/components/parameters/', '', $parameter['$ref']); - $param = $this->getCloudApiSpec()['components']['parameters'][$paramKey]; - $this->assertTrue( - $this->command->getDefinition()->hasOption($param['name']) || - $this->command->getDefinition()->hasArgument($param['name']), - "Command $expectedCommandName does not have expected argument or option {$param['name']}" - ); - } - - $usages = $this->command->getUsages(); - $this->assertContains($commandName . ' ' . $usage, $usages); - } - - public function testModifiedParameterDescriptions(): void { - $this->command = $this->getApiCommandByName('api:environments:domain-status-find'); - $this->assertStringContainsString('You may also use an environment alias', $this->command->getDefinition()->getArgument('environmentId')->getDescription()); - - $this->command = $this->getApiCommandByName('api:applications:find'); - $this->assertStringContainsString('You may also use an application alias or omit the argument', $this->command->getDefinition()->getArgument('applicationUuid')->getDescription()); - } - - /** - * @return string[][] - */ - public function providerTestApiCommandDefinitionRequestBody(): array { - return [ - ['api:accounts:ssh-key-create', 'post', 'api:accounts:ssh-key-create "mykey" "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQChwPHzTTDKDpSbpa2+d22LcbQmsw92eLsUK3Fmei1fiGDkd34NsYCN8m7lsi3NbvdMS83CtPQPWiCveYPzFs1/hHc4PYj8opD2CNnr5iWVVbyaulCYHCgVv4aB/ojcexg8q483A4xJeF15TiCr/gu34rK6ucTvC/tn/rCwJBudczvEwt0klqYwv8Cl/ytaQboSuem5KgSjO3lMrb6CWtfSNhE43ZOw+UBFBqxIninN868vGMkIv9VY34Pwj54rPn/ItQd6Ef4B0KHHaGmzK0vfP+AK7FxNMoHnj3iYT33KZNqtDozdn5tYyH/bThPebEtgqUn+/w5l6wZIC/8zzvls/127ngHk+jNa0PlNyS2TxhPUK4NaPHIEnnrlp07JEYC4ImcBjaYCWAdcTcUkcJjwZQkN4bGmyO9cjICH98SdLD/HxqzTHeaYDbAX/Hu9HfaBb5dXLWsjw3Xc6hoVnUUZbMQyfgb0KgxDLh92eNGxJkpZiL0VDNOWCxDWsNpzwhLNkLqCvI6lyxiLaUzvJAk6dPaRhExmCbU1lDO2eR0FdSwC1TEhJOT9eDIK1r2hztZKs2oa5FNFfB/IFHVWasVFC9N2h/r/egB5zsRxC9MqBLRBq95NBxaRSFng6ML5WZSw41Qi4C/JWVm89rdj2WqScDHYyAdwyyppWU4T5c9Fmw== example@example.com"'], - ['api:environments:file-copy', 'post', '12-d314739e-296f-11e9-b210-d663bd873d93 --source="14-0c7e79ab-1c4a-424e-8446-76ae8be7e851"'], - ]; - } - - /** - * @dataProvider providerTestApiCommandDefinitionRequestBody - * @param $commandName - * @param $method - * @param $usage - */ - public function testApiCommandDefinitionRequestBody(string $commandName, string $method, string $usage): void { - $this->command = $this->getApiCommandByName($commandName); - $resource = $this->getResourceFromSpec($this->command->getPath(), $method); - foreach ($resource['requestBody']['content']['application/hal+json']['example'] as $propKey => $value) { - $this->assertTrue($this->command->getDefinition()->hasArgument($propKey) || $this->command->getDefinition() - ->hasOption($propKey), - "Command {$this->command->getName()} does not have expected argument or option $propKey"); - } - $this->assertStringContainsString($usage, $this->command->getUsages()[0]); - } - - public function testGetApplicationUuidFromBltYml(): void { - $this->clientProphecy->addOption('headers', ['Accept' => 'application/hal+json, version=2'])->shouldBeCalled(); - $mockBody = $this->getMockResponseFromSpec('/applications/{applicationUuid}', 'get', '200'); - $this->clientProphecy->request('get', '/applications/' . $mockBody->uuid)->willReturn($mockBody)->shouldBeCalled(); - $this->command = $this->getApiCommandByName('api:applications:find'); - $bltConfigFilePath = Path::join($this->projectDir, 'blt', 'blt.yml'); - $this->fs->dumpFile($bltConfigFilePath, Yaml::dump(['cloud' => ['appId' => $mockBody->uuid]])); - $this->executeCommand(); - - $this->getDisplay(); - $this->fs->remove($bltConfigFilePath); - } - - public function testOrganizationMemberDeleteByUserUuid(): void { - $orgId = 'bfafd31a-83a6-4257-b0ec-afdeff83117a'; - $memberUuid = '26c4af83-545b-45cb-b165-d537adc9e0b4'; - - $this->clientProphecy->addOption('headers', ['Accept' => 'application/hal+json, version=2'])->shouldBeCalled(); - $this->mockRequest('postOrganizationMemberDelete', [$orgId, $memberUuid], NULL, 'Member removed'); - - $this->command = $this->getApiCommandByName('api:organizations:member-delete'); - $this->executeCommand( - [ - 'organizationUuid' => $orgId, - 'userUuid' => $memberUuid, - ], - ); - - $output = $this->getDisplay(); - $this->assertEquals(0, $this->getStatusCode()); - $this->assertStringContainsString("Organization member removed", $output); - } - - /** - * Test of deletion of the user from organization by user email. - */ - public function testOrganizationMemberDeleteByUserEmail(): void { - $this->clientProphecy->addOption('headers', ['Accept' => 'application/hal+json, version=2'])->shouldBeCalled(); - $membersResponse = $this->getMockResponseFromSpec('/organizations/{organizationUuid}/members', 'get', 200); - $orgId = 'bfafd31a-83a6-4257-b0ec-afdeff83117a'; - $memberMail = $membersResponse->_embedded->items[0]->mail; - $memberUuid = $membersResponse->_embedded->items[0]->uuid; - $this->clientProphecy->request('get', '/organizations/' . $orgId . '/members') - ->willReturn($membersResponse->_embedded->items)->shouldBeCalled(); - - $this->mockRequest('postOrganizationMemberDelete', [$orgId, $memberUuid], NULL, 'Member removed'); - - $this->command = $this->getApiCommandByName('api:organizations:member-delete'); - $this->executeCommand( - [ - 'organizationUuid' => $orgId, - 'userUuid' => $memberMail, - ], - ); - - $output = $this->getDisplay(); - $this->assertEquals(0, $this->getStatusCode()); - $this->assertStringContainsString("Organization member removed", $output); - } - - /** - * @group brokenProphecy - */ - public function testOrganizationMemberDeleteInvalidEmail(): void { - $membersResponse = $this->getMockResponseFromSpec('/organizations/{organizationUuid}/members', 'get', 200); - $orgId = 'bfafd31a-83a6-4257-b0ec-afdeff83117a'; - $memberUuid = $membersResponse->_embedded->items[0]->mail . 'INVALID'; - $this->clientProphecy->request('get', '/organizations/' . $orgId . '/members') - ->willReturn($membersResponse->_embedded->items)->shouldBeCalled(); - - $this->mockRequest('postOrganizationMemberDelete', [$orgId, $memberUuid], NULL, 'Member removed'); - - $this->command = $this->getApiCommandByName('api:organizations:member-delete'); - $this->expectException(AcquiaCliException::class); - $this->expectExceptionMessage('No matching user found in this organization'); - $this->executeCommand( - [ - 'organizationUuid' => $orgId, - 'userUuid' => $memberUuid, - ], - ); - } - - /** - * Test of deletion of the user from organization by user email. - */ - public function testOrganizationMemberDeleteNoMembers(): void { - $membersResponse = $this->getMockResponseFromSpec('/organizations/{organizationUuid}/members', 'get', 200); - $orgId = 'bfafd31a-83a6-4257-b0ec-afdeff83117a'; - $memberUuid = $membersResponse->_embedded->items[0]->mail; - $this->clientProphecy->request('get', '/organizations/' . $orgId . '/members') - ->willReturn([])->shouldBeCalled(); - - $this->command = $this->getApiCommandByName('api:organizations:member-delete'); - $this->expectException(AcquiaCliException::class); - $this->expectExceptionMessage('Organization has no members'); - $this->executeCommand( - [ - 'organizationUuid' => $orgId, - 'userUuid' => $memberUuid, - ], - ); - } - -} diff --git a/tests/phpunit/src/Commands/ClearCacheCommandTest.php b/tests/phpunit/src/Commands/ClearCacheCommandTest.php deleted file mode 100644 index 543be2ad0..000000000 --- a/tests/phpunit/src/Commands/ClearCacheCommandTest.php +++ /dev/null @@ -1,67 +0,0 @@ -injectCommand(ClearCacheCommand::class); - } - - /** - * @group serial - */ - public function testAliasesAreCached(): void { - ClearCacheCommand::clearCaches(); - $this->command = $this->injectCommand(IdeListCommand::class); - - // Request for applications. - $applicationsResponse = $this->getMockResponseFromSpec('/applications', - 'get', '200'); - $applicationsResponse = $this->filterApplicationsResponse($applicationsResponse, 1, TRUE); - $this->clientProphecy->request('get', '/applications') - ->willReturn($applicationsResponse->{'_embedded'}->items) - // Ensure this is only called once, even though we execute the command twice. - ->shouldBeCalledTimes(1); - - $this->clientProphecy->addQuery('filter', 'hosting=@*:devcloud2')->shouldBeCalled(); - $this->mockApplicationRequest(); - $this->mockRequest('getApplicationIdes', 'a47ac10b-58cc-4372-a567-0e02b2c3d470'); - $this->mockRequest('getAccount'); - - $alias = 'devcloud2'; - $args = ['applicationUuid' => $alias]; - $inputs = [ - // Would you like to link the Cloud application Sample application to this repository? - 'n', - ]; - - $this->executeCommand($args, $inputs); - // Run it twice, make sure API calls are made only once. - $this->executeCommand($args, $inputs); - - // Assert. - $output = $this->getDisplay(); - $this->assertEquals(0, $this->getStatusCode()); - } - - public function testClearCaches(): void { - $this->executeCommand(); - $output = $this->getDisplay(); - $this->assertStringContainsString('Acquia CLI caches were cleared', $output); - - $cache = CommandBase::getAliasCache(); - $this->assertCount(0, iterator_to_array($cache->getItems(), FALSE)); - } - -} diff --git a/tests/phpunit/src/Commands/Remote/DrushCommandTest.php b/tests/phpunit/src/Commands/Remote/DrushCommandTest.php deleted file mode 100644 index 2376421e3..000000000 --- a/tests/phpunit/src/Commands/Remote/DrushCommandTest.php +++ /dev/null @@ -1,72 +0,0 @@ -injectCommand(DrushCommand::class); - } - - /** - * @return array>> - */ - public function providerTestRemoteDrushCommand(): array { - return [ - [ - [ - '-vvv' => '', - 'drush_command' => 'status --fields=db-status', - ], - ], - [ - [ - '-vvv' => '', - 'drush_command' => 'status --fields=db-status', - ], - ], - ]; - } - - /** - * @dataProvider providerTestRemoteDrushCommand - * @group serial - */ - public function testRemoteDrushCommand(array $args): void { - $this->mockGetEnvironment(); - [$process, $localMachineHelper] = $this->mockForExecuteCommand(); - $localMachineHelper->checkRequiredBinariesExist(['ssh'])->shouldBeCalled(); - $sshCommand = [ - 'ssh', - 'site.dev@sitedev.ssh.hosted.acquia-sites.com', - '-t', - '-o StrictHostKeyChecking=no', - '-o AddressFamily inet', - '-o LogLevel=ERROR', - 'cd /var/www/html/site.dev/docroot; ', - 'drush', - '--uri=http://sitedev.hosted.acquia-sites.com status --fields=db-status', - ]; - $localMachineHelper - ->execute($sshCommand, Argument::type('callable'), NULL, TRUE, NULL) - ->willReturn($process->reveal()) - ->shouldBeCalled(); - - $this->command->sshHelper = new SshHelper($this->output, $localMachineHelper->reveal(), $this->logger); - $this->executeCommand($args, self::inputChooseEnvironment()); - - // Assert. - $this->getDisplay(); - } - -} diff --git a/tests/phpunit/src/Commands/Remote/SshCommandTest.php b/tests/phpunit/src/Commands/Remote/SshCommandTest.php deleted file mode 100644 index 57a37c46a..000000000 --- a/tests/phpunit/src/Commands/Remote/SshCommandTest.php +++ /dev/null @@ -1,55 +0,0 @@ -injectCommand(SshCommand::class); - } - - /** - * @group serial - */ - public function testRemoteAliasesDownloadCommand(): void { - ClearCacheCommand::clearCaches(); - $this->mockForGetEnvironmentFromAliasArg(); - [$process, $localMachineHelper] = $this->mockForExecuteCommand(); - $localMachineHelper->checkRequiredBinariesExist(['ssh'])->shouldBeCalled(); - $sshCommand = [ - 'ssh', - 'site.dev@sitedev.ssh.hosted.acquia-sites.com', - '-t', - '-o StrictHostKeyChecking=no', - '-o AddressFamily inet', - '-o LogLevel=ERROR', - 'cd /var/www/html/devcloud2.dev; exec $SHELL -l', - ]; - $localMachineHelper - ->execute($sshCommand, Argument::type('callable'), NULL, TRUE, NULL) - ->willReturn($process->reveal()) - ->shouldBeCalled(); - - $this->command->sshHelper = new SshHelper($this->output, $localMachineHelper->reveal(), $this->logger); - - $args = [ - 'alias' => 'devcloud2.dev', - ]; - $this->executeCommand($args); - - // Assert. - $output = $this->getDisplay(); - } - -}