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-1181: [pull:code] disable scripts for build branches #1614

Merged
merged 2 commits into from
Oct 26, 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
19 changes: 13 additions & 6 deletions src/Command/Pull/PullCommandBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -507,14 +507,21 @@
}

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->io->note('composer.json file not found. Skipping composer install.');
return;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Negative exists logic here seems to make sense, I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like to do any validation at the start of the method, hence the negative logic. I'm open to alternatives.

}
else {
$this->logger->notice('composer or composer.json file not found. Skipping composer install.');
if (!$this->localMachineHelper->commandExists('composer')) {
$this->io->note('Composer not found. Skipping composer install.');
return;
}
if (file_exists(Path::join($this->dir, 'vendor'))) {
$this->io->note('Composer dependencies already installed. Skipping composer install.');
return;
}
$this->checklist->addItem("Installing Composer dependencies");

Check warning on line 522 in src/Command/Pull/PullCommandBase.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "MethodCallRemoval": --- Original +++ New @@ @@ $this->io->note('Composer dependencies already installed. Skipping composer install.'); return; } - $this->checklist->addItem("Installing Composer dependencies"); + $this->composerInstall($outputCallback); $this->checklist->completePreviousItem(); }
$this->composerInstall($outputCallback);
$this->checklist->completePreviousItem();

Check warning on line 524 in src/Command/Pull/PullCommandBase.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "MethodCallRemoval": --- Original +++ New @@ @@ } $this->checklist->addItem("Installing Composer dependencies"); $this->composerInstall($outputCallback); - $this->checklist->completePreviousItem(); + } private function determineSite(string|\AcquiaCloudApi\Response\EnvironmentResponse|array $environment, InputInterface $input) : mixed {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if the mutation tests are catching something here or if they just need to be updated. It seems it's the latter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to idiosyncrasies with how the Symfony Command Tester class handles output, our test cases can't verify that these checklist items appear in the command output. Hence the escaped mutant. But it's not caused by this PR, so we can ignore it.

}

private function determineSite(string|\AcquiaCloudApi\Response\EnvironmentResponse|array $environment, InputInterface $input): mixed {
Expand Down
124 changes: 124 additions & 0 deletions tests/phpunit/src/Commands/Pull/PullCodeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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[][]
*/
Expand Down