Use ZipArchive methods as zip_* functions are deprecated in PHP8

This commit is contained in:
MarkBaker 2020-10-09 12:58:33 +02:00
parent 57d1854bae
commit 87a909aaf8
1 changed files with 9 additions and 8 deletions

View File

@ -34,19 +34,20 @@ class UnparsedDataCloneTest extends TestCase
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet); $writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
$writer->save($resultFilename); $writer->save($resultFilename);
$dupname = 'Unable to open saved file'; $dupname = 'Unable to open saved file';
$zip = zip_open($resultFilename);
if (is_resource($zip)) { $zip = new \ZipArchive();
if ($zip->open($resultFilename) !== false) {
$names = []; $names = [];
$dupname = ''; $dupname = '';
while ($zip_entry = zip_read($zip)) { for ($index = 0; $index < $zip->numFiles; ++$index) {
$zipname = zip_entry_name($zip_entry); $filename = $zip->getNameIndex($index);
if (in_array($zipname, $names)) { if (in_array($filename, $names)) {
$dupname .= "$zipname,"; $dupname .= "$filename,";
} else { } else {
$names[] = $zipname; $names[] = $filename;
} }
} }
zip_close($zip); $zip->close();
} }
unlink($resultFilename); unlink($resultFilename);
self::assertEquals('', $dupname); self::assertEquals('', $dupname);