xref: /PHP-8.3/ext/zip/tests/utils.inc (revision d114812f)
1<?php
2function dump_entries_name($z) {
3    for($i=0; $i<$z->numFiles; $i++) {
4        $sb = $z->statIndex($i);
5        echo $i . ' ' . $sb['name'] . "\n";
6    }
7}
8
9function verify_entries($zip, $entries = []) {
10    $verified = true;
11    $found    = [];
12
13    for ($index = 0; $index < $zip->numFiles; $index++) {
14        $stat = $zip->statIndex($index);
15
16        if (!in_array($stat["name"], $entries)) {
17            $verified = false;
18        }
19
20        $found[] = $stat["name"];
21    }
22
23    if (!$verified) {
24        var_dump($found);
25    }
26
27    return $verified;
28}
29
30/* recursively remove a directory */
31function rmdir_rf($dir) {
32    if ($handle = opendir($dir)) {
33        while (false !== ($item = readdir($handle))) {
34            if ($item != "." && $item != "..") {
35                if (is_dir($dir . '/' . $item)) {
36                    rmdir_rf($dir . '/' . $item);
37                } else {
38                    unlink($dir . '/' . $item);
39                }
40            }
41        }
42        closedir($handle);
43        rmdir($dir);
44    }
45}
46