From bbefffe673f880820fda0d9e2a6eeb0b7fcdc097 Mon Sep 17 00:00:00 2001 From: Szymon Wlodarski Date: Mon, 20 Jan 2025 11:57:23 +0100 Subject: [PATCH] SP-939: fix of warning: ZipArchive::close(): Failure to create temporary file: No such file or directory --- Model/SupportPackage.php | 12 ++++++++---- Test/Unit/Model/SupportPackageTest.php | 20 ++++++++++++++++---- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/Model/SupportPackage.php b/Model/SupportPackage.php index 3a0646f..0ce0c6b 100644 --- a/Model/SupportPackage.php +++ b/Model/SupportPackage.php @@ -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; } /** diff --git a/Test/Unit/Model/SupportPackageTest.php b/Test/Unit/Model/SupportPackageTest.php index 8ca669a..00183b5 100644 --- a/Test/Unit/Model/SupportPackageTest.php +++ b/Test/Unit/Model/SupportPackageTest.php @@ -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"}'); @@ -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')