Skip to content

Commit 37e199c

Browse files
test failing fix
1 parent faaad8a commit 37e199c

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

src/Command/Pull/PullCommandBase.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,28 @@ public function __construct(
6666
parent::__construct($this->localMachineHelper, $this->datastoreCloud, $this->datastoreAcli, $this->cloudCredentials, $this->telemetryHelper, $this->projectDir, $this->cloudApiClientService, $this->sshHelper, $this->sshDir, $logger, $this->selfUpdateManager);
6767
}
6868

69+
/**
70+
* Get the backup download URL.
71+
* This is primarily used for testing purposes.
72+
*/
73+
public function getBackupDownloadUrl(): ?UriInterface
74+
{
75+
return $this->backupDownloadUrl ?? null;
76+
}
77+
78+
/**
79+
* Set the backup download URL.
80+
* This is primarily used for testing purposes.
81+
*/
82+
public function setBackupDownloadUrl(string|UriInterface $url): void
83+
{
84+
if (is_string($url)) {
85+
$this->backupDownloadUrl = new \GuzzleHttp\Psr7\Uri($url);
86+
} else {
87+
$this->backupDownloadUrl = $url;
88+
}
89+
}
90+
6991
/**
7092
* @see https://github.com/drush-ops/drush/blob/c21a5a24a295cc0513bfdecead6f87f1a2cf91a2/src/Sql/SqlMysql.php#L168
7193
* @return string[]
@@ -404,6 +426,28 @@ private function validateGzipFile(string $localFilepath): void
404426
}
405427
}
406428

429+
public static function displayDownloadProgress(mixed $totalBytes, mixed $downloadedBytes, mixed &$progress, OutputInterface $output): void
430+
{
431+
if ($totalBytes > 0 && is_null($progress)) {
432+
$progress = new \Symfony\Component\Console\Helper\ProgressBar($output, $totalBytes);
433+
$progress->setFormat(' %current%/%max% [%bar%] %percent:3s%%');
434+
$progress->setProgressCharacter('💧');
435+
$progress->setOverwrite(true);
436+
$progress->start();
437+
}
438+
439+
if (!is_null($progress)) {
440+
if ($totalBytes === $downloadedBytes && $progress->getProgressPercent() !== 1.0) {
441+
$progress->finish();
442+
if ($output instanceof \Symfony\Component\Console\Output\ConsoleSectionOutput) {
443+
$output->clear();
444+
}
445+
return;
446+
}
447+
$progress->setProgress($downloadedBytes);
448+
}
449+
}
450+
407451
/**
408452
* Create an on-demand backup and wait for it to become available.
409453
*/

tests/phpunit/src/Commands/Pull/PullCommandTestBase.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,12 @@ protected function mockDownloadBackup(object $database, object $environment, obj
421421
$backup->completedAt,
422422
]) . '.sql.gz';
423423
$localFilepath = Path::join(sys_get_temp_dir(), $filename);
424+
425+
// Create a valid gzip file for validation.
426+
$content = 'Mock SQL dump content for testing';
427+
$gzippedContent = gzencode($content);
428+
file_put_contents($localFilepath, $gzippedContent);
429+
424430
$this->clientProphecy->addOption('sink', $localFilepath)
425431
->shouldBeCalled();
426432
$this->clientProphecy->addOption('curl.options', [
@@ -462,6 +468,7 @@ protected function mockDownloadCodebaseBackup(object $database, string $url, obj
462468
// Mock the HTTP client request for codebase downloads.
463469
$downloadUrl = $backup->links->download->href ?? 'https://example.com/download-backup';
464470
$response = $this->prophet->prophesize(ResponseInterface::class);
471+
$response->getStatusCode()->willReturn(200);
465472

466473
$capturedOpts = null;
467474
$this->httpClientProphecy
@@ -484,7 +491,12 @@ protected function mockDownloadCodebaseBackup(object $database, string $url, obj
484491
return true;
485492
})
486493
)
487-
->will(function () use (&$capturedOpts, $response): ResponseInterface {
494+
->will(function () use (&$capturedOpts, $response, $localFilepath): ResponseInterface {
495+
// Create a valid gzip file for validation.
496+
$content = 'Mock SQL dump content for testing';
497+
$gzippedContent = gzencode($content);
498+
file_put_contents($localFilepath, $gzippedContent);
499+
488500
// Simulate the download to force progress rendering.
489501
$progress = $capturedOpts['progress'];
490502
$progress(100, 0);

0 commit comments

Comments
 (0)