-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* CLI-1344: [push:artifact] support pushing to master * kill mutant
- Loading branch information
1 parent
7a9aa99
commit a845434
Showing
2 changed files
with
50 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
use Acquia\Cli\Tests\Commands\Pull\PullCommandTestBase; | ||
use Prophecy\Argument; | ||
use Prophecy\Prophecy\ObjectProphecy; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Filesystem\Filesystem; | ||
use Symfony\Component\Filesystem\Path; | ||
use Symfony\Component\Process\Process; | ||
|
@@ -27,12 +28,25 @@ public function testNoAuthenticationRequired(): void { | |
$this->assertStringNotContainsString('This command requires authentication', $help); | ||
} | ||
|
||
public function testPushArtifact(): void { | ||
/** | ||
* @return mixed[] | ||
*/ | ||
public function providerTestPushArtifact(): array { | ||
return [ | ||
[OutputInterface::VERBOSITY_NORMAL, FALSE], | ||
[OutputInterface::VERBOSITY_VERY_VERBOSE, TRUE], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider providerTestPushArtifact | ||
*/ | ||
public function testPushArtifact(int $verbosity, bool $printOutput): 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]); | ||
$this->setUpPushArtifact($localMachineHelper, $environments[0]->vcs->path, [$environments[0]->vcs->url], 'master:master', TRUE, TRUE, TRUE, $printOutput); | ||
$inputs = [ | ||
// Would you like Acquia CLI to search for a Cloud application that matches your local git config? | ||
'n', | ||
|
@@ -43,7 +57,7 @@ public function testPushArtifact(): void { | |
// Choose an Acquia environment: | ||
0, | ||
]; | ||
$this->executeCommand([], $inputs); | ||
$this->executeCommand([], $inputs, $verbosity); | ||
|
||
$output = $this->getDisplay(); | ||
|
||
|
@@ -57,16 +71,18 @@ public function testPushArtifact(): void { | |
$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 ([email protected]:site.git)', $output); | ||
if ($printOutput) { | ||
$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 ([email protected]:site.git)', $output); | ||
} | ||
} | ||
|
||
public function testPushTagArtifact(): void { | ||
|
@@ -212,7 +228,7 @@ public function testPushArtifactNoClone(): void { | |
$this->assertStringNotContainsString('Pushing changes to Acquia Git ([email protected]: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 { | ||
protected function setUpPushArtifact(ObjectProphecy $localMachineHelper, string $vcsPath, array $vcsUrls, string $destGitRef = 'master:master', bool $clone = TRUE, bool $commit = TRUE, bool $push = TRUE, bool $printOutput = 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'); | ||
|
@@ -225,52 +241,52 @@ protected function setUpPushArtifact(ObjectProphecy $localMachineHelper, string | |
$this->mockExecuteGitStatus(FALSE, $localMachineHelper, $this->projectDir); | ||
$commitHash = 'abc123'; | ||
$this->mockGetLocalCommitHash($localMachineHelper, $this->projectDir, $commitHash); | ||
$this->mockComposerInstall($localMachineHelper, $artifactDir); | ||
$this->mockComposerInstall($localMachineHelper, $artifactDir, $printOutput); | ||
$this->mockReadComposerJson($localMachineHelper, $artifactDir); | ||
$localMachineHelper->checkRequiredBinariesExist(['git'])->shouldBeCalled(); | ||
|
||
if ($clone) { | ||
$this->mockLocalGitConfig($localMachineHelper, $artifactDir); | ||
$this->mockCloneShallow($localMachineHelper, $vcsPath, $vcsUrls[0], $artifactDir); | ||
$this->mockLocalGitConfig($localMachineHelper, $artifactDir, $printOutput); | ||
$this->mockCloneShallow($localMachineHelper, $vcsPath, $vcsUrls[0], $artifactDir, $printOutput); | ||
} | ||
if ($commit) { | ||
$this->mockGitAddCommit($localMachineHelper, $artifactDir, $commitHash); | ||
$this->mockGitAddCommit($localMachineHelper, $artifactDir, $commitHash, $printOutput); | ||
} | ||
if ($push) { | ||
$this->mockGitPush($vcsUrls, $localMachineHelper, $artifactDir, $destGitRef); | ||
$this->mockGitPush($vcsUrls, $localMachineHelper, $artifactDir, $destGitRef, $printOutput); | ||
} | ||
} | ||
|
||
protected function mockCloneShallow(ObjectProphecy $localMachineHelper, string $vcsPath, string $vcsUrl, mixed $artifactDir): void { | ||
protected function mockCloneShallow(ObjectProphecy $localMachineHelper, string $vcsPath, string $vcsUrl, string $artifactDir, bool $printOutput = TRUE): void { | ||
$process = $this->prophet->prophesize(Process::class); | ||
$process->isSuccessful()->willReturn(TRUE)->shouldBeCalled(); | ||
$localMachineHelper->execute(['git', 'clone', '--depth=1', $vcsUrl, $artifactDir], Argument::type('callable'), NULL, TRUE) | ||
$localMachineHelper->execute(['git', 'clone', '--depth=1', $vcsUrl, $artifactDir], Argument::type('callable'), NULL, $printOutput) | ||
->willReturn($process->reveal())->shouldBeCalled(); | ||
$localMachineHelper->execute(['git', 'fetch', '--depth=1', $vcsUrl, $vcsPath . ':' . $vcsPath], Argument::type('callable'), Argument::type('string'), TRUE) | ||
$localMachineHelper->execute(['git', 'fetch', '--depth=1', '--update-head-ok', $vcsUrl, $vcsPath . ':' . $vcsPath], Argument::type('callable'), Argument::type('string'), $printOutput) | ||
->willReturn($process->reveal())->shouldBeCalled(); | ||
$localMachineHelper->execute(['git', 'checkout', $vcsPath], Argument::type('callable'), Argument::type('string'), TRUE) | ||
$localMachineHelper->execute(['git', 'checkout', $vcsPath], Argument::type('callable'), Argument::type('string'), $printOutput) | ||
->willReturn($process->reveal())->shouldBeCalled(); | ||
} | ||
|
||
protected function mockLocalGitConfig(ObjectProphecy $localMachineHelper, string $artifactDir): void { | ||
protected function mockLocalGitConfig(ObjectProphecy $localMachineHelper, string $artifactDir, bool $printOutput = TRUE): void { | ||
$process = $this->prophet->prophesize(Process::class); | ||
$localMachineHelper->execute(['git', 'config', '--local', 'core.excludesFile', 'false'], Argument::type('callable'), $artifactDir, TRUE) | ||
$localMachineHelper->execute(['git', 'config', '--local', 'core.excludesFile', 'false'], Argument::type('callable'), $artifactDir, $printOutput) | ||
->willReturn($process->reveal())->shouldBeCalled(); | ||
$localMachineHelper->execute(['git', 'config', '--local', 'core.fileMode', 'true'], Argument::type('callable'), $artifactDir, TRUE) | ||
$localMachineHelper->execute(['git', 'config', '--local', 'core.fileMode', 'true'], Argument::type('callable'), $artifactDir, $printOutput) | ||
->willReturn($process->reveal())->shouldBeCalled(); | ||
} | ||
|
||
protected function mockComposerInstall(ObjectProphecy $localMachineHelper, mixed $artifactDir): void { | ||
protected function mockComposerInstall(ObjectProphecy $localMachineHelper, mixed $artifactDir, bool $printOutput = TRUE): void { | ||
$localMachineHelper->checkRequiredBinariesExist(['composer'])->shouldBeCalled(); | ||
$process = $this->prophet->prophesize(Process::class); | ||
$process->isSuccessful()->willReturn(TRUE); | ||
$localMachineHelper->execute(['composer', 'install', '--no-dev', '--no-interaction', '--optimize-autoloader'], Argument::type('callable'), $artifactDir, TRUE) | ||
$localMachineHelper->execute(['composer', 'install', '--no-dev', '--no-interaction', '--optimize-autoloader'], Argument::type('callable'), $artifactDir, $printOutput) | ||
->willReturn($process->reveal())->shouldBeCalled(); | ||
} | ||
|
||
protected function mockGitAddCommit(ObjectProphecy $localMachineHelper, mixed $artifactDir, mixed $commitHash): void { | ||
protected function mockGitAddCommit(ObjectProphecy $localMachineHelper, string $artifactDir, string $commitHash, bool $printOutput): void { | ||
$process = $this->mockProcess(); | ||
$localMachineHelper->execute(['git', 'add', '-A'], Argument::type('callable'), $artifactDir, TRUE) | ||
$localMachineHelper->execute(['git', 'add', '-A'], Argument::type('callable'), $artifactDir, $printOutput) | ||
->willReturn($process->reveal())->shouldBeCalled(); | ||
$localMachineHelper->execute(['git', 'add', '-f', 'docroot/index.php'], NULL, $artifactDir, FALSE) | ||
->willReturn($process->reveal())->shouldBeCalled(); | ||
|
@@ -280,7 +296,7 @@ protected function mockGitAddCommit(ObjectProphecy $localMachineHelper, mixed $a | |
->willReturn($process->reveal())->shouldBeCalled(); | ||
$localMachineHelper->execute(['git', 'add', '-f', 'vendor'], NULL, $artifactDir, FALSE) | ||
->willReturn($process->reveal())->shouldBeCalled(); | ||
$localMachineHelper->execute(['git', 'commit', '-m', "Automated commit by Acquia CLI (source commit: $commitHash)"], Argument::type('callable'), $artifactDir, TRUE) | ||
$localMachineHelper->execute(['git', 'commit', '-m', "Automated commit by Acquia CLI (source commit: $commitHash)"], Argument::type('callable'), $artifactDir, $printOutput) | ||
->willReturn($process->reveal())->shouldBeCalled(); | ||
} | ||
|
||
|
@@ -303,10 +319,10 @@ protected function mockReadComposerJson(ObjectProphecy $localMachineHelper, stri | |
->willReturn($composerJson); | ||
} | ||
|
||
protected function mockGitPush(array $gitUrls, ObjectProphecy $localMachineHelper, string $artifactDir, string $destGitRef): void { | ||
protected function mockGitPush(array $gitUrls, ObjectProphecy $localMachineHelper, string $artifactDir, string $destGitRef, bool $printOutput): void { | ||
$process = $this->mockProcess(); | ||
foreach ($gitUrls as $gitUrl) { | ||
$localMachineHelper->execute(['git', 'push', $gitUrl, $destGitRef], Argument::type('callable'), $artifactDir, TRUE) | ||
$localMachineHelper->execute(['git', 'push', $gitUrl, $destGitRef], Argument::type('callable'), $artifactDir, $printOutput) | ||
->willReturn($process->reveal())->shouldBeCalled(); | ||
} | ||
} | ||
|