Skip to content

Commit 710e0df

Browse files
committed
make corruption tests Windows-safe
CI failed only on PHP 8.0 / windows-latest. Replace tempnam() with the sys_get_temp_dir() + md5(uniqid()) pattern the rest of the suite uses, and explicitly close the Zip handle in finally so Windows can unlink the temp file (open handles block deletion).
1 parent 07d07d2 commit 710e0df

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

tests/ZipTestCase.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,15 @@ public function testMissing()
5858
*/
5959
public function testNotAZip()
6060
{
61-
$tmp = tempnam(sys_get_temp_dir(), 'phpa-bad-');
61+
$tmp = sys_get_temp_dir() . '/phpa-bad-' . md5(uniqid('', true)) . '.bin';
6262
file_put_contents($tmp, str_repeat('this is not a zip file ', 50));
63+
$zip = new Zip();
64+
$zip->open($tmp);
6365
try {
64-
$zip = new Zip();
65-
$zip->open($tmp);
6666
$this->expectException(ArchiveCorruptedException::class);
6767
iterator_to_array($zip->yieldContents());
6868
} finally {
69+
try { $zip->close(); } catch (\Exception $e) { /* already errored */ }
6970
@unlink($tmp);
7071
}
7172
}
@@ -75,14 +76,15 @@ public function testNotAZip()
7576
*/
7677
public function testTruncatedFile()
7778
{
78-
$tmp = tempnam(sys_get_temp_dir(), 'phpa-trunc-');
79+
$tmp = sys_get_temp_dir() . '/phpa-trunc-' . md5(uniqid('', true)) . '.bin';
7980
file_put_contents($tmp, "PK\x03\x04");
81+
$zip = new Zip();
82+
$zip->open($tmp);
8083
try {
81-
$zip = new Zip();
82-
$zip->open($tmp);
8384
$this->expectException(ArchiveCorruptedException::class);
8485
iterator_to_array($zip->yieldContents());
8586
} finally {
87+
try { $zip->close(); } catch (\Exception $e) { /* already errored */ }
8688
@unlink($tmp);
8789
}
8890
}

0 commit comments

Comments
 (0)