xref: /PHP-8.0/ext/zip/tests/oo_getnameindex.phpt (revision f8d79582)
1--TEST--
2getNameIndex
3--SKIPIF--
4<?php
5if(!extension_loaded('zip')) die('skip');
6?>
7--FILE--
8<?php
9$dirname = __DIR__ . '/';
10include $dirname . 'utils.inc';
11$file = $dirname . 'oo_getnameindex.zip';
12
13@unlink($file);
14
15$zip = new ZipArchive;
16if (!$zip->open($file, ZIPARCHIVE::CREATE)) {
17    exit('failed');
18}
19
20$zip->addFromString('entry1.txt', 'entry #1');
21$zip->addFromString('entry2.txt', 'entry #2');
22$zip->addFromString('dir/entry2d.txt', 'entry #2');
23
24if (!$zip->status == ZIPARCHIVE::ER_OK) {
25    echo "failed to write zip\n";
26}
27$zip->close();
28
29if (!$zip->open($file)) {
30    exit('failed');
31}
32
33
34var_dump($zip->getNameIndex(0));
35var_dump($zip->getNameIndex(1));
36var_dump($zip->getNameIndex(2));
37var_dump($zip->getNameIndex(3));
38
39$zip->close();
40
41?>
42--EXPECT--
43string(10) "entry1.txt"
44string(10) "entry2.txt"
45string(15) "dir/entry2d.txt"
46bool(false)
47--CLEAN--
48<?php
49unlink(__DIR__ . '/oo_getnameindex.zip');
50?>
51