diff --git a/src/Command/Pull/PullCommandBase.php b/src/Command/Pull/PullCommandBase.php index 7158c475b..e67dc5370 100644 --- a/src/Command/Pull/PullCommandBase.php +++ b/src/Command/Pull/PullCommandBase.php @@ -392,7 +392,7 @@ private function importDatabaseDump(string $localDumpFilepath, string $dbHost, s } else { $this->io->warning('Install `pv` to see progress bar'); - $command = "gunzip $localDumpFilepath | MYSQL_PWD=$dbPassword mysql --host=$dbHost --user=$dbUser $dbName"; + $command = "gunzip -c $localDumpFilepath | MYSQL_PWD=$dbPassword mysql --host=$dbHost --user=$dbUser $dbName"; } $process = $this->localMachineHelper->executeFromCmd($command, $outputCallback, NULL, ($this->output->getVerbosity() > OutputInterface::VERBOSITY_NORMAL)); diff --git a/tests/phpunit/src/CommandTestBase.php b/tests/phpunit/src/CommandTestBase.php index 0983d2023..4c20c7a41 100644 --- a/tests/phpunit/src/CommandTestBase.php +++ b/tests/phpunit/src/CommandTestBase.php @@ -358,11 +358,12 @@ protected function mockCreateMySqlDumpOnLocal(ObjectProphecy $localMachineHelper } protected function mockExecutePvExists( - ObjectProphecy $localMachineHelper + ObjectProphecy $localMachineHelper, + bool $pvExists = TRUE ): void { $localMachineHelper ->commandExists('pv') - ->willReturn(TRUE) + ->willReturn($pvExists) ->shouldBeCalled(); } diff --git a/tests/phpunit/src/Commands/Pull/PullDatabaseCommandTest.php b/tests/phpunit/src/Commands/Pull/PullDatabaseCommandTest.php index 9eeed79d3..9dffbf465 100644 --- a/tests/phpunit/src/Commands/Pull/PullDatabaseCommandTest.php +++ b/tests/phpunit/src/Commands/Pull/PullDatabaseCommandTest.php @@ -17,6 +17,7 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Output\BufferedOutput; use Symfony\Component\Filesystem\Filesystem; +use Symfony\Component\Filesystem\Path; /** * @property \Acquia\Cli\Command\Pull\PullDatabaseCommand $command @@ -69,6 +70,15 @@ public function testPullDatabasesLocalConnectionFailure(): void { ], $inputs); } + public function testPullDatabaseNoPv(): void { + $this->setupPullDatabase(TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, FALSE, 0, TRUE, FALSE); + $inputs = $this->getInputs(); + + $this->executeCommand(['--no-scripts' => TRUE], $inputs); + $output = $this->getDisplay(); + $this->assertStringContainsString(' [WARNING] Install `pv` to see progress bar', $output); + } + public function testPullMultipleDatabases(): void { $this->setupPullDatabase(TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, TRUE); $inputs = [ @@ -177,7 +187,7 @@ public function testPullDatabaseWithMySqlImportError(): void { /** * @dataProvider providerTestPullDatabaseWithInvalidSslCertificate */ - public function testPullDatabaseWithInvalidSslCertificate(mixed $errorCode): void { + public function testPullDatabaseWithInvalidSslCertificate(int $errorCode): void { $this->setupPullDatabase(TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, FALSE, $errorCode); $inputs = $this->getInputs(); @@ -187,7 +197,7 @@ public function testPullDatabaseWithInvalidSslCertificate(mixed $errorCode): voi $this->assertStringContainsString('Trying alternative host other.example.com', $output); } - protected function setupPullDatabase(bool $mysqlConnectSuccessful, bool $mysqlDropSuccessful, bool $mysqlCreateSuccessful, bool $mysqlImportSuccessful, bool $mockIdeFs = FALSE, bool $onDemand = FALSE, bool $mockGetAcsfSites = TRUE, bool $multidb = FALSE, int $curlCode = 0, bool $existingBackups = TRUE): void { + protected function setupPullDatabase(bool $mysqlConnectSuccessful, bool $mysqlDropSuccessful, bool $mysqlCreateSuccessful, bool $mysqlImportSuccessful, bool $mockIdeFs = FALSE, bool $onDemand = FALSE, bool $mockGetAcsfSites = TRUE, bool $multidb = FALSE, int $curlCode = 0, bool $existingBackups = TRUE, bool $pvExists = TRUE): void { $applicationsResponse = $this->mockApplicationsRequest(); $this->mockApplicationRequest(); $environmentsResponse = $this->mockAcsfEnvironmentsRequest($applicationsResponse); @@ -231,8 +241,10 @@ protected function setupPullDatabase(bool $mysqlConnectSuccessful, bool $mysqlDr // Database. $this->mockExecuteMySqlDropDb($localMachineHelper, $mysqlDropSuccessful); $this->mockExecuteMySqlCreateDb($localMachineHelper, $mysqlCreateSuccessful); - $this->mockExecuteMySqlImport($localMachineHelper, $mysqlImportSuccessful); - + $this->mockExecuteMySqlImport($localMachineHelper, $mysqlImportSuccessful, $pvExists); + if ($multidb) { + $this->mockExecuteMySqlImport($localMachineHelper, $mysqlImportSuccessful, $pvExists, 'profserv2', 'profserv2dev', 'drupal'); + } $this->command->localMachineHelper = $localMachineHelper->reveal(); $this->command->sshHelper = $sshHelper->reveal(); } @@ -291,14 +303,20 @@ protected function mockExecuteMySqlCreateDb( protected function mockExecuteMySqlImport( ObjectProphecy $localMachineHelper, - bool $success + bool $success, + bool $pvExists, + string $dbName = 'jxr5000596dev', + string $dbMachineName = 'db554675', + string $localDbName = 'jxr5000596dev' ): void { $localMachineHelper->checkRequiredBinariesExist(['gunzip', 'mysql'])->shouldBeCalled(); - $this->mockExecutePvExists($localMachineHelper); + $this->mockExecutePvExists($localMachineHelper, $pvExists); $process = $this->mockProcess($success); + $filePath = Path::join(sys_get_temp_dir(), "dev-$dbName-$dbMachineName-2012-05-15T12:00:00Z.sql.gz"); + $command = $pvExists ? "pv $filePath --bytes --rate | gunzip | MYSQL_PWD=drupal mysql --host=localhost --user=drupal $localDbName" : "gunzip -c $filePath | MYSQL_PWD=drupal mysql --host=localhost --user=drupal $localDbName"; // MySQL import command. $localMachineHelper - ->executeFromCmd(Argument::type('string'), Argument::type('callable'), + ->executeFromCmd($command, Argument::type('callable'), NULL, TRUE, NULL) ->willReturn($process->reveal()) ->shouldBeCalled();