From 0563a2c3f9dbf34a4efa0b4dfb7b8dd63f796391 Mon Sep 17 00:00:00 2001 From: Dane Powell Date: Fri, 25 Aug 2023 12:01:56 -0700 Subject: [PATCH 1/6] BLT-5222: Add no-clone / no-commit --- src/Command/Push/PushArtifactCommand.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/Command/Push/PushArtifactCommand.php b/src/Command/Push/PushArtifactCommand.php index 58f5a3b89..3159cecc2 100644 --- a/src/Command/Push/PushArtifactCommand.php +++ b/src/Command/Push/PushArtifactCommand.php @@ -48,6 +48,8 @@ protected function configure(): void { ->addOption('dir', NULL, InputArgument::OPTIONAL, 'The directory containing the Drupal project to be pushed') ->addOption('no-sanitize', NULL, InputOption::VALUE_NONE, 'Do not sanitize the build artifact') ->addOption('dry-run', NULL, InputOption::VALUE_NONE, 'Do not push changes to Acquia Cloud') + ->addOption('no-clone', NULL, InputOption::VALUE_NONE) + ->addOption('no-commit', NULL, InputOption::VALUE_NONE) ->addOption('destination-git-urls', 'u', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'The URL(s) of your git repository to which the artifact branch will be pushed') ->addOption('destination-git-branch', 'b', InputOption::VALUE_REQUIRED, 'The destination branch to push the artifact to') ->addOption('destination-git-tag', 't', InputOption::VALUE_REQUIRED, 'The destination tag to push the artifact to. Using this option requires also using the --source-git-tag option') @@ -92,9 +94,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int $outputCallback = $this->getOutputCallback($output, $this->checklist); - $this->checklist->addItem('Preparing artifact directory'); - $this->cloneSourceBranch($outputCallback, $artifactDir, $destinationGitUrls[0], $sourceGitBranch); - $this->checklist->completePreviousItem(); + if (!$input->getOption('no-clone')) { + $this->checklist->addItem('Preparing artifact directory'); + $this->cloneSourceBranch($outputCallback, $artifactDir, $destinationGitUrls[0], $sourceGitBranch); + $this->checklist->completePreviousItem(); + } $this->checklist->addItem('Generating build artifact'); $this->buildArtifact($outputCallback, $artifactDir); @@ -106,9 +110,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->checklist->completePreviousItem(); } - $this->checklist->addItem("Committing changes (commit hash: $commitHash)"); - $this->commit($outputCallback, $artifactDir, $commitHash); - $this->checklist->completePreviousItem(); + if (!$input->getOption('no-commit')) { + $this->checklist->addItem("Committing changes (commit hash: $commitHash)"); + $this->commit($outputCallback, $artifactDir, $commitHash); + $this->checklist->completePreviousItem(); + } if (!$input->getOption('dry-run')) { if ($tagName = $input->getOption('destination-git-tag')) { @@ -305,8 +311,6 @@ private function generateCommitMessage(string $commitHash): array|string { /** * Push the artifact. - * - * @param array $vcsUrls */ private function pushArtifact(Closure $outputCallback, string $artifactDir, array $vcsUrls, string $destGitBranch): void { $this->localMachineHelper->checkRequiredBinariesExist(['git']); From 7db7d1664fa3461e7080276d875d78f6f6b0b2a3 Mon Sep 17 00:00:00 2001 From: Dane Powell Date: Fri, 25 Aug 2023 13:02:48 -0700 Subject: [PATCH 2/6] fix options --- src/Command/Push/PushArtifactCommand.php | 36 ++++++++++++++---------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/src/Command/Push/PushArtifactCommand.php b/src/Command/Push/PushArtifactCommand.php index 3159cecc2..021689c8d 100644 --- a/src/Command/Push/PushArtifactCommand.php +++ b/src/Command/Push/PushArtifactCommand.php @@ -63,6 +63,10 @@ protected function configure(): void { ->addUsage('--destination-git-urls=example@svn-1.prod.hosting.acquia.com:example.git --destination-git-branch=main-build'); } + protected function commandRequiresAuthentication(): bool { + return FALSE; + } + protected function execute(InputInterface $input, OutputInterface $output): int { $this->setDirAndRequireProjectCwd($input); $artifactDir = Path::join(sys_get_temp_dir(), 'acli-push-artifact'); @@ -76,21 +80,23 @@ protected function execute(InputInterface $input, OutputInterface $output): int throw new AcquiaCliException('Pushing code was aborted because your local Git repository has uncommitted changes. Either commit, reset, or stash your changes via git.'); } $this->checklist = new Checklist($output); - $applicationUuid = $this->determineCloudApplication(); - $destinationGitUrls = $this->determineDestinationGitUrls($applicationUuid); - $destinationGitRef = $this->determineDestinationGitRef(); - $sourceGitBranch = $this->determineSourceGitRef(); - - $destinationGitUrlsString = implode(',', $destinationGitUrls); - $refType = $this->input->getOption('destination-git-tag') ? 'tag' : 'branch'; - $this->io->note([ - "Acquia CLI will:", - "- git clone $sourceGitBranch from $destinationGitUrls[0]", - "- Compile the contents of $this->dir into an artifact in a temporary directory", - "- Copy the artifact files into the checked out copy of $sourceGitBranch", - "- Commit changes and push the $destinationGitRef $refType to the following git remote(s):", - " $destinationGitUrlsString", - ]); + + if (!$input->getOption('no-clone') || !$input->getOption('dry-run')) { + $applicationUuid = $this->determineCloudApplication(); + $destinationGitUrls = $this->determineDestinationGitUrls($applicationUuid); + $destinationGitRef = $this->determineDestinationGitRef(); + $sourceGitBranch = $this->determineSourceGitRef(); + $destinationGitUrlsString = implode(',', $destinationGitUrls); + $refType = $this->input->getOption('destination-git-tag') ? 'tag' : 'branch'; + $this->io->note([ + "Acquia CLI will:", + "- git clone $sourceGitBranch from $destinationGitUrls[0]", + "- Compile the contents of $this->dir into an artifact in a temporary directory", + "- Copy the artifact files into the checked out copy of $sourceGitBranch", + "- Commit changes and push the $destinationGitRef $refType to the following git remote(s):", + " $destinationGitUrlsString", + ]); + } $outputCallback = $this->getOutputCallback($output, $this->checklist); From 4b4cfd1eb902104b889e88ce7e312625f2b34acb Mon Sep 17 00:00:00 2001 From: Dane Powell Date: Fri, 20 Oct 2023 15:06:54 -0700 Subject: [PATCH 3/6] cleanup --- src/Command/Push/PushArtifactCommand.php | 36 +++++++++++++++--------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/Command/Push/PushArtifactCommand.php b/src/Command/Push/PushArtifactCommand.php index 021689c8d..d92a1f65c 100644 --- a/src/Command/Push/PushArtifactCommand.php +++ b/src/Command/Push/PushArtifactCommand.php @@ -47,9 +47,10 @@ protected function configure(): void { $this->setDescription('Build and push a code artifact to a Cloud Platform environment') ->addOption('dir', NULL, InputArgument::OPTIONAL, 'The directory containing the Drupal project to be pushed') ->addOption('no-sanitize', NULL, InputOption::VALUE_NONE, 'Do not sanitize the build artifact') - ->addOption('dry-run', NULL, InputOption::VALUE_NONE, 'Do not push changes to Acquia Cloud') - ->addOption('no-clone', NULL, InputOption::VALUE_NONE) - ->addOption('no-commit', NULL, InputOption::VALUE_NONE) + ->addOption('dry-run', NULL, InputOption::VALUE_NONE, 'Deprecated: Use no-push instead') + ->addOption('no-push', NULL, InputOption::VALUE_NONE, 'Do not push changes to Acquia Cloud') + ->addOption('no-clone', NULL, InputOption::VALUE_NONE, 'Do not clone repository. Implies no-commit and no-push') + ->addOption('no-commit', NULL, InputOption::VALUE_NONE, 'Do not commit changes. Implies no-push') ->addOption('destination-git-urls', 'u', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'The URL(s) of your git repository to which the artifact branch will be pushed') ->addOption('destination-git-branch', 'b', InputOption::VALUE_REQUIRED, 'The destination branch to push the artifact to') ->addOption('destination-git-tag', 't', InputOption::VALUE_REQUIRED, 'The destination tag to push the artifact to. Using this option requires also using the --source-git-tag option') @@ -69,6 +70,13 @@ protected function commandRequiresAuthentication(): bool { protected function execute(InputInterface $input, OutputInterface $output): int { $this->setDirAndRequireProjectCwd($input); + if ($input->getOption('no-clone')) { + $input->setOption('no-commit', TRUE); + $input->setOption('no-push', TRUE); + } + if ($input->getOption('no-commit')) { + $input->setOption('no-push', TRUE); + } $artifactDir = Path::join(sys_get_temp_dir(), 'acli-push-artifact'); $this->composerJsonPath = Path::join($this->dir, 'composer.json'); $this->docrootPath = Path::join($this->dir, 'docroot'); @@ -80,8 +88,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int throw new AcquiaCliException('Pushing code was aborted because your local Git repository has uncommitted changes. Either commit, reset, or stash your changes via git.'); } $this->checklist = new Checklist($output); + $outputCallback = $this->getOutputCallback($output, $this->checklist); - if (!$input->getOption('no-clone') || !$input->getOption('dry-run')) { + $destinationGitUrls = []; + $destinationGitRef = ''; + if (!$input->getOption('no-clone')) { $applicationUuid = $this->determineCloudApplication(); $destinationGitUrls = $this->determineDestinationGitUrls($applicationUuid); $destinationGitRef = $this->determineDestinationGitRef(); @@ -96,11 +107,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int "- Commit changes and push the $destinationGitRef $refType to the following git remote(s):", " $destinationGitUrlsString", ]); - } - $outputCallback = $this->getOutputCallback($output, $this->checklist); - - if (!$input->getOption('no-clone')) { $this->checklist->addItem('Preparing artifact directory'); $this->cloneSourceBranch($outputCallback, $artifactDir, $destinationGitUrls[0], $sourceGitBranch); $this->checklist->completePreviousItem(); @@ -122,7 +129,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->checklist->completePreviousItem(); } - if (!$input->getOption('dry-run')) { + if (!$input->getOption('dry-run') && !$input->getOption('no-push')) { if ($tagName = $input->getOption('destination-git-tag')) { $this->checklist->addItem("Creating $tagName tag."); $this->createTag($tagName, $outputCallback, $artifactDir); @@ -137,13 +144,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->checklist->completePreviousItem(); } else { - $this->logger->warning("The --dry-run option prevented changes from being pushed to Acquia Cloud. The artifact has been built at $artifactDir"); + $this->logger->warning("The --dry-run (deprecated) or --no-push option prevented changes from being pushed to Acquia Cloud. The artifact has been built at $artifactDir"); } return Command::SUCCESS; } - private function determineDestinationGitUrls(?string $applicationUuid): mixed { + /** + * @return string[] + */ + private function determineDestinationGitUrls(?string $applicationUuid): array { if ($this->input->getOption('destination-git-urls')) { return $this->input->getOption('destination-git-urls'); } @@ -393,7 +403,7 @@ private function validateSourceCode(): void { } } - private function determineSourceGitRef(): mixed { + private function determineSourceGitRef(): string { if ($this->input->getOption('source-git-tag')) { return $this->input->getOption('source-git-tag'); } @@ -408,7 +418,7 @@ private function determineSourceGitRef(): mixed { return $this->destinationGitRef; } - private function determineDestinationGitRef(): mixed { + private function determineDestinationGitRef(): string { if ($this->input->getOption('destination-git-tag')) { $this->destinationGitRef = $this->input->getOption('destination-git-tag'); return $this->destinationGitRef; From bd98fd69e8b4e4835ac3747d50dc7dde2b186b74 Mon Sep 17 00:00:00 2001 From: Dane Powell Date: Mon, 23 Oct 2023 15:09:17 -0700 Subject: [PATCH 4/6] kill mutant --- tests/phpunit/src/Commands/Push/PushArtifactCommandTest.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/phpunit/src/Commands/Push/PushArtifactCommandTest.php b/tests/phpunit/src/Commands/Push/PushArtifactCommandTest.php index b13a641a4..459438467 100644 --- a/tests/phpunit/src/Commands/Push/PushArtifactCommandTest.php +++ b/tests/phpunit/src/Commands/Push/PushArtifactCommandTest.php @@ -22,6 +22,11 @@ protected function createCommand(): Command { return $this->injectCommand(PushArtifactCommand::class); } + public function testNoAuthenticationRequired(): void { + $help = $this->command->getHelp(); + $this->assertStringNotContainsString('This command requires authentication', $help); + } + public function testPushArtifact(): void { touch(Path::join($this->projectDir, 'composer.json')); mkdir(Path::join($this->projectDir, 'docroot')); From b59733b86857e88381cd12978c5b38683a9a581e Mon Sep 17 00:00:00 2001 From: Dane Powell Date: Mon, 23 Oct 2023 15:47:04 -0700 Subject: [PATCH 5/6] add tests --- src/Command/Push/PushArtifactCommand.php | 2 +- .../Commands/Push/PushArtifactCommandTest.php | 150 +++++++++++++----- 2 files changed, 110 insertions(+), 42 deletions(-) diff --git a/src/Command/Push/PushArtifactCommand.php b/src/Command/Push/PushArtifactCommand.php index 0454a2180..01a1b288b 100644 --- a/src/Command/Push/PushArtifactCommand.php +++ b/src/Command/Push/PushArtifactCommand.php @@ -49,8 +49,8 @@ protected function configure(): void { ->addOption('no-sanitize', NULL, InputOption::VALUE_NONE, 'Do not sanitize the build artifact') ->addOption('dry-run', NULL, InputOption::VALUE_NONE, 'Deprecated: Use no-push instead') ->addOption('no-push', NULL, InputOption::VALUE_NONE, 'Do not push changes to Acquia Cloud') - ->addOption('no-clone', NULL, InputOption::VALUE_NONE, 'Do not clone repository. Implies no-commit and no-push') ->addOption('no-commit', NULL, InputOption::VALUE_NONE, 'Do not commit changes. Implies no-push') + ->addOption('no-clone', NULL, InputOption::VALUE_NONE, 'Do not clone repository. Implies no-commit and no-push') ->addOption('destination-git-urls', 'u', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'The URL(s) of your git repository to which the artifact branch will be pushed') ->addOption('destination-git-branch', 'b', InputOption::VALUE_REQUIRED, 'The destination branch to push the artifact to') ->addOption('destination-git-tag', 't', InputOption::VALUE_REQUIRED, 'The destination tag to push the artifact to. Using this option requires also using the --source-git-tag option') diff --git a/tests/phpunit/src/Commands/Push/PushArtifactCommandTest.php b/tests/phpunit/src/Commands/Push/PushArtifactCommandTest.php index 459438467..3d5ff59a4 100644 --- a/tests/phpunit/src/Commands/Push/PushArtifactCommandTest.php +++ b/tests/phpunit/src/Commands/Push/PushArtifactCommandTest.php @@ -28,15 +28,11 @@ public function testNoAuthenticationRequired(): void { } public function testPushArtifact(): void { - touch(Path::join($this->projectDir, 'composer.json')); - mkdir(Path::join($this->projectDir, 'docroot')); - $this->mockRequest('getApplications'); - $applicationsResponse = $this->mockApplicationsRequest(); - $this->mockApplicationRequest(); - $environmentsResponse = $this->mockEnvironmentsRequest($applicationsResponse); - $selectedEnvironment = $environmentsResponse->_embedded->items[0]; + $applications = $this->mockRequest('getApplications'); + $this->mockRequest('getApplicationByUuid', $applications[0]->uuid); + $environments = $this->mockRequest('getApplicationEnvironments', $applications[0]->uuid); $localMachineHelper = $this->mockLocalMachineHelper(); - $this->setUpPushArtifact($localMachineHelper, $selectedEnvironment->vcs->path, [$selectedEnvironment->vcs->url]); + $this->setUpPushArtifact($localMachineHelper, $environments[0]->vcs->path, [$environments[0]->vcs->url]); $inputs = [ // Would you like Acquia CLI to search for a Cloud application that matches your local git config? 'n', @@ -59,15 +55,12 @@ public function testPushArtifact(): void { } public function testPushTagArtifact(): void { - touch(Path::join($this->projectDir, 'composer.json')); - mkdir(Path::join($this->projectDir, 'docroot')); - $applicationsResponse = $this->mockApplicationsRequest(); - $this->mockApplicationRequest(); - $environmentsResponse = $this->mockEnvironmentsRequest($applicationsResponse); - $selectedEnvironment = $environmentsResponse->_embedded->items[0]; + $applications = $this->mockRequest('getApplications'); + $this->mockRequest('getApplicationByUuid', $applications[0]->uuid); + $environments = $this->mockRequest('getApplicationEnvironments', $applications[0]->uuid); $localMachineHelper = $this->mockLocalMachineHelper(); - $this->setUpPushArtifact($localMachineHelper, '1.2.0', [$selectedEnvironment->vcs->url]); $gitTag = '1.2.0-build'; + $this->setUpPushArtifact($localMachineHelper, '1.2.0', [$environments[0]->vcs->url], $gitTag); $artifactDir = Path::join(sys_get_temp_dir(), 'acli-push-artifact'); $this->mockGitTag($localMachineHelper, $gitTag, $artifactDir); $inputs = [ @@ -91,12 +84,9 @@ public function testPushTagArtifact(): void { } public function testPushArtifactWithAcquiaCliFile(): void { - touch(Path::join($this->projectDir, 'composer.json')); - mkdir(Path::join($this->projectDir, 'docroot')); - $this->mockRequest('getApplications'); - $applicationsResponse = $this->mockApplicationsRequest(); - $this->mockApplicationRequest(); - $this->mockEnvironmentsRequest($applicationsResponse); + $applications = $this->mockRequest('getApplications'); + $this->mockRequest('getApplicationByUuid', $applications[0]->uuid); + $this->mockRequest('getApplicationEnvironments', $applications[0]->uuid); $this->datastoreAcli->set('push.artifact.destination-git-urls', [ 'https://github.com/example1/cli.git', 'https://github.com/example2/cli.git', @@ -105,7 +95,7 @@ public function testPushArtifactWithAcquiaCliFile(): void { $this->setUpPushArtifact($localMachineHelper, 'master', $this->datastoreAcli->get('push.artifact.destination-git-urls')); $this->executeCommand([ '--destination-git-branch' => 'master', - ], []); + ]); $this->prophet->checkPredictions(); $output = $this->getDisplay(); @@ -114,12 +104,9 @@ public function testPushArtifactWithAcquiaCliFile(): void { } public function testPushArtifactWithArgs(): void { - touch(Path::join($this->projectDir, 'composer.json')); - mkdir(Path::join($this->projectDir, 'docroot')); - $this->mockRequest('getApplications'); - $applicationsResponse = $this->mockApplicationsRequest(); - $this->mockApplicationRequest(); - $this->mockEnvironmentsRequest($applicationsResponse); + $applications = $this->mockRequest('getApplications'); + $this->mockRequest('getApplicationByUuid', $applications[0]->uuid); + $this->mockRequest('getApplicationEnvironments', $applications[0]->uuid); $destinationGitUrls = [ 'https://github.com/example1/cli.git', 'https://github.com/example2/cli.git', @@ -129,7 +116,7 @@ public function testPushArtifactWithArgs(): void { $this->executeCommand([ '--destination-git-branch' => 'master', '--destination-git-urls' => $destinationGitUrls, - ], []); + ]); $this->prophet->checkPredictions(); $output = $this->getDisplay(); @@ -137,7 +124,81 @@ public function testPushArtifactWithArgs(): void { $this->assertStringContainsString('Pushing changes to Acquia Git (https://github.com/example2/cli.git)', $output); } - protected function setUpPushArtifact(mixed $localMachineHelper, mixed $vcsPath, mixed $vcsUrls): void { + public function testPushArtifactNoPush(): void { + $applications = $this->mockRequest('getApplications'); + $this->mockRequest('getApplicationByUuid', $applications[0]->uuid); + $environments = $this->mockRequest('getApplicationEnvironments', $applications[0]->uuid); + $localMachineHelper = $this->mockLocalMachineHelper(); + $this->setUpPushArtifact($localMachineHelper, $environments[0]->vcs->path, [$environments[0]->vcs->url], 'master:master', TRUE, TRUE, FALSE); + $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 ... ? + 'y', + // Choose an Acquia environment: + 0, + ]; + $this->executeCommand(['--no-push' => TRUE], $inputs); + $this->prophet->checkPredictions(); + $output = $this->getDisplay(); + + $this->assertStringContainsString('Initializing Git', $output); + $this->assertStringContainsString('Adding and committing changed files', $output); + $this->assertStringNotContainsString('Pushing changes to Acquia Git (site@svn-3.hosted.acquia-sites.com:site.git)', $output); + } + + public function testPushArtifactNoCommit(): void { + $applications = $this->mockRequest('getApplications'); + $this->mockRequest('getApplicationByUuid', $applications[0]->uuid); + $environments = $this->mockRequest('getApplicationEnvironments', $applications[0]->uuid); + $localMachineHelper = $this->mockLocalMachineHelper(); + $this->setUpPushArtifact($localMachineHelper, $environments[0]->vcs->path, [$environments[0]->vcs->url], 'master:master', TRUE, FALSE, FALSE); + $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 ... ? + 'y', + // Choose an Acquia environment: + 0, + ]; + $this->executeCommand(['--no-commit' => TRUE], $inputs); + $this->prophet->checkPredictions(); + $output = $this->getDisplay(); + + $this->assertStringContainsString('Initializing Git', $output); + $this->assertStringNotContainsString('Adding and committing changed files', $output); + $this->assertStringNotContainsString('Pushing changes to Acquia Git (site@svn-3.hosted.acquia-sites.com:site.git)', $output); + } + + public function testPushArtifactNoClone(): void { + $localMachineHelper = $this->mockLocalMachineHelper(); + $this->setUpPushArtifact($localMachineHelper, 'nothing', [], 'something', FALSE, FALSE, FALSE); + $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 ... ? + 'y', + // Choose an Acquia environment: + 0, + ]; + $this->executeCommand(['--no-clone' => TRUE], $inputs); + $this->prophet->checkPredictions(); + $output = $this->getDisplay(); + + $this->assertStringNotContainsString('Initializing Git', $output); + $this->assertStringNotContainsString('Adding and committing changed files', $output); + $this->assertStringNotContainsString('Pushing changes to Acquia Git (site@svn-3.hosted.acquia-sites.com:site.git)', $output); + } + + protected function setUpPushArtifact(ObjectProphecy $localMachineHelper, string $vcsPath, array $vcsUrls, string $destGitRef = 'master:master', bool $clone = TRUE, bool $commit = TRUE, bool $push = TRUE): void { + touch(Path::join($this->projectDir, 'composer.json')); + mkdir(Path::join($this->projectDir, 'docroot')); $artifactDir = Path::join(sys_get_temp_dir(), 'acli-push-artifact'); $this->createMockGitConfigFile(); $finder = $this->mockFinder(); @@ -146,21 +207,28 @@ protected function setUpPushArtifact(mixed $localMachineHelper, mixed $vcsPath, $localMachineHelper->getFilesystem()->willReturn($fs)->shouldBeCalled(); $this->command->localMachineHelper = $localMachineHelper->reveal(); - $commitHash = 'abc123'; $this->mockExecuteGitStatus(FALSE, $localMachineHelper, $this->projectDir); + $commitHash = 'abc123'; $this->mockGetLocalCommitHash($localMachineHelper, $this->projectDir, $commitHash); - $this->mockCloneShallow($localMachineHelper, $vcsPath, $vcsUrls[0], $artifactDir); - $this->mockLocalGitConfig($localMachineHelper, $artifactDir); $this->mockComposerInstall($localMachineHelper, $artifactDir); $this->mockReadComposerJson($localMachineHelper, $artifactDir); - $this->mockGitAddCommit($localMachineHelper, $artifactDir, $commitHash); - $this->mockGitPush($vcsUrls, $localMachineHelper, $vcsPath, $artifactDir); + $localMachineHelper->checkRequiredBinariesExist(['git'])->shouldBeCalled(); + + if ($clone) { + $this->mockLocalGitConfig($localMachineHelper, $artifactDir); + $this->mockCloneShallow($localMachineHelper, $vcsPath, $vcsUrls[0], $artifactDir); + } + if ($commit) { + $this->mockGitAddCommit($localMachineHelper, $artifactDir, $commitHash); + } + if ($push) { + $this->mockGitPush($vcsUrls, $localMachineHelper, $artifactDir, $destGitRef); + } } - protected function mockCloneShallow(ObjectProphecy $localMachineHelper, mixed $vcsPath, mixed $vcsUrl, mixed $artifactDir): void { + protected function mockCloneShallow(ObjectProphecy $localMachineHelper, string $vcsPath, string $vcsUrl, mixed $artifactDir): void { $process = $this->prophet->prophesize(Process::class); $process->isSuccessful()->willReturn(TRUE)->shouldBeCalled(); - $localMachineHelper->checkRequiredBinariesExist(['git'])->shouldBeCalled(); $localMachineHelper->execute(['git', 'clone', '--depth=1', $vcsUrl, $artifactDir], Argument::type('callable'), NULL, TRUE) ->willReturn($process->reveal())->shouldBeCalled(); $localMachineHelper->execute(['git', 'fetch', '--depth=1', $vcsUrl, $vcsPath . ':' . $vcsPath], Argument::type('callable'), Argument::type('string'), TRUE) @@ -169,7 +237,7 @@ protected function mockCloneShallow(ObjectProphecy $localMachineHelper, mixed $v ->willReturn($process->reveal())->shouldBeCalled(); } - protected function mockLocalGitConfig(ObjectProphecy $localMachineHelper, mixed $artifactDir): void { + protected function mockLocalGitConfig(ObjectProphecy $localMachineHelper, string $artifactDir): void { $process = $this->prophet->prophesize(Process::class); $localMachineHelper->execute(['git', 'config', '--local', 'core.excludesFile', 'false'], Argument::type('callable'), $artifactDir, TRUE) ->willReturn($process->reveal())->shouldBeCalled(); @@ -220,15 +288,15 @@ protected function mockReadComposerJson(ObjectProphecy $localMachineHelper, stri ->willReturn($composerJson); } - protected function mockGitPush(mixed $gitUrls, ObjectProphecy $localMachineHelper, mixed $gitBranch, mixed $artifactDir): void { + protected function mockGitPush(array $gitUrls, ObjectProphecy $localMachineHelper, string $artifactDir, string $destGitRef): void { $process = $this->mockProcess(); foreach ($gitUrls as $gitUrl) { - $localMachineHelper->execute(Argument::containing($gitUrl), Argument::type('callable'), $artifactDir, TRUE) + $localMachineHelper->execute(['git', 'push', $gitUrl, $destGitRef], Argument::type('callable'), $artifactDir, TRUE) ->willReturn($process->reveal())->shouldBeCalled(); } } - protected function mockGitTag(ObjectProphecy $localMachineHelper, mixed $gitTag, mixed $artifactDir): void { + protected function mockGitTag(ObjectProphecy $localMachineHelper, string $gitTag, string $artifactDir): void { $process = $this->mockProcess(); $localMachineHelper->execute([ 'git', From 2b83df7f10ece28169f3addedadeefd7d4b85e88 Mon Sep 17 00:00:00 2001 From: Dane Powell Date: Mon, 23 Oct 2023 16:07:02 -0700 Subject: [PATCH 6/6] kill mutants --- src/Command/Push/PushArtifactCommand.php | 1 - .../src/Commands/Push/PushArtifactCommandTest.php | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Command/Push/PushArtifactCommand.php b/src/Command/Push/PushArtifactCommand.php index 01a1b288b..21eb95c6d 100644 --- a/src/Command/Push/PushArtifactCommand.php +++ b/src/Command/Push/PushArtifactCommand.php @@ -72,7 +72,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->setDirAndRequireProjectCwd($input); if ($input->getOption('no-clone')) { $input->setOption('no-commit', TRUE); - $input->setOption('no-push', TRUE); } if ($input->getOption('no-commit')) { $input->setOption('no-push', TRUE); diff --git a/tests/phpunit/src/Commands/Push/PushArtifactCommandTest.php b/tests/phpunit/src/Commands/Push/PushArtifactCommandTest.php index 3d5ff59a4..8e367a7c9 100644 --- a/tests/phpunit/src/Commands/Push/PushArtifactCommandTest.php +++ b/tests/phpunit/src/Commands/Push/PushArtifactCommandTest.php @@ -51,6 +51,20 @@ public function testPushArtifact(): void { $this->assertStringContainsString('[0] Sample application 1', $output); $this->assertStringContainsString('Choose a Cloud Platform environment', $output); $this->assertStringContainsString('[0] Dev, dev (vcs: master)', $output); + $this->assertStringContainsString('Acquia CLI will:', $output); + $this->assertStringContainsString('- git clone master from site@svn-3.hosted.acquia-sites.com:site.git', $output); + $this->assertStringContainsString('- Compile the contents of vfs://root/project into an artifact', $output); + $this->assertStringContainsString('- Copy the artifact files into the checked out copy of master', $output); + $this->assertStringContainsString('- Commit changes and push the master branch', $output); + $this->assertStringContainsString('Removing', $output); + $this->assertStringContainsString('Initializing Git', $output); + $this->assertStringContainsString('Global .gitignore file', $output); + $this->assertStringContainsString('Removing vendor', $output); + $this->assertStringContainsString('Mirroring source', $output); + $this->assertStringContainsString('Installing Composer', $output); + $this->assertStringContainsString('Finding Drupal', $output); + $this->assertStringContainsString('Removing sensitive', $output); + $this->assertStringContainsString('Adding and committing', $output); $this->assertStringContainsString('Pushing changes to Acquia Git (site@svn-3.hosted.acquia-sites.com:site.git)', $output); } @@ -81,6 +95,7 @@ public function testPushTagArtifact(): void { $this->assertStringContainsString('Select a Cloud Platform application:', $output); $this->assertStringContainsString('[0] Sample application 1', $output); $this->assertStringContainsString('Pushing changes to Acquia Git (site@svn-3.hosted.acquia-sites.com:site.git)', $output); + $this->assertStringContainsString('Commit changes and push the 1.2.0-build tag', $output); } public function testPushArtifactWithAcquiaCliFile(): void {