1--TEST--
2PharData::convertToZip|Tar|Phar() repeated (phardata_based archives)
3--EXTENSIONS--
4phar
5zlib
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--CLEAN--
79<?php
80unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.tar');
81unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.1.2.tar');
82unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.zip');
83unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.1.zip');
84?>
85--EXPECT--
86=================== new PharData() ==================
87bool(false)
88bool(false)
89bool(true)
90string(0) ""
91NULL
92================= convertToTar() =====================
93bool(false)
94bool(true)
95bool(false)
96string(0) ""
97NULL
98================= convertToZip() =====================
99bool(false)
100bool(false)
101bool(true)
102string(0) ""
103NULL
104================= convertToPhar() ====================
105Cannot write out executable phar archive, phar is read-only
106================ convertToTar(GZ) ====================
107bool(false)
108bool(true)
109bool(false)
110string(0) ""
111NULL
112================= convertToPhar() ====================
113Cannot write out executable phar archive, phar is read-only
114