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->save($resultFilename);
$dupname = 'Unable to open saved file';
$zip = zip_open($resultFilename);
if (is_resource($zip)) {
$zip = new \ZipArchive();
if ($zip->open($resultFilename) !== false) {
$names = [];
$dupname = '';
while ($zip_entry = zip_read($zip)) {
$zipname = zip_entry_name($zip_entry);
if (in_array($zipname, $names)) {
$dupname .= "$zipname,";
for ($index = 0; $index < $zip->numFiles; ++$index) {
$filename = $zip->getNameIndex($index);
if (in_array($filename, $names)) {
$dupname .= "$filename,";
} else {
$names[] = $zipname;
$names[] = $filename;
}
}
zip_close($zip);
$zip->close();
}
unlink($resultFilename);
self::assertEquals('', $dupname);