1--TEST--
2Phar::conversion to other formats
3--SKIPIF--
4<?php if (!extension_loaded("phar")) die("skip"); ?>
5<?php if (!extension_loaded("zlib")) die("skip no zlib"); ?>
6<?php if (!extension_loaded("bz2")) die("skip no bz2"); ?>
7--INI--
8phar.require_hash=0
9phar.readonly=0
10--FILE--
11<?php
12
13$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar';
14$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '2.tbz';
15$pname = 'phar://' . $fname;
16$stub = '<?php echo "first stub\n"; __HALT_COMPILER(); ?>';
17$file = $stub;
18
19$files = array();
20$files['a'] = 'a';
21$files['b'] = 'b';
22$files['c'] = 'c';
23
24include 'files/phar_test.inc';
25
26$phar = new Phar($fname);
27$zip = $phar->convertToData(Phar::ZIP);
28echo $zip->getPath() . "\n";
29$tgz = $phar->convertToData(Phar::TAR, Phar::GZ);
30echo $tgz->getPath() . "\n";
31$tbz = $phar->convertToData(Phar::TAR, Phar::BZ2);
32echo $tbz->getPath() . "\n";
33try {
34$phar = $tbz->convertToExecutable(Phar::PHAR, Phar::NONE);
35} catch (Exception $e) {
36echo $e->getMessage() . "\n";
37}
38copy($tbz->getPath(), $fname2);
39$tbz = new PharData($fname2);
40$phar = $tbz->convertToExecutable(Phar::PHAR, Phar::NONE);
41echo $phar->getPath() . "\n";
42$phar['a'] = 'hi';
43$phar['a']->setMetadata('hi');
44$zip = $phar->convertToExecutable(Phar::ZIP);
45echo $zip->getPath() . "\n";
46echo $zip['a']->getMetadata() . "\n";
47$data = $zip->convertToData();
48echo $data->getPath() . "\n";
49// extra code coverage
50try {
51$data->setStub('hi');
52} catch (Exception $e) {
53echo $e->getMessage() . "\n";
54}
55try {
56$data->setDefaultStub();
57} catch (Exception $e) {
58echo $e->getMessage() . "\n";
59}
60try {
61$data->setAlias('hi');
62} catch (Exception $e) {
63echo $e->getMessage() . "\n";
64}
65$tar = $phar->convertToExecutable(Phar::TAR);
66echo $tar->getPath() . "\n";
67$data = $tar->convertToData();
68echo $data->getPath() . "\n";
69$tgz = $tar->convertToExecutable(null, Phar::GZ);
70echo $tgz->getPath() . "\n";
71try {
72$tgz->convertToExecutable(25);
73} catch (Exception $e) {
74echo $e->getMessage() . "\n";
75}
76try {
77$tgz->convertToExecutable(Phar::ZIP, Phar::GZ);
78} catch (Exception $e) {
79echo $e->getMessage() . "\n";
80}
81try {
82$tgz->convertToExecutable(Phar::ZIP, Phar::BZ2);
83} catch (Exception $e) {
84echo $e->getMessage() . "\n";
85}
86try {
87$phar->convertToData();
88} catch (Exception $e) {
89echo $e->getMessage() . "\n";
90}
91try {
92$tgz->convertToData(Phar::PHAR);
93} catch (Exception $e) {
94echo $e->getMessage() . "\n";
95}
96try {
97$tgz->convertToData(25);
98} catch (Exception $e) {
99echo $e->getMessage() . "\n";
100}
101try {
102$tgz->convertToData(Phar::ZIP, Phar::GZ);
103} catch (Exception $e) {
104echo $e->getMessage() . "\n";
105}
106try {
107$tgz->convertToData(Phar::ZIP, Phar::BZ2);
108} catch (Exception $e) {
109echo $e->getMessage() . "\n";
110}
111try {
112$tgz->convertToExecutable(Phar::TAR, 25);
113} catch (Exception $e) {
114echo $e->getMessage() . "\n";
115}
116try {
117$tgz->convertToData(Phar::TAR, 25);
118} catch (Exception $e) {
119echo $e->getMessage() . "\n";
120}
121// extra code coverage
122try {
123$data->setStub('hi');
124} catch (Exception $e) {
125echo $e->getMessage() . "\n";
126}
127try {
128$data->setAlias('hi');
129} catch (Exception $e) {
130echo $e->getMessage() . "\n";
131}
132try {
133$data->setDefaultStub();
134} catch (Exception $e) {
135echo $e->getMessage() . "\n";
136}
137try {
138$tgz->convertToData(Phar::TAR, Phar::GZ, '.phar.tgz.oops');
139} catch (Exception $e) {
140echo $e->getMessage() . "\n";
141}
142
143try {
144$phar->convertToExecutable(Phar::TAR, Phar::GZ, '.tgz.oops');
145} catch (Exception $e) {
146echo $e->getMessage() . "\n";
147}
148
149try {
150$tgz->convertToData(Phar::TAR, Phar::GZ, '.phar/.tgz.oops');
151} catch (Exception $e) {
152echo $e->getMessage() . "\n";
153}
154?>
155===DONE===
156--CLEAN--
157<?php
158unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar');
159unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar');
160unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar.gz');
161unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.zip');
162unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.tar.gz');
163unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.tar');
164unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.tar.bz2');
165unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '2.tbz');
166unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '2.phar');
167unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '2.phar.tar');
168unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '2.tar');
169unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '2.phar.zip');
170unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '2.zip');
171unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '2.phar.tar.gz');
172__HALT_COMPILER();
173?>
174--EXPECTF--
175%sphar_convert_again.zip
176%sphar_convert_again.tar.gz
177%sphar_convert_again.tar.bz2
178Unable to add newly converted phar "%sphar_convert_again.phar" to the list of phars, a phar with that name already exists
179%sphar_convert_again2.phar
180%sphar_convert_again2.phar.zip
181hi
182%sphar_convert_again2.zip
183A Phar stub cannot be set in a plain zip archive
184A Phar stub cannot be set in a plain zip archive
185A Phar alias cannot be set in a plain zip archive
186%sphar_convert_again2.phar.tar
187%sphar_convert_again2.tar
188%sphar_convert_again2.phar.tar.gz
189Unknown file format specified, please pass one of Phar::PHAR, Phar::TAR or Phar::ZIP
190Cannot compress entire archive with gzip, zip archives do not support whole-archive compression
191Cannot compress entire archive with bz2, zip archives do not support whole-archive compression
192Cannot write out data phar archive, use Phar::TAR or Phar::ZIP
193Cannot write out data phar archive, use Phar::TAR or Phar::ZIP
194Unknown file format specified, please pass one of Phar::TAR or Phar::ZIP
195Cannot compress entire archive with gzip, zip archives do not support whole-archive compression
196Cannot compress entire archive with bz2, zip archives do not support whole-archive compression
197Unknown compression specified, please pass one of Phar::GZ or Phar::BZ2
198Unknown compression specified, please pass one of Phar::GZ or Phar::BZ2
199A Phar stub cannot be set in a plain tar archive
200A Phar alias cannot be set in a plain tar archive
201A Phar stub cannot be set in a plain tar archive
202data phar "%sphar_convert_again2.phar.tgz.oops" has invalid extension phar.tgz.oops
203phar "%sphar_convert_again2.tgz.oops" has invalid extension tgz.oops
204data phar "%sphar_convert_again2.phar/.tgz.oops" has invalid extension phar/.tgz.oops
205===DONE===
206