Skip to content

Commit

Permalink
CLI-1221: TypeError and warning in remote:alises:download (#1636)
Browse files Browse the repository at this point in the history
* CLI-1221: TypeError and warning in remote:alises:download

* add test
  • Loading branch information
danepowell authored Nov 17, 2023
1 parent b839f67 commit 7daef90
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
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

0 comments on commit 7daef90

Please sign in to comment.