From b12cc9410729580560dc73778bbdf7684329e4b9 Mon Sep 17 00:00:00 2001 From: Dane Powell Date: Thu, 14 Nov 2024 14:39:10 -0800 Subject: [PATCH] CLI-1429: Allow production environments for log:tail and drush commands (#1828) * CLI-1429: Allow production environments for log:tail and drush commands * kill mutant * kill mutant --- src/Command/App/LogTailCommand.php | 2 +- src/Command/Remote/DrushCommand.php | 2 +- .../src/Commands/App/LogTailCommandTest.php | 32 +++++++++++++++++-- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/Command/App/LogTailCommand.php b/src/Command/App/LogTailCommand.php index feaf60209..eb00a1337 100644 --- a/src/Command/App/LogTailCommand.php +++ b/src/Command/App/LogTailCommand.php @@ -54,7 +54,7 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { - $environment = $this->determineEnvironment($input, $output); + $environment = $this->determineEnvironment($input, $output, true); $acquiaCloudClient = $this->cloudApiClientService->getClient(); $logs = $this->promptChooseLogs(); $logTypes = array_map(static function (mixed $log) { diff --git a/src/Command/Remote/DrushCommand.php b/src/Command/Remote/DrushCommand.php index be04d1400..36e7c52fa 100644 --- a/src/Command/Remote/DrushCommand.php +++ b/src/Command/Remote/DrushCommand.php @@ -33,7 +33,7 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): ?int { - $environment = $this->determineEnvironment($input, $output); + $environment = $this->determineEnvironment($input, $output, true); $alias = self::getEnvironmentAlias($environment); $acliArguments = $input->getArguments(); $drushArguments = (array) $acliArguments['drush_command']; diff --git a/tests/phpunit/src/Commands/App/LogTailCommandTest.php b/tests/phpunit/src/Commands/App/LogTailCommandTest.php index d5427160f..0e682f829 100644 --- a/tests/phpunit/src/Commands/App/LogTailCommandTest.php +++ b/tests/phpunit/src/Commands/App/LogTailCommandTest.php @@ -103,6 +103,34 @@ public function testLogTailCommandWithEnvArg(): void $this->assertStringContainsString('Drupal request', $output); } + public function testLogTailProd(): void + { + $applications = $this->mockRequest('getApplications'); + $application = $this->mockRequest('getApplicationByUuid', $applications[self::$INPUT_DEFAULT_CHOICE]->uuid); + $this->mockRequest('getApplicationEnvironments', $application->uuid); + $this->mockLogStreamRequest('15-a47ac10b-58cc-4372-a567-0e02b2c3d470'); + $this->executeCommand( + [], + [ + // Would you like Acquia CLI to search for a Cloud application that matches your local git config? + 'n', + // Select the application. + 0, + // Would you like to link the project at ... ? + 'y', + // Select environment. + 1, + // Select log. + 0, + ] + ); + + // Assert. + $output = $this->getDisplay(); + $this->assertStringContainsString('Apache request', $output); + $this->assertStringContainsString('Drupal request', $output); + } + public function testLogTailNode(): void { $applications = $this->mockRequest('getApplications'); @@ -129,7 +157,7 @@ public function testLogTailNode(): void ]); } - private function mockLogStreamRequest(): void + private function mockLogStreamRequest(string $environment = '24-a47ac10b-58cc-4372-a567-0e02b2c3d470'): void { $response = self::getMockResponseFromSpec( '/environments/{environmentId}/logstream', @@ -138,7 +166,7 @@ private function mockLogStreamRequest(): void ); $this->clientProphecy->request( 'get', - '/environments/24-a47ac10b-58cc-4372-a567-0e02b2c3d470/logstream' + '/environments/' . $environment . '/logstream' ) ->willReturn($response) ->shouldBeCalled();