Skip to content

Commit 1d64708

Browse files
authored
Merge pull request #118 from swlodarski-sumoheavy/10.1.x
SP-939: fix of warning: ZipArchive::close(): Failure to create temporary file: No such file or directory
2 parents 467af6c + bbefffe commit 1d64708

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

Model/SupportPackage.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -130,20 +130,24 @@ public function __construct(
130130
*/
131131
public function prepareDownloadArchive()
132132
{
133-
$path = $this->directoryList->getPath(DirectoryList::TMP) . '/bitpay-support.zip';
133+
$zipDir = $this->directoryList->getPath(DirectoryList::TMP) . DIRECTORY_SEPARATOR;
134+
if (!$this->fileDriver->isExists($zipDir)) {
135+
$this->fileDriver->createDirectory($zipDir);
136+
}
137+
$zipPath = $zipDir . 'bitpay-support.zip';
134138

135-
$this->zipArchive->open($path, \ZipArchive::CREATE);
139+
$this->zipArchive->open($zipPath, ZipArchive::CREATE | ZipArchive::OVERWRITE);
136140
$this->zipArchive->addFromString(
137141
'bitpay-support.json',
138142
$this->jsonSerializer->serialize($this->prepareSupportDetails())
139143
);
140-
$logPath = $this->directoryList->getPath(DirectoryList::LOG) . '/bitpay.log';
144+
$logPath = $this->directoryList->getPath(DirectoryList::LOG) . DIRECTORY_SEPARATOR . 'bitpay.log';
141145
if ($this->fileDriver->isExists($logPath)) {
142146
$this->zipArchive->addFile($logPath, 'bitpay.log');
143147
}
144148
$this->zipArchive->close();
145149

146-
return $path;
150+
return $zipPath;
147151
}
148152

149153
/**

Test/Unit/Model/SupportPackageTest.php

+16-4
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,21 @@ public function testPrepareDownloadArchive()
184184
[DirectoryList::LOG, '/log']
185185
]));
186186

187-
$this->fileDriverMock->method('isExists')
188-
->with($logPath)
189-
->willReturn(true);
187+
$invokedCount = $this->exactly(2);
188+
$this->fileDriverMock->expects($invokedCount)
189+
->method('isExists')
190+
->willReturnCallback(function ($parameters) use ($invokedCount, $tmpPath, $logPath) {
191+
if ($invokedCount->getInvocationCount() === 1) {
192+
$this->assertSame($tmpPath . '/', $parameters);
193+
194+
return true;
195+
}
196+
197+
if ($invokedCount->getInvocationCount() === 2) {
198+
$this->assertSame($logPath, $parameters);
199+
return true;
200+
}
201+
});
190202

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

216228
$this->zipArchiveMock->expects($this->once())
217229
->method('open')
218-
->with($archivePath, \ZipArchive::CREATE)
230+
->with($archivePath, ZipArchive::CREATE | ZipArchive::OVERWRITE)
219231
->willReturn(true);
220232
$this->zipArchiveMock->expects($this->once())
221233
->method('addFromString')

0 commit comments

Comments
 (0)