Skip to content

Commit 4d64180

Browse files
CLI-1435: PHP error - undefined array key handled in pull command (#1844)
* PHP error : undefined array key handled * Fix test case: * Fix test case: * fix the failure test case * fix the failure testcase * Fix the failure test case * fix mutation test * cleanup --------- Co-authored-by: Dane Powell <git@danepowell.com>
1 parent 304cc82 commit 4d64180

File tree

5 files changed

+56
-5
lines changed

5 files changed

+56
-5
lines changed

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
22
<!-- phpunit.xml.dist -->
3-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" failOnDeprecation="true" displayDetailsOnTestsThatTriggerDeprecations="true" failOnWarning="true" failOnRisky="true" cacheDirectory="var">
3+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" failOnDeprecation="true" displayDetailsOnTestsThatTriggerDeprecations="true" displayDetailsOnTestsThatTriggerWarnings="true" failOnWarning="true" failOnRisky="true" cacheDirectory="var">
44
<php>
55
<env name="AMPLITUDE_KEY" value=""/>
66
<env name="BUGSNAG_KEY" value=""/>

src/Command/CommandBase.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,6 +1517,9 @@ private function promptChooseAcsfSite(EnvironmentResponse $cloudEnvironment): mi
15171517
foreach ($acsfSites['sites'] as $domain => $acsfSite) {
15181518
$choices[] = "{$acsfSite['name']} ($domain)";
15191519
}
1520+
if (!count($choices)) {
1521+
throw new AcquiaCliException('No sites found in this environment');
1522+
}
15201523
$choice = $this->io->choice('Choose a site', $choices, $choices[0]);
15211524
$key = array_search($choice, $choices, true);
15221525
$sites = array_values($acsfSites['sites']);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{"cloud":{"site":"profserv2","env":"01dev"},"memcache_inc":"profiles\/gardens\/modules\/acquia\/memcache\/memcache.inc",
2+
"sites": {
3+
}}

tests/phpunit/src/CommandTestBase.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,16 @@ public function mockAcsfEnvironmentsRequest(
282282

283283
/**
284284
* @return array<mixed>
285+
* @throws \Acquia\Cli\Exception\AcquiaCliException
285286
*/
286-
protected function mockGetAcsfSites(mixed $sshHelper): array
287+
protected function mockGetAcsfSites(SshHelper|ObjectProphecy $sshHelper, bool $existAcsfSites = true): array
287288
{
288289
$acsfMultisiteFetchProcess = $this->mockProcess();
289-
$multisiteConfig = file_get_contents(Path::join($this->realFixtureDir, '/multisite-config.json'));
290+
if ($existAcsfSites) {
291+
$multisiteConfig = file_get_contents(Path::join($this->realFixtureDir, '/multisite-config.json'));
292+
} else {
293+
$multisiteConfig = file_get_contents(Path::join($this->realFixtureDir, '/no-multisite-config.json'));
294+
}
290295
$acsfMultisiteFetchProcess->getOutput()
291296
->willReturn($multisiteConfig)
292297
->shouldBeCalled();

tests/phpunit/src/Commands/Pull/PullFilesCommandTest.php

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ protected function createCommand(): CommandBase
3232
);
3333
}
3434

35-
public function testRefreshAcsfFiles(): void
35+
/**
36+
* @throws \Exception
37+
*/
38+
public function testPullFilesAcsf(): void
3639
{
3740
$applicationsResponse = $this->mockApplicationsRequest();
3841
$this->mockApplicationRequest();
@@ -69,7 +72,41 @@ public function testRefreshAcsfFiles(): void
6972
$this->assertStringContainsString('[0] Dev, dev (vcs: master)', $output);
7073
}
7174

72-
public function testRefreshCloudFiles(): void
75+
/**
76+
* @throws \Exception
77+
*/
78+
public function testPullFilesAcsfNoSites(): void
79+
{
80+
$applicationsResponse = $this->mockApplicationsRequest();
81+
$this->mockApplicationRequest();
82+
$this->mockAcsfEnvironmentsRequest($applicationsResponse);
83+
$sshHelper = $this->mockSshHelper();
84+
$this->mockGetAcsfSites($sshHelper, false);
85+
$this->command->sshHelper = $sshHelper->reveal();
86+
87+
$inputs = [
88+
// Would you like Acquia CLI to search for a Cloud application that matches your local git config?
89+
'n',
90+
// Select a Cloud Platform application:
91+
0,
92+
// Would you like to link the project at ... ?
93+
'n',
94+
// Choose an Acquia environment:
95+
0,
96+
// Choose site from which to copy files:
97+
0,
98+
];
99+
100+
101+
$this->expectException(AcquiaCliException::class);
102+
$this->expectExceptionMessage('No sites found in this environment');
103+
$this->executeCommand([], $inputs);
104+
}
105+
106+
/**
107+
* @throws \Exception
108+
*/
109+
public function testPullFilesCloud(): void
73110
{
74111
$applicationsResponse = $this->mockApplicationsRequest();
75112
$this->mockApplicationRequest();
@@ -108,6 +145,9 @@ public function testRefreshCloudFiles(): void
108145
$this->assertStringContainsString('[0] Dev, dev (vcs: master)', $output);
109146
}
110147

148+
/**
149+
* @throws \Exception
150+
*/
111151
public function testInvalidCwd(): void
112152
{
113153
IdeHelper::setCloudIdeEnvVars();

0 commit comments

Comments
 (0)