Skip to content

Commit

Permalink
Merge pull request #118 from swlodarski-sumoheavy/10.1.x
Browse files Browse the repository at this point in the history
SP-939: fix of warning: ZipArchive::close(): Failure to create temporary file: No such file or directory
  • Loading branch information
p-maguire authored Jan 21, 2025
2 parents 467af6c + bbefffe commit 1d64708
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
12 changes: 8 additions & 4 deletions Model/SupportPackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,20 +130,24 @@ public function __construct(
*/
public function prepareDownloadArchive()
{
$path = $this->directoryList->getPath(DirectoryList::TMP) . '/bitpay-support.zip';
$zipDir = $this->directoryList->getPath(DirectoryList::TMP) . DIRECTORY_SEPARATOR;
if (!$this->fileDriver->isExists($zipDir)) {
$this->fileDriver->createDirectory($zipDir);
}
$zipPath = $zipDir . 'bitpay-support.zip';

$this->zipArchive->open($path, \ZipArchive::CREATE);
$this->zipArchive->open($zipPath, ZipArchive::CREATE | ZipArchive::OVERWRITE);
$this->zipArchive->addFromString(
'bitpay-support.json',
$this->jsonSerializer->serialize($this->prepareSupportDetails())
);
$logPath = $this->directoryList->getPath(DirectoryList::LOG) . '/bitpay.log';
$logPath = $this->directoryList->getPath(DirectoryList::LOG) . DIRECTORY_SEPARATOR . 'bitpay.log';
if ($this->fileDriver->isExists($logPath)) {
$this->zipArchive->addFile($logPath, 'bitpay.log');
}
$this->zipArchive->close();

return $path;
return $zipPath;
}

/**
Expand Down
20 changes: 16 additions & 4 deletions Test/Unit/Model/SupportPackageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,21 @@ public function testPrepareDownloadArchive()
[DirectoryList::LOG, '/log']
]));

$this->fileDriverMock->method('isExists')
->with($logPath)
->willReturn(true);
$invokedCount = $this->exactly(2);
$this->fileDriverMock->expects($invokedCount)
->method('isExists')
->willReturnCallback(function ($parameters) use ($invokedCount, $tmpPath, $logPath) {
if ($invokedCount->getInvocationCount() === 1) {
$this->assertSame($tmpPath . '/', $parameters);

return true;
}

if ($invokedCount->getInvocationCount() === 2) {
$this->assertSame($logPath, $parameters);
return true;
}
});

$this->jsonSerializerMock->method('serialize')
->willReturn('{"key":"value"}');
Expand Down Expand Up @@ -215,7 +227,7 @@ public function testPrepareDownloadArchive()

$this->zipArchiveMock->expects($this->once())
->method('open')
->with($archivePath, \ZipArchive::CREATE)
->with($archivePath, ZipArchive::CREATE | ZipArchive::OVERWRITE)
->willReturn(true);
$this->zipArchiveMock->expects($this->once())
->method('addFromString')
Expand Down

0 comments on commit 1d64708

Please sign in to comment.