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-1221: TypeError and warning in remote:alises:download #1636

Merged
merged 2 commits into from
Nov 17, 2023
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
17 changes: 9 additions & 8 deletions src/Command/CommandBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\LoggerInterface;
use Safe\Exceptions\FilesystemException;
use stdClass;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Console\Command\Command;
Expand Down Expand Up @@ -454,16 +455,12 @@ public function promptChooseFromObjectsOrArrays(array|ArrayObject $items, string
/**
* Load configuration from .git/config.
*
* @return string[][]|null
* @return string[][]
* A multidimensional array keyed by file section.
*/
private function getGitConfig(): ?array {
private function getGitConfig(): array {
$filePath = $this->projectDir . '/.git/config';
if (file_exists($filePath)) {
return parse_ini_file($filePath, TRUE);
}

return NULL;
return @\Safe\parse_ini_file($filePath, TRUE);
}

/**
Expand Down Expand Up @@ -574,7 +571,8 @@ protected function inferCloudAppFromLocalGitConfig(
$answer = $this->io->confirm('Would you like Acquia CLI to search for a Cloud application that matches your local git config?');
if ($answer) {
$this->output->writeln('Searching for a matching Cloud application...');
if ($gitConfig = $this->getGitConfig()) {
try {
$gitConfig = $this->getGitConfig();
$localGitRemotes = $this->getGitRemotes($gitConfig);
if ($cloudApplication = $this->findCloudApplicationByGitUrl($acquiaCloudClient,
$localGitRemotes)) {
Expand All @@ -585,6 +583,9 @@ protected function inferCloudAppFromLocalGitConfig(
$this->output->writeln('<comment>Could not find a matching Cloud application.</comment>');
return NULL;
}
catch (FilesystemException $e) {
throw new AcquiaCliException($e->getMessage());
}
}
}

Expand Down
16 changes: 10 additions & 6 deletions tests/phpunit/src/Commands/InferApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Acquia\Cli\Tests\Commands;

use Acquia\Cli\Command\App\LinkCommand;
use Acquia\Cli\Exception\AcquiaCliException;
use Acquia\Cli\Tests\CommandTestBase;
use Symfony\Component\Console\Command\Command;

Expand All @@ -20,13 +21,8 @@ protected function createCommand(): Command {
return $this->injectCommand(LinkCommand::class);
}

public function setUp(mixed $output = NULL): void {
parent::setUp();
$this->createMockGitConfigFile();
}

public function testInfer(): void {

$this->createMockGitConfigFile();
$applicationsResponse = $this->mockApplicationsRequest();
$this->mockApplicationRequest();
$environmentResponse = $this->getMockEnvironmentResponse();
Expand Down Expand Up @@ -56,6 +52,7 @@ public function testInfer(): void {
}

public function testInferFailure(): void {
$this->createMockGitConfigFile();
$applicationsResponse = $this->mockApplicationsRequest();
$this->mockApplicationRequest();

Expand Down Expand Up @@ -87,4 +84,11 @@ public function testInferFailure(): void {
$this->assertStringContainsString('The Cloud application Sample application 1 has been linked', $output);
}

public function testInferInvalidGitConfig(): void {
$this->expectException(AcquiaCliException::class);
$this->executeCommand([], [
'y',
]);
}

}
6 changes: 3 additions & 3 deletions tests/phpunit/src/Commands/Ssh/SshKeyUploadCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function providerTestUpload(): array {
// Would you like to wait until Cloud Platform is ready? (yes/no)
'y',
// Would you like Acquia CLI to search for a Cloud application that matches your local git config? (yes/no)
'y',
'n',
],
// Perms.
TRUE,
Expand All @@ -52,7 +52,7 @@ public function providerTestUpload(): array {
// Would you like to wait until Cloud Platform is ready? (yes/no)
'y',
// Would you like Acquia CLI to search for a Cloud application that matches your local git config? (yes/no)
'y',
'n',
],
// Perms.
FALSE,
Expand All @@ -63,7 +63,7 @@ public function providerTestUpload(): array {
/**
* @dataProvider providerTestUpload
*/
public function testUpload(mixed $args, mixed $inputs, mixed $perms): void {
public function testUpload(array $args, array $inputs, bool $perms): void {
$sshKeysRequestBody = $this->getMockRequestBodyFromSpec('/account/ssh-keys');
$body = [
'json' => [
Expand Down