1--TEST--
2PharData::convertToZip|Tar|Phar() repeated (phardata_based archives)
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=1
8--FILE--
9<?php
10
11$fname = __DIR__ . '/' . basename(__FILE__, '.php') . '.zip';
12
13echo "=================== new PharData() ==================\n";
14$phar = new PharData($fname);
15$phar['a'] = 'a';
16$phar['b'] = 'b';
17$phar['c'] = 'c';
18
19var_dump($phar->isFileFormat(Phar::PHAR));
20var_dump($phar->isFileFormat(Phar::TAR));
21var_dump($phar->isFileFormat(Phar::ZIP));
22var_dump($phar->getStub());
23var_dump($phar->getAlias());
24
25echo "================= convertToTar() =====================\n";
26
27$phar = $phar->convertToData(Phar::TAR);
28var_dump($phar->isFileFormat(Phar::PHAR));
29var_dump($phar->isFileFormat(Phar::TAR));
30var_dump($phar->isFileFormat(Phar::ZIP));
31var_dump($phar->getStub());
32var_dump($phar->getAlias());
33
34echo "================= convertToZip() =====================\n";
35
36$phar = $phar->convertToData(Phar::ZIP, Phar::NONE, '.1.zip');
37var_dump($phar->isFileFormat(Phar::PHAR));
38var_dump($phar->isFileFormat(Phar::TAR));
39var_dump($phar->isFileFormat(Phar::ZIP));
40var_dump($phar->getStub());
41var_dump($phar->getAlias());
42
43echo "================= convertToPhar() ====================\n";
44
45try {
46	$phar = $phar->convertToExecutable(Phar::PHAR);
47	var_dump($phar->isFileFormat(Phar::PHAR));
48	var_dump($phar->isFileFormat(Phar::TAR));
49	var_dump($phar->isFileFormat(Phar::ZIP));
50	var_dump(strlen($phar->getStub()));
51	var_dump($phar->getAlias());
52} catch(Exception $e) {
53	echo $e->getMessage()."\n";
54}
55
56echo "================ convertToTar(GZ) ====================\n";
57
58$phar = $phar->convertToData(Phar::TAR, Phar::GZ, '.2.tar');
59var_dump($phar->isFileFormat(Phar::PHAR));
60var_dump($phar->isFileFormat(Phar::TAR));
61var_dump($phar->isFileFormat(Phar::ZIP));
62var_dump($phar->getStub());
63var_dump($phar->getAlias());
64
65echo "================= convertToPhar() ====================\n";
66
67try {
68	$phar = $phar->convertToExecutable(Phar::PHAR);
69	var_dump($phar->isFileFormat(Phar::PHAR));
70	var_dump($phar->isFileFormat(Phar::TAR));
71	var_dump($phar->isFileFormat(Phar::ZIP));
72	var_dump(strlen($phar->getStub()));
73	var_dump($phar->getAlias());
74} catch(Exception $e) {
75	echo $e->getMessage()."\n";
76}
77?>
78===DONE===
79--CLEAN--
80<?php
81echo __DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.gz' . "\n";
82
83unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.gz');
84unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.tar.gz');
85unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.tar');
86unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.1.2.tar');
87unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.zip');
88unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.1.zip');
89
90?>
91--EXPECT--
92=================== new PharData() ==================
93bool(false)
94bool(false)
95bool(true)
96string(0) ""
97NULL
98================= convertToTar() =====================
99bool(false)
100bool(true)
101bool(false)
102string(0) ""
103NULL
104================= convertToZip() =====================
105bool(false)
106bool(false)
107bool(true)
108string(0) ""
109NULL
110================= convertToPhar() ====================
111Cannot write out executable phar archive, phar is read-only
112================ convertToTar(GZ) ====================
113bool(false)
114bool(true)
115bool(false)
116string(0) ""
117NULL
118================= convertToPhar() ====================
119Cannot write out executable phar archive, phar is read-only
120===DONE===
121