diff --git a/tests/phpunit/src/AcsfApi/AcsfServiceTest.php b/tests/phpunit/src/AcsfApi/AcsfServiceTest.php deleted file mode 100644 index 7466f875e..000000000 --- a/tests/phpunit/src/AcsfApi/AcsfServiceTest.php +++ /dev/null @@ -1,55 +0,0 @@ -cloudCredentials = new AcsfCredentials($this->datastoreCloud); - - } - - /** - * @return array - */ - public function providerTestIsMachineAuthenticated(): array { - return [ - [ - ['ACSF_USERNAME' => 'key', 'ACSF_KEY' => 'secret'], - TRUE, - ], - [ - ['ACSF_USERNAME' => 'key', 'ACSF_KEY' => 'secret'], - TRUE, - ], - [ - ['ACSF_USERNAME' => NULL, 'ACSF_KEY' => NULL], - FALSE, - ], - [ - ['ACSF_USERNAME' => 'key', 'ACSF_KEY' => NULL], - FALSE, - ], - ]; - } - - /** - * @dataProvider providerTestIsMachineAuthenticated - */ - public function testIsMachineAuthenticated(array $envVars, bool $isAuthenticated): void { - self::setEnvVars($envVars); - $clientService = new AcsfClientService(new AcsfConnectorFactory(['key' => NULL, 'secret' => NULL]), $this->prophet->prophesize(Application::class)->reveal(), $this->cloudCredentials); - $this->assertEquals($isAuthenticated, $clientService->isMachineAuthenticated()); - self::unsetEnvVars($envVars); - } - -} diff --git a/tests/phpunit/src/AcsfApi/EnvVarAcsfAuthenticationTest.php b/tests/phpunit/src/AcsfApi/EnvVarAcsfAuthenticationTest.php deleted file mode 100644 index e2755f49d..000000000 --- a/tests/phpunit/src/AcsfApi/EnvVarAcsfAuthenticationTest.php +++ /dev/null @@ -1,35 +0,0 @@ -cloudCredentials = new AcsfCredentials($this->datastoreCloud); - putenv('ACSF_USERNAME=' . $this->key); - putenv('ACSF_KEY=' . $this->secret); - putenv('ACSF_FACTORY_URI=' . $this->acsfCurrentFactoryUrl); - } - - protected function tearDown(): void { - parent::tearDown(); - putenv('ACSF_USERNAME'); - putenv('ACSF_KEY'); - } - - public function testKeyAndSecret(): void { - $this->removeMockCloudConfigFile(); - self::assertEquals($this->key, $this->cloudCredentials->getCloudKey()); - self::assertEquals($this->secret, $this->cloudCredentials->getCloudSecret()); - self::assertEquals($this->acsfCurrentFactoryUrl, $this->cloudCredentials->getBaseUri()); - } - -} 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 << - */ - public function providerTestIsMachineAuthenticated(): array { - return [ - [ - ['ACLI_ACCESS_TOKEN' => NULL, 'ACLI_KEY' => NULL, 'ACLI_SECRET' => NULL], - FALSE, - ], - [ - ['ACLI_ACCESS_TOKEN' => NULL, 'ACLI_KEY' => 'key', 'ACLI_SECRET' => NULL], - FALSE, - ], - ]; - } - - /** - * @dataProvider providerTestIsMachineAuthenticated - */ - public function testIsMachineAuthenticated(array $envVars, bool $isAuthenticated): void { - self::setEnvVars($envVars); - $cloudDatastore = $this->prophet->prophesize(CloudDataStore::class); - $clientService = new AcsfClientService(new AcsfConnectorFactory(['key' => NULL, 'secret' => NULL, 'accessToken' => NULL]), $this->application, new AcsfCredentials($cloudDatastore->reveal())); - $this->assertEquals($isAuthenticated, $clientService->isMachineAuthenticated()); - $clientService->getClient(); - self::unsetEnvVars($envVars); - } - - public function testEmbeddedItems(): void { - putenv('ACQUIA_CLI_USE_CLOUD_API_SPEC_CACHE=1'); - $cloudDatastore = $this->prophet->prophesize(CloudDataStore::class); - $clientService = new AcsfClientService(new AcsfConnectorFactory(['key' => NULL, 'secret' => NULL, 'accessToken' => NULL]), $this->application, new AcsfCredentials($cloudDatastore->reveal())); - $client = $clientService->getClient(); - $mockBody = ['_embedded' => ['items' => 'foo']]; - $response = new Response(200, [], json_encode($mockBody)); - $body = $client->processResponse($response); - $this->assertEquals('foo', $body); - } - - public function testErrorMessage(): void { - putenv('ACQUIA_CLI_USE_CLOUD_API_SPEC_CACHE=1'); - $cloudDatastore = $this->prophet->prophesize(CloudDataStore::class); - $clientService = new AcsfClientService(new AcsfConnectorFactory(['key' => NULL, 'secret' => NULL, 'accessToken' => NULL]), $this->application, new AcsfCredentials($cloudDatastore->reveal())); - $client = $clientService->getClient(); - $mockBody = ['error' => 'foo', 'message' => 'bar']; - $response = new Response(200, [], json_encode($mockBody)); - $this->expectException(ApiErrorException::class); - $this->expectExceptionMessage('bar'); - $client->processResponse($response); - } - - public function testErrorCode(): void { - putenv('ACQUIA_CLI_USE_CLOUD_API_SPEC_CACHE=1'); - $cloudDatastore = $this->prophet->prophesize(CloudDataStore::class); - $clientService = new AcsfClientService(new AcsfConnectorFactory(['key' => NULL, 'secret' => NULL, 'accessToken' => NULL]), $this->application, new AcsfCredentials($cloudDatastore->reveal())); - $client = $clientService->getClient(); - $mockBody = ['message' => 'bar']; - $response = new Response(400, [], json_encode($mockBody)); - $this->expectException(ApiErrorException::class); - $this->expectExceptionMessage('bar'); - $client->processResponse($response); - } - -} diff --git a/tests/phpunit/src/CloudApi/ClientServiceTest.php b/tests/phpunit/src/CloudApi/ClientServiceTest.php deleted file mode 100644 index ae5d4e993..000000000 --- a/tests/phpunit/src/CloudApi/ClientServiceTest.php +++ /dev/null @@ -1,50 +0,0 @@ - - */ - public function providerTestIsMachineAuthenticated(): array { - return [ - [ - ['ACLI_ACCESS_TOKEN' => 'token', 'ACLI_KEY' => 'key', 'ACLI_SECRET' => 'secret'], - TRUE, - ], - [ - ['ACLI_ACCESS_TOKEN' => NULL, 'ACLI_KEY' => 'key', 'ACLI_SECRET' => 'secret'], - TRUE, - ], - [ - ['ACLI_ACCESS_TOKEN' => NULL, 'ACLI_KEY' => NULL, 'ACLI_SECRET' => NULL], - FALSE, - ], - [ - ['ACLI_ACCESS_TOKEN' => NULL, 'ACLI_KEY' => 'key', 'ACLI_SECRET' => NULL], - FALSE, - ], - ]; - } - - /** - * @dataProvider providerTestIsMachineAuthenticated - */ - public function testIsMachineAuthenticated(array $envVars, bool $isAuthenticated): void { - self::setEnvVars($envVars); - $cloudDatastore = $this->prophet->prophesize(CloudDataStore::class); - $clientService = new ClientService(new ConnectorFactory(['key' => NULL, 'secret' => NULL, 'accessToken' => NULL]), $this->application, new CloudCredentials($cloudDatastore->reveal())); - $this->assertEquals($isAuthenticated, $clientService->isMachineAuthenticated()); - self::unsetEnvVars($envVars); - } - -} diff --git a/tests/phpunit/src/CloudApi/EnvVarAuthenticationTest.php b/tests/phpunit/src/CloudApi/EnvVarAuthenticationTest.php deleted file mode 100644 index fcbd28799..000000000 --- a/tests/phpunit/src/CloudApi/EnvVarAuthenticationTest.php +++ /dev/null @@ -1,33 +0,0 @@ -key); - putenv('ACLI_SECRET=' . $this->secret); - putenv('ACLI_CLOUD_API_BASE_URI=' . $this->cloudApiBaseUri); - } - - protected function tearDown(): void { - parent::tearDown(); - putenv('ACLI_KEY'); - putenv('ACLI_SECRET'); - } - - public function testKeyAndSecret(): void { - $this->removeMockCloudConfigFile(); - self::assertEquals($this->key, $this->cloudCredentials->getCloudKey()); - self::assertEquals($this->secret, $this->cloudCredentials->getCloudSecret()); - self::assertEquals($this->cloudApiBaseUri, $this->cloudCredentials->getBaseUri()); - } - -} diff --git a/tests/phpunit/src/Misc/ApiSpecTest.php b/tests/phpunit/src/Misc/ApiSpecTest.php deleted file mode 100644 index de7df9115..000000000 --- a/tests/phpunit/src/Misc/ApiSpecTest.php +++ /dev/null @@ -1,21 +0,0 @@ -assertFileExists($apiSpecFile); - $apiSpec = file_get_contents($apiSpecFile); - $this->assertStringNotContainsString('x-internal', $apiSpec); - $this->assertStringNotContainsString('cloud.acquia.dev', $apiSpec); - $this->assertStringNotContainsString('network.acquia-sites.com', $apiSpec); - } - -} diff --git a/tests/phpunit/src/Misc/EnvDbCredsTest.php b/tests/phpunit/src/Misc/EnvDbCredsTest.php deleted file mode 100644 index fb02fd52d..000000000 --- a/tests/phpunit/src/Misc/EnvDbCredsTest.php +++ /dev/null @@ -1,59 +0,0 @@ -dbUser = 'myuserisgood'; - $this->dbPassword = 'mypasswordisgreat'; - $this->dbName = 'mynameisgrand'; - $this->dbHost = 'myhostismeh'; - TestBase::setEnvVars($this->getEnvVars()); - parent::setUp(); - } - - public function tearDown(): void { - parent::tearDown(); - TestBase::unsetEnvVars($this->getEnvVars()); - } - - /** - * @return array - */ - protected function getEnvVars(): array { - return [ - 'ACLI_DB_HOST' => $this->dbHost, - 'ACLI_DB_NAME' => $this->dbName, - 'ACLI_DB_PASSWORD' => $this->dbPassword, - 'ACLI_DB_USER' => $this->dbUser, - ]; - } - - protected function createCommand(): CommandBase { - return $this->injectCommand(ClearCacheCommand::class); - } - - public function testEnvDbCreds(): void { - $this->assertEquals($this->dbUser, $this->command->getLocalDbUser()); - $this->assertEquals($this->dbPassword, $this->command->getLocalDbPassword()); - $this->assertEquals($this->dbName, $this->command->getLocalDbName()); - $this->assertEquals($this->dbHost, $this->command->getLocalDbHost()); - } - -} diff --git a/tests/phpunit/src/Misc/ExceptionListenerTest.php b/tests/phpunit/src/Misc/ExceptionListenerTest.php deleted file mode 100644 index 8d87f7519..000000000 --- a/tests/phpunit/src/Misc/ExceptionListenerTest.php +++ /dev/null @@ -1,117 +0,0 @@ -environmentId can also be a site alias. E.g. myapp.dev.' . PHP_EOL . 'Run acli remote:aliases:list to see a list of all available aliases.'; - private static string $appAliasHelp = 'The applicationUuid argument must be a valid UUID or unique application alias accessible to your Cloud Platform user.' . PHP_EOL . PHP_EOL . 'An alias consists of an application name optionally prefixed with a hosting realm, e.g. myapp or prod.myapp.' . PHP_EOL . PHP_EOL . 'Run acli remote:aliases:list to see a list of all available aliases.'; - - /** - * @dataProvider providerTestHelp - */ - public function testHelp(Throwable $error, string|array $helpText): void { - $exceptionListener = new ExceptionListener(); - $commandProphecy = $this->prophet->prophesize(Command::class); - $applicationProphecy = $this->prophet->prophesize(Application::class); - $messages1 = ['You can find Acquia CLI documentation at https://docs.acquia.com/acquia-cli/', 'You can submit a support ticket at https://support-acquia.force.com/s/contactsupport' . PHP_EOL . 'Re-run the command with the -vvv flag and include the full command output in your support ticket.']; - if (is_array($helpText)) { - $messages = array_merge($helpText, $messages1); - } - else { - $messages = array_merge([$helpText], $messages1); - } - $messages[0] = "How to fix it: $messages[0]"; - $applicationProphecy->setHelpMessages($messages)->shouldBeCalled(); - $commandProphecy->getApplication()->willReturn($applicationProphecy->reveal()); - $consoleErrorEvent = new ConsoleErrorEvent($this->input, $this->output, $error, $commandProphecy->reveal()); - $exceptionListener->onConsoleError($consoleErrorEvent); - $this->prophet->checkPredictions(); - self::assertTrue(TRUE); - } - - /** - * @return string[][] - */ - public function providerTestHelp(): array { - return [ - [ - new IdentityProviderException('invalid_client', 0, ''), - 'Run acli auth:login to reset your API credentials.', - ], - [ - new RuntimeException('Not enough arguments (missing: "environmentId").'), - self::$siteAliasHelp, - ], - [ - new RuntimeException('Not enough arguments (missing: "environmentUuid").'), - self::$siteAliasHelp, - ], - [ - new AcquiaCliException('No applications match the alias {applicationAlias}'), - self::$appAliasHelp, - ], - [ - new AcquiaCliException('Multiple applications match the alias {applicationAlias}'), - self::$appAliasHelp, - ], - [ - new AcquiaCliException('{environmentId} must be a valid UUID or site alias.'), - self::$siteAliasHelp, - ], - [ - new AcquiaCliException('{environmentUuid} must be a valid UUID or site alias.'), - self::$siteAliasHelp, - ], - [ - new AcquiaCliException('Access token file not found at {file}'), - 'Get help for this error at https://docs.acquia.com/ide/known-issues/#the-automated-cloud-platform-api-authentication-might-fail', - ], - [ - new AcquiaCliException('Access token expiry file not found at {file}'), - 'Get help for this error at https://docs.acquia.com/ide/known-issues/#the-automated-cloud-platform-api-authentication-might-fail', - ], - [ - new AcquiaCliException('This machine is not yet authenticated with the Cloud Platform.'), - 'Run `acli auth:login` to re-authenticated with the Cloud Platform.', - ], - [ - new AcquiaCliException('This machine is not yet authenticated with Site Factory.'), - 'Run `acli auth:acsf-login` to re-authenticate with Site Factory.', - ], - [ - new AcquiaCliException('Could not extract aliases to {destination}'), - 'Check that you have write access to the directory', - ], - [ - new AcquiaCliException('Invalid key in datastore at {filepath}'), - 'Delete the datastore and run this command again.', - ], - [ - new ApiErrorException((object) ['error' => '', 'message' => "There are no available Cloud IDEs for this application.\n"]), - 'Delete an existing IDE via acli ide:delete or contact your Account Manager or Acquia Sales to purchase additional IDEs.', - ], - [ - new ApiErrorException((object) ['error' => '', 'message' => 'This resource requires additional authentication.']), - ['This is likely because you have Federated Authentication required for your organization.', 'Run `acli login` to authenticate via API token and then try again.'], - ], - [ - new ApiErrorException((object) ['error' => 'asdf', 'message' => 'fdsa']), - 'You can learn more about Cloud Platform API at https://docs.acquia.com/cloud-platform/develop/api/', - ], - ]; - } - -} diff --git a/tests/phpunit/src/Misc/LocalMachineHelperTest.php b/tests/phpunit/src/Misc/LocalMachineHelperTest.php deleted file mode 100644 index 9036737ac..000000000 --- a/tests/phpunit/src/Misc/LocalMachineHelperTest.php +++ /dev/null @@ -1,120 +0,0 @@ -localMachineHelper; - $opened = $localMachineHelper->startBrowser('https://google.com', 'cat'); - $this->assertTrue($opened, 'Failed to open browser'); - putenv('DISPLAY'); - } - - /** - * @return bool[][] - */ - public function providerTestExecuteFromCmd(): array { - return [ - [FALSE, NULL, NULL], - [FALSE, FALSE, FALSE], - [TRUE, FALSE, FALSE], - ]; - } - - /** - * @dataProvider providerTestExecuteFromCmd() - */ - public function testExecuteFromCmd(bool $interactive, bool|NULL $isTty, bool|NULL $printOutput): void { - $localMachineHelper = $this->localMachineHelper; - $localMachineHelper->setIsTty($isTty); - $this->input->setInteractive($interactive); - $process = $localMachineHelper->executeFromCmd('echo "hello world"', NULL, NULL, $printOutput); - $this->assertTrue($process->isSuccessful()); - assert(is_a($this->output, BufferedOutput::class)); - $buffer = $this->output->fetch(); - if ($printOutput === FALSE) { - $this->assertEmpty($buffer); - } - else { - $this->assertStringContainsString("hello world", $buffer); - } - } - - public function testExecuteWithCwd(): void { - $this->setupFsFixture(); - $localMachineHelper = $this->localMachineHelper; - $process = $localMachineHelper->execute(['ls', '-lash'], NULL, $this->fixtureDir, FALSE); - $this->assertTrue($process->isSuccessful()); - $this->assertStringContainsString('xdebug.ini', $process->getOutput()); - } - - public function testCommandExists(): void { - $localMachineHelper = $this->localMachineHelper; - $exists = $localMachineHelper->commandExists('cat'); - $this->assertIsBool($exists); - } - - public function testHomeDirWindowsCmd(): void { - self::setEnvVars([ - 'HOMEPATH' => 'something', - ]); - self::unsetEnvVars([ - 'MSYSTEM', - 'HOME', - ]); - $home = LocalMachineHelper::getHomeDir(); - $this->assertEquals('something', $home); - } - - public function testHomeDirWindowsMsys2(): void { - self::setEnvVars([ - 'HOMEPATH' => 'something', - 'MSYSTEM' => 'MSYS2', - ]); - self::unsetEnvVars(['HOME']); - $home = LocalMachineHelper::getHomeDir(); - $this->assertEquals('something', $home); - } - - /** - * I don't know why, but apparently Ming is unsupported ¯\_(ツ)_/¯. - */ - public function testHomeDirWindowsMing(): void { - self::setEnvVars(['MSYSTEM' => 'MING']); - self::unsetEnvVars(['HOME']); - $this->expectException(AcquiaCliException::class); - $this->expectExceptionMessage('Could not determine $HOME directory. Ensure $HOME is set in your shell.'); - LocalMachineHelper::getHomeDir(); - } - - public function testConfigDirLegacy(): void { - self::setEnvVars(['HOME' => 'vfs://root']); - $configDir = LocalMachineHelper::getConfigDir(); - $this->assertEquals('vfs://root/.acquia', $configDir); - } - - public function testConfigDirFromXdg(): void { - self::setEnvVars(['XDG_CONFIG_HOME' => 'vfs://root/.config']); - $configDir = LocalMachineHelper::getConfigDir(); - $this->assertEquals('vfs://root/.config/acquia', $configDir); - } - - public function testConfigDirDefault(): void { - self::setEnvVars(['HOME' => 'vfs://root']); - self::unsetEnvVars(['XDG_CONFIG_HOME']); - unlink('vfs://root/.acquia/cloud_api.conf'); - rmdir('vfs://root/.acquia'); - $configDir = LocalMachineHelper::getConfigDir(); - $this->assertEquals('vfs://root/.config/acquia', $configDir); - } - -}