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