diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 2f5d6be9c..1668c800e 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,6 +1,6 @@ - + diff --git a/src/Command/CommandBase.php b/src/Command/CommandBase.php index ce2e92dfc..4a16eaf67 100644 --- a/src/Command/CommandBase.php +++ b/src/Command/CommandBase.php @@ -1517,6 +1517,9 @@ private function promptChooseAcsfSite(EnvironmentResponse $cloudEnvironment): mi foreach ($acsfSites['sites'] as $domain => $acsfSite) { $choices[] = "{$acsfSite['name']} ($domain)"; } + if (!count($choices)) { + throw new AcquiaCliException('No sites found in this environment'); + } $choice = $this->io->choice('Choose a site', $choices, $choices[0]); $key = array_search($choice, $choices, true); $sites = array_values($acsfSites['sites']); diff --git a/tests/fixtures/no-multisite-config.json b/tests/fixtures/no-multisite-config.json new file mode 100644 index 000000000..2ed37d370 --- /dev/null +++ b/tests/fixtures/no-multisite-config.json @@ -0,0 +1,3 @@ +{"cloud":{"site":"profserv2","env":"01dev"},"memcache_inc":"profiles\/gardens\/modules\/acquia\/memcache\/memcache.inc", + "sites": { + }} diff --git a/tests/phpunit/src/CommandTestBase.php b/tests/phpunit/src/CommandTestBase.php index c4faf3dbd..3546266c3 100644 --- a/tests/phpunit/src/CommandTestBase.php +++ b/tests/phpunit/src/CommandTestBase.php @@ -282,11 +282,16 @@ public function mockAcsfEnvironmentsRequest( /** * @return array + * @throws \Acquia\Cli\Exception\AcquiaCliException */ - protected function mockGetAcsfSites(mixed $sshHelper): array + protected function mockGetAcsfSites(SshHelper|ObjectProphecy $sshHelper, bool $existAcsfSites = true): array { $acsfMultisiteFetchProcess = $this->mockProcess(); - $multisiteConfig = file_get_contents(Path::join($this->realFixtureDir, '/multisite-config.json')); + if ($existAcsfSites) { + $multisiteConfig = file_get_contents(Path::join($this->realFixtureDir, '/multisite-config.json')); + } else { + $multisiteConfig = file_get_contents(Path::join($this->realFixtureDir, '/no-multisite-config.json')); + } $acsfMultisiteFetchProcess->getOutput() ->willReturn($multisiteConfig) ->shouldBeCalled(); diff --git a/tests/phpunit/src/Commands/Pull/PullFilesCommandTest.php b/tests/phpunit/src/Commands/Pull/PullFilesCommandTest.php index 2b373a6be..cf5b102c4 100644 --- a/tests/phpunit/src/Commands/Pull/PullFilesCommandTest.php +++ b/tests/phpunit/src/Commands/Pull/PullFilesCommandTest.php @@ -32,7 +32,10 @@ protected function createCommand(): CommandBase ); } - public function testRefreshAcsfFiles(): void + /** + * @throws \Exception + */ + public function testPullFilesAcsf(): void { $applicationsResponse = $this->mockApplicationsRequest(); $this->mockApplicationRequest(); @@ -69,7 +72,41 @@ public function testRefreshAcsfFiles(): void $this->assertStringContainsString('[0] Dev, dev (vcs: master)', $output); } - public function testRefreshCloudFiles(): void + /** + * @throws \Exception + */ + public function testPullFilesAcsfNoSites(): void + { + $applicationsResponse = $this->mockApplicationsRequest(); + $this->mockApplicationRequest(); + $this->mockAcsfEnvironmentsRequest($applicationsResponse); + $sshHelper = $this->mockSshHelper(); + $this->mockGetAcsfSites($sshHelper, false); + $this->command->sshHelper = $sshHelper->reveal(); + + $inputs = [ + // Would you like Acquia CLI to search for a Cloud application that matches your local git config? + 'n', + // Select a Cloud Platform application: + 0, + // Would you like to link the project at ... ? + 'n', + // Choose an Acquia environment: + 0, + // Choose site from which to copy files: + 0, + ]; + + + $this->expectException(AcquiaCliException::class); + $this->expectExceptionMessage('No sites found in this environment'); + $this->executeCommand([], $inputs); + } + + /** + * @throws \Exception + */ + public function testPullFilesCloud(): void { $applicationsResponse = $this->mockApplicationsRequest(); $this->mockApplicationRequest(); @@ -108,6 +145,9 @@ public function testRefreshCloudFiles(): void $this->assertStringContainsString('[0] Dev, dev (vcs: master)', $output); } + /** + * @throws \Exception + */ public function testInvalidCwd(): void { IdeHelper::setCloudIdeEnvVars();