1--TEST--
2Phar::conversion to other formats
3--EXTENSIONS--
4phar
5zlib
6bz2
7--INI--
8phar.require_hash=0
9phar.readonly=0
10--FILE--
11<?php
12
13$fname = __DIR__ . '/' . basename(__FILE__, '.php') . '.phar';
14$fname2 = __DIR__ . '/' . 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--CLEAN--
156<?php
157unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar');
158unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.tar');
159unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.tar.gz');
160unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.zip');
161unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.tar.gz');
162unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.tar');
163unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.tar.bz2');
164unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '2.tbz');
165unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '2.phar');
166unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '2.phar.tar');
167unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '2.tar');
168unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '2.phar.zip');
169unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '2.zip');
170unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '2.phar.tar.gz');
171__HALT_COMPILER();
172?>
173--EXPECTF--
174%sphar_convert_again.zip
175%sphar_convert_again.tar.gz
176%sphar_convert_again.tar.bz2
177Unable to add newly converted phar "%sphar_convert_again.phar" to the list of phars, a phar with that name already exists
178%sphar_convert_again2.phar
179%sphar_convert_again2.phar.zip
180hi
181%sphar_convert_again2.zip
182A Phar stub cannot be set in a plain zip archive
183A Phar stub cannot be set in a plain zip archive
184A Phar alias cannot be set in a plain zip archive
185%sphar_convert_again2.phar.tar
186%sphar_convert_again2.tar
187%sphar_convert_again2.phar.tar.gz
188Unknown file format specified, please pass one of Phar::PHAR, Phar::TAR or Phar::ZIP
189Cannot compress entire archive with gzip, zip archives do not support whole-archive compression
190Cannot compress entire archive with bz2, zip archives do not support whole-archive compression
191Cannot write out data phar archive, use Phar::TAR or Phar::ZIP
192Cannot write out data phar archive, use Phar::TAR or Phar::ZIP
193Unknown file format specified, please pass one of Phar::TAR or Phar::ZIP
194Cannot compress entire archive with gzip, zip archives do not support whole-archive compression
195Cannot compress entire archive with bz2, zip archives do not support whole-archive compression
196Unknown compression specified, please pass one of Phar::GZ or Phar::BZ2
197Unknown compression specified, please pass one of Phar::GZ or Phar::BZ2
198A Phar stub cannot be set in a plain tar archive
199A Phar alias cannot be set in a plain tar archive
200A Phar stub cannot be set in a plain tar archive
201data phar "%sphar_convert_again2.phar.tgz.oops" has invalid extension phar.tgz.oops
202phar "%sphar_convert_again2.tgz.oops" has invalid extension tgz.oops
203data phar "%sphar_convert_again2.phar/.tgz.oops" has invalid extension phar/.tgz.oops
204