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