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-1316: [log:tail] warning for non-interactive mode #1719

Merged
merged 2 commits into from
Apr 5, 2024
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
4 changes: 2 additions & 2 deletions src/Command/CommandBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ protected function promptChooseLogs(): object|array|null {
* @param array[]|object[] $items An array of objects or arrays.
* @param string $uniqueProperty The property of the $item that will be used to identify the object.
*/
public function promptChooseFromObjectsOrArrays(array|ArrayObject $items, string $uniqueProperty, string $labelProperty, string $questionText, bool $multiselect = FALSE): object|array|null {
protected function promptChooseFromObjectsOrArrays(array|ArrayObject $items, string $uniqueProperty, string $labelProperty, string $questionText, bool $multiselect = FALSE): object|array|null {
$list = [];
foreach ($items as $item) {
if (is_array($item)) {
Expand All @@ -407,7 +407,7 @@ public function promptChooseFromObjectsOrArrays(array|ArrayObject $items, string
}
}
$labels = array_values($list);
$default = $multiselect ? NULL : $labels[0];
$default = $multiselect ? 0 : $labels[0];
$question = new ChoiceQuestion($questionText, $labels, $default);
$question->setMultiselect($multiselect);
$choiceId = $this->io->askQuestion($question);
Expand Down
24 changes: 22 additions & 2 deletions tests/phpunit/src/Commands/App/LogTailCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Acquia\Cli\Command\CommandBase;
use Acquia\Cli\Tests\CommandTestBase;
use AcquiaLogstream\LogstreamManager;
use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy;

/**
Expand All @@ -17,8 +18,24 @@ class LogTailCommandTest extends CommandTestBase {

protected LogstreamManager|ObjectProphecy $logStreamManagerProphecy;

/**
* @return int[]
*/
public function providerLogTailCommand(): array {
return [
[0],
[NULL],
];
}

protected function createCommand(): CommandBase {
// Must initialize this here instead of in setUp() because we need the
// prophet to be initialized first.
$this->logStreamManagerProphecy = $this->prophet->prophesize(LogstreamManager::class);
$this->logStreamManagerProphecy->setColourise(TRUE)->shouldBeCalled();
$this->logStreamManagerProphecy->setParams(Argument::type('object'))->shouldBeCalled();
$this->logStreamManagerProphecy->setLogTypeFilter(["bal-request"])->shouldBeCalled();
$this->logStreamManagerProphecy->stream()->shouldBeCalled();

return new LogTailCommand(
$this->localMachineHelper,
Expand All @@ -35,7 +52,10 @@ protected function createCommand(): CommandBase {
);
}

public function testLogTailCommand(): void {
/**
* @dataProvider providerLogTailCommand
*/
public function testLogTailCommand(?int $stream): void {
$this->mockGetEnvironment();
$this->mockLogStreamRequest();
$this->executeCommand([], [
Expand All @@ -48,7 +68,7 @@ public function testLogTailCommand(): void {
// Select environment.
0,
// Select log.
0,
$stream,
]);

// Assert.
Expand Down