Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI-713: Fixes #875: Apache access logstream failing #876

Merged
merged 3 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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