xref: /PHP-8.0/ext/zip/tests/oo_addemptydir.phpt (revision 0b21a894)
1--TEST--
2ziparchive::addEmptyDir
3--SKIPIF--
4<?php
5if(!extension_loaded('zip')) die('skip');
6?>
7--FILE--
8<?php
9
10$dirname = __DIR__ . '/';
11include $dirname . 'utils.inc';
12$file = $dirname . 'oo_addemptydir.zip';
13
14copy($dirname . 'test.zip', $file);
15
16$zip = new ZipArchive;
17if (!$zip->open($file)) {
18    exit('failed');
19}
20
21var_dump($zip->lastId); // -1 (nothing added)
22$zip->addEmptyDir('emptydir');
23var_dump($zip->lastId); // 4
24$zip->addEmptyDir('emptydir');
25var_dump($zip->lastId); // -1 (already exists)
26$zip->addEmptyDir('emptydir', ZipArchive::FL_OVERWRITE);
27var_dump($zip->lastId); // 4
28if ($zip->status == ZIPARCHIVE::ER_OK) {
29    if (!verify_entries($zip, [
30        "bar",
31        "foobar/",
32        "foobar/baz",
33        "entry1.txt",
34        "emptydir/"
35    ])) {
36        echo "failed\n";
37    } else {
38        echo "OK";
39    }
40    $zip->close();
41} else {
42    echo "failed3\n";
43}
44@unlink($file);
45?>
46--EXPECT--
47int(-1)
48int(4)
49int(-1)
50int(4)
51OK
52