Skip to content

Commit

Permalink
CLI-713: Fixes #875: Apache access logstream failing (#876)
Browse files Browse the repository at this point in the history
* CLI-713: Fixes #875: Apache access logstream failing

* Fix tests.

* Fix tests.

Co-authored-by: Matthew Grasmick <[email protected]>
  • Loading branch information
danepowell and grasmash authored Apr 8, 2022
1 parent e98ba80 commit c58e59e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 36 deletions.
8 changes: 4 additions & 4 deletions src/Command/App/LogTailCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
20 changes: 7 additions & 13 deletions src/Command/CommandBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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',
Expand Down
6 changes: 2 additions & 4 deletions tests/phpunit/src/Commands/App/LogTailCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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);
}

Expand All @@ -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'],
Expand All @@ -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);
}

Expand Down
15 changes: 0 additions & 15 deletions tests/phpunit/src/TestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c58e59e

Please sign in to comment.