Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danepowell committed Dec 8, 2023
1 parent e4cd0ab commit 7437e0b
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 157 deletions.
12 changes: 6 additions & 6 deletions src/Command/Pull/PullCommandBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protected function getLocalFilesDir(string $site): string {
return $this->dir . '/docroot/sites/' . $site . '/files';
}

public static function getBackupPath(mixed $environment, DatabaseResponse $database, mixed $backupResponse): string {
public static function getBackupPath(object $environment, object $database, object $backupResponse): string {
// Databases have a machine name not exposed via the API; we can only
// approximately reconstruct it and match the filename you'd get downloading
// a backup from Cloud UI.
Expand Down Expand Up @@ -445,7 +445,7 @@ protected function getLocalGitCommitHash(): string {
return trim($process->getOutput());
}

private function promptChooseEnvironment(mixed $acquiaCloudClient, string $applicationUuid, bool $allowProduction = FALSE): EnvironmentResponse {
private function promptChooseEnvironment(Client $acquiaCloudClient, string $applicationUuid, bool $allowProduction = FALSE): EnvironmentResponse {

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

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "FalseValue": --- Original +++ New @@ @@ } return trim($process->getOutput()); } - private function promptChooseEnvironment(Client $acquiaCloudClient, string $applicationUuid, bool $allowProduction = FALSE) : EnvironmentResponse + private function promptChooseEnvironment(Client $acquiaCloudClient, string $applicationUuid, bool $allowProduction = true) : EnvironmentResponse { $environmentResource = new Environments($acquiaCloudClient); $applicationEnvironments = iterator_to_array($environmentResource->getAll($applicationUuid));
$environmentResource = new Environments($acquiaCloudClient);
$applicationEnvironments = iterator_to_array($environmentResource->getAll($applicationUuid));
$choices = [];
Expand Down Expand Up @@ -542,7 +542,7 @@ protected function runComposerScripts(callable $outputCallback = NULL): void {
$this->checklist->completePreviousItem();
}

private function determineSite(string|\AcquiaCloudApi\Response\EnvironmentResponse|array $environment, InputInterface $input): mixed {
private function determineSite(string|EnvironmentResponse|array $environment, InputInterface $input): mixed {
if (isset($this->site)) {
return $this->site;
}
Expand Down Expand Up @@ -710,7 +710,7 @@ protected function matchIdePhpVersion(
}
}

private function environmentPhpVersionMatches(\AcquiaCloudApi\Response\EnvironmentResponse $environment): bool {
private function environmentPhpVersionMatches(EnvironmentResponse $environment): bool {
$currentPhpVersion = $this->getIdePhpVersion();
return $environment->configuration->php->version === $currentPhpVersion;
}
Expand Down Expand Up @@ -787,9 +787,9 @@ protected function getHostFromDatabaseResponse(mixed $environment, DatabaseRespo

private function getDatabaseBackup(
Client $acquiaCloudClient,
string|\AcquiaCloudApi\Response\EnvironmentResponse|array $environment,
string|EnvironmentResponse|array $environment,
DatabaseResponse $database
): mixed {
): BackupResponse {
$databaseBackups = new DatabaseBackups($acquiaCloudClient);
$backupsResponse = $databaseBackups->getAll($environment->uuid, $database->name);
if (!count($backupsResponse)) {
Expand Down
23 changes: 23 additions & 0 deletions tests/phpunit/src/CommandTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,29 @@ protected function mockReadIdePhpVersion(string $phpVersion = '7.1'): LocalMachi
return $localMachineHelper;
}

/**
* @return array<mixed>
*/
protected static function inputChooseEnvironment(): array {
return [
// Would you like Acquia CLI to search for a Cloud application that matches your local git config?
'n',
// Select a Cloud Platform application:
self::$INPUT_DEFAULT_CHOICE,
// Would you like to link the project at ... ?
'n',
// Choose an Acquia environment:
self::$INPUT_DEFAULT_CHOICE,
];
}

public function mockGetEnvironment(): mixed {
$applications = $this->mockRequest('getApplications');
$application = $this->mockRequest('getApplicationByUuid', $applications[self::$INPUT_DEFAULT_CHOICE]->uuid);
$environments = $this->mockRequest('getApplicationEnvironments', $application->uuid);
return $environments[self::$INPUT_DEFAULT_CHOICE];
}

protected function mockLocalMachineHelper(): LocalMachineHelper|ObjectProphecy {
$localMachineHelper = $this->prophet->prophesize(LocalMachineHelper::class);
$localMachineHelper->useTty()->willReturn(FALSE);
Expand Down
5 changes: 1 addition & 4 deletions tests/phpunit/src/Commands/App/LogTailCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ protected function createCommand(): Command {
}

public function testLogTailCommand(): void {

$applications = $this->mockRequest('getApplications');
$this->mockRequest('getApplicationByUuid', $applications[self::$INPUT_DEFAULT_CHOICE]->uuid);
$this->mockRequest('getApplicationEnvironments', $applications[self::$INPUT_DEFAULT_CHOICE]->uuid);
$this->mockGetEnvironment();
$this->mockLogStreamRequest();
$this->executeCommand([], [
// Would you like Acquia CLI to search for a Cloud application that matches your local git config?
Expand Down
91 changes: 14 additions & 77 deletions tests/phpunit/src/Commands/Pull/PullCodeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,14 @@ public function testCloneRepo(): void {
$this->acliRepoRoot = '';
$this->command = $this->createCommand();
// Client responses.
$applications = $this->mockRequest('getApplications');
$this->mockRequest('getApplicationByUuid', $applications[self::$INPUT_DEFAULT_CHOICE]->uuid);
$environments = $this->mockRequest('getApplicationEnvironments', $applications[self::$INPUT_DEFAULT_CHOICE]->uuid);
$environment = $this->mockGetEnvironment();
$localMachineHelper = $this->mockReadIdePhpVersion();
$process = $this->mockProcess();
$dir = Path::join($this->vfsRoot->url(), 'empty-dir');
mkdir($dir);
$localMachineHelper->checkRequiredBinariesExist(["git"])->shouldBeCalled();
$this->mockExecuteGitClone($localMachineHelper, $environments[self::$INPUT_DEFAULT_CHOICE], $process, $dir);
$this->mockExecuteGitCheckout($localMachineHelper, $environments[self::$INPUT_DEFAULT_CHOICE]->vcs->path, $dir, $process);
$this->mockExecuteGitClone($localMachineHelper, $environment, $process, $dir);
$this->mockExecuteGitCheckout($localMachineHelper, $environment->vcs->path, $dir, $process);
$localMachineHelper->getFinder()->willReturn(new Finder());

$this->command->localMachineHelper = $localMachineHelper->reveal();
Expand All @@ -60,9 +58,7 @@ public function testCloneRepo(): void {
}

public function testPullCode(): void {
$applications = $this->mockRequest('getApplications');
$this->mockRequest('getApplicationByUuid', $applications[self::$INPUT_DEFAULT_CHOICE]->uuid);
$environments = $this->mockRequest('getApplicationEnvironments', $applications[self::$INPUT_DEFAULT_CHOICE]->uuid);
$environment = $this->mockGetEnvironment();
$this->createMockGitConfigFile();

$localMachineHelper = $this->mockReadIdePhpVersion();
Expand All @@ -72,23 +68,12 @@ public function testPullCode(): void {
$this->command->localMachineHelper = $localMachineHelper->reveal();

$process = $this->mockProcess();
$this->mockExecuteGitFetchAndCheckout($localMachineHelper, $process, $this->projectDir, $environments[self::$INPUT_DEFAULT_CHOICE]->vcs->path);
$this->mockExecuteGitFetchAndCheckout($localMachineHelper, $process, $this->projectDir, $environment->vcs->path);
$this->mockExecuteGitStatus(FALSE, $localMachineHelper, $this->projectDir);

$inputs = [
// Would you like Acquia CLI to search for a Cloud application that matches your local git config?
'n',
// Select a Cloud Platform application:
self::$INPUT_DEFAULT_CHOICE,
// Would you like to link the project at ... ?
'n',
// Choose an Acquia environment:
self::$INPUT_DEFAULT_CHOICE,
];

$this->executeCommand([
'--no-scripts' => TRUE,
], $inputs);
], self::inputChooseEnvironment());
$this->prophet->checkPredictions();
$output = $this->getDisplay();

Expand All @@ -100,9 +85,7 @@ public function testPullCode(): void {

public function testWithScripts(): void {
touch(Path::join($this->projectDir, 'composer.json'));
$applications = $this->mockRequest('getApplications');
$this->mockRequest('getApplicationByUuid', $applications[self::$INPUT_DEFAULT_CHOICE]->uuid);
$environments = $this->mockRequest('getApplicationEnvironments', $applications[self::$INPUT_DEFAULT_CHOICE]->uuid);
$environment = $this->mockGetEnvironment();
$this->createMockGitConfigFile();

$localMachineHelper = $this->mockReadIdePhpVersion();
Expand All @@ -112,7 +95,7 @@ public function testWithScripts(): void {
$this->command->localMachineHelper = $localMachineHelper->reveal();

$process = $this->mockProcess();
$this->mockExecuteGitFetchAndCheckout($localMachineHelper, $process, $this->projectDir, $environments[self::$INPUT_DEFAULT_CHOICE]->vcs->path);
$this->mockExecuteGitFetchAndCheckout($localMachineHelper, $process, $this->projectDir, $environment->vcs->path);
$this->mockExecuteGitStatus(FALSE, $localMachineHelper, $this->projectDir);
$process = $this->mockProcess();
$this->mockExecuteComposerExists($localMachineHelper);
Expand All @@ -121,18 +104,7 @@ public function testWithScripts(): void {
$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:
self::$INPUT_DEFAULT_CHOICE,
// Would you like to link the project at ... ?
'n',
// Choose an Acquia environment:
self::$INPUT_DEFAULT_CHOICE,
];

$this->executeCommand([], $inputs);
$this->executeCommand([], self::inputChooseEnvironment());
$this->prophet->checkPredictions();
$output = $this->getDisplay();

Expand All @@ -143,9 +115,7 @@ public function testWithScripts(): void {
}

public function testNoComposerJson(): void {
$applications = $this->mockRequest('getApplications');
$this->mockRequest('getApplicationByUuid', $applications[self::$INPUT_DEFAULT_CHOICE]->uuid);
$environments = $this->mockRequest('getApplicationEnvironments', $applications[self::$INPUT_DEFAULT_CHOICE]->uuid);
$environment = $this->mockGetEnvironment();
$this->createMockGitConfigFile();

$localMachineHelper = $this->mockReadIdePhpVersion();
Expand All @@ -155,25 +125,14 @@ public function testNoComposerJson(): void {
$this->command->localMachineHelper = $localMachineHelper->reveal();

$process = $this->mockProcess();
$this->mockExecuteGitFetchAndCheckout($localMachineHelper, $process, $this->projectDir, $environments[self::$INPUT_DEFAULT_CHOICE]->vcs->path);
$this->mockExecuteGitFetchAndCheckout($localMachineHelper, $process, $this->projectDir, $environment->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:
self::$INPUT_DEFAULT_CHOICE,
// Would you like to link the project at ... ?
'n',
// Choose an Acquia environment:
self::$INPUT_DEFAULT_CHOICE,
];

$this->executeCommand([], $inputs);
$this->executeCommand([], self::inputChooseEnvironment());
$this->prophet->checkPredictions();
$output = $this->getDisplay();
$this->assertStringContainsString('composer.json file not found. Skipping composer install.', $output);
Expand Down Expand Up @@ -204,18 +163,7 @@ public function testNoComposer(): void {
$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:
self::$INPUT_DEFAULT_CHOICE,
// Would you like to link the project at ... ?
'n',
// Choose an Acquia environment:
self::$INPUT_DEFAULT_CHOICE,
];

$this->executeCommand([], $inputs);
$this->executeCommand([], self::inputChooseEnvironment());
$this->prophet->checkPredictions();
$output = $this->getDisplay();

Expand Down Expand Up @@ -245,18 +193,7 @@ public function testWithVendorDir(): void {
$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:
self::$INPUT_DEFAULT_CHOICE,
// Would you like to link the project at ... ?
'n',
// Choose an Acquia environment:
self::$INPUT_DEFAULT_CHOICE,
];

$this->executeCommand([], $inputs);
$this->executeCommand([], self::inputChooseEnvironment());
$this->prophet->checkPredictions();
$output = $this->getDisplay();

Expand Down
Loading

0 comments on commit 7437e0b

Please sign in to comment.