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