From 0146d8341bce43d3d13e0c6113828c5a5c1568d8 Mon Sep 17 00:00:00 2001 From: Dane Powell Date: Wed, 25 Oct 2023 13:51:45 -0700 Subject: [PATCH 1/2] CLI-1181: [pull:code] disable scripts for build branches --- src/Command/Pull/PullCommandBase.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Command/Pull/PullCommandBase.php b/src/Command/Pull/PullCommandBase.php index ee1e86629..1c3c2c61d 100644 --- a/src/Command/Pull/PullCommandBase.php +++ b/src/Command/Pull/PullCommandBase.php @@ -507,14 +507,21 @@ private function promptChooseDatabases( } protected function runComposerScripts(callable $outputCallback = NULL): void { - if (file_exists($this->dir . '/composer.json') && $this->localMachineHelper->commandExists('composer')) { - $this->checklist->addItem("Installing Composer dependencies"); - $this->composerInstall($outputCallback); - $this->checklist->completePreviousItem(); + if (!file_exists(Path::join($this->dir, 'composer.json'))) { + $this->logger->notice('composer.json file not found. Skipping composer install.'); + return; } - else { - $this->logger->notice('composer or composer.json file not found. Skipping composer install.'); + if (!$this->localMachineHelper->commandExists('composer')) { + $this->logger->notice('Composer not found. Skipping composer install.'); + return; } + if (file_exists(Path::join($this->dir, 'vendor'))) { + $this->logger->notice('Composer dependencies already installed. Skipping composer install.'); + return; + } + $this->checklist->addItem("Installing Composer dependencies"); + $this->composerInstall($outputCallback); + $this->checklist->completePreviousItem(); } private function determineSite(string|\AcquiaCloudApi\Response\EnvironmentResponse|array $environment, InputInterface $input): mixed { From 7d62f10efc03f6c8495696e15ffdb61a40cdf862 Mon Sep 17 00:00:00 2001 From: Dane Powell Date: Wed, 25 Oct 2023 14:42:34 -0700 Subject: [PATCH 2/2] add tests --- src/Command/Pull/PullCommandBase.php | 6 +- .../src/Commands/Pull/PullCodeCommandTest.php | 124 ++++++++++++++++++ 2 files changed, 127 insertions(+), 3 deletions(-) diff --git a/src/Command/Pull/PullCommandBase.php b/src/Command/Pull/PullCommandBase.php index 1c3c2c61d..6e24e8795 100644 --- a/src/Command/Pull/PullCommandBase.php +++ b/src/Command/Pull/PullCommandBase.php @@ -508,15 +508,15 @@ private function promptChooseDatabases( protected function runComposerScripts(callable $outputCallback = NULL): void { if (!file_exists(Path::join($this->dir, 'composer.json'))) { - $this->logger->notice('composer.json file not found. Skipping composer install.'); + $this->io->note('composer.json file not found. Skipping composer install.'); return; } if (!$this->localMachineHelper->commandExists('composer')) { - $this->logger->notice('Composer not found. Skipping composer install.'); + $this->io->note('Composer not found. Skipping composer install.'); return; } if (file_exists(Path::join($this->dir, 'vendor'))) { - $this->logger->notice('Composer dependencies already installed. Skipping composer install.'); + $this->io->note('Composer dependencies already installed. Skipping composer install.'); return; } $this->checklist->addItem("Installing Composer dependencies"); diff --git a/tests/phpunit/src/Commands/Pull/PullCodeCommandTest.php b/tests/phpunit/src/Commands/Pull/PullCodeCommandTest.php index b1d794b28..8fee5e232 100644 --- a/tests/phpunit/src/Commands/Pull/PullCodeCommandTest.php +++ b/tests/phpunit/src/Commands/Pull/PullCodeCommandTest.php @@ -145,6 +145,130 @@ public function testWithScripts(): void { $this->assertStringContainsString('[0] Dev, dev (vcs: master)', $output); } + public function testNoComposerJson(): void { + $applicationsResponse = $this->mockApplicationsRequest(); + $this->mockApplicationRequest(); + $environmentsResponse = $this->mockEnvironmentsRequest($applicationsResponse); + $selectedEnvironment = $environmentsResponse->_embedded->items[0]; + $this->createMockGitConfigFile(); + + $localMachineHelper = $this->mockReadIdePhpVersion(); + $localMachineHelper->checkRequiredBinariesExist(["git"])->shouldBeCalled(); + $finder = $this->mockFinder(); + $localMachineHelper->getFinder()->willReturn($finder->reveal()); + $this->command->localMachineHelper = $localMachineHelper->reveal(); + + $process = $this->mockProcess(); + $this->mockExecuteGitFetchAndCheckout($localMachineHelper, $process, $this->projectDir, $selectedEnvironment->vcs->path); + $this->mockExecuteGitStatus(FALSE, $localMachineHelper, $this->projectDir); + $process = $this->mockProcess(); + $this->mockExecuteDrushExists($localMachineHelper); + $this->mockExecuteDrushStatus($localMachineHelper, TRUE, $this->projectDir); + $this->mockExecuteDrushCacheRebuild($localMachineHelper, $process); + + $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, + ]; + + $this->executeCommand([], $inputs); + $this->prophet->checkPredictions(); + $output = $this->getDisplay(); + $this->assertStringContainsString('composer.json file not found. Skipping composer install.', $output); + } + + public function testNoComposer(): void { + touch(Path::join($this->projectDir, 'composer.json')); + $applicationsResponse = $this->mockApplicationsRequest(); + $this->mockApplicationRequest(); + $environmentsResponse = $this->mockEnvironmentsRequest($applicationsResponse); + $selectedEnvironment = $environmentsResponse->_embedded->items[0]; + $this->createMockGitConfigFile(); + + $localMachineHelper = $this->mockReadIdePhpVersion(); + $localMachineHelper->checkRequiredBinariesExist(["git"])->shouldBeCalled(); + $finder = $this->mockFinder(); + $localMachineHelper->getFinder()->willReturn($finder->reveal()); + $this->command->localMachineHelper = $localMachineHelper->reveal(); + + $process = $this->mockProcess(); + $this->mockExecuteGitFetchAndCheckout($localMachineHelper, $process, $this->projectDir, $selectedEnvironment->vcs->path); + $this->mockExecuteGitStatus(FALSE, $localMachineHelper, $this->projectDir); + $process = $this->mockProcess(); + $localMachineHelper + ->commandExists('composer') + ->willReturn(FALSE) + ->shouldBeCalled(); + $this->mockExecuteDrushExists($localMachineHelper); + $this->mockExecuteDrushStatus($localMachineHelper, TRUE, $this->projectDir); + $this->mockExecuteDrushCacheRebuild($localMachineHelper, $process); + + $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, + ]; + + $this->executeCommand([], $inputs); + $this->prophet->checkPredictions(); + $output = $this->getDisplay(); + + $this->assertStringContainsString('Composer not found. Skipping composer install.', $output); + } + + public function testWithVendorDir(): void { + touch(Path::join($this->projectDir, 'composer.json')); + touch(Path::join($this->projectDir, 'vendor')); + $applicationsResponse = $this->mockApplicationsRequest(); + $this->mockApplicationRequest(); + $environmentsResponse = $this->mockEnvironmentsRequest($applicationsResponse); + $selectedEnvironment = $environmentsResponse->_embedded->items[0]; + $this->createMockGitConfigFile(); + + $localMachineHelper = $this->mockReadIdePhpVersion(); + $localMachineHelper->checkRequiredBinariesExist(["git"])->shouldBeCalled(); + $finder = $this->mockFinder(); + $localMachineHelper->getFinder()->willReturn($finder->reveal()); + $this->command->localMachineHelper = $localMachineHelper->reveal(); + + $process = $this->mockProcess(); + $this->mockExecuteGitFetchAndCheckout($localMachineHelper, $process, $this->projectDir, $selectedEnvironment->vcs->path); + $this->mockExecuteGitStatus(FALSE, $localMachineHelper, $this->projectDir); + $process = $this->mockProcess(); + $this->mockExecuteComposerExists($localMachineHelper); + $this->mockExecuteDrushExists($localMachineHelper); + $this->mockExecuteDrushStatus($localMachineHelper, TRUE, $this->projectDir); + $this->mockExecuteDrushCacheRebuild($localMachineHelper, $process); + + $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, + ]; + + $this->executeCommand([], $inputs); + $this->prophet->checkPredictions(); + $output = $this->getDisplay(); + + $this->assertStringContainsString('Composer dependencies already installed. Skipping composer install.', $output); + } + /** * @return string[][] */