xref: /PHP-8.1/ext/phar/tests/zip/phar_copy.phpt (revision 74859783)
1--TEST--
2Phar: copy() zip-based
3--EXTENSIONS--
4phar
5--INI--
6phar.readonly=0
7phar.require_hash=1
8--FILE--
9<?php
10
11$fname = __DIR__ . '/' . basename(__FILE__, '.php') . '.phar.zip.php';
12$fname2 = __DIR__ . '/' . basename(__FILE__, '.php') . '2.phar.php';
13
14$pname = 'phar://'.$fname;
15$iname = '/file.txt';
16$ename = '/error/..';
17
18$p = new Phar($fname);
19
20try
21{
22    $p['a'] = 'hi';
23    $p->startBuffering();
24    $p->copy('a', 'b');
25    echo file_get_contents($p['b']->getPathName());
26    $p->copy('b', 'c');
27    $p->stopBuffering();
28    echo file_get_contents($p['c']->getPathName());
29    copy($fname, $fname2);
30    var_dump($p->isFileFormat(Phar::ZIP));
31    $p->copy('a', $ename);
32}
33catch(Exception $e)
34{
35    echo $e->getMessage() . "\n";
36}
37ini_set('phar.readonly',1);
38$p2 = new Phar($fname2);
39var_dump($p2->isFileFormat(Phar::ZIP));
40echo "\n";
41echo 'a: ' , file_get_contents($p2['a']->getPathName());
42echo 'b: ' ,file_get_contents($p2['b']->getPathName());
43echo 'c: ' ,file_get_contents($p2['c']->getPathName());
44?>
45===DONE===
46--CLEAN--
47<?php unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.zip.php'); ?>
48<?php unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '2.phar.php'); ?>
49--EXPECTF--
50hihibool(true)
51file "/error/.." contains invalid characters upper directory reference, cannot be copied from "a" in phar %s
52bool(true)
53
54a: hib: hic: hi===DONE===
55