Skip to content

Commit

Permalink
kill mutant
Browse files Browse the repository at this point in the history
  • Loading branch information
danepowell committed May 7, 2024
1 parent f0cfaa0 commit 26b140f
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 34 deletions.
8 changes: 4 additions & 4 deletions tests/phpunit/src/CommandTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected function setCommand(CommandBase $command): void {
* An array of strings representing each input passed to the command input
* stream.
*/
protected function executeCommand(array $args = [], array $inputs = []): void {
protected function executeCommand(array $args = [], array $inputs = [], int $verbosity = Output::VERBOSITY_VERY_VERBOSE): void {
$cwd = $this->projectDir;
$tester = $this->getCommandTester();
$tester->setInputs($inputs);
Expand All @@ -95,7 +95,7 @@ protected function executeCommand(array $args = [], array $inputs = []): void {
}

try {
$tester->execute($args, ['verbosity' => Output::VERBOSITY_VERY_VERBOSE]);
$tester->execute($args, ['verbosity' => $verbosity]);
}
catch (Exception $e) {
if (getenv('ACLI_PRINT_COMMAND_OUTPUT')) {
Expand Down Expand Up @@ -374,12 +374,12 @@ protected function mockNotificationResponseFromObject(object $responseWithNotifi
return $this->mockRequest('getNotificationByUuid', $uuid);
}

protected function mockCreateMySqlDumpOnLocal(ObjectProphecy $localMachineHelper): void {
protected function mockCreateMySqlDumpOnLocal(ObjectProphecy $localMachineHelper, bool $printOutput = TRUE): void {
$localMachineHelper->checkRequiredBinariesExist(["mysqldump", "gzip"])->shouldBeCalled();
$process = $this->mockProcess();
$process->getOutput()->willReturn('');
$command = 'MYSQL_PWD=drupal mysqldump --host=localhost --user=drupal drupal | pv --rate --bytes | gzip -9 > ' . sys_get_temp_dir() . '/acli-mysql-dump-drupal.sql.gz';
$localMachineHelper->executeFromCmd($command, Argument::type('callable'), NULL, TRUE)->willReturn($process->reveal())
$localMachineHelper->executeFromCmd($command, Argument::type('callable'), NULL, $printOutput)->willReturn($process->reveal())
->shouldBeCalled();
}

Expand Down
102 changes: 72 additions & 30 deletions tests/phpunit/src/Commands/Push/PushDatabaseCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,32 @@

use Acquia\Cli\Command\CommandBase;
use Acquia\Cli\Command\Push\PushDatabaseCommand;
use Acquia\Cli\Helpers\LocalMachineHelper;
use Acquia\Cli\Helpers\SshHelper;
use Acquia\Cli\Tests\CommandTestBase;
use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Path;
use Symfony\Component\Process\Process;

/**
* @property \Acquia\Cli\Command\Push\PushDatabaseCommand $command
*/
class PushDatabaseCommandTest extends CommandTestBase {

/**
* @return mixed[]
*/
public function providerTestPushDatabase(): array {
return [
[OutputInterface::VERBOSITY_NORMAL, FALSE],
[OutputInterface::VERBOSITY_VERY_VERBOSE, TRUE],
];
}

protected function createCommand(): CommandBase {

return $this->injectCommand(PushDatabaseCommand::class);
}

Expand All @@ -24,26 +40,34 @@ public function setUp(): void {
parent::setUp();
}

public function testPushDatabase(): void {
$applicationsResponse = $this->mockApplicationsRequest();
$this->mockApplicationRequest();
$environmentsResponse = $this->mockAcsfEnvironmentsRequest($applicationsResponse);
$selectedEnvironment = $environmentsResponse->_embedded->items[0];
/**
* @dataProvider providerTestPushDatabase
*/
public function testPushDatabase(int $verbosity, bool $printOutput): void {
$applications = $this->mockRequest('getApplications');
$application = $this->mockRequest('getApplicationByUuid', $applications[self::$INPUT_DEFAULT_CHOICE]->uuid);
$tamper = function ($responses): void {
foreach ($responses as $response) {
$response->ssh_url = 'profserv2.01dev@profserv201dev.ssh.enterprise-g1.acquia-sites.com';
$response->domains = ["profserv201dev.enterprise-g1.acquia-sites.com"];
}
};
$environments = $this->mockRequest('getApplicationEnvironments', $application->uuid, NULL, NULL, $tamper);
$this->createMockGitConfigFile();
$this->mockAcsfDatabasesResponse($selectedEnvironment);
$sshHelper = $this->mockSshHelper();
$this->mockGetAcsfSites($sshHelper);
$this->mockAcsfDatabasesResponse($environments[self::$INPUT_DEFAULT_CHOICE]);
$process = $this->mockProcess();

$localMachineHelper = $this->mockLocalMachineHelper();
$localMachineHelper->checkRequiredBinariesExist(['ssh'])->shouldBeCalled();
$this->mockGetAcsfSitesLMH($localMachineHelper);

// Database.
$this->mockExecutePvExists($localMachineHelper);
$this->mockCreateMySqlDumpOnLocal($localMachineHelper);
$this->mockUploadDatabaseDump($localMachineHelper, $process);
$this->mockImportDatabaseDumpOnRemote($sshHelper, $selectedEnvironment, $process);
$this->mockCreateMySqlDumpOnLocal($localMachineHelper, $printOutput);
$this->mockUploadDatabaseDump($localMachineHelper, $process, $printOutput);
$this->mockImportDatabaseDumpOnRemote($localMachineHelper, $process, $printOutput);

$this->command->sshHelper = $sshHelper->reveal();
$this->command->sshHelper = new SshHelper($this->output, $localMachineHelper->reveal(), $this->logger);

$inputs = [
// Would you like Acquia CLI to search for a Cloud application that matches your local git config?
Expand All @@ -60,7 +84,7 @@ public function testPushDatabase(): void {
'y',
];

$this->executeCommand([], $inputs);
$this->executeCommand([], $inputs, $verbosity);

$output = $this->getDisplay();

Expand All @@ -76,7 +100,8 @@ public function testPushDatabase(): void {

protected function mockUploadDatabaseDump(
ObjectProphecy $localMachineHelper,
ObjectProphecy $process
ObjectProphecy $process,
bool $printOutput = TRUE,
): void {
$localMachineHelper->checkRequiredBinariesExist(['rsync'])->shouldBeCalled();
$command = [
Expand All @@ -86,22 +111,7 @@ protected function mockUploadDatabaseDump(
sys_get_temp_dir() . '/acli-mysql-dump-drupal.sql.gz',
'profserv2.01dev@profserv201dev.ssh.enterprise-g1.acquia-sites.com:/mnt/tmp/profserv2.01dev/acli-mysql-dump-drupal.sql.gz',
];
$localMachineHelper->execute($command, Argument::type('callable'), NULL, TRUE, NULL)
->willReturn($process->reveal())
->shouldBeCalled();
}

protected function mockImportDatabaseDumpOnRemote(
ObjectProphecy $sshHelper,
object $environmentsResponse,
mixed $process
): void {
$sshHelper->executeCommand(
$environmentsResponse->ssh_url,
['pv /mnt/tmp/profserv2.01dev/acli-mysql-dump-drupal.sql.gz --bytes --rate | gunzip | MYSQL_PWD=password mysql --host=fsdb-74.enterprise-g1.hosting.acquia.com.enterprise-g1.hosting.acquia.com --user=s164 profserv2db14390'],
TRUE,
NULL
)
$localMachineHelper->execute($command, Argument::type('callable'), NULL, $printOutput, NULL)
->willReturn($process->reveal())
->shouldBeCalled();
}
Expand All @@ -118,4 +128,36 @@ protected function mockExecuteMySqlImport(
->shouldBeCalled();
}

protected function mockGetAcsfSitesLMH(ObjectProphecy $localMachineHelper): void {
$acsfMultisiteFetchProcess = $this->mockProcess();
$multisiteConfig = file_get_contents(Path::join($this->realFixtureDir, '/multisite-config.json'));
$acsfMultisiteFetchProcess->getOutput()->willReturn($multisiteConfig)->shouldBeCalled();
$cmd = [
0 => 'ssh',
1 => 'profserv2.01dev@profserv201dev.ssh.enterprise-g1.acquia-sites.com',
2 => '-t',
3 => '-o StrictHostKeyChecking=no',
4 => '-o AddressFamily inet',
5 => '-o LogLevel=ERROR',
6 => 'cat',
7 => '/var/www/site-php/profserv2.01dev/multisite-config.json',
];
$localMachineHelper->execute($cmd, Argument::type('callable'), NULL, FALSE, NULL)->willReturn($acsfMultisiteFetchProcess->reveal())->shouldBeCalled();
}

private function mockImportDatabaseDumpOnRemote(ObjectProphecy|LocalMachineHelper $localMachineHelper, Process|ObjectProphecy $process, bool $printOutput = TRUE): void {
$cmd = [
0 => 'ssh',
1 => 'profserv2.01dev@profserv201dev.ssh.enterprise-g1.acquia-sites.com',
2 => '-t',
3 => '-o StrictHostKeyChecking=no',
4 => '-o AddressFamily inet',
5 => '-o LogLevel=ERROR',
6 => 'pv /mnt/tmp/profserv2.01dev/acli-mysql-dump-drupal.sql.gz --bytes --rate | gunzip | MYSQL_PWD=password mysql --host=fsdb-74.enterprise-g1.hosting.acquia.com.enterprise-g1.hosting.acquia.com --user=s164 profserv2db14390',
];
$localMachineHelper->execute($cmd, Argument::type('callable'), NULL, $printOutput, NULL)
->willReturn($process->reveal())
->shouldBeCalled();
}

}

0 comments on commit 26b140f

Please sign in to comment.