xref: /PHP-7.3/ext/phar/tests/phar_copy.phpt (revision f1d7e3ca)
1--TEST--
2Phar: copy()
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 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
13$fname2 = dirname(__FILE__) . '/' . 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['a']->compress(Phar::GZ);
28	$p['b']->setMetadata('a');
29	$p->copy('b', 'c');
30	$p->stopBuffering();
31	echo file_get_contents($p['c']->getPathName());
32	copy($fname, $fname2);
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);
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()), $p2['c']->getMetaData(), "\n";
45ini_set('phar.readonly', 0);
46try {
47$p2->copy('notexisting', 'another');
48} catch (Exception $e) {
49echo $e->getMessage() . "\n";
50}
51try {
52$p2->copy('a', 'b');
53} catch (Exception $e) {
54echo $e->getMessage() . "\n";
55}
56$p2['a']->compress(Phar::GZ);
57$p2->copy('a', 'd');
58echo $p2['d']->getContent() . "\n";
59try {
60$p2->copy('d', '.phar/stub.php');
61} catch (Exception $e) {
62echo $e->getMessage(),"\n";
63}
64try {
65$p2->copy('.phar/stub.php', 'd');
66} catch (Exception $e) {
67echo $e->getMessage(),"\n";
68}
69?>
70===DONE===
71--CLEAN--
72<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
73<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '2.phar.php'); ?>
74--EXPECTF--
75hihifile "/error/.." contains invalid characters upper directory reference, cannot be copied from "a" in phar %s
76
77a: hib: hic: hia
78file "notexisting" cannot be copied to file "another", file does not exist in %sphar_copy2.phar.php
79file "a" cannot be copied to file "b", file must not already exist in phar %sphar_copy2.phar.php
80hi
81file "d" cannot be copied to file ".phar/stub.php", cannot copy to Phar meta-file in %sphar_copy2.phar.php
82file ".phar/stub.php" cannot be copied to file "d", cannot copy Phar meta-file in %sphar_copy2.phar.php
83===DONE===
84