Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danepowell committed Oct 25, 2023
1 parent 0146d83 commit 7d62f10
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Command/Pull/PullCommandBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");

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(); }
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

0 comments on commit 7d62f10

Please sign in to comment.