From c58e59e6ce0977713047928bfd7d8558500c8ba5 Mon Sep 17 00:00:00 2001 From: Dane Powell Date: Fri, 8 Apr 2022 12:47:33 -0600 Subject: [PATCH] CLI-713: Fixes #875: Apache access logstream failing (#876) * CLI-713: Fixes #875: Apache access logstream failing * Fix tests. * Fix tests. Co-authored-by: Matthew Grasmick --- src/Command/App/LogTailCommand.php | 8 ++++---- src/Command/CommandBase.php | 20 +++++++------------ .../src/Commands/App/LogTailCommandTest.php | 6 ++---- tests/phpunit/src/TestBase.php | 15 -------------- 4 files changed, 13 insertions(+), 36 deletions(-) diff --git a/src/Command/App/LogTailCommand.php b/src/Command/App/LogTailCommand.php index 44d66386a..cc3260819 100644 --- a/src/Command/App/LogTailCommand.php +++ b/src/Command/App/LogTailCommand.php @@ -30,12 +30,12 @@ protected function configure() { * @return int 0 if everything went fine, or an exit code * @throws \Exception */ - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { $environment_id = $this->determineCloudEnvironment(); $acquia_cloud_client = $this->cloudApiClientService->getClient(); - $logs = $this->promptChooseLogs($acquia_cloud_client, $environment_id); - $log_types = array_map(function ($log) { - return $log->type; + $logs = $this->promptChooseLogs(); + $log_types = array_map(static function ($log) { + return $log['type']; }, $logs); $logs_resource = new Logs($acquia_cloud_client); $stream = $logs_resource->stream($environment_id); diff --git a/src/Command/CommandBase.php b/src/Command/CommandBase.php index 01f53d37e..2b912f704 100644 --- a/src/Command/CommandBase.php +++ b/src/Command/CommandBase.php @@ -19,7 +19,6 @@ use AcquiaCloudApi\Endpoints\Applications; use AcquiaCloudApi\Endpoints\Environments; use AcquiaCloudApi\Endpoints\Ides; -use AcquiaCloudApi\Endpoints\Logs; use AcquiaCloudApi\Endpoints\Subscriptions; use AcquiaCloudApi\Response\ApplicationResponse; use AcquiaCloudApi\Response\EnvironmentResponse; @@ -41,11 +40,9 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Exception\RuntimeException; use Symfony\Component\Console\Helper\ProgressBar; -use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Logger\ConsoleLogger; -use Symfony\Component\Console\Output\NullOutput; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\ChoiceQuestion; use Symfony\Component\Console\Question\Question; @@ -551,18 +548,15 @@ protected function promptChooseEnvironment( /** * Prompts the user to choose from a list of logs for a given Cloud Platform environment. * - * @param Client $acquia_cloud_client - * @param string $environment_id - * * @return null|object|array */ - protected function promptChooseLogs( - Client $acquia_cloud_client, - string $environment_id - ) { - $logs_resource = new Logs($acquia_cloud_client); - $logs = $logs_resource->getAll($environment_id); - + protected function promptChooseLogs() { + $logs = array_map(static function ($log_type, $log_label) { + return [ + 'type' => $log_type, + 'label' => $log_label, + ]; + }, array_keys(LogstreamManager::AVAILABLE_TYPES), LogstreamManager::AVAILABLE_TYPES); return $this->promptChooseFromObjectsOrArrays( $logs, 'type', diff --git a/tests/phpunit/src/Commands/App/LogTailCommandTest.php b/tests/phpunit/src/Commands/App/LogTailCommandTest.php index e4dcb85f6..754cff3dd 100644 --- a/tests/phpunit/src/Commands/App/LogTailCommandTest.php +++ b/tests/phpunit/src/Commands/App/LogTailCommandTest.php @@ -31,7 +31,6 @@ public function testLogTailCommand(): void { $applications_response = $this->mockApplicationsRequest(); $this->mockApplicationRequest(); $this->mockEnvironmentsRequest($applications_response); - $this->mockLogListRequest(); $this->mockLogStreamRequest(); $this->executeCommand([], [ // Would you like Acquia CLI to search for a Cloud application that matches your local git config? @@ -52,7 +51,7 @@ public function testLogTailCommand(): void { $this->assertStringContainsString('Please select a Cloud Platform application:', $output); $this->assertStringContainsString('[0] Sample application 1', $output); $this->assertStringContainsString('[1] Sample application 2', $output); - $this->assertStringContainsString('Apache access', $output); + $this->assertStringContainsString('Apache request', $output); $this->assertStringContainsString('Drupal request', $output); } @@ -62,7 +61,6 @@ public function testLogTailCommand(): void { * @throws \Psr\Cache\InvalidArgumentException */ public function testLogTailCommandWithEnvArg(): void { - $this->mockLogListRequest(); $this->mockLogStreamRequest(); $this->executeCommand( ['environmentId' => '24-a47ac10b-58cc-4372-a567-0e02b2c3d470'], @@ -73,7 +71,7 @@ public function testLogTailCommandWithEnvArg(): void { // Assert. $this->prophet->checkPredictions(); $output = $this->getDisplay(); - $this->assertStringContainsString('Apache access', $output); + $this->assertStringContainsString('Apache request', $output); $this->assertStringContainsString('Drupal request', $output); } diff --git a/tests/phpunit/src/TestBase.php b/tests/phpunit/src/TestBase.php index d65e22578..22bf90415 100644 --- a/tests/phpunit/src/TestBase.php +++ b/tests/phpunit/src/TestBase.php @@ -620,21 +620,6 @@ protected function mockIdeDeleteRequest(string $ide_uuid) { return $ide_delete_response; } - /** - * @return object - * @throws \Psr\Cache\InvalidArgumentException - */ - protected function mockLogListRequest() { - $response = $this->getMockResponseFromSpec('/environments/{environmentId}/logs', - 'get', '200'); - $this->clientProphecy->request('get', - '/environments/24-a47ac10b-58cc-4372-a567-0e02b2c3d470/logs') - ->willReturn($response->{'_embedded'}->items) - ->shouldBeCalled(); - - return $response; - } - /** * @return object * @throws \Psr\Cache\InvalidArgumentException