diff --git a/.phpstorm.meta.php b/.phpstorm.meta.php index b5f34b836..d49f754b9 100644 --- a/.phpstorm.meta.php +++ b/.phpstorm.meta.php @@ -1,12 +1,14 @@ AccountResponse::class, 'getApplications' => ApplicationsResponse::class, 'getApplicationByUuid' => ApplicationResponse::class, 'getApplicationEnvironments' => EnvironmentsResponse::class, diff --git a/src/Command/Auth/AuthLoginCommand.php b/src/Command/Auth/AuthLoginCommand.php index a9effd9c0..97a987e60 100644 --- a/src/Command/Auth/AuthLoginCommand.php +++ b/src/Command/Auth/AuthLoginCommand.php @@ -5,6 +5,7 @@ namespace Acquia\Cli\Command\Auth; use Acquia\Cli\Command\CommandBase; +use AcquiaCloudApi\Endpoints\Account; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; @@ -61,10 +62,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int } private function writeApiCredentialsToDisk(string $apiKey, string $apiSecret): void { - $tokenInfo = $this->cloudApiClientService->getClient()->request('get', "/account/tokens/$apiKey"); + $account = new Account($this->cloudApiClientService->getClient()); + $accountInfo = $account->get(); $keys = $this->datastoreCloud->get('keys'); $keys[$apiKey] = [ - 'label' => $tokenInfo->label, + 'label' => $accountInfo->mail, 'secret' => $apiSecret, 'uuid' => $apiKey, ]; diff --git a/tests/phpunit/src/Commands/Acsf/AcsfApiCommandTest.php b/tests/phpunit/src/Commands/Acsf/AcsfApiCommandTest.php index 2e555524b..cb002bb41 100644 --- a/tests/phpunit/src/Commands/Acsf/AcsfApiCommandTest.php +++ b/tests/phpunit/src/Commands/Acsf/AcsfApiCommandTest.php @@ -7,7 +7,6 @@ use Acquia\Cli\AcsfApi\AcsfClient; use Acquia\Cli\AcsfApi\AcsfClientService; use Acquia\Cli\AcsfApi\AcsfCredentials; -use Acquia\Cli\CloudApi\ClientService; use Acquia\Cli\Command\Acsf\AcsfApiBaseCommand; use Acquia\Cli\Command\Acsf\AcsfCommandFactory; use Acquia\Cli\Command\CommandBase; @@ -32,7 +31,7 @@ public function setUp(): void { protected function createCommand(): CommandBase { $this->createMockCloudConfigFile($this->getAcsfCredentialsFileContents()); $this->cloudCredentials = new AcsfCredentials($this->datastoreCloud); - $this->setClientProphecies(AcsfClientService::class); + $this->setClientProphecies(); return $this->injectCommand(AcsfApiBaseCommand::class); } @@ -119,11 +118,11 @@ public function testAcsfCommandExecutionForHttpGetMultiple(mixed $method, mixed $contents = json_decode($output, TRUE); } - protected function setClientProphecies(?string $clientServiceClass = ClientService::class): void { + protected function setClientProphecies(): void { $this->clientProphecy = $this->prophet->prophesize(AcsfClient::class); $this->clientProphecy->addOption('headers', ['User-Agent' => 'acli/UNKNOWN']); $this->clientProphecy->addOption('debug', Argument::type(OutputInterface::class)); - $this->clientServiceProphecy = $this->prophet->prophesize($clientServiceClass); + $this->clientServiceProphecy = $this->prophet->prophesize(AcsfClientService::class); $this->clientServiceProphecy->getClient() ->willReturn($this->clientProphecy->reveal()); $this->clientServiceProphecy->isMachineAuthenticated() diff --git a/tests/phpunit/src/Commands/Auth/AuthLoginCommandTest.php b/tests/phpunit/src/Commands/Auth/AuthLoginCommandTest.php index 97873fa64..6d3cfaadc 100644 --- a/tests/phpunit/src/Commands/Auth/AuthLoginCommandTest.php +++ b/tests/phpunit/src/Commands/Auth/AuthLoginCommandTest.php @@ -9,7 +9,9 @@ use Acquia\Cli\Config\CloudDataConfig; use Acquia\Cli\DataStore\CloudDataStore; use Acquia\Cli\Tests\CommandTestBase; +use AcquiaCloudApi\Connector\Connector; use Generator; +use Prophecy\Argument; use Symfony\Component\Validator\Exception\ValidatorException; /** @@ -21,41 +23,18 @@ protected function createCommand(): CommandBase { return $this->injectCommand(AuthLoginCommand::class); } - public function providerTestAuthLoginCommand(): Generator { - yield 'Keys as args' => [ - // $machineIsAuthenticated - FALSE, - // $assertCloudPrompts - FALSE, - // No interaction - [], - // Args. - ['--key' => $this->key, '--secret' => $this->secret], - // Output to assert. - 'Saved credentials', - ]; - } - - /** - * @dataProvider providerTestAuthLoginCommand - * @group brokenProphecy - */ - public function testAuthLoginCommand(bool $machineIsAuthenticated, bool $assertCloudPrompts, array $inputs, array $args, string $outputToAssert): void { - $this->mockRequest('getAccountToken', $this->key); - if (!$machineIsAuthenticated) { - $this->clientServiceProphecy->isMachineAuthenticated()->willReturn(FALSE); - $this->removeMockCloudConfigFile(); - $this->createDataStores(); - $this->command = $this->createCommand(); - } + public function testAuthLoginCommand(): void { + $this->mockRequest('getAccount'); + $this->clientServiceProphecy->setConnector(Argument::type(Connector::class))->shouldBeCalled(); + $this->clientServiceProphecy->isMachineAuthenticated()->willReturn(FALSE); + $this->removeMockCloudConfigFile(); + $this->createDataStores(); + $this->command = $this->createCommand(); - $this->executeCommand($args, $inputs); + $this->executeCommand(['--key' => $this->key, '--secret' => $this->secret]); $output = $this->getDisplay(); - if ($assertCloudPrompts) { - $this->assertInteractivePrompts($output); - } - $this->assertStringContainsString($outputToAssert, $output); + $this->assertStringContainsString('Saved credentials', $output); $this->assertKeySavedCorrectly(); } diff --git a/tests/phpunit/src/TestBase.php b/tests/phpunit/src/TestBase.php index 053976fb7..2b418350d 100644 --- a/tests/phpunit/src/TestBase.php +++ b/tests/phpunit/src/TestBase.php @@ -731,11 +731,11 @@ public function mockGuzzleClientForUpdate(array $releases): ObjectProphecy { return $guzzleClient; } - protected function setClientProphecies(?string $clientServiceClass = ClientService::class): void { + protected function setClientProphecies(): void { $this->clientProphecy = $this->prophet->prophesize(Client::class); $this->clientProphecy->addOption('headers', ['User-Agent' => 'acli/UNKNOWN']); $this->clientProphecy->addOption('debug', Argument::type(OutputInterface::class)); - $this->clientServiceProphecy = $this->prophet->prophesize($clientServiceClass); + $this->clientServiceProphecy = $this->prophet->prophesize(ClientService::class); $this->clientServiceProphecy->getClient() ->willReturn($this->clientProphecy->reveal()); $this->clientServiceProphecy->isMachineAuthenticated()