summaryrefslogtreecommitdiff
path: root/ext/phar/tests/zip
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@baserock.org>2013-03-14 05:42:27 +0000
committer <>2013-04-03 16:25:08 +0000
commitc4dd7a1a684490673e25aaf4fabec5df138854c4 (patch)
tree4d57c44caae4480efff02b90b9be86f44bf25409 /ext/phar/tests/zip
downloadphp2-master.tar.gz
Imported from /home/lorry/working-area/delta_php2/php-5.4.13.tar.bz2.HEADphp-5.4.13master
Diffstat (limited to 'ext/phar/tests/zip')
-rw-r--r--ext/phar/tests/zip/033.phpt56
-rw-r--r--ext/phar/tests/zip/033a.phpt45
-rw-r--r--ext/phar/tests/zip/alias_acrobatics.phpt46
-rw-r--r--ext/phar/tests/zip/all.phpt66
-rw-r--r--ext/phar/tests/zip/allU.phpt65
-rw-r--r--ext/phar/tests/zip/badalias.phpt25
-rw-r--r--ext/phar/tests/zip/bug48791.phpt15
-rw-r--r--ext/phar/tests/zip/bzip2.phpt83
-rw-r--r--ext/phar/tests/zip/corrupt_001.phpt23
-rw-r--r--ext/phar/tests/zip/corrupt_002.phpt17
-rw-r--r--ext/phar/tests/zip/corrupt_003.phpt17
-rw-r--r--ext/phar/tests/zip/corrupt_004.phpt17
-rw-r--r--ext/phar/tests/zip/corrupt_005.phpt17
-rw-r--r--ext/phar/tests/zip/corrupt_006.phpt17
-rw-r--r--ext/phar/tests/zip/corrupt_007.phpt17
-rw-r--r--ext/phar/tests/zip/corrupt_008.phpt101
-rw-r--r--ext/phar/tests/zip/corrupt_009.phpt17
-rw-r--r--ext/phar/tests/zip/corrupt_010.phpt17
-rw-r--r--ext/phar/tests/zip/create_new_and_modify.phpt45
-rw-r--r--ext/phar/tests/zip/create_new_phar_b.phpt27
-rw-r--r--ext/phar/tests/zip/delete.phpt31
-rw-r--r--ext/phar/tests/zip/delete_in_phar.phpt49
-rw-r--r--ext/phar/tests/zip/delete_in_phar_b.phpt48
-rw-r--r--ext/phar/tests/zip/delete_in_phar_confirm.phpt53
-rw-r--r--ext/phar/tests/zip/dir.phpt43
-rw-r--r--ext/phar/tests/zip/exists_as_phar.phpt38
-rw-r--r--ext/phar/tests/zip/files/badalias1.phar.zipbin0 -> 353 bytes
-rw-r--r--ext/phar/tests/zip/files/badalias2.phar.zipbin0 -> 353 bytes
-rw-r--r--ext/phar/tests/zip/files/badalias3.phar.zipbin0 -> 353 bytes
-rw-r--r--ext/phar/tests/zip/files/badalias4.phar.zipbin0 -> 353 bytes
-rw-r--r--ext/phar/tests/zip/files/badalias5.phar.zipbin0 -> 353 bytes
-rw-r--r--ext/phar/tests/zip/files/bz2_alias.phar.zipbin0 -> 105534 bytes
-rw-r--r--ext/phar/tests/zip/files/bzip2.zipbin0 -> 603 bytes
-rw-r--r--ext/phar/tests/zip/files/cdir_offset.zipbin0 -> 191 bytes
-rw-r--r--ext/phar/tests/zip/files/compress_unsup1.zipbin0 -> 105 bytes
-rw-r--r--ext/phar/tests/zip/files/compress_unsup10.zipbin0 -> 105 bytes
-rw-r--r--ext/phar/tests/zip/files/compress_unsup14.zipbin0 -> 105 bytes
-rw-r--r--ext/phar/tests/zip/files/compress_unsup18.zipbin0 -> 105 bytes
-rw-r--r--ext/phar/tests/zip/files/compress_unsup19.zipbin0 -> 105 bytes
-rw-r--r--ext/phar/tests/zip/files/compress_unsup2.zipbin0 -> 105 bytes
-rw-r--r--ext/phar/tests/zip/files/compress_unsup3.zipbin0 -> 105 bytes
-rw-r--r--ext/phar/tests/zip/files/compress_unsup4.zipbin0 -> 105 bytes
-rw-r--r--ext/phar/tests/zip/files/compress_unsup5.zipbin0 -> 105 bytes
-rw-r--r--ext/phar/tests/zip/files/compress_unsup6.zipbin0 -> 105 bytes
-rw-r--r--ext/phar/tests/zip/files/compress_unsup7.zipbin0 -> 105 bytes
-rw-r--r--ext/phar/tests/zip/files/compress_unsup9.zipbin0 -> 105 bytes
-rw-r--r--ext/phar/tests/zip/files/compress_unsup97.zipbin0 -> 105 bytes
-rw-r--r--ext/phar/tests/zip/files/compress_unsup98.zipbin0 -> 105 bytes
-rw-r--r--ext/phar/tests/zip/files/compress_unsupunknown.zipbin0 -> 105 bytes
-rw-r--r--ext/phar/tests/zip/files/corrupt2.php.inc60
-rw-r--r--ext/phar/tests/zip/files/corrupt3.php.inc9
-rw-r--r--ext/phar/tests/zip/files/corrupt_count1.php.inc11
-rw-r--r--ext/phar/tests/zip/files/corrupt_zipmaker.php.inc332
-rw-r--r--ext/phar/tests/zip/files/count1.zipbin0 -> 191 bytes
-rw-r--r--ext/phar/tests/zip/files/count2.zipbin0 -> 191 bytes
-rw-r--r--ext/phar/tests/zip/files/disknumber.zipbin0 -> 105 bytes
-rw-r--r--ext/phar/tests/zip/files/encrypted.zipbin0 -> 191 bytes
-rw-r--r--ext/phar/tests/zip/files/extralen_toolong.zipbin0 -> 112 bytes
-rw-r--r--ext/phar/tests/zip/files/filecomment.zipbin0 -> 191 bytes
-rw-r--r--ext/phar/tests/zip/files/frontcontroller.phar.inc13
-rw-r--r--ext/phar/tests/zip/files/frontcontroller.phar.zipbin0 -> 804 bytes
-rw-r--r--ext/phar/tests/zip/files/frontcontroller10.phar.inc20
-rw-r--r--ext/phar/tests/zip/files/frontcontroller10.phar.zipbin0 -> 796 bytes
-rw-r--r--ext/phar/tests/zip/files/frontcontroller11.phar.inc20
-rw-r--r--ext/phar/tests/zip/files/frontcontroller11.phar.zipbin0 -> 783 bytes
-rw-r--r--ext/phar/tests/zip/files/frontcontroller12.phar.inc20
-rw-r--r--ext/phar/tests/zip/files/frontcontroller12.phar.zipbin0 -> 793 bytes
-rw-r--r--ext/phar/tests/zip/files/frontcontroller2.phar.inc12
-rw-r--r--ext/phar/tests/zip/files/frontcontroller2.phar.zipbin0 -> 677 bytes
-rw-r--r--ext/phar/tests/zip/files/frontcontroller3.phar.inc18
-rw-r--r--ext/phar/tests/zip/files/frontcontroller3.phar.zipbin0 -> 818 bytes
-rw-r--r--ext/phar/tests/zip/files/frontcontroller4.phar.inc18
-rw-r--r--ext/phar/tests/zip/files/frontcontroller4.phar.zipbin0 -> 813 bytes
-rw-r--r--ext/phar/tests/zip/files/frontcontroller5.phar.inc12
-rw-r--r--ext/phar/tests/zip/files/frontcontroller5.phar.zipbin0 -> 707 bytes
-rw-r--r--ext/phar/tests/zip/files/frontcontroller6.phar.inc12
-rw-r--r--ext/phar/tests/zip/files/frontcontroller6.phar.zipbin0 -> 708 bytes
-rw-r--r--ext/phar/tests/zip/files/frontcontroller7.phar.inc12
-rw-r--r--ext/phar/tests/zip/files/frontcontroller7.phar.zipbin0 -> 709 bytes
-rw-r--r--ext/phar/tests/zip/files/frontcontroller8.phar.inc13
-rw-r--r--ext/phar/tests/zip/files/frontcontroller8.phar.zipbin0 -> 896 bytes
-rw-r--r--ext/phar/tests/zip/files/frontcontroller9.phar.inc14
-rw-r--r--ext/phar/tests/zip/files/frontcontroller9.phar.zipbin0 -> 923 bytes
-rw-r--r--ext/phar/tests/zip/files/make_invalid_tar.php.inc12
-rw-r--r--ext/phar/tests/zip/files/metadata.phar.inc11
-rw-r--r--ext/phar/tests/zip/files/metadata.phar.zipbin0 -> 779 bytes
-rw-r--r--ext/phar/tests/zip/files/nozipend.zipbin0 -> 169 bytes
-rw-r--r--ext/phar/tests/zip/files/odt.odtbin0 -> 8873 bytes
-rw-r--r--ext/phar/tests/zip/files/stdin.zipbin0 -> 186 bytes
-rw-r--r--ext/phar/tests/zip/files/test.odtbin0 -> 8303 bytes
-rw-r--r--ext/phar/tests/zip/files/truncfilename.zipbin0 -> 190 bytes
-rw-r--r--ext/phar/tests/zip/files/zip.zipbin0 -> 619 bytes
-rw-r--r--ext/phar/tests/zip/files/zipmaker.php.inc70
-rw-r--r--ext/phar/tests/zip/files/zlib_alias.phar.zipbin0 -> 624 bytes
-rw-r--r--ext/phar/tests/zip/frontcontroller1.phar.phpt16
-rw-r--r--ext/phar/tests/zip/frontcontroller10.phar.phpt24
-rw-r--r--ext/phar/tests/zip/frontcontroller11.phar.phpt22
-rw-r--r--ext/phar/tests/zip/frontcontroller12.phar.phpt21
-rw-r--r--ext/phar/tests/zip/frontcontroller13.phar.phpt21
-rw-r--r--ext/phar/tests/zip/frontcontroller14.phar.phpt16
-rw-r--r--ext/phar/tests/zip/frontcontroller15.phar.phpt21
-rw-r--r--ext/phar/tests/zip/frontcontroller16.phar.phpt18
-rw-r--r--ext/phar/tests/zip/frontcontroller17.phar.phpt17
-rw-r--r--ext/phar/tests/zip/frontcontroller18.phar.phpt17
-rw-r--r--ext/phar/tests/zip/frontcontroller19.phar.phpt17
-rw-r--r--ext/phar/tests/zip/frontcontroller2.phar.phpt17
-rw-r--r--ext/phar/tests/zip/frontcontroller20.phar.phpt17
-rw-r--r--ext/phar/tests/zip/frontcontroller21.phar.phpt25
-rw-r--r--ext/phar/tests/zip/frontcontroller3.phar.phpt20
-rw-r--r--ext/phar/tests/zip/frontcontroller4.phar.phpt14
-rw-r--r--ext/phar/tests/zip/frontcontroller5.phar.phpt15
-rw-r--r--ext/phar/tests/zip/frontcontroller6.phar.phpt22
-rw-r--r--ext/phar/tests/zip/frontcontroller7.phar.phpt15
-rw-r--r--ext/phar/tests/zip/frontcontroller8.phar.phpt21
-rw-r--r--ext/phar/tests/zip/frontcontroller9.phar.phpt19
-rw-r--r--ext/phar/tests/zip/getalias.phpt59
-rw-r--r--ext/phar/tests/zip/largezip.phpt29
-rw-r--r--ext/phar/tests/zip/metadata_write_commit.phpt88
-rw-r--r--ext/phar/tests/zip/metadata_write_commitU.phpt88
-rw-r--r--ext/phar/tests/zip/notphar.phpt24
-rw-r--r--ext/phar/tests/zip/odt.phpt35
-rw-r--r--ext/phar/tests/zip/open_for_write_existing.phpt39
-rw-r--r--ext/phar/tests/zip/open_for_write_existing_b.phpt55
-rw-r--r--ext/phar/tests/zip/open_for_write_existing_b_5_2.phpt53
-rw-r--r--ext/phar/tests/zip/open_for_write_existing_c.phpt49
-rw-r--r--ext/phar/tests/zip/open_for_write_existing_c_5_2.phpt47
-rw-r--r--ext/phar/tests/zip/open_for_write_newfile.phpt42
-rw-r--r--ext/phar/tests/zip/open_for_write_newfile_b.phpt63
-rw-r--r--ext/phar/tests/zip/open_for_write_newfile_b_5_2.phpt61
-rw-r--r--ext/phar/tests/zip/open_for_write_newfile_c.phpt57
-rw-r--r--ext/phar/tests/zip/open_for_write_newfile_c_5_2.phpt55
-rw-r--r--ext/phar/tests/zip/phar_begin_setstub_commit.phpt71
-rw-r--r--ext/phar/tests/zip/phar_begin_setstub_commitU.phpt71
-rw-r--r--ext/phar/tests/zip/phar_buildfromiterator4.phpt66
-rw-r--r--ext/phar/tests/zip/phar_buildfromiterator5.phpt59
-rw-r--r--ext/phar/tests/zip/phar_buildfromiterator6.phpt60
-rw-r--r--ext/phar/tests/zip/phar_buildfromiterator7.phpt60
-rw-r--r--ext/phar/tests/zip/phar_buildfromiterator8.phpt73
-rw-r--r--ext/phar/tests/zip/phar_buildfromiterator9.phpt65
-rw-r--r--ext/phar/tests/zip/phar_commitwrite.phpt47
-rw-r--r--ext/phar/tests/zip/phar_convert_phar.phpt57
-rw-r--r--ext/phar/tests/zip/phar_copy.phpt55
-rw-r--r--ext/phar/tests/zip/phar_magic.phpt44
-rw-r--r--ext/phar/tests/zip/phar_magicU.phpt41
-rw-r--r--ext/phar/tests/zip/phar_oo_compressallbz2.phpt70
-rw-r--r--ext/phar/tests/zip/phar_oo_compressallgz.phpt58
-rw-r--r--ext/phar/tests/zip/phar_setalias.phpt62
-rw-r--r--ext/phar/tests/zip/phar_setalias2.phpt49
-rw-r--r--ext/phar/tests/zip/phar_setdefaultstub.phpt80
-rw-r--r--ext/phar/tests/zip/phar_setsignaturealgo2.phpt115
-rw-r--r--ext/phar/tests/zip/phar_stub.phpt75
-rw-r--r--ext/phar/tests/zip/phar_stub_error.phpt55
-rw-r--r--ext/phar/tests/zip/refcount1.phpt70
-rw-r--r--ext/phar/tests/zip/refcount1_5_2.phpt64
-rw-r--r--ext/phar/tests/zip/rename.phpt34
-rw-r--r--ext/phar/tests/zip/rename_dir.phpt34
-rw-r--r--ext/phar/tests/zip/rmdir.phpt38
-rw-r--r--ext/phar/tests/zip/unixzip.phpt29
-rw-r--r--ext/phar/tests/zip/zlib.phpt19
159 files changed, 4544 insertions, 0 deletions
diff --git a/ext/phar/tests/zip/033.phpt b/ext/phar/tests/zip/033.phpt
new file mode 100644
index 0000000..c980758
--- /dev/null
+++ b/ext/phar/tests/zip/033.phpt
@@ -0,0 +1,56 @@
+--TEST--
+Phar::chmod zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+phar.require_hash=0
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip';
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.phar.zip';
+$alias = 'phar://hio';
+
+$phar = new Phar($fname);
+$phar['a.php'] = '<?php echo "This is a\n"; include "'.$alias.'/b.php"; ?>';
+$phar->setAlias('hio');
+$phar->addEmptyDir('test');
+$phar->stopBuffering();
+
+try {
+ var_dump($phar['a.php']->isExecutable());
+ $phar['a.php']->chmod(0777);
+ copy($fname, $fname2);
+ $phar->setAlias('unused');
+ $phar2 = new Phar($fname2);
+ var_dump($phar2['a.php']->isExecutable());
+ $phar['a.php']->chmod(0666);
+ var_dump($phar['a.php']->isExecutable());
+ echo "test dir\n";
+ var_dump($phar['test']->isDir());
+ var_dump($phar['test']->isReadable());
+ $phar['test']->chmod(0000);
+ var_dump($phar['test']->isReadable());
+ $phar['test']->chmod(0666);
+ var_dump($phar['test']->isReadable());
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar.zip');
+?>
+--EXPECT--
+bool(false)
+bool(true)
+bool(false)
+test dir
+bool(true)
+bool(true)
+bool(false)
+bool(true)
+===DONE===
diff --git a/ext/phar/tests/zip/033a.phpt b/ext/phar/tests/zip/033a.phpt
new file mode 100644
index 0000000..429d3bd
--- /dev/null
+++ b/ext/phar/tests/zip/033a.phpt
@@ -0,0 +1,45 @@
+--TEST--
+Phar::chmod zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+phar.require_hash=0
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip';
+$alias = 'phar://hio';
+
+$phar = new Phar($fname);
+$phar['a.php'] = '<?php echo "This is a\n"; include "'.$alias.'/b.php"; ?>';
+$phar->setAlias('hio');
+$phar->addEmptyDir('test');
+$phar->stopBuffering();
+ini_set('phar.readonly', 1);
+
+try {
+ var_dump($phar['a.php']->isExecutable());
+ $phar['a.php']->chmod(0777);
+ var_dump($phar['a.php']->isExecutable());
+ $phar['a.php']->chmod(0666);
+ var_dump($phar['a.php']->isExecutable());
+ echo "test dir\n";
+ var_dump($phar['test']->isExecutable());
+ $phar['test']->chmod(0777);
+ var_dump($phar['test']->isExecutable());
+ $phar['test']->chmod(0666);
+ var_dump($phar['test']->isExecutable());
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip');
+?>
+--EXPECTF--
+bool(false)
+Cannot modify permissions for file "a.php" in phar "%sa.phar.zip", write operations are prohibited
+===DONE===
diff --git a/ext/phar/tests/zip/alias_acrobatics.phpt b/ext/phar/tests/zip/alias_acrobatics.phpt
new file mode 100644
index 0000000..2a58e39
--- /dev/null
+++ b/ext/phar/tests/zip/alias_acrobatics.phpt
@@ -0,0 +1,46 @@
+--TEST--
+Phar: alias edge cases
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip';
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.phar.zip';
+
+$p = new Phar($fname);
+
+$p->setAlias('foo');
+$p['unused'] = 'hi';
+try {
+$a = new Phar($fname2, 0, 'foo');
+} catch (Exception $e) {
+echo $e->getMessage(),"\n";
+}
+copy($fname, $fname2);
+echo "2\n";
+try {
+$a = new Phar($fname2);
+} catch (Exception $e) {
+echo $e->getMessage(),"\n";
+}
+try {
+$b = new Phar($fname, 0, 'another');
+} catch (Exception $e) {
+echo $e->getMessage(),"\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar.zip');
+?>
+--EXPECTF--
+alias "foo" is already used for archive "%salias_acrobatics.phar.zip" cannot be overloaded with "%salias_acrobatics.2.phar.zip"
+2
+phar error: Unable to add zip-based phar "%salias_acrobatics.2.phar.zip" with implicit alias, alias is already in use
+alias "another" is already used for archive "%salias_acrobatics.phar.zip" cannot be overloaded with "%salias_acrobatics.phar.zip"
+===DONE===
diff --git a/ext/phar/tests/zip/all.phpt b/ext/phar/tests/zip/all.phpt
new file mode 100644
index 0000000..49d79a4
--- /dev/null
+++ b/ext/phar/tests/zip/all.phpt
@@ -0,0 +1,66 @@
+--TEST--
+Phar: test that creation of zip-based phar generates valid zip with all bells/whistles
+--SKIPIF--
+<?php
+if (!extension_loaded("phar")) die("skip");
+if (version_compare(PHP_VERSION, "6.0", ">")) die("skip pre-unicode version of PHP required");
+if (!extension_loaded("spl")) die("skip SPL not available");
+if (!extension_loaded("zlib")) die("skip zlib not available");
+if (!extension_loaded("bz2")) die("skip bz2 not available");
+?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip.php';
+$pname = 'phar://' . $fname;
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.phar.zip.php';
+$pname2 = 'phar://' . $fname2;
+
+$phar = new Phar($fname);
+
+$phar->setMetadata('hi there');
+$phar['a'] = 'hi';
+$phar['a']->setMetadata('a meta');
+$phar['b'] = 'hi2';
+$phar['b']->compress(Phar::GZ);
+$phar['c'] = 'hi3';
+$phar['c']->compress(Phar::BZ2);
+$phar['b']->chmod(0444);
+$phar->setStub("<?php ok __HALT_COMPILER();");
+$phar->setAlias("hime");
+unset($phar);
+copy($fname, $fname2);
+Phar::unlinkArchive($fname);
+var_dump(file_exists($fname), file_exists($pname . '/a'));
+
+$phar = new Phar($fname2);
+var_dump($phar['a']->getContent(), $phar['b']->getContent(), $phar['c']->getContent());
+var_dump($phar['a']->isCompressed(), $phar['b']->isCompressed() == Phar::GZ, $phar['c']->isCompressed() == Phar::BZ2);
+var_dump((string) decoct(fileperms($pname2 . '/b')));
+var_dump($phar->getStub());
+var_dump($phar->getAlias());
+var_dump($phar->getMetadata());
+var_dump($phar['a']->getMetadata());
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip.php'); ?>
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar.zip.php'); ?>
+--EXPECT--
+bool(false)
+bool(false)
+string(2) "hi"
+string(3) "hi2"
+string(3) "hi3"
+bool(false)
+bool(true)
+bool(true)
+string(6) "100444"
+string(32) "<?php ok __HALT_COMPILER(); ?>
+"
+string(4) "hime"
+string(8) "hi there"
+string(6) "a meta"
+===DONE===
diff --git a/ext/phar/tests/zip/allU.phpt b/ext/phar/tests/zip/allU.phpt
new file mode 100644
index 0000000..93fe5da
--- /dev/null
+++ b/ext/phar/tests/zip/allU.phpt
@@ -0,0 +1,65 @@
+--TEST--
+Phar: test that creation of zip-based phar generates valid zip with all bells/whistles
+--SKIPIF--
+<?php
+if (!extension_loaded("phar")) die("skip");
+if (version_compare(PHP_VERSION, "6.0", "<")) die("skip Unicode support required");
+if (!extension_loaded("spl")) die("skip SPL not available");
+if (!extension_loaded("zlib")) die("skip zlib not available");
+if (!extension_loaded("bz2")) die("skip bz2 not available");
+?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip.php';
+$pname = 'phar://' . $fname;
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.phar.zip.php';
+$pname2 = 'phar://' . $fname2;
+
+$phar = new Phar($fname);
+
+$phar->setMetadata('hi there');
+$phar['a'] = 'hi';
+$phar['a']->setMetadata('a meta');
+$phar['b'] = 'hi2';
+$phar['b']->compress(Phar::GZ);
+$phar['c'] = 'hi3';
+$phar['c']->compress(Phar::BZ2);
+$phar['b']->chmod(0444);
+$phar->setStub("<?php ok __HALT_COMPILER();");
+$phar->setAlias("hime");
+unset($phar);
+copy($fname, $fname2);
+Phar::unlinkArchive($fname);
+var_dump(file_exists($fname), file_exists($pname . '/a'));
+
+$phar = new Phar($fname2);
+var_dump($phar['a']->getContent(), $phar['b']->getContent(), $phar['c']->getContent());
+var_dump($phar['a']->isCompressed(), $phar['b']->isCompressed() == Phar::GZ, $phar['c']->isCompressed() == Phar::BZ2);
+var_dump((string) decoct(fileperms($pname2 . '/b')));
+var_dump($phar->getStub());
+var_dump($phar->getAlias());
+var_dump($phar->getMetadata());
+var_dump($phar['a']->getMetadata());
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar.zip.php'); ?>
+--EXPECT--
+bool(false)
+bool(false)
+string(2) "hi"
+string(3) "hi2"
+string(3) "hi3"
+bool(false)
+bool(true)
+bool(true)
+unicode(6) "100444"
+string(32) "<?php ok __HALT_COMPILER(); ?>
+"
+string(4) "hime"
+unicode(8) "hi there"
+unicode(6) "a meta"
+===DONE===
diff --git a/ext/phar/tests/zip/badalias.phpt b/ext/phar/tests/zip/badalias.phpt
new file mode 100644
index 0000000..0291c4b
--- /dev/null
+++ b/ext/phar/tests/zip/badalias.phpt
@@ -0,0 +1,25 @@
+--TEST--
+Phar: invalid aliases
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zlib")) die("skip no zlib"); ?>
+<?php if (!extension_loaded("bz2")) die("skip no bz2"); ?>
+--FILE--
+<?php
+$e = dirname(__FILE__) . '/files/';
+for ($i = 1; $i <= 5; $i++) {
+try {
+new Phar($e . "badalias$i.phar.zip");
+} catch (Exception $ee) {
+echo $ee->getMessage(), "\n";
+}
+}
+?>
+===DONE===
+--EXPECTF--
+phar error: invalid alias "hi/there" in zip-based phar "%sbadalias1.phar.zip"
+phar error: invalid alias "hi\there" in zip-based phar "%sbadalias2.phar.zip"
+phar error: invalid alias "hi\there" in zip-based phar "%sbadalias3.phar.zip"
+phar error: invalid alias "hi;there" in zip-based phar "%sbadalias4.phar.zip"
+phar error: invalid alias "hi:there" in zip-based phar "%sbadalias5.phar.zip"
+===DONE===
diff --git a/ext/phar/tests/zip/bug48791.phpt b/ext/phar/tests/zip/bug48791.phpt
new file mode 100644
index 0000000..45c5271
--- /dev/null
+++ b/ext/phar/tests/zip/bug48791.phpt
@@ -0,0 +1,15 @@
+--TEST--
+Phar: Bug #48791: open office documents always reported as corrupted by phar extension
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+<?php if (!extension_loaded("zlib")) die("skip zlib not available"); ?>
+--FILE--
+<?php
+echo file_get_contents('phar://' . dirname(__FILE__) . '/files/test.odt/content.xml'), "\n";
+?>
+===DONE===
+--EXPECT--
+<?xml version="1.0" encoding="UTF-8"?>
+<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rpt="http://openoffice.org/2005/report" xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" xmlns:rdfa="http://docs.oasis-open.org/opendocument/meta/rdfa#" office:version="1.2"><office:scripts/><office:font-face-decls><style:font-face style:name="OpenSymbol" svg:font-family="OpenSymbol"/><style:font-face style:name="Tahoma1" svg:font-family="Tahoma"/><style:font-face style:name="Times New Roman" svg:font-family="&apos;Times New Roman&apos;" style:font-family-generic="roman" style:font-pitch="variable"/><style:font-face style:name="Arial" svg:font-family="Arial" style:font-family-generic="swiss" style:font-pitch="variable"/><style:font-face style:name="Arial Unicode MS" svg:font-family="&apos;Arial Unicode MS&apos;" style:font-family-generic="system" style:font-pitch="variable"/><style:font-face style:name="MS Mincho" svg:font-family="&apos;MS Mincho&apos;" style:font-family-generic="system" style:font-pitch="variable"/><style:font-face style:name="Tahoma" svg:font-family="Tahoma" style:font-family-generic="system" style:font-pitch="variable"/></office:font-face-decls><office:automatic-styles><style:style style:name="P1" style:family="paragraph" style:parent-style-name="Standard" style:list-style-name="L1"/><style:style style:name="T1" style:family="text"><style:text-properties style:font-name="Arial"/></style:style><text:list-style style:name="L1"><text:list-level-style-bullet text:level="1" text:style-name="Bullet_20_Symbols" style:num-suffix="." text:bullet-char="•"><style:list-level-properties text:list-level-position-and-space-mode="label-alignment"><style:list-level-label-alignment text:label-followed-by="listtab" text:list-tab-stop-position="1.27cm" fo:text-indent="-0.635cm" fo:margin-left="1.27cm"/></style:list-level-properties></text:list-level-style-bullet><text:list-level-style-bullet text:level="2" text:style-name="Bullet_20_Symbols" style:num-suffix="." text:bullet-char="◦"><style:list-level-properties text:list-level-position-and-space-mode="label-alignment"><style:list-level-label-alignment text:label-followed-by="listtab" text:list-tab-stop-position="1.905cm" fo:text-indent="-0.635cm" fo:margin-left="1.905cm"/></style:list-level-properties></text:list-level-style-bullet><text:list-level-style-bullet text:level="3" text:style-name="Bullet_20_Symbols" style:num-suffix="." text:bullet-char="▪"><style:list-level-properties text:list-level-position-and-space-mode="label-alignment"><style:list-level-label-alignment text:label-followed-by="listtab" text:list-tab-stop-position="2.54cm" fo:text-indent="-0.635cm" fo:margin-left="2.54cm"/></style:list-level-properties></text:list-level-style-bullet><text:list-level-style-bullet text:level="4" text:style-name="Bullet_20_Symbols" style:num-suffix="." text:bullet-char="•"><style:list-level-properties text:list-level-position-and-space-mode="label-alignment"><style:list-level-label-alignment text:label-followed-by="listtab" text:list-tab-stop-position="3.175cm" fo:text-indent="-0.635cm" fo:margin-left="3.175cm"/></style:list-level-properties></text:list-level-style-bullet><text:list-level-style-bullet text:level="5" text:style-name="Bullet_20_Symbols" style:num-suffix="." text:bullet-char="◦"><style:list-level-properties text:list-level-position-and-space-mode="label-alignment"><style:list-level-label-alignment text:label-followed-by="listtab" text:list-tab-stop-position="3.81cm" fo:text-indent="-0.635cm" fo:margin-left="3.81cm"/></style:list-level-properties></text:list-level-style-bullet><text:list-level-style-bullet text:level="6" text:style-name="Bullet_20_Symbols" style:num-suffix="." text:bullet-char="▪"><style:list-level-properties text:list-level-position-and-space-mode="label-alignment"><style:list-level-label-alignment text:label-followed-by="listtab" text:list-tab-stop-position="4.445cm" fo:text-indent="-0.635cm" fo:margin-left="4.445cm"/></style:list-level-properties></text:list-level-style-bullet><text:list-level-style-bullet text:level="7" text:style-name="Bullet_20_Symbols" style:num-suffix="." text:bullet-char="•"><style:list-level-properties text:list-level-position-and-space-mode="label-alignment"><style:list-level-label-alignment text:label-followed-by="listtab" text:list-tab-stop-position="5.08cm" fo:text-indent="-0.635cm" fo:margin-left="5.08cm"/></style:list-level-properties></text:list-level-style-bullet><text:list-level-style-bullet text:level="8" text:style-name="Bullet_20_Symbols" style:num-suffix="." text:bullet-char="◦"><style:list-level-properties text:list-level-position-and-space-mode="label-alignment"><style:list-level-label-alignment text:label-followed-by="listtab" text:list-tab-stop-position="5.715cm" fo:text-indent="-0.635cm" fo:margin-left="5.715cm"/></style:list-level-properties></text:list-level-style-bullet><text:list-level-style-bullet text:level="9" text:style-name="Bullet_20_Symbols" style:num-suffix="." text:bullet-char="▪"><style:list-level-properties text:list-level-position-and-space-mode="label-alignment"><style:list-level-label-alignment text:label-followed-by="listtab" text:list-tab-stop-position="6.35cm" fo:text-indent="-0.635cm" fo:margin-left="6.35cm"/></style:list-level-properties></text:list-level-style-bullet><text:list-level-style-bullet text:level="10" text:style-name="Bullet_20_Symbols" style:num-suffix="." text:bullet-char="•"><style:list-level-properties text:list-level-position-and-space-mode="label-alignment"><style:list-level-label-alignment text:label-followed-by="listtab" text:list-tab-stop-position="6.985cm" fo:text-indent="-0.635cm" fo:margin-left="6.985cm"/></style:list-level-properties></text:list-level-style-bullet></text:list-style></office:automatic-styles><office:body><office:text><text:sequence-decls><text:sequence-decl text:display-outline-level="0" text:name="Illustration"/><text:sequence-decl text:display-outline-level="0" text:name="Table"/><text:sequence-decl text:display-outline-level="0" text:name="Text"/><text:sequence-decl text:display-outline-level="0" text:name="Drawing"/></text:sequence-decls><text:h text:style-name="Heading_20_1" text:outline-level="1">Überschrift</text:h><text:list xml:id="list38593008" text:style-name="L1"><text:list-item><text:p text:style-name="P1"><text:span text:style-name="T1">Name:<text:tab/><text:tab/>$$n_fn$$</text:span></text:p></text:list-item><text:list-item><text:p text:style-name="P1"><text:span text:style-name="T1">Firma:<text:tab/><text:tab/>$$org_name$$</text:span></text:p></text:list-item><text:list-item><text:p text:style-name="P1"><text:span text:style-name="T1">Menge:<text:tab/>$$#menge$$</text:span></text:p></text:list-item></text:list></office:text></office:body></office:document-content>
+===DONE===
diff --git a/ext/phar/tests/zip/bzip2.phpt b/ext/phar/tests/zip/bzip2.phpt
new file mode 100644
index 0000000..a703ce6
--- /dev/null
+++ b/ext/phar/tests/zip/bzip2.phpt
@@ -0,0 +1,83 @@
+--TEST--
+Phar: process bzip2-compressed zip entry
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+<?php if (!extension_loaded("bz2")) die("skip bz2 not available"); ?>
+--FILE--
+<?php
+try {
+ $a = new PharData(dirname(__FILE__) . '/files/bzip2.zip');
+ foreach ($a as $entry => $file) {
+ echo $file->getContent();
+ }
+ $a = new Phar(dirname(__FILE__) . '/files/bz2_alias.phar.zip');
+ var_dump($a->getAlias());
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--EXPECT--
+<?php
+include dirname(__FILE__) . '/corrupt_zipmaker.php.inc';
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii');
+$a->addFile('hi2', null, 'hii2', null, null, 'encrypt', 'encrypt');
+$a->writeZip(dirname(__FILE__) . '/encrypted.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii');
+$a->addFile('', null, 'stdin');
+$a->writeZip(dirname(__FILE__) . '/stdin.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hii', null, 'hii', null, null, 'filename_len', 'filename_len');
+$a->addFile('hi', null, 'hii');
+$a->writeZip(dirname(__FILE__) . '/truncfilename.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress');
+$a->writeZip(dirname(__FILE__) . '/compress_unsup1.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 2);
+$a->writeZip(dirname(__FILE__) . '/compress_unsup2.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 3);
+$a->writeZip(dirname(__FILE__) . '/compress_unsup3.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 4);
+$a->writeZip(dirname(__FILE__) . '/compress_unsup4.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 5);
+$a->writeZip(dirname(__FILE__) . '/compress_unsup5.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 6);
+$a->writeZip(dirname(__FILE__) . '/compress_unsup6.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 7);
+$a->writeZip(dirname(__FILE__) . '/compress_unsup7.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 9);
+$a->writeZip(dirname(__FILE__) . '/compress_unsup9.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 10);
+$a->writeZip(dirname(__FILE__) . '/compress_unsup10.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 14);
+$a->writeZip(dirname(__FILE__) . '/compress_unsup14.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 18);
+$a->writeZip(dirname(__FILE__) . '/compress_unsup18.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 19);
+$a->writeZip(dirname(__FILE__) . '/compress_unsup19.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 97);
+$a->writeZip(dirname(__FILE__) . '/compress_unsup97.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 98);
+$a->writeZip(dirname(__FILE__) . '/compress_unsup98.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 11);
+$a->writeZip(dirname(__FILE__) . '/compress_unsupunknown.zip');
+?>
+string(175) "hitheresuperlongzipistoostupidtodowhatIsaysoIhavetousethisridiculouslylongaliasbecauseitisstupiddidImentionthatalreadythemadnessdoesnotstopIhateinfozipIhateinfozipIhateinfozip"
+===DONE===
diff --git a/ext/phar/tests/zip/corrupt_001.phpt b/ext/phar/tests/zip/corrupt_001.phpt
new file mode 100644
index 0000000..0b019c6
--- /dev/null
+++ b/ext/phar/tests/zip/corrupt_001.phpt
@@ -0,0 +1,23 @@
+--TEST--
+Phar: corrupted zip (count mismatch)
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+--FILE--
+<?php
+try {
+ new PharData(dirname(__FILE__) . '/files/count1.zip');
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+try {
+ new PharData(dirname(__FILE__) . '/files/count2.zip');
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--EXPECTF--
+phar error: corrupt zip archive, conflicting file count in end of central directory record in zip-based phar "%scount1.zip"
+phar error: corrupt zip archive, conflicting file count in end of central directory record in zip-based phar "%scount2.zip"
+===DONE===
diff --git a/ext/phar/tests/zip/corrupt_002.phpt b/ext/phar/tests/zip/corrupt_002.phpt
new file mode 100644
index 0000000..86a2712
--- /dev/null
+++ b/ext/phar/tests/zip/corrupt_002.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Phar: corrupted zip (no end of zip record)
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+--FILE--
+<?php
+try {
+ new PharData(dirname(__FILE__) . '/files/nozipend.zip');
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--EXPECTF--
+phar error: end of central directory not found in zip-based phar "%snozipend.zip"
+===DONE===
diff --git a/ext/phar/tests/zip/corrupt_003.phpt b/ext/phar/tests/zip/corrupt_003.phpt
new file mode 100644
index 0000000..c41e015
--- /dev/null
+++ b/ext/phar/tests/zip/corrupt_003.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Phar: corrupted zip (truncated file comment)
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+--FILE--
+<?php
+try {
+ new PharData(dirname(__FILE__) . '/files/filecomment.zip');
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--EXPECTF--
+phar error: corrupt zip archive, zip file comment truncated in zip-based phar "%sfilecomment.zip"
+===DONE===
diff --git a/ext/phar/tests/zip/corrupt_004.phpt b/ext/phar/tests/zip/corrupt_004.phpt
new file mode 100644
index 0000000..3760e8f
--- /dev/null
+++ b/ext/phar/tests/zip/corrupt_004.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Phar: corrupted zip (central directory offset incorrect)
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+--FILE--
+<?php
+try {
+ new PharData(dirname(__FILE__) . '/files/cdir_offset.zip');
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--EXPECTF--
+phar error: corrupted central directory entry, no magic signature in zip-based phar "%scdir_offset.zip"
+===DONE===
diff --git a/ext/phar/tests/zip/corrupt_005.phpt b/ext/phar/tests/zip/corrupt_005.phpt
new file mode 100644
index 0000000..6b5d31d
--- /dev/null
+++ b/ext/phar/tests/zip/corrupt_005.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Phar: encrypted zip
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+--FILE--
+<?php
+try {
+ new PharData(dirname(__FILE__) . '/files/encrypted.zip');
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--EXPECTF--
+phar error: Cannot process encrypted zip files in zip-based phar "%sencrypted.zip"
+===DONE===
diff --git a/ext/phar/tests/zip/corrupt_006.phpt b/ext/phar/tests/zip/corrupt_006.phpt
new file mode 100644
index 0000000..9c83617
--- /dev/null
+++ b/ext/phar/tests/zip/corrupt_006.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Phar: zip with file created from stdin
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+--FILE--
+<?php
+try {
+ new PharData(dirname(__FILE__) . '/files/stdin.zip');
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--EXPECTF--
+phar error: Cannot process zips created from stdin (zero-length filename) in zip-based phar "%sstdin.zip"
+===DONE===
diff --git a/ext/phar/tests/zip/corrupt_007.phpt b/ext/phar/tests/zip/corrupt_007.phpt
new file mode 100644
index 0000000..80c9139
--- /dev/null
+++ b/ext/phar/tests/zip/corrupt_007.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Phar: corrupted zip (truncated filename record)
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+--FILE--
+<?php
+try {
+ new PharData(dirname(__FILE__) . '/files/truncfilename.zip');
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--EXPECTF--
+phar error: corrupted central directory entry, no magic signature in zip-based phar "%struncfilename.zip"
+===DONE===
diff --git a/ext/phar/tests/zip/corrupt_008.phpt b/ext/phar/tests/zip/corrupt_008.phpt
new file mode 100644
index 0000000..5a20f4d
--- /dev/null
+++ b/ext/phar/tests/zip/corrupt_008.phpt
@@ -0,0 +1,101 @@
+--TEST--
+Phar: unsupported compression methods
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+--FILE--
+<?php
+try {
+ new PharData(dirname(__FILE__) . '/files/compress_unsup1.zip');
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+try {
+ new PharData(dirname(__FILE__) . '/files/compress_unsup2.zip');
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+try {
+ new PharData(dirname(__FILE__) . '/files/compress_unsup3.zip');
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+try {
+ new PharData(dirname(__FILE__) . '/files/compress_unsup4.zip');
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+try {
+ new PharData(dirname(__FILE__) . '/files/compress_unsup5.zip');
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+try {
+ new PharData(dirname(__FILE__) . '/files/compress_unsup6.zip');
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+try {
+ new PharData(dirname(__FILE__) . '/files/compress_unsup7.zip');
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+try {
+ new PharData(dirname(__FILE__) . '/files/compress_unsup9.zip');
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+try {
+ new PharData(dirname(__FILE__) . '/files/compress_unsup10.zip');
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+try {
+ new PharData(dirname(__FILE__) . '/files/compress_unsup14.zip');
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+try {
+ new PharData(dirname(__FILE__) . '/files/compress_unsup18.zip');
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+try {
+ new PharData(dirname(__FILE__) . '/files/compress_unsup19.zip');
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+try {
+ new PharData(dirname(__FILE__) . '/files/compress_unsup97.zip');
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+try {
+ new PharData(dirname(__FILE__) . '/files/compress_unsup98.zip');
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+try {
+ new PharData(dirname(__FILE__) . '/files/compress_unsupunknown.zip');
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--EXPECTF--
+phar error: unsupported compression method (Shrunk) used in this zip in zip-based phar "%scompress_unsup1.zip"
+phar error: unsupported compression method (Reduce) used in this zip in zip-based phar "%scompress_unsup2.zip"
+phar error: unsupported compression method (Reduce) used in this zip in zip-based phar "%scompress_unsup3.zip"
+phar error: unsupported compression method (Reduce) used in this zip in zip-based phar "%scompress_unsup4.zip"
+phar error: unsupported compression method (Reduce) used in this zip in zip-based phar "%scompress_unsup5.zip"
+phar error: unsupported compression method (Implode) used in this zip in zip-based phar "%scompress_unsup6.zip"
+phar error: unsupported compression method (Tokenize) used in this zip in zip-based phar "%scompress_unsup7.zip"
+phar error: unsupported compression method (Deflate64) used in this zip in zip-based phar "%scompress_unsup9.zip"
+phar error: unsupported compression method (PKWare Implode/old IBM TERSE) used in this zip in zip-based phar "%scompress_unsup10.zip"
+phar error: unsupported compression method (LZMA) used in this zip in zip-based phar "%scompress_unsup14.zip"
+phar error: unsupported compression method (IBM TERSE) used in this zip in zip-based phar "%scompress_unsup18.zip"
+phar error: unsupported compression method (IBM LZ77) used in this zip in zip-based phar "%scompress_unsup19.zip"
+phar error: unsupported compression method (WavPack) used in this zip in zip-based phar "%scompress_unsup97.zip"
+phar error: unsupported compression method (PPMd) used in this zip in zip-based phar "%scompress_unsup98.zip"
+phar error: unsupported compression method (unknown) used in this zip in zip-based phar "%scompress_unsupunknown.zip"
+===DONE===
diff --git a/ext/phar/tests/zip/corrupt_009.phpt b/ext/phar/tests/zip/corrupt_009.phpt
new file mode 100644
index 0000000..91f142d
--- /dev/null
+++ b/ext/phar/tests/zip/corrupt_009.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Phar: corrupted zip (extra field way too long)
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+--FILE--
+<?php
+try {
+ new PharData(dirname(__FILE__) . '/files/extralen_toolong.zip');
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--EXPECTF--
+phar error: Unable to process extra field header for file in central directory in zip-based phar "%sextralen_toolong.zip"
+===DONE===
diff --git a/ext/phar/tests/zip/corrupt_010.phpt b/ext/phar/tests/zip/corrupt_010.phpt
new file mode 100644
index 0000000..ead723c
--- /dev/null
+++ b/ext/phar/tests/zip/corrupt_010.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Phar: unable to process zip (zip spanning multiple archives)
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+--FILE--
+<?php
+try {
+ new PharData(dirname(__FILE__) . '/files/disknumber.zip');
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--EXPECTF--
+phar error: split archives spanning multiple zips cannot be processed in zip-based phar "%sdisknumber.zip"
+===DONE===
diff --git a/ext/phar/tests/zip/create_new_and_modify.phpt b/ext/phar/tests/zip/create_new_and_modify.phpt
new file mode 100644
index 0000000..5a3ec33
--- /dev/null
+++ b/ext/phar/tests/zip/create_new_and_modify.phpt
@@ -0,0 +1,45 @@
+--TEST--
+Phar: create and modify zip-based phar
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip.php';
+$pname = 'phar://' . $fname;
+
+@unlink($fname);
+
+file_put_contents($pname . '/a.php', "brand new!\n");
+
+$phar = new Phar($fname);
+var_dump($phar->isFileFormat(Phar::ZIP));
+$sig1 = md5_file($fname);
+
+include $pname . '/a.php';
+
+file_put_contents($pname .'/a.php', "modified!\n");
+file_put_contents($pname .'/b.php', "another!\n");
+
+$phar = new Phar($fname);
+$sig2 = md5_file($fname);
+
+var_dump($sig1 != $sig2);
+
+include $pname . '/a.php';
+include $pname . '/b.php';
+
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip.php'); ?>
+--EXPECTF--
+bool(true)
+brand new!
+bool(true)
+modified!
+another!
+===DONE===
diff --git a/ext/phar/tests/zip/create_new_phar_b.phpt b/ext/phar/tests/zip/create_new_phar_b.phpt
new file mode 100644
index 0000000..5fda5b4
--- /dev/null
+++ b/ext/phar/tests/zip/create_new_phar_b.phpt
@@ -0,0 +1,27 @@
+--TEST--
+Phar: create a completely new zip-based phar
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=1
+phar.require_hash=1
+--FILE--
+<?php
+
+file_put_contents('phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip/a.php',
+ 'brand new!');
+include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip/a.php';
+?>
+
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip'); ?>
+--EXPECTF--
+
+Warning: file_put_contents(phar://%screate_new_phar_b.phar.zip/a.php): failed to open stream: phar error: write operations disabled by the php.ini setting phar.readonly in %screate_new_phar_b.php on line %d
+
+Warning: include(phar://%screate_new_phar_b.phar.zip/a.php): failed to open stream: %s in %screate_new_phar_b.php on line %d
+
+Warning: include(): Failed opening 'phar://%screate_new_phar_b.phar.zip/a.php' for inclusion (include_path='%s') in %screate_new_phar_b.php on line %d
+
+===DONE===
diff --git a/ext/phar/tests/zip/delete.phpt b/ext/phar/tests/zip/delete.phpt
new file mode 100644
index 0000000..06078b3
--- /dev/null
+++ b/ext/phar/tests/zip/delete.phpt
@@ -0,0 +1,31 @@
+--TEST--
+Phar: delete test, zip-based phar
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+phar.require_hash=0
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip';
+$alias = 'phar://' . $fname;
+$file = "<?php
+Phar::mapPhar('hio');
+__HALT_COMPILER(); ?>";
+
+$phar = new Phar($fname);
+$phar['a'] = 'a';
+$phar->setStub($file);
+$phar->stopBuffering();
+
+echo file_get_contents($alias . '/a') . "\n";
+$phar->delete('a');
+echo file_get_contents($alias . '/a') . "\n";
+?>
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip'); ?>
+--EXPECTF--
+a
+
+Warning: file_get_contents(phar://%sdelete.phar.zip/a): failed to open stream: phar error: "a" is not a file in phar "%sdelete.phar.zip" in %sdelete.php on line %d \ No newline at end of file
diff --git a/ext/phar/tests/zip/delete_in_phar.phpt b/ext/phar/tests/zip/delete_in_phar.phpt
new file mode 100644
index 0000000..b7bda7c
--- /dev/null
+++ b/ext/phar/tests/zip/delete_in_phar.phpt
@@ -0,0 +1,49 @@
+--TEST--
+Phar: delete a file within a zip-based .phar
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+phar.require_hash=0
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip';
+$alias = 'phar://' . $fname;
+
+$phar = new Phar($fname);
+$phar['a.php'] = '<?php echo "This is a\n"; ?>';
+$phar['b.php'] = '<?php echo "This is b\n"; ?>';
+$phar['b/c.php'] = '<?php echo "This is b/c\n"; ?>';
+$phar->setStub('<?php __HALT_COMPILER(); ?>');
+$phar->stopBuffering();
+
+include $alias . '/a.php';
+include $alias . '/b.php';
+include $alias . '/b/c.php';
+unlink($alias . '/b/c.php');
+?>
+===AFTER===
+<?php
+include $alias . '/a.php';
+include $alias . '/b.php';
+include $alias . '/b/c.php';
+?>
+
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip'); ?>
+--EXPECTF--
+This is a
+This is b
+This is b/c
+===AFTER===
+This is a
+This is b
+
+Warning: include(%sdelete_in_phar.phar.zip/b/c.php): failed to open stream: phar error: "b/c.php" is not a file in phar "%sdelete_in_phar.phar.zip" in %sdelete_in_phar.php on line %d
+
+Warning: include(): Failed opening 'phar://%sdelete_in_phar.phar.zip/b/c.php' for inclusion (include_path='%s') in %sdelete_in_phar.php on line %d
+
+===DONE===
+ \ No newline at end of file
diff --git a/ext/phar/tests/zip/delete_in_phar_b.phpt b/ext/phar/tests/zip/delete_in_phar_b.phpt
new file mode 100644
index 0000000..eb1a6cc
--- /dev/null
+++ b/ext/phar/tests/zip/delete_in_phar_b.phpt
@@ -0,0 +1,48 @@
+--TEST--
+Phar: delete a file within a zip-based .phar
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+phar.require_hash=0
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip';
+$alias = 'phar://' . $fname;
+
+$phar = new Phar($fname);
+$phar['a.php'] = '<?php echo "This is a\n"; ?>';
+$phar['b.php'] = '<?php echo "This is b\n"; ?>';
+$phar['b/c.php'] = '<?php echo "This is b/c\n"; ?>';
+$phar->setStub('<?php __HALT_COMPILER(); ?>');
+$phar->stopBuffering();
+ini_set('phar.readonly', 1);
+
+include $alias . '/a.php';
+include $alias . '/b.php';
+include $alias . '/b/c.php';
+unlink($alias . '/b/c.php');
+?>
+===AFTER===
+<?php
+include $alias . '/a.php';
+include $alias . '/b.php';
+include $alias . '/b/c.php';
+?>
+
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip'); ?>
+--EXPECTF--
+This is a
+This is b
+This is b/c
+
+Warning: unlink(): phar error: write operations disabled by the php.ini setting phar.readonly in %sdelete_in_phar_b.php on line %d
+===AFTER===
+This is a
+This is b
+This is b/c
+
+===DONE===
diff --git a/ext/phar/tests/zip/delete_in_phar_confirm.phpt b/ext/phar/tests/zip/delete_in_phar_confirm.phpt
new file mode 100644
index 0000000..fdd0b42
--- /dev/null
+++ b/ext/phar/tests/zip/delete_in_phar_confirm.phpt
@@ -0,0 +1,53 @@
+--TEST--
+Phar: delete a file within a zip-based .phar (confirm disk file is changed)
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+phar.require_hash=0
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip';
+$alias = 'phar://' . $fname;
+
+$phar = new Phar($fname);
+$phar['a.php'] = '<?php echo "This is a\n"; ?>';
+$phar['b.php'] = '<?php echo "This is b\n"; ?>';
+$phar['b/c.php'] = '<?php echo "This is b/c\n"; ?>';
+$phar->setStub('<?php __HALT_COMPILER(); ?>');
+$phar->stopBuffering();
+
+include $alias . '/a.php';
+include $alias . '/b.php';
+include $alias . '/b/c.php';
+
+$md5 = md5_file($fname);
+unlink($alias . '/b/c.php');
+clearstatcache();
+$md52 = md5_file($fname);
+if ($md5 == $md52) echo 'file was not modified';
+?>
+===AFTER===
+<?php
+include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip/a.php';
+include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip/b.php';
+include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip/b/c.php';
+?>
+
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip'); ?>
+--EXPECTF--
+This is a
+This is b
+This is b/c
+===AFTER===
+This is a
+This is b
+
+Warning: include(%sdelete_in_phar_confirm.phar.zip/b/c.php): failed to open stream: phar error: "b/c.php" is not a file in phar "%sdelete_in_phar_confirm.phar.zip" in %sdelete_in_phar_confirm.php on line %d
+
+Warning: include(): Failed opening 'phar://%sdelete_in_phar_confirm.phar.zip/b/c.php' for inclusion (include_path='%s') in %sdelete_in_phar_confirm.php on line %d
+
+===DONE===
diff --git a/ext/phar/tests/zip/dir.phpt b/ext/phar/tests/zip/dir.phpt
new file mode 100644
index 0000000..3cbeacd
--- /dev/null
+++ b/ext/phar/tests/zip/dir.phpt
@@ -0,0 +1,43 @@
+--TEST--
+Phar: mkdir/rmdir test zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+phar.require_hash=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip.php';
+$pname = 'phar://' . $fname;
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.1.phar.php';
+$pname2 = 'phar://' . $fname2;
+$fname3 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.phar.php';
+$pname3 = 'phar://' . $fname3;
+$phar = new Phar($fname);
+var_dump($phar->isFileFormat(Phar::ZIP));
+
+$phar->addEmptyDir('test');
+var_dump($phar['test']->isDir());
+var_dump($phar['test/']->isDir());
+copy($fname, $fname2);
+mkdir($pname . '/another/dir/');
+var_dump($phar['another/dir']->isDir());
+rmdir($pname . '/another/dir/');
+copy($fname, $fname3);
+clearstatcache();
+var_dump(file_exists($pname . '/another/dir/'));
+var_dump(file_exists($pname2 . '/test/'));
+var_dump(file_exists($pname3 . '/another/dir/'));
+?>
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip.php'); ?>
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.1.phar.php'); ?>
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar.php'); ?>
+--EXPECT--
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(false)
+bool(true)
+bool(false)
diff --git a/ext/phar/tests/zip/exists_as_phar.phpt b/ext/phar/tests/zip/exists_as_phar.phpt
new file mode 100644
index 0000000..ccb37e8
--- /dev/null
+++ b/ext/phar/tests/zip/exists_as_phar.phpt
@@ -0,0 +1,38 @@
+--TEST--
+Phar: phar-based phar named with ".zip" fails
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+phar.require_hash=0
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar';
+$tname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip';
+$alias = 'phar://hio';
+
+$phar = new Phar($fname);
+$phar['a.php'] = '<?php echo "This is a\n"; include "'.$alias.'/b.php"; ?>';
+$phar->setAlias('hio');
+$phar->addEmptyDir('test');
+$phar->stopBuffering();
+copy($fname, $tname);
+$phar->setAlias('hio2');
+
+try {
+ $p = new Phar($tname);
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar');
+?>
+--EXPECTF--
+phar zip error: phar "%sexists_as_phar.phar.zip" already exists as a regular phar and must be deleted from disk prior to creating as a zip-based phar
+===DONE===
diff --git a/ext/phar/tests/zip/files/badalias1.phar.zip b/ext/phar/tests/zip/files/badalias1.phar.zip
new file mode 100644
index 0000000..0e3adfc
--- /dev/null
+++ b/ext/phar/tests/zip/files/badalias1.phar.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/badalias2.phar.zip b/ext/phar/tests/zip/files/badalias2.phar.zip
new file mode 100644
index 0000000..7b5baaa
--- /dev/null
+++ b/ext/phar/tests/zip/files/badalias2.phar.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/badalias3.phar.zip b/ext/phar/tests/zip/files/badalias3.phar.zip
new file mode 100644
index 0000000..7b5baaa
--- /dev/null
+++ b/ext/phar/tests/zip/files/badalias3.phar.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/badalias4.phar.zip b/ext/phar/tests/zip/files/badalias4.phar.zip
new file mode 100644
index 0000000..49b7be0
--- /dev/null
+++ b/ext/phar/tests/zip/files/badalias4.phar.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/badalias5.phar.zip b/ext/phar/tests/zip/files/badalias5.phar.zip
new file mode 100644
index 0000000..9f2b0e8
--- /dev/null
+++ b/ext/phar/tests/zip/files/badalias5.phar.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/bz2_alias.phar.zip b/ext/phar/tests/zip/files/bz2_alias.phar.zip
new file mode 100644
index 0000000..8d3082a
--- /dev/null
+++ b/ext/phar/tests/zip/files/bz2_alias.phar.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/bzip2.zip b/ext/phar/tests/zip/files/bzip2.zip
new file mode 100644
index 0000000..2f27f02
--- /dev/null
+++ b/ext/phar/tests/zip/files/bzip2.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/cdir_offset.zip b/ext/phar/tests/zip/files/cdir_offset.zip
new file mode 100644
index 0000000..9172554
--- /dev/null
+++ b/ext/phar/tests/zip/files/cdir_offset.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/compress_unsup1.zip b/ext/phar/tests/zip/files/compress_unsup1.zip
new file mode 100644
index 0000000..bd1f72b
--- /dev/null
+++ b/ext/phar/tests/zip/files/compress_unsup1.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/compress_unsup10.zip b/ext/phar/tests/zip/files/compress_unsup10.zip
new file mode 100644
index 0000000..2a7f221
--- /dev/null
+++ b/ext/phar/tests/zip/files/compress_unsup10.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/compress_unsup14.zip b/ext/phar/tests/zip/files/compress_unsup14.zip
new file mode 100644
index 0000000..d494143
--- /dev/null
+++ b/ext/phar/tests/zip/files/compress_unsup14.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/compress_unsup18.zip b/ext/phar/tests/zip/files/compress_unsup18.zip
new file mode 100644
index 0000000..7ef2217
--- /dev/null
+++ b/ext/phar/tests/zip/files/compress_unsup18.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/compress_unsup19.zip b/ext/phar/tests/zip/files/compress_unsup19.zip
new file mode 100644
index 0000000..8086d45
--- /dev/null
+++ b/ext/phar/tests/zip/files/compress_unsup19.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/compress_unsup2.zip b/ext/phar/tests/zip/files/compress_unsup2.zip
new file mode 100644
index 0000000..d827d2d
--- /dev/null
+++ b/ext/phar/tests/zip/files/compress_unsup2.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/compress_unsup3.zip b/ext/phar/tests/zip/files/compress_unsup3.zip
new file mode 100644
index 0000000..d4acc60
--- /dev/null
+++ b/ext/phar/tests/zip/files/compress_unsup3.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/compress_unsup4.zip b/ext/phar/tests/zip/files/compress_unsup4.zip
new file mode 100644
index 0000000..76a4dc1
--- /dev/null
+++ b/ext/phar/tests/zip/files/compress_unsup4.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/compress_unsup5.zip b/ext/phar/tests/zip/files/compress_unsup5.zip
new file mode 100644
index 0000000..d42155d
--- /dev/null
+++ b/ext/phar/tests/zip/files/compress_unsup5.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/compress_unsup6.zip b/ext/phar/tests/zip/files/compress_unsup6.zip
new file mode 100644
index 0000000..5084640
--- /dev/null
+++ b/ext/phar/tests/zip/files/compress_unsup6.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/compress_unsup7.zip b/ext/phar/tests/zip/files/compress_unsup7.zip
new file mode 100644
index 0000000..65c2e23
--- /dev/null
+++ b/ext/phar/tests/zip/files/compress_unsup7.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/compress_unsup9.zip b/ext/phar/tests/zip/files/compress_unsup9.zip
new file mode 100644
index 0000000..df0c767
--- /dev/null
+++ b/ext/phar/tests/zip/files/compress_unsup9.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/compress_unsup97.zip b/ext/phar/tests/zip/files/compress_unsup97.zip
new file mode 100644
index 0000000..907f365
--- /dev/null
+++ b/ext/phar/tests/zip/files/compress_unsup97.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/compress_unsup98.zip b/ext/phar/tests/zip/files/compress_unsup98.zip
new file mode 100644
index 0000000..54f19fb
--- /dev/null
+++ b/ext/phar/tests/zip/files/compress_unsup98.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/compress_unsupunknown.zip b/ext/phar/tests/zip/files/compress_unsupunknown.zip
new file mode 100644
index 0000000..1706954
--- /dev/null
+++ b/ext/phar/tests/zip/files/compress_unsupunknown.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/corrupt2.php.inc b/ext/phar/tests/zip/files/corrupt2.php.inc
new file mode 100644
index 0000000..3edf620
--- /dev/null
+++ b/ext/phar/tests/zip/files/corrupt2.php.inc
@@ -0,0 +1,60 @@
+<?php
+include dirname(__FILE__) . '/corrupt_zipmaker.php.inc';
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii');
+$a->addFile('hi2', null, 'hii2', null, null, 'encrypt', 'encrypt');
+$a->writeZip(dirname(__FILE__) . '/encrypted.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii');
+$a->addFile('', null, 'stdin');
+$a->writeZip(dirname(__FILE__) . '/stdin.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hii', null, 'hii', null, null, 'filename_len', 'filename_len');
+$a->addFile('hi', null, 'hii');
+$a->writeZip(dirname(__FILE__) . '/truncfilename.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress');
+$a->writeZip(dirname(__FILE__) . '/compress_unsup1.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 2);
+$a->writeZip(dirname(__FILE__) . '/compress_unsup2.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 3);
+$a->writeZip(dirname(__FILE__) . '/compress_unsup3.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 4);
+$a->writeZip(dirname(__FILE__) . '/compress_unsup4.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 5);
+$a->writeZip(dirname(__FILE__) . '/compress_unsup5.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 6);
+$a->writeZip(dirname(__FILE__) . '/compress_unsup6.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 7);
+$a->writeZip(dirname(__FILE__) . '/compress_unsup7.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 9);
+$a->writeZip(dirname(__FILE__) . '/compress_unsup9.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 10);
+$a->writeZip(dirname(__FILE__) . '/compress_unsup10.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 14);
+$a->writeZip(dirname(__FILE__) . '/compress_unsup14.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 18);
+$a->writeZip(dirname(__FILE__) . '/compress_unsup18.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 19);
+$a->writeZip(dirname(__FILE__) . '/compress_unsup19.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 97);
+$a->writeZip(dirname(__FILE__) . '/compress_unsup97.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 98);
+$a->writeZip(dirname(__FILE__) . '/compress_unsup98.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 11);
+$a->writeZip(dirname(__FILE__) . '/compress_unsupunknown.zip');
+?>
diff --git a/ext/phar/tests/zip/files/corrupt3.php.inc b/ext/phar/tests/zip/files/corrupt3.php.inc
new file mode 100644
index 0000000..05ba70b
--- /dev/null
+++ b/ext/phar/tests/zip/files/corrupt3.php.inc
@@ -0,0 +1,9 @@
+<?php
+include dirname(__FILE__) . '/corrupt_zipmaker.php.inc';
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, null, 'extralen1');
+$a->writeZip(dirname(__FILE__) . '/extralen_toolong.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii');
+$a->writeZip(dirname(__FILE__) . '/disknumber.zip', 'disknumber');
+?>
diff --git a/ext/phar/tests/zip/files/corrupt_count1.php.inc b/ext/phar/tests/zip/files/corrupt_count1.php.inc
new file mode 100644
index 0000000..314fdef
--- /dev/null
+++ b/ext/phar/tests/zip/files/corrupt_count1.php.inc
@@ -0,0 +1,11 @@
+<?php
+include dirname(__FILE__) . '/corrupt_zipmaker.php.inc';
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii');
+$a->addFile('hi2', null, 'hii2');
+$a->writeZip(dirname(__FILE__) . '/count1.zip', 'count1');
+$a->writeZip(dirname(__FILE__) . '/count2.zip', 'count2');
+$a->writeZip(dirname(__FILE__) . '/nozipend.zip', 'none');
+$a->writeZip(dirname(__FILE__) . '/filecomment.zip', 'comment');
+$a->writeZip(dirname(__FILE__) . '/cdir_offset.zip', 'cdir_offset');
+?>
diff --git a/ext/phar/tests/zip/files/corrupt_zipmaker.php.inc b/ext/phar/tests/zip/files/corrupt_zipmaker.php.inc
new file mode 100644
index 0000000..9fbfe34
--- /dev/null
+++ b/ext/phar/tests/zip/files/corrupt_zipmaker.php.inc
@@ -0,0 +1,332 @@
+<?php
+// this corrupt zip maker uses portions of Vincent Lascaux's File_Archive to create
+// specifically corrupted zip archives for unit-testing zip support in the phar extension
+// and was modified by Greg Beaver
+/**
+ * ZIP archive writer
+ *
+ * PHP versions 4 and 5
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA
+ *
+ * @category File Formats
+ * @package File_Archive
+ * @author Vincent Lascaux <vincentlascaux@php.net>
+ * @copyright 1997-2005 The PHP Group
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL
+ * @version CVS: $Id$
+ * @link http://pear.php.net/package/File_Archive
+ */
+
+/**
+ * ZIP archive writer
+ */
+class corrupt_zipmaker
+{
+ /**
+ * @var int Current position in the writer
+ * @access private
+ */
+ var $offset = 0;
+
+ /**
+ * @var string Optionnal comment to add to the zip
+ * @access private
+ */
+ var $comment = "";
+
+ /**
+ * @var string Data written at the end of the ZIP file
+ * @access private
+ */
+ var $central = "";
+
+ /**
+ * @var string Data written at the start of the ZIP file
+ * @access private
+ */
+ var $start = "";
+
+ /**
+ * Set a comment on the ZIP file
+ */
+ function setComment($comment) { $this->comment = $comment; }
+
+ /**
+ * @param int $time Unix timestamp of the date to convert
+ * @return the date formated as a ZIP date
+ */
+ function getMTime($time)
+ {
+ $mtime = ($time !== null ? getdate($time) : getdate());
+ $mtime = preg_replace(
+ "/(..){1}(..){1}(..){1}(..){1}/",
+ "\\x\\4\\x\\3\\x\\2\\x\\1",
+ dechex(($mtime['year']-1980<<25)|
+ ($mtime['mon' ]<<21)|
+ ($mtime['mday' ]<<16)|
+ ($mtime['hours' ]<<11)|
+ ($mtime['minutes']<<5)|
+ ($mtime['seconds']>>1)));
+ eval('$mtime = "'.$mtime.'";');
+ return $mtime;
+ }
+
+ private function getFileEntry($compmethod, $mtime, $crc32, $complength, $uncomplength, $filename, $data, $corrupt, $fakecomp)
+ {
+ switch ($corrupt) {
+ case null :
+ $file = "PK\x03\x04\x14\x00\x00\x00" . pack('v', $compmethod) .
+ $mtime .
+ pack("VVVvv", $crc32, $complength, $uncomplength, strlen($filename), 0x00) .
+ $filename .
+ $data;
+ break;
+ case 'compress' :
+ $file = "PK\x03\x04\x14\x00\x00\x00" . pack('v', $fakecomp) .
+ $mtime .
+ pack("VVVvv", $crc32, $complength, $uncomplength, strlen($filename), 0x00) .
+ $filename .
+ $data;
+ break;
+ case 'encrypt' :
+ $file = "PK\x03\x04\x14\x00\x01\x00" . pack('v', $compmethod) .
+ $mtime .
+ pack("VVVvv", $crc32, $complength, $uncomplength, strlen($filename), 0x00) .
+ $filename .
+ $data;
+ break;
+ case 'crc32' :
+ $file = "PK\x03\x04\x14\x00\x00\x00" . pack('v', $compmethod) .
+ $mtime .
+ pack("VVVvv", $crc32 + 1, $complength, $uncomplength, strlen($filename), 0x00) .
+ $filename .
+ $data;
+ break;
+ case 'complength' :
+ $file = "PK\x03\x04\x14\x00\x00\x00" . pack('v', $compmethod) .
+ $mtime .
+ pack("VVVvv", $crc32, $complength + 1, $uncomplength, strlen($filename), 0x00) .
+ $filename .
+ $data;
+ break;
+ case 'uncomplength' :
+ $file = "PK\x03\x04\x14\x00\x00\x00" . pack('v', $compmethod) .
+ $mtime .
+ pack("VVVvv", $crc32, $complength, $uncomplength - 1, strlen($filename), 0x00) .
+ $filename .
+ $data;
+ break;
+ case 'filename_len' :
+ $file = "PK\x03\x04\x14\x00\x00\x00" . pack('v', $compmethod) .
+ $mtime .
+ pack("VVVvv", $crc32, $complength, $uncomplength, strlen($filename) - 1, 0x00) .
+ $filename .
+ $data;
+ break;
+ case 'extra_len' :
+ $file = "PK\x03\x04\x14\x00\x00\x00" . pack('v', $compmethod) .
+ $mtime .
+ pack("VVVvv", $crc32, $complength, $uncomplength, strlen($filename), 1) .
+ $filename .
+ $data;
+ break;
+ case 'filename' :
+ $file = "PK\x03\x04\x14\x00\x00\x00" . pack('v', $compmethod) .
+ $mtime .
+ pack("VVVvv", $crc32, $complength, $uncomplength, strlen($filename), 0x00) .
+ substr($filename, 1) .
+ $data;
+ break;
+ case 'data' :
+ $file = "PK\x03\x04\x14\x00\x00\x00" . pack('v', $compmethod) .
+ $mtime .
+ pack("VVVvv", $crc32, $complength, $uncomplength, strlen($filename), 0x00) .
+ $filename .
+ substr($data, 1);
+ break;
+ }
+ return $file;
+ }
+
+ private function getCentralEntry($compmethod, $mtime, $crc32, $complength, $uncomplength, $filename, $comment, $corrupt, &$offset, $fakecomp)
+ {
+ settype($comment, 'string');
+ switch ($corrupt) {
+ case null :
+ $central = "PK\x01\x02\x00\x00\x14\x00\x00\x00" . pack('v', $compmethod) .
+ $mtime .
+ pack("VVVvvvvvVV", $crc32, $complength, $uncomplength, strlen($filename), 0x00,strlen($comment),0x00,0x00,
+ 0x0000, $this->offset).
+ $filename . $comment;
+ $offset = strlen($central);
+ break;
+ case 'encrypt' :
+ $central = "PK\x01\x02\x00\x00\x14\x00\x01\x00" . pack('v', $compmethod) .
+ $mtime .
+ pack("VVVvvvvvVV", $crc32, $complength, $uncomplength, strlen($filename), 0x00,strlen($comment),0x00,0x00,
+ 0x0000, $this->offset).
+ $filename . $comment;
+ $offset = strlen($central);
+ break;
+ case 'compress' :
+ $central = "PK\x01\x02\x00\x00\x14\x00\x00\x00" . pack('v', $fakecomp) .
+ $mtime .
+ pack("VVVvvvvvVV", $crc32, $complength, $uncomplength, strlen($filename), 0x00,strlen($comment),0x00,0x00,
+ 0x0000, $this->offset).
+ $filename . $comment;
+ $offset = strlen($central);
+ break;
+ case 'crc32' :
+ $central = "PK\x01\x02\x00\x00\x14\x00\x00\x00" . pack('v', $compmethod) .
+ $mtime .
+ pack("VVVvvvvvVV", $crc32 + 1, $complength, $uncomplength, strlen($filename), 0x00,strlen($comment),0x00,0x00,
+ 0x0000, $this->offset).
+ $filename . $comment;
+ $offset = strlen($central);
+ break;
+ case 'complength' :
+ $central = "PK\x01\x02\x00\x00\x14\x00\x00\x00" . pack('v', $compmethod) .
+ $mtime .
+ pack("VVVvvvvvVV", $crc32, $complength - 1, $uncomplength, strlen($filename), 0x00,strlen($comment),0x00,0x00,
+ 0x0000, $this->offset).
+ $filename . $comment;
+ $offset = strlen($central);
+ break;
+ case 'uncomplength' :
+ $central = "PK\x01\x02\x00\x00\x14\x00\x00\x00" . pack('v', $compmethod) .
+ $mtime .
+ pack("VVVvvvvvVV", $crc32, $complength, $uncomplength - 1, strlen($filename), 0x00,strlen($comment),0x00,0x00,
+ 0x0000, $this->offset).
+ $filename . $comment;
+ $offset = strlen($central);
+ break;
+ case 'filename_len' :
+ $central = "PK\x01\x02\x00\x00\x14\x00\x00\x00" . pack('v', $compmethod) .
+ $mtime .
+ pack("VVVvvvvvVV", $crc32, $complength, $uncomplength, strlen($filename) - 1, 0x00,strlen($comment),0x00,0x00,
+ 0x0000, $this->offset).
+ $filename . $comment;
+ $offset = strlen($central);
+ break;
+ case 'offset' :
+ $central = "PK\x01\x02\x00\x00\x14\x00\x00\x00" . pack('v', $compmethod) .
+ $mtime .
+ pack("VVVvvvvvVV", $crc32, $complength, $uncomplength, strlen($filename), 0x00,strlen($comment),0x00,0x00,
+ 0x0000, $this->offset - 1).
+ $filename . $comment;
+ $offset = strlen($central) - 1;
+ break;
+ case 'comment' :
+ $central = "PK\x01\x02\x00\x00\x14\x00\x00\x00" . pack('v', $compmethod) .
+ $mtime .
+ pack("VVVvvvvvVV", $crc32, $complength, $uncomplength, strlen($filename), 0x00,strlen($comment) + 1,0x00,0x00,
+ 0x0000, $this->offset).
+ $filename . $comment;
+ $offset = strlen($central);
+ break;
+ case 'extralen1' :
+ $extra = 'nu' . 0xffff; // way huge size
+ $central = "PK\x01\x02\x00\x00\x14\x00\x00\x00" . pack('v', $compmethod) .
+ $mtime .
+ pack("VVVvvvvvVV", $crc32, $complength, $uncomplength, strlen($filename), strlen($extra),strlen($comment),0x00,0x00,
+ 0x0000, $this->offset).
+ $filename . $extra . $comment;
+ $offset = strlen($central);
+ break;
+ }
+ return $central;
+ }
+
+ function addFile($filename, $mtime, $data, $comment = null, $compress = null, $filecorrupt = null, $centralcorrupt = null, $fakecomp = 1)
+ {
+ $mtime = $this->getMTime($mtime ? $mtime : null);
+
+ $uncomplength = strlen($data);
+ $crc32 = crc32($data) & 0xFFFFFFFF;
+ $compmethod = 0;
+ switch ($compress) {
+ case 'gz' :
+ $data = gzcompress($data);
+ $compmethod = 8;
+ break;
+ case 'bz2' :
+ $data = bzcompress($data);
+ $compmethod = 12;
+ break;
+ }
+ $complength = strlen($data);
+
+ $this->start .= ($file = $this->getFileEntry($compmethod, $mtime, $crc32, $complength, $uncomplength, $filename, $data, $filecorrupt, $fakecomp));
+
+ $offset = 0;
+ $this->central .= $this->getCentralEntry($compmethod, $mtime, $crc32, $complength, $uncomplength, $filename, $comment, $centralcorrupt, $offset, $fakecomp);
+
+ $this->offset += $offset;
+ $this->count++;
+ }
+
+ function writeZip($zipfile, $corrupt = null)
+ {
+ $write = $this->start . $this->central;
+ switch ($corrupt) {
+ case null :
+ $write .= "PK\x05\x06\x00\x00\x00\x00" .
+ pack("vvVVv", $this->count, $this->count,
+ $this->offset, strlen($this->start),
+ strlen($this->comment)) . $this->comment;
+ break;
+ case 'disknumber' :
+ $write .= "PK\x05\x06\x01\x00\x01\x00" .
+ pack("vvVVv", $this->count, $this->count,
+ $this->offset, strlen($this->start),
+ strlen($this->comment)) . $this->comment;
+ break;
+ case 'count1' :
+ $write .= "PK\x05\x06\x00\x00\x00\x00" .
+ pack("vvVVv", $this->count + 1, $this->count,
+ $this->offset, strlen($this->start),
+ strlen($this->comment)) . $this->comment;
+ break;
+ case 'count2' :
+ $write .= "PK\x05\x06\x00\x00\x00\x00" .
+ pack("vvVVv", $this->count, $this->count + 1,
+ $this->offset, strlen($this->start),
+ strlen($this->comment)) . $this->comment;
+ break;
+ case 'cdir_offset' :
+ $write .= "PK\x05\x06\x00\x00\x00\x00" .
+ pack("vvVVv", $this->count, $this->count,
+ $this->offset, strlen($this->start) - 3,
+ strlen($this->comment)) . $this->comment;
+ break;
+ case 'cdir_len' :
+ $write .= "PK\x05\x06\x00\x00\x00\x00" .
+ pack("vvVVv", $this->count, $this->count,
+ $this->offset - 5, strlen($this->start),
+ strlen($this->comment)) . $this->comment;
+ break;
+ case 'comment' :
+ $write .= "PK\x05\x06\x00\x00\x00\x00" .
+ pack("vvVVv", $this->count, $this->count,
+ strlen($this->start), $this->offset + 1,
+ strlen($this->comment) + 1) . $this->comment;
+ break;
+ case 'none' :
+ }
+ file_put_contents($zipfile, $write);
+ }
+}
+?> \ No newline at end of file
diff --git a/ext/phar/tests/zip/files/count1.zip b/ext/phar/tests/zip/files/count1.zip
new file mode 100644
index 0000000..73b5561
--- /dev/null
+++ b/ext/phar/tests/zip/files/count1.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/count2.zip b/ext/phar/tests/zip/files/count2.zip
new file mode 100644
index 0000000..6aa2619
--- /dev/null
+++ b/ext/phar/tests/zip/files/count2.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/disknumber.zip b/ext/phar/tests/zip/files/disknumber.zip
new file mode 100644
index 0000000..f20db05
--- /dev/null
+++ b/ext/phar/tests/zip/files/disknumber.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/encrypted.zip b/ext/phar/tests/zip/files/encrypted.zip
new file mode 100644
index 0000000..dee73ca
--- /dev/null
+++ b/ext/phar/tests/zip/files/encrypted.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/extralen_toolong.zip b/ext/phar/tests/zip/files/extralen_toolong.zip
new file mode 100644
index 0000000..a03a403
--- /dev/null
+++ b/ext/phar/tests/zip/files/extralen_toolong.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/filecomment.zip b/ext/phar/tests/zip/files/filecomment.zip
new file mode 100644
index 0000000..414b121
--- /dev/null
+++ b/ext/phar/tests/zip/files/filecomment.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/frontcontroller.phar.inc b/ext/phar/tests/zip/files/frontcontroller.phar.inc
new file mode 100644
index 0000000..241dceb
--- /dev/null
+++ b/ext/phar/tests/zip/files/frontcontroller.phar.inc
@@ -0,0 +1,13 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller.phar.zip');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller.phar.zip');
+$a['a.php'] = 'hio';
+$a['a.jpg'] = 'hio';
+$a['a.phps'] = '<?php function hio(){}';
+$a['index.php'] = 'here is my index';
+$a->setStub('<?php
+Phar::webPhar();
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
diff --git a/ext/phar/tests/zip/files/frontcontroller.phar.zip b/ext/phar/tests/zip/files/frontcontroller.phar.zip
new file mode 100644
index 0000000..28992ff
--- /dev/null
+++ b/ext/phar/tests/zip/files/frontcontroller.phar.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/frontcontroller10.phar.inc b/ext/phar/tests/zip/files/frontcontroller10.phar.inc
new file mode 100644
index 0000000..c973cc1
--- /dev/null
+++ b/ext/phar/tests/zip/files/frontcontroller10.phar.inc
@@ -0,0 +1,20 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller10.phar.zip');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller10.phar.zip');
+$a['index.php'] = '<?php
+var_dump($_SERVER["PHP_SELF"]);
+var_dump($_SERVER["SCRIPT_NAME"]);
+var_dump($_SERVER["SCRIPT_FILENAME"]);
+var_dump($_SERVER["REQUEST_URI"]);
+var_dump($_SERVER["PHAR_PHP_SELF"]);
+var_dump($_SERVER["PHAR_SCRIPT_NAME"]);
+var_dump($_SERVER["PHAR_SCRIPT_FILENAME"]);
+var_dump($_SERVER["PHAR_REQUEST_URI"]);
+';
+$a->setStub('<?php
+Phar::mungServer(array("PHP_SELF", "SCRIPT_NAME", "SCRIPT_FILENAME", "REQUEST_URI", "OOPSIE"));
+Phar::webPhar();
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
diff --git a/ext/phar/tests/zip/files/frontcontroller10.phar.zip b/ext/phar/tests/zip/files/frontcontroller10.phar.zip
new file mode 100644
index 0000000..d206c89
--- /dev/null
+++ b/ext/phar/tests/zip/files/frontcontroller10.phar.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/frontcontroller11.phar.inc b/ext/phar/tests/zip/files/frontcontroller11.phar.inc
new file mode 100644
index 0000000..c24a6f1
--- /dev/null
+++ b/ext/phar/tests/zip/files/frontcontroller11.phar.inc
@@ -0,0 +1,20 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller11.phar.zip');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller11.phar.zip');
+$a['index.php'] = '<?php
+var_dump($_SERVER["PHP_SELF"]);
+var_dump($_SERVER["SCRIPT_NAME"]);
+var_dump($_SERVER["SCRIPT_FILENAME"]);
+var_dump($_SERVER["REQUEST_URI"]);
+var_dump($_SERVER["PHAR_PHP_SELF"]);
+var_dump($_SERVER["PHAR_SCRIPT_NAME"]);
+var_dump($_SERVER["PHAR_SCRIPT_FILENAME"]);
+var_dump($_SERVER["PHAR_REQUEST_URI"]);
+';
+$a->setStub('<?php
+Phar::mungServer(array(array(), "SCRIPT_NAME", "SCRIPT_FILENAME", "REQUEST_URI"));
+Phar::webPhar();
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
diff --git a/ext/phar/tests/zip/files/frontcontroller11.phar.zip b/ext/phar/tests/zip/files/frontcontroller11.phar.zip
new file mode 100644
index 0000000..9942183
--- /dev/null
+++ b/ext/phar/tests/zip/files/frontcontroller11.phar.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/frontcontroller12.phar.inc b/ext/phar/tests/zip/files/frontcontroller12.phar.inc
new file mode 100644
index 0000000..c5f38ff
--- /dev/null
+++ b/ext/phar/tests/zip/files/frontcontroller12.phar.inc
@@ -0,0 +1,20 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller12.phar.zip');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller12.phar.zip');
+$a['index.php'] = '<?php
+var_dump($_SERVER["PHP_SELF"]);
+var_dump($_SERVER[b"SCRIPT_NAME"]);
+var_dump($_SERVER[b"SCRIPT_FILENAME"]);
+var_dump($_SERVER[b"REQUEST_URI"]);
+var_dump($_SERVER[b"PHAR_PHP_SELF"]);
+var_dump($_SERVER[b"PHAR_SCRIPT_NAME"]);
+var_dump($_SERVER[b"PHAR_SCRIPT_FILENAME"]);
+var_dump($_SERVER[b"PHAR_REQUEST_URI"]);
+';
+$a->setStub('<?php
+Phar::mungServer(array("PHP_SELF", "SCRIPT_NAME", "SCRIPT_FILENAME", "REQUEST_URI"));
+Phar::webPhar();
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
diff --git a/ext/phar/tests/zip/files/frontcontroller12.phar.zip b/ext/phar/tests/zip/files/frontcontroller12.phar.zip
new file mode 100644
index 0000000..ed9be3d
--- /dev/null
+++ b/ext/phar/tests/zip/files/frontcontroller12.phar.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/frontcontroller2.phar.inc b/ext/phar/tests/zip/files/frontcontroller2.phar.inc
new file mode 100644
index 0000000..6cfa052
--- /dev/null
+++ b/ext/phar/tests/zip/files/frontcontroller2.phar.inc
@@ -0,0 +1,12 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller2.phar.zip');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller2.phar.zip');
+$a['a.php'] = 'hio';
+$a['a.jpg'] = 'hio';
+$a['a.phps'] = '<?php function hio(){}';
+$a->setStub('<?php
+Phar::webPhar("whatever", "a.php");
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
diff --git a/ext/phar/tests/zip/files/frontcontroller2.phar.zip b/ext/phar/tests/zip/files/frontcontroller2.phar.zip
new file mode 100644
index 0000000..3d7c0bb
--- /dev/null
+++ b/ext/phar/tests/zip/files/frontcontroller2.phar.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/frontcontroller3.phar.inc b/ext/phar/tests/zip/files/frontcontroller3.phar.inc
new file mode 100644
index 0000000..ccd55b7
--- /dev/null
+++ b/ext/phar/tests/zip/files/frontcontroller3.phar.inc
@@ -0,0 +1,18 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller3.phar.zip');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller3.phar.zip');
+$a['a.php'] = 'hio';
+$a['a.jpg'] = 'hio';
+$a['a.phps'] = '<?php function hio(){}';
+$a->setStub('<?php
+function s($a)
+{
+ static $b = array(b"/hi" => b"a.phps");
+ if (isset($b[$a])) return $b[$a];
+ return $a;
+}
+Phar::webPhar("whatever", "/index.php", null, array(), "s");
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
diff --git a/ext/phar/tests/zip/files/frontcontroller3.phar.zip b/ext/phar/tests/zip/files/frontcontroller3.phar.zip
new file mode 100644
index 0000000..6f35a80
--- /dev/null
+++ b/ext/phar/tests/zip/files/frontcontroller3.phar.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/frontcontroller4.phar.inc b/ext/phar/tests/zip/files/frontcontroller4.phar.inc
new file mode 100644
index 0000000..9f664cf
--- /dev/null
+++ b/ext/phar/tests/zip/files/frontcontroller4.phar.inc
@@ -0,0 +1,18 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller4.phar.zip');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller4.phar.zip');
+$a['a.php'] = 'hio';
+$a['a.jpg'] = 'hio';
+$a['a.phps'] = '<?php function hio(){}';
+$a->setStub('<?php
+function s($a)
+{
+ static $b = array(b"/hi" => false);
+ if (isset($b[$a])) return $b[$a];
+ return $a;
+}
+Phar::webPhar("whatever", "index.php", null, array(), "s");
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
diff --git a/ext/phar/tests/zip/files/frontcontroller4.phar.zip b/ext/phar/tests/zip/files/frontcontroller4.phar.zip
new file mode 100644
index 0000000..fb27ccb
--- /dev/null
+++ b/ext/phar/tests/zip/files/frontcontroller4.phar.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/frontcontroller5.phar.inc b/ext/phar/tests/zip/files/frontcontroller5.phar.inc
new file mode 100644
index 0000000..931fa97
--- /dev/null
+++ b/ext/phar/tests/zip/files/frontcontroller5.phar.inc
@@ -0,0 +1,12 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller5.phar.zip');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller5.phar.zip');
+$a['a.php'] = 'hio';
+$a['a.jpg'] = 'hio';
+$a['a.phps'] = '<?php function hio(){}';
+$a->setStub('<?php
+Phar::webPhar("whatever", "index.php", null, array(0 => "oops"));
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
diff --git a/ext/phar/tests/zip/files/frontcontroller5.phar.zip b/ext/phar/tests/zip/files/frontcontroller5.phar.zip
new file mode 100644
index 0000000..7fa7ab6
--- /dev/null
+++ b/ext/phar/tests/zip/files/frontcontroller5.phar.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/frontcontroller6.phar.inc b/ext/phar/tests/zip/files/frontcontroller6.phar.inc
new file mode 100644
index 0000000..da178fe
--- /dev/null
+++ b/ext/phar/tests/zip/files/frontcontroller6.phar.inc
@@ -0,0 +1,12 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller6.phar.zip');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller6.phar.zip');
+$a['a.php'] = 'hio';
+$a['a.jpg'] = 'hio';
+$a['a.phps'] = '<?php function hio(){}';
+$a->setStub('<?php
+Phar::webPhar("whatever", "index.php", null, array("php" => 100));
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
diff --git a/ext/phar/tests/zip/files/frontcontroller6.phar.zip b/ext/phar/tests/zip/files/frontcontroller6.phar.zip
new file mode 100644
index 0000000..eac313c
--- /dev/null
+++ b/ext/phar/tests/zip/files/frontcontroller6.phar.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/frontcontroller7.phar.inc b/ext/phar/tests/zip/files/frontcontroller7.phar.inc
new file mode 100644
index 0000000..a186491
--- /dev/null
+++ b/ext/phar/tests/zip/files/frontcontroller7.phar.inc
@@ -0,0 +1,12 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller7.phar.zip');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller7.phar.zip');
+$a['a.php'] = 'hio';
+$a['a.jpg'] = 'hio';
+$a['a.phps'] = '<?php function hio(){}';
+$a->setStub('<?php
+Phar::webPhar("whatever", "index.php", null, array("php" => null));
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
diff --git a/ext/phar/tests/zip/files/frontcontroller7.phar.zip b/ext/phar/tests/zip/files/frontcontroller7.phar.zip
new file mode 100644
index 0000000..be72052
--- /dev/null
+++ b/ext/phar/tests/zip/files/frontcontroller7.phar.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/frontcontroller8.phar.inc b/ext/phar/tests/zip/files/frontcontroller8.phar.inc
new file mode 100644
index 0000000..e04ac41
--- /dev/null
+++ b/ext/phar/tests/zip/files/frontcontroller8.phar.inc
@@ -0,0 +1,13 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller8.phar.zip');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller8.phar.zip');
+$a['a.phps'] = 'hio1';
+$a['a.jpg'] = 'hio2';
+$a['a.php'] = '<?php function hio(){}';
+$a['fronk.gronk'] = 'hio3';
+$a->setStub('<?php
+Phar::webPhar("whatever", "index.php", null, array("jpg" => "foo/bar", "phps" => Phar::PHP, "php" => Phar::PHPS));
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
diff --git a/ext/phar/tests/zip/files/frontcontroller8.phar.zip b/ext/phar/tests/zip/files/frontcontroller8.phar.zip
new file mode 100644
index 0000000..d065cd5
--- /dev/null
+++ b/ext/phar/tests/zip/files/frontcontroller8.phar.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/frontcontroller9.phar.inc b/ext/phar/tests/zip/files/frontcontroller9.phar.inc
new file mode 100644
index 0000000..5044045
--- /dev/null
+++ b/ext/phar/tests/zip/files/frontcontroller9.phar.inc
@@ -0,0 +1,14 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller9.phar.zip');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller9.phar.zip');
+$a['a.phps'] = 'hio1';
+$a['a.jpg'] = 'hio2';
+$a['a.php'] = '<?php function hio(){}';
+$a['fronk.gronk'] = 'hio3';
+$a->setStub('<?php
+Phar::mungServer(array());
+Phar::webPhar("whatever", "index.php", null, array("jpg" => "foo/bar", "phps" => Phar::PHP, "php" => Phar::PHPS));
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
diff --git a/ext/phar/tests/zip/files/frontcontroller9.phar.zip b/ext/phar/tests/zip/files/frontcontroller9.phar.zip
new file mode 100644
index 0000000..82c4eb7
--- /dev/null
+++ b/ext/phar/tests/zip/files/frontcontroller9.phar.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/make_invalid_tar.php.inc b/ext/phar/tests/zip/files/make_invalid_tar.php.inc
new file mode 100644
index 0000000..cec8ef7
--- /dev/null
+++ b/ext/phar/tests/zip/files/make_invalid_tar.php.inc
@@ -0,0 +1,12 @@
+<?php
+include dirname(__FILE__) . '/tarmaker.php.inc';
+class corrupter extends tarmaker {
+function close()
+{
+ parent::close();
+ $fp = fopen($this->path, 'r+b');
+ fseek($fp, 20);
+ fwrite($fp, 'oopsie');
+ fclose($fp);
+}
+} \ No newline at end of file
diff --git a/ext/phar/tests/zip/files/metadata.phar.inc b/ext/phar/tests/zip/files/metadata.phar.inc
new file mode 100644
index 0000000..932fc96
--- /dev/null
+++ b/ext/phar/tests/zip/files/metadata.phar.inc
@@ -0,0 +1,11 @@
+<?php
+@unlink(dirname(__FILE__) . '/metadata.phar.zip');
+$a = new Phar(dirname(__FILE__) . '/metadata.phar.zip');
+$a['a'] = 'a';
+$a['b'] = 'b';
+$a['b']->setMetadata('hi there');
+$a['c'] = 'c';
+$a['c']->setMetadata(array('hi', 'there'));
+$a['d'] = 'd';
+$a['d']->setMetadata(array('hi'=>'there','foo'=>'bar'));
+?>
diff --git a/ext/phar/tests/zip/files/metadata.phar.zip b/ext/phar/tests/zip/files/metadata.phar.zip
new file mode 100644
index 0000000..3c5cf00
--- /dev/null
+++ b/ext/phar/tests/zip/files/metadata.phar.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/nozipend.zip b/ext/phar/tests/zip/files/nozipend.zip
new file mode 100644
index 0000000..f976072
--- /dev/null
+++ b/ext/phar/tests/zip/files/nozipend.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/odt.odt b/ext/phar/tests/zip/files/odt.odt
new file mode 100644
index 0000000..527e09f
--- /dev/null
+++ b/ext/phar/tests/zip/files/odt.odt
Binary files differ
diff --git a/ext/phar/tests/zip/files/stdin.zip b/ext/phar/tests/zip/files/stdin.zip
new file mode 100644
index 0000000..4376eb6
--- /dev/null
+++ b/ext/phar/tests/zip/files/stdin.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/test.odt b/ext/phar/tests/zip/files/test.odt
new file mode 100644
index 0000000..c5cefe5
--- /dev/null
+++ b/ext/phar/tests/zip/files/test.odt
Binary files differ
diff --git a/ext/phar/tests/zip/files/truncfilename.zip b/ext/phar/tests/zip/files/truncfilename.zip
new file mode 100644
index 0000000..d8a526a
--- /dev/null
+++ b/ext/phar/tests/zip/files/truncfilename.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/zip.zip b/ext/phar/tests/zip/files/zip.zip
new file mode 100644
index 0000000..5ee9cae
--- /dev/null
+++ b/ext/phar/tests/zip/files/zip.zip
Binary files differ
diff --git a/ext/phar/tests/zip/files/zipmaker.php.inc b/ext/phar/tests/zip/files/zipmaker.php.inc
new file mode 100644
index 0000000..aceab0d
--- /dev/null
+++ b/ext/phar/tests/zip/files/zipmaker.php.inc
@@ -0,0 +1,70 @@
+<?php
+// stolen from PEAR2_Pyrus_Developer_Creator_Zip by Greg Beaver, the original author, for use in unit tests
+class zipmaker
+{
+ /**
+ * Path to archive file
+ *
+ * @var string
+ */
+ protected $archive;
+ /**
+ * @var ZIPArchive
+ */
+ protected $zip;
+ protected $path;
+ function __construct($path)
+ {
+ if (!class_exists('ZIPArchive')) {
+ throw new Exception(
+ 'Zip extension is not available');
+ }
+ $this->path = $path;
+ }
+
+ /**
+ * save a file inside this package
+ * @param string relative path within the package
+ * @param string|resource file contents or open file handle
+ */
+ function addFile($path, $fileOrStream)
+ {
+ if (is_resource($fileOrStream)) {
+ $this->zip->addFromString($path, stream_get_contents($fileOrStream));
+ } else {
+ $this->zip->addFromString($path, $fileOrStream);
+ }
+ }
+
+ /**
+ * Initialize the package creator
+ */
+ function init()
+ {
+ $this->zip = new ZipArchive;
+ if (true !== $this->zip->open($this->path, ZIPARCHIVE::CREATE)) {
+ throw new Exception(
+ 'Cannot open ZIP archive ' . $this->path
+ );
+ }
+ }
+
+ /**
+ * Create an internal directory, creating parent directories as needed
+ *
+ * This is a no-op for the tar creator
+ * @param string $dir
+ */
+ function mkdir($dir)
+ {
+ $this->zip->addEmptyDir($dir);
+ }
+
+ /**
+ * Finish saving the package
+ */
+ function close()
+ {
+ $this->zip->close();
+ }
+} \ No newline at end of file
diff --git a/ext/phar/tests/zip/files/zlib_alias.phar.zip b/ext/phar/tests/zip/files/zlib_alias.phar.zip
new file mode 100644
index 0000000..d6f98e8
--- /dev/null
+++ b/ext/phar/tests/zip/files/zlib_alias.phar.zip
Binary files differ
diff --git a/ext/phar/tests/zip/frontcontroller1.phar.phpt b/ext/phar/tests/zip/frontcontroller1.phar.phpt
new file mode 100644
index 0000000..b4ace60
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller1.phar.phpt
@@ -0,0 +1,16 @@
+--TEST--
+Phar front controller other zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zlib")) die("skip zlib not available"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller1.phar.php
+REQUEST_URI=/frontcontroller1.phar.php/a.jpg
+PATH_INFO=/a.jpg
+--FILE_EXTERNAL--
+files/frontcontroller.phar.zip
+--EXPECTHEADERS--
+Content-type: image/jpeg
+Content-length: 3
+--EXPECT--
+hio
diff --git a/ext/phar/tests/zip/frontcontroller10.phar.phpt b/ext/phar/tests/zip/frontcontroller10.phar.phpt
new file mode 100644
index 0000000..56d16c2
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller10.phar.phpt
@@ -0,0 +1,24 @@
+--TEST--
+Phar front controller rewrite array invalid zip-based
+--INI--
+default_charset=UTF-8
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller10.phar.php
+REQUEST_URI=/frontcontroller10.phar.php/hi
+PATH_INFO=/hi
+--FILE_EXTERNAL--
+files/frontcontroller4.phar.zip
+--EXPECTHEADERS--
+Content-type: text/html; charset=UTF-8
+Status: 403 Access Denied
+--EXPECT--
+<html>
+ <head>
+ <title>Access Denied</title>
+ </head>
+ <body>
+ <h1>403 - File /hi Access Denied</h1>
+ </body>
+</html> \ No newline at end of file
diff --git a/ext/phar/tests/zip/frontcontroller11.phar.phpt b/ext/phar/tests/zip/frontcontroller11.phar.phpt
new file mode 100644
index 0000000..e4900cd
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller11.phar.phpt
@@ -0,0 +1,22 @@
+--TEST--
+Phar front controller mime type extension is not a string zip-based
+--INI--
+default_charset=
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zlib")) die("skip zlib not available"); ?>
+<?php die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller11.phar.php
+REQUEST_URI=/frontcontroller11.phar.php/a.php
+PATH_INFO=/a.php
+--FILE_EXTERNAL--
+files/frontcontroller5.phar.zip
+--EXPECTHEADERS--
+Content-type: text/html
+--EXPECTF--
+Fatal error: Uncaught exception 'PharException' with message 'Key of MIME type overrides array must be a file extension, was "0"' in %sfrontcontroller11.phar.php:2
+Stack trace:
+#0 %sfrontcontroller11.phar.php(2): Phar::webPhar('whatever', 'index.php', '', Array)
+#1 {main}
+ thrown in %sfrontcontroller11.phar.php on line 2 \ No newline at end of file
diff --git a/ext/phar/tests/zip/frontcontroller12.phar.phpt b/ext/phar/tests/zip/frontcontroller12.phar.phpt
new file mode 100644
index 0000000..504d037
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller12.phar.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Phar front controller mime type unknown int zip-based
+--INI--
+default_charset=UTF-8
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zlib")) die("skip zlib not available"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller12.phar.php
+REQUEST_URI=/frontcontroller12.phar.php/a.php
+PATH_INFO=/a.php
+--FILE_EXTERNAL--
+files/frontcontroller6.phar.zip
+--EXPECTHEADERS--
+Content-type: text/html; charset=UTF-8
+--EXPECTF--
+Fatal error: Uncaught exception 'PharException' with message 'Unknown mime type specifier used, only Phar::PHP, Phar::PHPS and a mime type string are allowed' in %sfrontcontroller12.phar.php:2
+Stack trace:
+#0 %sfrontcontroller12.phar.php(2): Phar::webPhar('whatever', 'index.php', '', Array)
+#1 {main}
+ thrown in %sfrontcontroller12.phar.php on line 2 \ No newline at end of file
diff --git a/ext/phar/tests/zip/frontcontroller13.phar.phpt b/ext/phar/tests/zip/frontcontroller13.phar.phpt
new file mode 100644
index 0000000..4b9e910
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller13.phar.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Phar front controller mime type not string/int zip-based
+--INI--
+default_charset=UTF-8
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zlib")) die("skip zlib not available"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller13.phar.php
+REQUEST_URI=/frontcontroller13.phar.php/a.php
+PATH_INFO=/a.php
+--FILE_EXTERNAL--
+files/frontcontroller7.phar.zip
+--EXPECTHEADERS--
+Content-type: text/html; charset=UTF-8
+--EXPECTF--
+Fatal error: Uncaught exception 'PharException' with message 'Unknown mime type specifier used (not a string or int), only Phar::PHP, Phar::PHPS and a mime type string are allowed' in %sfrontcontroller13.phar.php:2
+Stack trace:
+#0 %sfrontcontroller13.phar.php(2): Phar::webPhar('whatever', 'index.php', '', Array)
+#1 {main}
+ thrown in %sfrontcontroller13.phar.php on line 2 \ No newline at end of file
diff --git a/ext/phar/tests/zip/frontcontroller14.phar.phpt b/ext/phar/tests/zip/frontcontroller14.phar.phpt
new file mode 100644
index 0000000..496160b
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller14.phar.phpt
@@ -0,0 +1,16 @@
+--TEST--
+Phar front controller mime type override, other zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zlib")) die("skip zlib not available"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller14.phar.php
+REQUEST_URI=/frontcontroller14.phar.php/a.jpg
+PATH_INFO=/a.jpg
+--FILE_EXTERNAL--
+files/frontcontroller8.phar.zip
+--EXPECTHEADERS--
+Content-type: foo/bar
+Content-length: 4
+--EXPECT--
+hio2
diff --git a/ext/phar/tests/zip/frontcontroller15.phar.phpt b/ext/phar/tests/zip/frontcontroller15.phar.phpt
new file mode 100644
index 0000000..f6cd29a
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller15.phar.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Phar front controller mime type override, Phar::PHPS zip-based
+--INI--
+default_charset=UTF-8
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zlib")) die("skip zlib not available"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller15.phar.php
+REQUEST_URI=/frontcontroller15.phar.php/a.php
+PATH_INFO=/a.php
+--FILE_EXTERNAL--
+files/frontcontroller8.phar.zip
+--EXPECTHEADERS--
+Content-type: text/html; charset=UTF-8
+--EXPECT--
+<code><span style="color: #000000">
+<span style="color: #0000BB">&lt;?php&nbsp;</span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">hio</span><span style="color: #007700">(){}</span>
+</span>
+</code>
+
diff --git a/ext/phar/tests/zip/frontcontroller16.phar.phpt b/ext/phar/tests/zip/frontcontroller16.phar.phpt
new file mode 100644
index 0000000..d3f457b
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller16.phar.phpt
@@ -0,0 +1,18 @@
+--TEST--
+Phar front controller mime type override, Phar::PHP zip-based
+--INI--
+default_charset=UTF-8
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zlib")) die("skip zlib not available"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller16.phar.php
+REQUEST_URI=/frontcontroller16.phar.php/a.phps
+PATH_INFO=/a.phps
+--FILE_EXTERNAL--
+files/frontcontroller8.phar.zip
+--EXPECTHEADERS--
+Content-type: text/html; charset=UTF-8
+--EXPECT--
+hio1
+
diff --git a/ext/phar/tests/zip/frontcontroller17.phar.phpt b/ext/phar/tests/zip/frontcontroller17.phar.phpt
new file mode 100644
index 0000000..5d52653
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller17.phar.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Phar front controller mime type unknown zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zlib")) die("skip zlib not available"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller17.phar.php
+REQUEST_URI=/frontcontroller17.phar.php/fronk.gronk
+PATH_INFO=/fronk.gronk
+--FILE_EXTERNAL--
+files/frontcontroller8.phar.zip
+--EXPECTHEADERS--
+Content-type: application/octet-stream
+Content-length: 4
+--EXPECT--
+hio3
+
diff --git a/ext/phar/tests/zip/frontcontroller18.phar.phpt b/ext/phar/tests/zip/frontcontroller18.phar.phpt
new file mode 100644
index 0000000..dbd09ca
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller18.phar.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Phar front controller $_SERVER munging failure zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zlib")) die("skip zlib not available"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller18.phar.php
+REQUEST_URI=/frontcontroller18.phar.php/fronk.gronk
+PATH_INFO=/fronk.gronk
+--FILE_EXTERNAL--
+files/frontcontroller9.phar.zip
+--EXPECTF--
+Fatal error: Uncaught exception 'PharException' with message 'No values passed to Phar::mungServer(), expecting an array of any of these strings: PHP_SELF, REQUEST_URI, SCRIPT_FILENAME, SCRIPT_NAME' in %sfrontcontroller18.phar.php:2
+Stack trace:
+#0 %sfrontcontroller18.phar.php(2): Phar::mungServer(Array)
+#1 {main}
+ thrown in %sfrontcontroller18.phar.php on line 2
diff --git a/ext/phar/tests/zip/frontcontroller19.phar.phpt b/ext/phar/tests/zip/frontcontroller19.phar.phpt
new file mode 100644
index 0000000..0eb87bf
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller19.phar.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Phar front controller $_SERVER munging failure 2 zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zlib")) die("skip zlib not available"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller19.phar.php
+REQUEST_URI=/frontcontroller19.phar.php/
+PATH_INFO=/
+--FILE_EXTERNAL--
+files/frontcontroller10.phar.zip
+--EXPECTF--
+Fatal error: Uncaught exception 'PharException' with message 'Too many values passed to Phar::mungServer(), expecting an array of any of these strings: PHP_SELF, REQUEST_URI, SCRIPT_FILENAME, SCRIPT_NAME' in %sfrontcontroller19.phar.php:2
+Stack trace:
+#0 %sfrontcontroller19.phar.php(2): Phar::mungServer(Array)
+#1 {main}
+ thrown in %sfrontcontroller19.phar.php on line 2
diff --git a/ext/phar/tests/zip/frontcontroller2.phar.phpt b/ext/phar/tests/zip/frontcontroller2.phar.phpt
new file mode 100644
index 0000000..e143e79
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller2.phar.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Phar front controller PHP test zip-based
+--INI--
+default_charset=UTF-8
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zlib")) die("skip zlib not available"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller2.phar.php
+REQUEST_URI=/frontcontroller2.phar.php/a.php
+PATH_INFO=/a.php
+--FILE_EXTERNAL--
+files/frontcontroller.phar.zip
+--EXPECTHEADERS--
+Content-type: text/html; charset=UTF-8
+--EXPECT--
+hio
diff --git a/ext/phar/tests/zip/frontcontroller20.phar.phpt b/ext/phar/tests/zip/frontcontroller20.phar.phpt
new file mode 100644
index 0000000..b1caf52
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller20.phar.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Phar front controller $_SERVER munging failure 3 zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zlib")) die("skip zlib not available"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller20.phar.php
+REQUEST_URI=/frontcontroller20.phar.php/
+PATH_INFO=/
+--FILE_EXTERNAL--
+files/frontcontroller11.phar.zip
+--EXPECTF--
+Fatal error: Uncaught exception 'PharException' with message 'Non-string value passed to Phar::mungServer(), expecting an array of any of these strings: PHP_SELF, REQUEST_URI, SCRIPT_FILENAME, SCRIPT_NAME' in %sfrontcontroller20.phar.php:2
+Stack trace:
+#0 %sfrontcontroller20.phar.php(2): Phar::mungServer(Array)
+#1 {main}
+ thrown in %sfrontcontroller20.phar.php on line 2
diff --git a/ext/phar/tests/zip/frontcontroller21.phar.phpt b/ext/phar/tests/zip/frontcontroller21.phar.phpt
new file mode 100644
index 0000000..74caa2c
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller21.phar.phpt
@@ -0,0 +1,25 @@
+--TEST--
+Phar front controller $_SERVER munging success zip-based
+--INI--
+default_charset=UTF-8
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zlib")) die("skip zlib not available"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller21.phar.php
+REQUEST_URI=/frontcontroller21.phar.php/index.php?test=hi
+PATH_INFO=/index.php
+QUERY_STRING=test=hi
+--FILE_EXTERNAL--
+files/frontcontroller12.phar.zip
+--EXPECTHEADERS--
+Content-type: text/html; charset=UTF-8
+--EXPECTF--
+%unicode|string%(10) "/index.php"
+string(10) "/index.php"
+string(%d) "phar://%sfrontcontroller21.phar.php/index.php"
+string(18) "/index.php?test=hi"
+string(37) "/frontcontroller21.phar.php/index.php"
+string(27) "/frontcontroller21.phar.php"
+string(%d) "%sfrontcontroller21.phar.php"
+string(45) "/frontcontroller21.phar.php/index.php?test=hi" \ No newline at end of file
diff --git a/ext/phar/tests/zip/frontcontroller3.phar.phpt b/ext/phar/tests/zip/frontcontroller3.phar.phpt
new file mode 100644
index 0000000..88a8a24
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller3.phar.phpt
@@ -0,0 +1,20 @@
+--TEST--
+Phar front controller phps zip-based
+--INI--
+default_charset=UTF-8
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zlib")) die("skip zlib not available"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller3.phar.php
+REQUEST_URI=/frontcontroller3.phar.php/a.phps
+PATH_INFO=/a.phps
+--FILE_EXTERNAL--
+files/frontcontroller.phar.zip
+--EXPECTHEADERS--
+Content-type: text/html; charset=UTF-8
+--EXPECT--
+<code><span style="color: #000000">
+<span style="color: #0000BB">&lt;?php&nbsp;</span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">hio</span><span style="color: #007700">(){}</span>
+</span>
+</code>
diff --git a/ext/phar/tests/zip/frontcontroller4.phar.phpt b/ext/phar/tests/zip/frontcontroller4.phar.phpt
new file mode 100644
index 0000000..ff85eb6
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller4.phar.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Phar front controller index.php relocate (no /) zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zlib")) die("skip zlib not available"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller4.phar.php
+REQUEST_URI=/frontcontroller4.phar.php
+--FILE_EXTERNAL--
+files/frontcontroller.phar.zip
+--EXPECTHEADERS--
+Status: 301 Moved Permanently
+Location: /frontcontroller4.phar.php/index.php
+--EXPECT--
diff --git a/ext/phar/tests/zip/frontcontroller5.phar.phpt b/ext/phar/tests/zip/frontcontroller5.phar.phpt
new file mode 100644
index 0000000..1705fac
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller5.phar.phpt
@@ -0,0 +1,15 @@
+--TEST--
+Phar front controller index.php relocate zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zlib")) die("skip zlib not available"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller5.phar.php
+REQUEST_URI=/frontcontroller5.phar.php/
+PATH_INFO=/
+--FILE_EXTERNAL--
+files/frontcontroller.phar.zip
+--EXPECTHEADERS--
+Status: 301 Moved Permanently
+Location: /frontcontroller5.phar.php/index.php
+--EXPECT--
diff --git a/ext/phar/tests/zip/frontcontroller6.phar.phpt b/ext/phar/tests/zip/frontcontroller6.phar.phpt
new file mode 100644
index 0000000..15489f6
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller6.phar.phpt
@@ -0,0 +1,22 @@
+--TEST--
+Phar front controller 404 zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zlib")) die("skip zlib not available"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller6.phar.php
+REQUEST_URI=/frontcontroller6.phar.php/notfound.php
+PATH_INFO=/notfound.php
+--FILE_EXTERNAL--
+files/frontcontroller.phar.zip
+--EXPECTHEADERS--
+Status: 404 Not Found
+--EXPECT--
+<html>
+ <head>
+ <title>File Not Found</title>
+ </head>
+ <body>
+ <h1>404 - File /notfound.php Not Found</h1>
+ </body>
+</html> \ No newline at end of file
diff --git a/ext/phar/tests/zip/frontcontroller7.phar.phpt b/ext/phar/tests/zip/frontcontroller7.phar.phpt
new file mode 100644
index 0000000..828da0a
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller7.phar.phpt
@@ -0,0 +1,15 @@
+--TEST--
+Phar front controller alternate index file zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zlib")) die("skip zlib not available"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller7.phar.php
+REQUEST_URI=/frontcontroller7.phar.php/
+PATH_INFO=/
+--FILE_EXTERNAL--
+files/frontcontroller2.phar.zip
+--EXPECTHEADERS--
+Status: 301 Moved Permanently
+Location: /frontcontroller7.phar.php/a.php
+--EXPECT--
diff --git a/ext/phar/tests/zip/frontcontroller8.phar.phpt b/ext/phar/tests/zip/frontcontroller8.phar.phpt
new file mode 100644
index 0000000..1b0d133
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller8.phar.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Phar front controller no index file 404 zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller8.phar.php
+REQUEST_URI=/frontcontroller8.phar.php/
+PATH_INFO=/
+--FILE_EXTERNAL--
+files/frontcontroller3.phar.zip
+--EXPECTHEADERS--
+Status: 404 Not Found
+--EXPECT--
+<html>
+ <head>
+ <title>File Not Found</title>
+ </head>
+ <body>
+ <h1>404 - File /index.php Not Found</h1>
+ </body>
+</html> \ No newline at end of file
diff --git a/ext/phar/tests/zip/frontcontroller9.phar.phpt b/ext/phar/tests/zip/frontcontroller9.phar.phpt
new file mode 100644
index 0000000..4f12c9c
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller9.phar.phpt
@@ -0,0 +1,19 @@
+--TEST--
+Phar front controller rewrite array zip-based
+--INI--
+default_charset=UTF-8
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller9.phar.php
+REQUEST_URI=/frontcontroller9.phar.php/hi
+PATH_INFO=/hi
+--FILE_EXTERNAL--
+files/frontcontroller3.phar.zip
+--EXPECTHEADERS--
+Content-type: text/html; charset=UTF-8
+--EXPECT--
+<code><span style="color: #000000">
+<span style="color: #0000BB">&lt;?php&nbsp;</span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">hio</span><span style="color: #007700">(){}</span>
+</span>
+</code> \ No newline at end of file
diff --git a/ext/phar/tests/zip/getalias.phpt b/ext/phar/tests/zip/getalias.phpt
new file mode 100644
index 0000000..9c91763
--- /dev/null
+++ b/ext/phar/tests/zip/getalias.phpt
@@ -0,0 +1,59 @@
+--TEST--
+Phar: getAlias() with an existing phar.zip
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip';
+
+// sanity check with a virgin phar.zip
+$phar = new Phar($fname);
+var_dump($phar->getAlias());
+unset($phar);
+
+copy(dirname(__FILE__) . '/files/metadata.phar.zip', $fname);
+
+// existing phar.zip, no alias set
+$phar = new Phar($fname);
+var_dump($phar->getAlias());
+
+// check that default alias can be overwritten
+$phar->setAlias('jiminycricket');
+var_dump($phar->getAlias());
+unset($phar);
+
+// existing phar.zip, alias set
+$phar = new Phar($fname);
+var_dump($phar->getAlias());
+
+// check that alias can't be set manually
+try {
+ $phar['.phar/alias.txt'] = 'pinocchio';
+} catch (Exception $e) {
+ echo $e->getMessage()."\n";
+}
+var_dump($phar->getAlias());
+
+// check that user-defined alias can be overwritten
+$phar->setAlias('pinocchio');
+var_dump($phar->getAlias());
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip');
+__HALT_COMPILER();
+?>
+--EXPECTF--
+string(%d) "%sgetalias.phar.zip"
+string(%d) "%sgetalias.phar.zip"
+string(13) "jiminycricket"
+string(13) "jiminycricket"
+Cannot set alias ".phar/alias.txt" directly in phar "%sgetalias.phar.zip", use setAlias
+string(13) "jiminycricket"
+string(9) "pinocchio"
+===DONE===
diff --git a/ext/phar/tests/zip/largezip.phpt b/ext/phar/tests/zip/largezip.phpt
new file mode 100644
index 0000000..a8438eb
--- /dev/null
+++ b/ext/phar/tests/zip/largezip.phpt
@@ -0,0 +1,29 @@
+--TEST--
+Phar: large zip file (zip edge cases)
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip.php';
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.phar.zip.php';
+$pname = 'phar://' . $fname;
+$pname2 = 'phar://' . $fname2;
+
+$p = new Phar($fname);
+$p['big'] = str_repeat(str_repeat('hi', 100), 1000);
+$p['big2'] = str_repeat(str_repeat('hi', 100), 1000);
+
+copy($fname, $fname2);
+$p2 = new Phar($fname2);
+var_dump(strlen($p2['big']->getContent()));
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip.php'); ?>
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar.zip.php'); ?>
+--EXPECT--
+int(200000)
+===DONE===
diff --git a/ext/phar/tests/zip/metadata_write_commit.phpt b/ext/phar/tests/zip/metadata_write_commit.phpt
new file mode 100644
index 0000000..1629636
--- /dev/null
+++ b/ext/phar/tests/zip/metadata_write_commit.phpt
@@ -0,0 +1,88 @@
+--TEST--
+Phar with meta-data (write) zip-based
+--SKIPIF--
+<?php
+if (!extension_loaded("phar")) die("skip");
+if (version_compare(PHP_VERSION, "6.0", ">")) die("skip pre-unicode version of PHP required");
+?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip.php';
+$f2name = dirname(__FILE__) . '/files/metadata.phar.zip';
+$pname = 'phar://' . $fname;
+$p2name = 'phar://' . $f2name;
+
+$file = "<?php __HALT_COMPILER(); ?>";
+
+$files = array();
+$files['a'] = array('cont' => 'a');
+$files['b'] = array('cont' => 'b', 'meta' => 'hi there');
+$files['c'] = array('cont' => 'c', 'meta' => array('hi', 'there'));
+$files['d'] = array('cont' => 'd', 'meta' => array('hi'=>'there','foo'=>'bar'));
+
+foreach($files as $name => $cont) {
+ var_dump(file_get_contents($p2name.'/'.$name));
+}
+
+copy($f2name, $fname);
+$phar = new Phar($fname);
+$phar->startBuffering();
+$phar['a']->setMetadata(42);
+$phar['b']->setMetadata(NULL);
+$phar['c']->setMetadata(array(25, 'foo'=>'bar'));
+$phar['d']->setMetadata(true);
+$phar->setMetadata('hi');
+
+foreach($files as $name => $cont) {
+ var_dump($phar[$name]->getMetadata());
+}
+$phar->stopBuffering();
+
+unset($phar);
+
+$phar = new Phar($fname);
+
+foreach($files as $name => $cont) {
+ var_dump(file_get_contents($pname.'/'.$name));
+}
+
+foreach($files as $name => $cont) {
+ var_dump($phar[$name]->getMetadata());
+}
+var_dump($phar->getMetadata());
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip.php'); ?>
+--EXPECT--
+string(1) "a"
+string(1) "b"
+string(1) "c"
+string(1) "d"
+int(42)
+NULL
+array(2) {
+ [0]=>
+ int(25)
+ ["foo"]=>
+ string(3) "bar"
+}
+bool(true)
+string(1) "a"
+string(1) "b"
+string(1) "c"
+string(1) "d"
+int(42)
+NULL
+array(2) {
+ [0]=>
+ int(25)
+ ["foo"]=>
+ string(3) "bar"
+}
+bool(true)
+string(2) "hi"
+===DONE===
diff --git a/ext/phar/tests/zip/metadata_write_commitU.phpt b/ext/phar/tests/zip/metadata_write_commitU.phpt
new file mode 100644
index 0000000..bc589af
--- /dev/null
+++ b/ext/phar/tests/zip/metadata_write_commitU.phpt
@@ -0,0 +1,88 @@
+--TEST--
+Phar with meta-data (write) zip-based
+--SKIPIF--
+<?php
+if (!extension_loaded("phar")) die("skip");
+if (version_compare(PHP_VERSION, "6.0", "<")) die("skip Unicode support required");
+?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip.php';
+$f2name = dirname(__FILE__) . '/files/metadata.phar.zip';
+$pname = 'phar://' . $fname;
+$p2name = 'phar://' . $f2name;
+
+$file = "<?php __HALT_COMPILER(); ?>";
+
+$files = array();
+$files['a'] = array('cont' => 'a');
+$files['b'] = array('cont' => 'b', 'meta' => 'hi there');
+$files['c'] = array('cont' => 'c', 'meta' => array('hi', 'there'));
+$files['d'] = array('cont' => 'd', 'meta' => array('hi'=>'there','foo'=>'bar'));
+
+foreach($files as $name => $cont) {
+ var_dump(file_get_contents($p2name.'/'.$name));
+}
+
+copy($f2name, $fname);
+$phar = new Phar($fname);
+$phar->startBuffering();
+$phar['a']->setMetadata(42);
+$phar['b']->setMetadata(NULL);
+$phar['c']->setMetadata(array(25, 'foo'=>'bar'));
+$phar['d']->setMetadata(true);
+$phar->setMetadata('hi');
+
+foreach($files as $name => $cont) {
+ var_dump($phar[$name]->getMetadata());
+}
+$phar->stopBuffering();
+
+unset($phar);
+
+$phar = new Phar($fname);
+
+foreach($files as $name => $cont) {
+ var_dump(file_get_contents($pname.'/'.$name));
+}
+
+foreach($files as $name => $cont) {
+ var_dump($phar[$name]->getMetadata());
+}
+var_dump($phar->getMetadata());
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip.php'); ?>
+--EXPECT--
+string(1) "a"
+string(1) "b"
+string(1) "c"
+string(1) "d"
+int(42)
+NULL
+array(2) {
+ [0]=>
+ int(25)
+ [u"foo"]=>
+ unicode(3) "bar"
+}
+bool(true)
+string(1) "a"
+string(1) "b"
+string(1) "c"
+string(1) "d"
+int(42)
+NULL
+array(2) {
+ [0]=>
+ int(25)
+ [u"foo"]=>
+ unicode(3) "bar"
+}
+bool(true)
+unicode(2) "hi"
+===DONE===
diff --git a/ext/phar/tests/zip/notphar.phpt b/ext/phar/tests/zip/notphar.phpt
new file mode 100644
index 0000000..c0648c4
--- /dev/null
+++ b/ext/phar/tests/zip/notphar.phpt
@@ -0,0 +1,24 @@
+--TEST--
+Phar: a non-executable zip with no stub named .phar.zip
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=1
+detect_unicode=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip';
+$pname = 'phar://' . $fname;
+
+copy(dirname(__FILE__) . '/files/zip.zip', $fname);
+include $fname;
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip');
+__HALT_COMPILER();
+?>
+--EXPECTF--
+Warning: include(phar://%snotphar.phar.zip/.phar/stub.php): failed to open stream: '%snotphar.phar.zip' is not a phar archive. Use PharData::__construct() for a standard zip or tar archive in %snotphar.php on line %d
+PK%a
diff --git a/ext/phar/tests/zip/odt.phpt b/ext/phar/tests/zip/odt.phpt
new file mode 100644
index 0000000..b007d44
--- /dev/null
+++ b/ext/phar/tests/zip/odt.phpt
@@ -0,0 +1,35 @@
+--TEST--
+Phar: test a zip archive created by openoffice
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+<?php if (!extension_loaded("zlib")) die("skip zlib not available"); ?>
+--FILE--
+<?php
+$a = new PharData(dirname(__FILE__) . '/files/odt.odt');
+foreach (new RecursiveIteratorIterator($a, RecursiveIteratorIterator::LEAVES_ONLY) as $b) {
+ if ($b->isDir()) {
+ echo "dir " . $b->getPathName() . "\n";
+ } else {
+ echo $b->getPathName() . "\n";
+ }
+}
+// this next line is for increased code coverage
+try {
+ $b = new Phar(dirname(__FILE__) . '/files/odt.odt');
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--EXPECTF--
+phar://%sodt.odt/Configurations2/accelerator%ccurrent.xml
+phar://%sodt.odt/META-INF%cmanifest.xml
+phar://%sodt.odt/Thumbnails%cthumbnail.png
+phar://%sodt.odt%ccontent.xml
+phar://%sodt.odt%cmeta.xml
+phar://%sodt.odt%cmimetype
+phar://%sodt.odt%csettings.xml
+phar://%sodt.odt%cstyles.xml
+Cannot create phar '%sodt.odt', file extension (or combination) not recognised or the directory does not exist
+===DONE===
diff --git a/ext/phar/tests/zip/open_for_write_existing.phpt b/ext/phar/tests/zip/open_for_write_existing.phpt
new file mode 100644
index 0000000..bbf036c
--- /dev/null
+++ b/ext/phar/tests/zip/open_for_write_existing.phpt
@@ -0,0 +1,39 @@
+--TEST--
+Phar: fopen a .phar for writing (existing file) zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+phar.require_hash=0
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip';
+$alias = 'phar://' . $fname;
+
+$phar = new Phar($fname);
+$phar->setStub('<?php __HALT_COMPILER(); ?>');
+
+$files = array();
+
+$files['a.php'] = '<?php echo "This is a\n"; ?>';
+$files['b.php'] = '<?php echo "This is b\n"; ?>';
+$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>';
+
+foreach ($files as $n => $file) {
+ $phar[$n] = $file;
+}
+$phar->stopBuffering();
+
+$fp = fopen($alias . '/b/c.php', 'wb');
+fwrite($fp, b'extra');
+fclose($fp);
+include $alias . '/b/c.php';
+?>
+
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip'); ?>
+--EXPECT--
+extra
+===DONE===
diff --git a/ext/phar/tests/zip/open_for_write_existing_b.phpt b/ext/phar/tests/zip/open_for_write_existing_b.phpt
new file mode 100644
index 0000000..b997c68
--- /dev/null
+++ b/ext/phar/tests/zip/open_for_write_existing_b.phpt
@@ -0,0 +1,55 @@
+--TEST--
+Phar: fopen a .phar for writing (existing file) zip-based
+--SKIPIF--
+<?php
+if (!extension_loaded("phar")) die("skip");
+if (version_compare(PHP_VERSION, "5.3", "<")) die("skip requires 5.3 or later");
+?>
+--INI--
+phar.readonly=0
+phar.require_hash=0
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip';
+$alias = 'phar://' . $fname;
+
+$phar = new Phar($fname);
+$phar->setStub('<?php __HALT_COMPILER(); ?>');
+
+$files = array();
+
+$files['a.php'] = '<?php echo "This is a\n"; ?>';
+$files['b.php'] = '<?php echo "This is b\n"; ?>';
+$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>';
+
+foreach ($files as $n => $file) {
+ $phar[$n] = $file;
+}
+$phar->stopBuffering();
+
+ini_set('phar.readonly', 1);
+
+function err_handler($errno, $errstr, $errfile, $errline) {
+ echo "Catchable fatal error: $errstr in $errfile on line $errline\n";
+}
+
+set_error_handler("err_handler", E_RECOVERABLE_ERROR);
+
+$fp = fopen($alias . '/b/c.php', 'wb');
+fwrite($fp, b'extra');
+fclose($fp);
+include $alias . '/b/c.php';
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip'); ?>
+--EXPECTF--
+
+Warning: fopen(phar://%sopen_for_write_existing_b.phar.zip/b/c.php): failed to open stream: phar error: write operations disabled by the php.ini setting phar.readonly in %sopen_for_write_existing_b.php on line %d
+
+Warning: fwrite() expects parameter 1 to be resource, boolean given in %spen_for_write_existing_b.php on line %d
+
+Warning: fclose() expects parameter 1 to be resource, boolean given in %spen_for_write_existing_b.php on line %d
+This is b/c
+===DONE===
diff --git a/ext/phar/tests/zip/open_for_write_existing_b_5_2.phpt b/ext/phar/tests/zip/open_for_write_existing_b_5_2.phpt
new file mode 100644
index 0000000..b88a496
--- /dev/null
+++ b/ext/phar/tests/zip/open_for_write_existing_b_5_2.phpt
@@ -0,0 +1,53 @@
+--TEST--
+Phar: fopen a .phar for writing (existing file) zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (version_compare(PHP_VERSION, "5.3", ">")) die("skip requires 5.2 or earlier"); ?>
+--INI--
+phar.readonly=0
+phar.require_hash=0
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip';
+$alias = 'phar://' . $fname;
+
+$phar = new Phar($fname);
+$phar->setStub('<?php __HALT_COMPILER(); ?>');
+
+$files = array();
+
+$files['a.php'] = '<?php echo "This is a\n"; ?>';
+$files['b.php'] = '<?php echo "This is b\n"; ?>';
+$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>';
+
+foreach ($files as $n => $file) {
+ $phar[$n] = $file;
+}
+$phar->stopBuffering();
+
+ini_set('phar.readonly', 1);
+
+function err_handler($errno, $errstr, $errfile, $errline) {
+ echo "Catchable fatal error: $errstr in $errfile on line $errline\n";
+}
+
+set_error_handler("err_handler", E_RECOVERABLE_ERROR);
+
+$fp = fopen($alias . '/b/c.php', 'wb');
+fwrite($fp, 'extra');
+fclose($fp);
+include $alias . '/b/c.php';
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip'); ?>
+--EXPECTF--
+
+Warning: fopen(phar://%sopen_for_write_existing_b_5_2.phar.zip/b/c.php): failed to open stream: phar error: write operations disabled by the php.ini setting phar.readonly in %sopen_for_write_existing_b_5_2.php on line %d
+
+Warning: fwrite(): supplied argument is not a valid stream resource in %spen_for_write_existing_b_5_2.php on line %d
+
+Warning: fclose(): supplied argument is not a valid stream resource in %spen_for_write_existing_b_5_2.php on line %d
+This is b/c
+===DONE===
diff --git a/ext/phar/tests/zip/open_for_write_existing_c.phpt b/ext/phar/tests/zip/open_for_write_existing_c.phpt
new file mode 100644
index 0000000..313ee4a
--- /dev/null
+++ b/ext/phar/tests/zip/open_for_write_existing_c.phpt
@@ -0,0 +1,49 @@
+--TEST--
+Phar: fopen a .phar for writing (existing file) zip-based
+--SKIPIF--
+<?php
+if (!extension_loaded("phar")) die("skip");
+if (version_compare(PHP_VERSION, "5.3", "<")) die("skip requires 5.3 or later");
+?>
+--INI--
+phar.readonly=0
+phar.require_hash=0
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip';
+$alias = 'phar://' . $fname;
+
+$phar = new Phar($fname);
+$phar->setStub('<?php __HALT_COMPILER(); ?>');
+
+$files = array();
+
+$files['a.php'] = '<?php echo "This is a\n"; ?>';
+$files['b.php'] = '<?php echo "This is b\n"; ?>';
+$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>';
+
+foreach ($files as $n => $file) {
+ $phar[$n] = $file;
+}
+$phar->stopBuffering();
+
+ini_set('phar.readonly', 1);
+
+$fp = fopen($alias . '/b/c.php', 'wb');
+fwrite($fp, b'extra');
+fclose($fp);
+include $alias . '/b/c.php';
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip'); ?>
+--EXPECTF--
+
+Warning: fopen(phar://%sopen_for_write_existing_c.phar.zip/b/c.php): failed to open stream: phar error: write operations disabled by the php.ini setting phar.readonly in %sopen_for_write_existing_c.php on line %d
+
+Warning: fwrite() expects parameter 1 to be resource, boolean given in %spen_for_write_existing_c.php on line %d
+
+Warning: fclose() expects parameter 1 to be resource, boolean given in %spen_for_write_existing_c.php on line %d
+This is b/c
+===DONE===
diff --git a/ext/phar/tests/zip/open_for_write_existing_c_5_2.phpt b/ext/phar/tests/zip/open_for_write_existing_c_5_2.phpt
new file mode 100644
index 0000000..9e23fd5
--- /dev/null
+++ b/ext/phar/tests/zip/open_for_write_existing_c_5_2.phpt
@@ -0,0 +1,47 @@
+--TEST--
+Phar: fopen a .phar for writing (existing file) zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (version_compare(PHP_VERSION, "5.3", ">")) die("skip requires 5.2 or earlier"); ?>
+--INI--
+phar.readonly=0
+phar.require_hash=0
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip';
+$alias = 'phar://' . $fname;
+
+$phar = new Phar($fname);
+$phar->setStub('<?php __HALT_COMPILER(); ?>');
+
+$files = array();
+
+$files['a.php'] = '<?php echo "This is a\n"; ?>';
+$files['b.php'] = '<?php echo "This is b\n"; ?>';
+$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>';
+
+foreach ($files as $n => $file) {
+ $phar[$n] = $file;
+}
+$phar->stopBuffering();
+
+ini_set('phar.readonly', 1);
+
+$fp = fopen($alias . '/b/c.php', 'wb');
+fwrite($fp, 'extra');
+fclose($fp);
+include $alias . '/b/c.php';
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip'); ?>
+--EXPECTF--
+
+Warning: fopen(phar://%sopen_for_write_existing_c_5_2.phar.zip/b/c.php): failed to open stream: phar error: write operations disabled by the php.ini setting phar.readonly in %sopen_for_write_existing_c_5_2.php on line %d
+
+Warning: fwrite(): supplied argument is not a valid stream resource in %sopen_for_write_existing_c_5_2.php on line %d
+
+Warning: fclose(): supplied argument is not a valid stream resource in %sopen_for_write_existing_c_5_2.php on line %d
+This is b/c
+===DONE===
diff --git a/ext/phar/tests/zip/open_for_write_newfile.phpt b/ext/phar/tests/zip/open_for_write_newfile.phpt
new file mode 100644
index 0000000..ffcae0f
--- /dev/null
+++ b/ext/phar/tests/zip/open_for_write_newfile.phpt
@@ -0,0 +1,42 @@
+--TEST--
+Phar: fopen a .phar for writing (new file) zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+phar.require_hash=0
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip';
+$alias = 'phar://' . $fname;
+
+$phar = new Phar($fname);
+$phar->setStub('<?php __HALT_COMPILER(); ?>');
+
+$files = array();
+
+$files['a.php'] = '<?php echo "This is a\n"; ?>';
+$files['b.php'] = '<?php echo "This is b\n"; ?>';
+$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>';
+
+foreach ($files as $n => $file) {
+ $phar[$n] = $file;
+}
+$phar->stopBuffering();
+
+$fp = fopen($alias . '/b/new.php', 'wb');
+fwrite($fp, b'extra');
+fclose($fp);
+
+include $alias . '/b/c.php';
+include $alias . '/b/new.php';
+?>
+
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip'); ?>
+--EXPECT--
+This is b/c
+extra
+===DONE===
diff --git a/ext/phar/tests/zip/open_for_write_newfile_b.phpt b/ext/phar/tests/zip/open_for_write_newfile_b.phpt
new file mode 100644
index 0000000..96fd2e4
--- /dev/null
+++ b/ext/phar/tests/zip/open_for_write_newfile_b.phpt
@@ -0,0 +1,63 @@
+--TEST--
+Phar: fopen a .phar for writing (new file) zip-based
+--SKIPIF--
+<?php
+if (!extension_loaded("phar")) die("skip");
+if (version_compare(PHP_VERSION, "5.3", "<")) die("skip requires 5.3 or later");
+?>
+--INI--
+phar.readonly=0
+phar.require_hash=0
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip';
+$alias = 'phar://' . $fname;
+
+$phar = new Phar($fname);
+$phar->setStub('<?php __HALT_COMPILER(); ?>');
+
+$files = array();
+
+$files['a.php'] = '<?php echo "This is a\n"; ?>';
+$files['b.php'] = '<?php echo "This is b\n"; ?>';
+$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>';
+
+foreach ($files as $n => $file) {
+ $phar[$n] = $file;
+}
+$phar->stopBuffering();
+
+ini_set('phar.readonly', 1);
+
+function err_handler($errno, $errstr, $errfile, $errline) {
+ echo "Catchable fatal error: $errstr in $errfile on line $errline\n";
+}
+
+set_error_handler("err_handler", E_RECOVERABLE_ERROR);
+
+$fp = fopen($alias . '/b/new.php', 'wb');
+fwrite($fp, b'extra');
+fclose($fp);
+
+include $alias . '/b/c.php';
+include $alias . '/b/new.php';
+?>
+
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip'); ?>
+--EXPECTF--
+
+Warning: fopen(phar://%sopen_for_write_newfile_b.phar.zip/b/new.php): failed to open stream: phar error: write operations disabled by the php.ini setting phar.readonly in %sopen_for_write_newfile_b.php on line %d
+
+Warning: fwrite() expects parameter 1 to be resource, boolean given in %sopen_for_write_newfile_b.php on line %d
+
+Warning: fclose() expects parameter 1 to be resource, boolean given in %sopen_for_write_newfile_b.php on line %d
+This is b/c
+
+Warning: include(phar://%sopen_for_write_newfile_b.phar.zip/b/new.php): failed to open stream: phar error: "b/new.php" is not a file in phar "%sopen_for_write_newfile_b.phar.zip" in %sopen_for_write_newfile_b.php on line %d
+
+Warning: include(): Failed opening 'phar://%sopen_for_write_newfile_b.phar.zip/b/new.php' for inclusion (include_path='%s') in %sopen_for_write_newfile_b.php on line %d
+
+===DONE===
diff --git a/ext/phar/tests/zip/open_for_write_newfile_b_5_2.phpt b/ext/phar/tests/zip/open_for_write_newfile_b_5_2.phpt
new file mode 100644
index 0000000..3032427
--- /dev/null
+++ b/ext/phar/tests/zip/open_for_write_newfile_b_5_2.phpt
@@ -0,0 +1,61 @@
+--TEST--
+Phar: fopen a .phar for writing (new file) zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (version_compare(PHP_VERSION, "5.3", ">")) die("skip requires 5.2 or earlier"); ?>
+--INI--
+phar.readonly=0
+phar.require_hash=0
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip';
+$alias = 'phar://' . $fname;
+
+$phar = new Phar($fname);
+$phar->setStub('<?php __HALT_COMPILER(); ?>');
+
+$files = array();
+
+$files['a.php'] = '<?php echo "This is a\n"; ?>';
+$files['b.php'] = '<?php echo "This is b\n"; ?>';
+$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>';
+
+foreach ($files as $n => $file) {
+ $phar[$n] = $file;
+}
+$phar->stopBuffering();
+
+ini_set('phar.readonly', 1);
+
+function err_handler($errno, $errstr, $errfile, $errline) {
+ echo "Catchable fatal error: $errstr in $errfile on line $errline\n";
+}
+
+set_error_handler("err_handler", E_RECOVERABLE_ERROR);
+
+$fp = fopen($alias . '/b/new.php', 'wb');
+fwrite($fp, 'extra');
+fclose($fp);
+
+include $alias . '/b/c.php';
+include $alias . '/b/new.php';
+?>
+
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip'); ?>
+--EXPECTF--
+
+Warning: fopen(phar://%sopen_for_write_newfile_b_5_2.phar.zip/b/new.php): failed to open stream: phar error: write operations disabled by the php.ini setting phar.readonly in %sopen_for_write_newfile_b_5_2.php on line %d
+
+Warning: fwrite(): supplied argument is not a valid stream resource in %sopen_for_write_newfile_b_5_2.php on line %d
+
+Warning: fclose(): supplied argument is not a valid stream resource in %sopen_for_write_newfile_b_5_2.php on line %d
+This is b/c
+
+Warning: include(phar://%sopen_for_write_newfile_b_5_2.phar.zip/b/new.php): failed to open stream: phar error: "b/new.php" is not a file in phar "%sopen_for_write_newfile_b_5_2.phar.zip" in %sopen_for_write_newfile_b_5_2.php on line %d
+
+Warning: include(): Failed opening 'phar://%sopen_for_write_newfile_b_5_2.phar.zip/b/new.php' for inclusion (include_path='%s') in %sopen_for_write_newfile_b_5_2.php on line %d
+
+===DONE===
diff --git a/ext/phar/tests/zip/open_for_write_newfile_c.phpt b/ext/phar/tests/zip/open_for_write_newfile_c.phpt
new file mode 100644
index 0000000..ef580cb
--- /dev/null
+++ b/ext/phar/tests/zip/open_for_write_newfile_c.phpt
@@ -0,0 +1,57 @@
+--TEST--
+Phar: fopen a .phar for writing (new file) zip-based
+--SKIPIF--
+<?php
+if (!extension_loaded("phar")) die("skip");
+if (version_compare(PHP_VERSION, "5.3", "<")) die("skip requires 5.3 or later");
+?>
+--INI--
+phar.readonly=0
+phar.require_hash=0
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip';
+$alias = 'phar://' . $fname;
+
+$phar = new Phar($fname);
+$phar->setStub('<?php __HALT_COMPILER(); ?>');
+
+$files = array();
+
+$files['a.php'] = '<?php echo "This is a\n"; ?>';
+$files['b.php'] = '<?php echo "This is b\n"; ?>';
+$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>';
+
+foreach ($files as $n => $file) {
+ $phar[$n] = $file;
+}
+$phar->stopBuffering();
+
+ini_set('phar.readonly', 1);
+
+$fp = fopen($alias . '/b/new.php', 'wb');
+fwrite($fp, b'extra');
+fclose($fp);
+
+include $alias . '/b/c.php';
+include $alias . '/b/new.php';
+?>
+
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip'); ?>
+--EXPECTF--
+
+Warning: fopen(phar://%sopen_for_write_newfile_c.phar.zip/b/new.php): failed to open stream: phar error: write operations disabled by the php.ini setting phar.readonly in %sopen_for_write_newfile_c.php on line %d
+
+Warning: fwrite() expects parameter 1 to be resource, boolean given in %sopen_for_write_newfile_c.php on line %d
+
+Warning: fclose() expects parameter 1 to be resource, boolean given in %sopen_for_write_newfile_c.php on line %d
+This is b/c
+
+Warning: include(phar://%sopen_for_write_newfile_c.phar.zip/b/new.php): failed to open stream: phar error: "b/new.php" is not a file in phar "%sopen_for_write_newfile_c.phar.zip" in %sopen_for_write_newfile_c.php on line %d
+
+Warning: include(): Failed opening 'phar://%sopen_for_write_newfile_c.phar.zip/b/new.php' for inclusion (include_path='%s') in %sopen_for_write_newfile_c.php on line %d
+
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/zip/open_for_write_newfile_c_5_2.phpt b/ext/phar/tests/zip/open_for_write_newfile_c_5_2.phpt
new file mode 100644
index 0000000..9bf5af5
--- /dev/null
+++ b/ext/phar/tests/zip/open_for_write_newfile_c_5_2.phpt
@@ -0,0 +1,55 @@
+--TEST--
+Phar: fopen a .phar for writing (new file) zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (version_compare(PHP_VERSION, "5.3", ">")) die("skip requires 5.2 or earlier"); ?>
+--INI--
+phar.readonly=0
+phar.require_hash=0
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip';
+$alias = 'phar://' . $fname;
+
+$phar = new Phar($fname);
+$phar->setStub('<?php __HALT_COMPILER(); ?>');
+
+$files = array();
+
+$files['a.php'] = '<?php echo "This is a\n"; ?>';
+$files['b.php'] = '<?php echo "This is b\n"; ?>';
+$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>';
+
+foreach ($files as $n => $file) {
+ $phar[$n] = $file;
+}
+$phar->stopBuffering();
+
+ini_set('phar.readonly', 1);
+
+$fp = fopen($alias . '/b/new.php', 'wb');
+fwrite($fp, 'extra');
+fclose($fp);
+
+include $alias . '/b/c.php';
+include $alias . '/b/new.php';
+?>
+
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip'); ?>
+--EXPECTF--
+
+Warning: fopen(phar://%sopen_for_write_newfile_c_5_2.phar.zip/b/new.php): failed to open stream: phar error: write operations disabled by the php.ini setting phar.readonly in %sopen_for_write_newfile_c_5_2.php on line %d
+
+Warning: fwrite(): supplied argument is not a valid stream resource in %sopen_for_write_newfile_c_5_2.php on line %d
+
+Warning: fclose(): supplied argument is not a valid stream resource in %sopen_for_write_newfile_c_5_2.php on line %d
+This is b/c
+
+Warning: include(phar://%sopen_for_write_newfile_c_5_2.phar.zip/b/new.php): failed to open stream: phar error: "b/new.php" is not a file in phar "%sopen_for_write_newfile_c_5_2.phar.zip" in %sopen_for_write_newfile_c_5_2.php on line %d
+
+Warning: include(): Failed opening 'phar://%sopen_for_write_newfile_c_5_2.phar.zip/b/new.php' for inclusion (include_path='%s') in %sopen_for_write_newfile_c_5_2.php on line %d
+
+===DONE===
diff --git a/ext/phar/tests/zip/phar_begin_setstub_commit.phpt b/ext/phar/tests/zip/phar_begin_setstub_commit.phpt
new file mode 100644
index 0000000..dc59f2f
--- /dev/null
+++ b/ext/phar/tests/zip/phar_begin_setstub_commit.phpt
@@ -0,0 +1,71 @@
+--TEST--
+Phar::startBuffering()/setStub()/stopBuffering() zip-based
+--SKIPIF--
+<?php
+if (!extension_loaded("phar")) die("skip");
+if (version_compare(PHP_VERSION, "6.0", ">")) die("skip pre-unicode version of PHP required");
+?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+$p = new Phar(dirname(__FILE__) . '/brandnewphar.phar.zip', 0, 'brandnewphar.phar');
+var_dump($p->isFileFormat(Phar::ZIP));
+//var_dump($p->getStub());
+var_dump($p->isBuffering());
+$p->startBuffering();
+var_dump($p->isBuffering());
+$p['a.php'] = '<?php var_dump("Hello");';
+$p->setStub('<?php var_dump("First"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>');
+include 'phar://brandnewphar.phar/a.php';
+var_dump($p->getStub());
+$p['b.php'] = '<?php var_dump("World");';
+$p->setStub('<?php var_dump("Second"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER();');
+include 'phar://brandnewphar.phar/b.php';
+var_dump($p->getStub());
+$p->stopBuffering();
+echo "===COMMIT===\n";
+var_dump($p->isBuffering());
+include 'phar://brandnewphar.phar/a.php';
+include 'phar://brandnewphar.phar/b.php';
+var_dump($p->getStub());
+
+// add portion to test setting stub from resource
+file_put_contents(dirname(__FILE__) . '/myfakestub.php', '<?php var_dump("First resource"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>');
+$a = fopen(dirname(__FILE__) . '/myfakestub.php', 'rb');
+$p->setStub($a);
+var_dump($p->getStub());
+$c = strlen('<?php var_dump("First resource"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>');
+file_put_contents(dirname(__FILE__) . '/myfakestub.php', '<?php var_dump("First resource"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>' . 'extra stuff');
+fseek($a, 0);
+$p->setStub($a, $c);
+var_dump($p->getStub());
+fclose($a);
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/brandnewphar.phar.zip');
+unlink(dirname(__FILE__) . '/myfakestub.php');
+?>
+--EXPECT--
+bool(true)
+bool(false)
+bool(true)
+string(5) "Hello"
+string(84) "<?php var_dump("First"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>
+"
+string(5) "World"
+string(85) "<?php var_dump("Second"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>
+"
+===COMMIT===
+bool(false)
+string(5) "Hello"
+string(5) "World"
+string(85) "<?php var_dump("Second"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>
+"
+string(93) "<?php var_dump("First resource"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>
+"
+string(93) "<?php var_dump("First resource"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>
+"
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/zip/phar_begin_setstub_commitU.phpt b/ext/phar/tests/zip/phar_begin_setstub_commitU.phpt
new file mode 100644
index 0000000..2956fc6
--- /dev/null
+++ b/ext/phar/tests/zip/phar_begin_setstub_commitU.phpt
@@ -0,0 +1,71 @@
+--TEST--
+Phar::startBuffering()/setStub()/stopBuffering() zip-based
+--SKIPIF--
+<?php
+if (!extension_loaded("phar")) die("skip");
+if (version_compare(PHP_VERSION, "6.0", "<")) die("skip Unicode support required");
+?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+$p = new Phar(dirname(__FILE__) . '/brandnewphar.phar.zip', 0, 'brandnewphar.phar');
+var_dump($p->isFileFormat(Phar::ZIP));
+//var_dump($p->getStub());
+var_dump($p->isBuffering());
+$p->startBuffering();
+var_dump($p->isBuffering());
+$p['a.php'] = '<?php var_dump("Hello");';
+$p->setStub('<?php var_dump("First"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>');
+include 'phar://brandnewphar.phar/a.php';
+var_dump($p->getStub());
+$p['b.php'] = '<?php var_dump("World");';
+$p->setStub('<?php var_dump("Second"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER();');
+include 'phar://brandnewphar.phar/b.php';
+var_dump($p->getStub());
+$p->stopBuffering();
+echo "===COMMIT===\n";
+var_dump($p->isBuffering());
+include 'phar://brandnewphar.phar/a.php';
+include 'phar://brandnewphar.phar/b.php';
+var_dump($p->getStub());
+
+// add portion to test setting stub from resource
+file_put_contents(dirname(__FILE__) . '/myfakestub.php', '<?php var_dump("First resource"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>');
+$a = fopen(dirname(__FILE__) . '/myfakestub.php', 'rb');
+$p->setStub($a);
+var_dump($p->getStub());
+$c = strlen('<?php var_dump("First resource"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>');
+file_put_contents(dirname(__FILE__) . '/myfakestub.php', '<?php var_dump("First resource"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>' . 'extra stuff');
+fseek($a, 0);
+$p->setStub($a, $c);
+var_dump($p->getStub());
+fclose($a);
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/brandnewphar.phar.zip');
+unlink(dirname(__FILE__) . '/myfakestub.php');
+?>
+--EXPECT--
+bool(true)
+bool(false)
+bool(true)
+unicode(5) "Hello"
+string(84) "<?php var_dump("First"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>
+"
+unicode(5) "World"
+string(85) "<?php var_dump("Second"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>
+"
+===COMMIT===
+bool(false)
+unicode(5) "Hello"
+unicode(5) "World"
+string(85) "<?php var_dump("Second"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>
+"
+string(93) "<?php var_dump("First resource"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>
+"
+string(93) "<?php var_dump("First resource"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>
+"
+===DONE===
diff --git a/ext/phar/tests/zip/phar_buildfromiterator4.phpt b/ext/phar/tests/zip/phar_buildfromiterator4.phpt
new file mode 100644
index 0000000..cc11fe5
--- /dev/null
+++ b/ext/phar/tests/zip/phar_buildfromiterator4.phpt
@@ -0,0 +1,66 @@
+--TEST--
+Phar::buildFromIterator() iterator, 1 file passed in zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+class myIterator implements Iterator
+{
+ var $a;
+ function __construct(array $a)
+ {
+ $this->a = $a;
+ }
+ function next() {
+ echo "next\n";
+ return next($this->a);
+ }
+ function current() {
+ echo "current\n";
+ return current($this->a);
+ }
+ function key() {
+ echo "key\n";
+ return key($this->a);
+ }
+ function valid() {
+ echo "valid\n";
+ return current($this->a);
+ }
+ function rewind() {
+ echo "rewind\n";
+ return reset($this->a);
+ }
+}
+try {
+ chdir(dirname(__FILE__));
+ $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar.zip');
+ var_dump($phar->buildFromIterator(new myIterator(array('a' => basename(__FILE__, 'php') . 'phpt'))));
+ var_dump($phar->isFileFormat(Phar::ZIP));
+} catch (Exception $e) {
+ var_dump(get_class($e));
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/buildfromiterator.phar.zip');
+__HALT_COMPILER();
+?>
+--EXPECTF--
+rewind
+valid
+current
+key
+next
+valid
+array(1) {
+ ["a"]=>
+ string(%d) "%sphar_buildfromiterator4.phpt"
+}
+bool(true)
+===DONE===
diff --git a/ext/phar/tests/zip/phar_buildfromiterator5.phpt b/ext/phar/tests/zip/phar_buildfromiterator5.phpt
new file mode 100644
index 0000000..1d14686
--- /dev/null
+++ b/ext/phar/tests/zip/phar_buildfromiterator5.phpt
@@ -0,0 +1,59 @@
+--TEST--
+Phar::buildFromIterator() iterator, iterator returns non-string zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+class myIterator implements Iterator
+{
+ var $a;
+ function __construct(array $a)
+ {
+ $this->a = $a;
+ }
+ function next() {
+ echo "next\n";
+ return next($this->a);
+ }
+ function current() {
+ echo "current\n";
+ return current($this->a);
+ }
+ function key() {
+ echo "key\n";
+ return key($this->a);
+ }
+ function valid() {
+ echo "valid\n";
+ return current($this->a);
+ }
+ function rewind() {
+ echo "rewind\n";
+ return reset($this->a);
+ }
+}
+try {
+ chdir(dirname(__FILE__));
+ $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar.zip');
+ var_dump($phar->buildFromIterator(new myIterator(array('a' => new stdClass))));
+} catch (Exception $e) {
+ var_dump(get_class($e));
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/buildfromiterator.phar.zip');
+__HALT_COMPILER();
+?>
+--EXPECTF--
+rewind
+valid
+current
+%s(24) "UnexpectedValueException"
+Iterator myIterator returned an invalid value (must return a string)
+===DONE===
diff --git a/ext/phar/tests/zip/phar_buildfromiterator6.phpt b/ext/phar/tests/zip/phar_buildfromiterator6.phpt
new file mode 100644
index 0000000..936dda9
--- /dev/null
+++ b/ext/phar/tests/zip/phar_buildfromiterator6.phpt
@@ -0,0 +1,60 @@
+--TEST--
+Phar::buildFromIterator() iterator, key is int zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+class myIterator implements Iterator
+{
+ var $a;
+ function __construct(array $a)
+ {
+ $this->a = $a;
+ }
+ function next() {
+ echo "next\n";
+ return next($this->a);
+ }
+ function current() {
+ echo "current\n";
+ return current($this->a);
+ }
+ function key() {
+ echo "key\n";
+ return key($this->a);
+ }
+ function valid() {
+ echo "valid\n";
+ return current($this->a);
+ }
+ function rewind() {
+ echo "rewind\n";
+ return reset($this->a);
+ }
+}
+try {
+ chdir(dirname(__FILE__));
+ $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar.zip');
+ var_dump($phar->buildFromIterator(new myIterator(array(basename(__FILE__, 'php') . 'phpt'))));
+} catch (Exception $e) {
+ var_dump(get_class($e));
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/buildfromiterator.phar.zip');
+__HALT_COMPILER();
+?>
+--EXPECTF--
+rewind
+valid
+current
+key
+%s(24) "UnexpectedValueException"
+Iterator myIterator returned an invalid key (must return a string)
+===DONE===
diff --git a/ext/phar/tests/zip/phar_buildfromiterator7.phpt b/ext/phar/tests/zip/phar_buildfromiterator7.phpt
new file mode 100644
index 0000000..777dbf8
--- /dev/null
+++ b/ext/phar/tests/zip/phar_buildfromiterator7.phpt
@@ -0,0 +1,60 @@
+--TEST--
+Phar::buildFromIterator() iterator, file can't be opened zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+class myIterator implements Iterator
+{
+ var $a;
+ function __construct(array $a)
+ {
+ $this->a = $a;
+ }
+ function next() {
+ echo "next\n";
+ return next($this->a);
+ }
+ function current() {
+ echo "current\n";
+ return current($this->a);
+ }
+ function key() {
+ echo "key\n";
+ return key($this->a);
+ }
+ function valid() {
+ echo "valid\n";
+ return current($this->a);
+ }
+ function rewind() {
+ echo "rewind\n";
+ return reset($this->a);
+ }
+}
+try {
+ chdir(dirname(__FILE__));
+ $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar.zip');
+ var_dump($phar->buildFromIterator(new myIterator(array('a' => basename(__FILE__, 'php') . '/oopsie/there.phpt'))));
+} catch (Exception $e) {
+ var_dump(get_class($e));
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/buildfromiterator.phar.zip');
+__HALT_COMPILER();
+?>
+--EXPECTF--
+rewind
+valid
+current
+key
+%s(24) "UnexpectedValueException"
+Iterator myIterator returned a file that could not be opened "phar_buildfromiterator7./oopsie/there.phpt"
+===DONE===
diff --git a/ext/phar/tests/zip/phar_buildfromiterator8.phpt b/ext/phar/tests/zip/phar_buildfromiterator8.phpt
new file mode 100644
index 0000000..d2b1be2
--- /dev/null
+++ b/ext/phar/tests/zip/phar_buildfromiterator8.phpt
@@ -0,0 +1,73 @@
+--TEST--
+Phar::buildFromIterator() iterator, SplFileInfo as current zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+try {
+ chdir(dirname(__FILE__));
+ $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar.zip');
+ $a = $phar->buildFromIterator(new RegexIterator(new DirectoryIterator('.'), '/^frontcontroller\d{0,2}\.phar\.phpt\\z|^\.\\z|^\.\.\\z/'), dirname(__FILE__) . DIRECTORY_SEPARATOR);
+ asort($a);
+ var_dump($a);
+ var_dump($phar->isFileFormat(Phar::ZIP));
+} catch (Exception $e) {
+ var_dump(get_class($e));
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/buildfromiterator.phar.zip');
+__HALT_COMPILER();
+?>
+--EXPECTF--
+array(21) {
+ ["frontcontroller1.phar.phpt"]=>
+ string(%d) "%sfrontcontroller1.phar.phpt"
+ ["frontcontroller10.phar.phpt"]=>
+ string(%d) "%sfrontcontroller10.phar.phpt"
+ ["frontcontroller11.phar.phpt"]=>
+ string(%d) "%sfrontcontroller11.phar.phpt"
+ ["frontcontroller12.phar.phpt"]=>
+ string(%d) "%sfrontcontroller12.phar.phpt"
+ ["frontcontroller13.phar.phpt"]=>
+ string(%d) "%sfrontcontroller13.phar.phpt"
+ ["frontcontroller14.phar.phpt"]=>
+ string(%d) "%sfrontcontroller14.phar.phpt"
+ ["frontcontroller15.phar.phpt"]=>
+ string(%d) "%sfrontcontroller15.phar.phpt"
+ ["frontcontroller16.phar.phpt"]=>
+ string(%d) "%sfrontcontroller16.phar.phpt"
+ ["frontcontroller17.phar.phpt"]=>
+ string(%d) "%sfrontcontroller17.phar.phpt"
+ ["frontcontroller18.phar.phpt"]=>
+ string(%d) "%sfrontcontroller18.phar.phpt"
+ ["frontcontroller19.phar.phpt"]=>
+ string(%d) "%sfrontcontroller19.phar.phpt"
+ ["frontcontroller2.phar.phpt"]=>
+ string(%d) "%sfrontcontroller2.phar.phpt"
+ ["frontcontroller20.phar.phpt"]=>
+ string(%d) "%sfrontcontroller20.phar.phpt"
+ ["frontcontroller21.phar.phpt"]=>
+ string(%d) "%sfrontcontroller21.phar.phpt"
+ ["frontcontroller3.phar.phpt"]=>
+ string(%d) "%sfrontcontroller3.phar.phpt"
+ ["frontcontroller4.phar.phpt"]=>
+ string(%d) "%sfrontcontroller4.phar.phpt"
+ ["frontcontroller5.phar.phpt"]=>
+ string(%d) "%sfrontcontroller5.phar.phpt"
+ ["frontcontroller6.phar.phpt"]=>
+ string(%d) "%sfrontcontroller6.phar.phpt"
+ ["frontcontroller7.phar.phpt"]=>
+ string(%d) "%sfrontcontroller7.phar.phpt"
+ ["frontcontroller8.phar.phpt"]=>
+ string(%d) "%sfrontcontroller8.phar.phpt"
+ ["frontcontroller9.phar.phpt"]=>
+ string(%d) "%sfrontcontroller9.phar.phpt"
+}
+bool(true)
+===DONE===
diff --git a/ext/phar/tests/zip/phar_buildfromiterator9.phpt b/ext/phar/tests/zip/phar_buildfromiterator9.phpt
new file mode 100644
index 0000000..0b56307
--- /dev/null
+++ b/ext/phar/tests/zip/phar_buildfromiterator9.phpt
@@ -0,0 +1,65 @@
+--TEST--
+Phar::buildFromIterator() iterator, 1 file resource passed in
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+class myIterator implements Iterator
+{
+ var $a;
+ function __construct(array $a)
+ {
+ $this->a = $a;
+ }
+ function next() {
+ echo "next\n";
+ return next($this->a);
+ }
+ function current() {
+ echo "current\n";
+ return current($this->a);
+ }
+ function key() {
+ echo "key\n";
+ return key($this->a);
+ }
+ function valid() {
+ echo "valid\n";
+ return current($this->a);
+ }
+ function rewind() {
+ echo "rewind\n";
+ return reset($this->a);
+ }
+}
+try {
+ chdir(dirname(__FILE__));
+ $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar');
+ var_dump($phar->buildFromIterator(new myIterator(array('a' => $a = fopen(basename(__FILE__, 'php') . 'phpt', 'r')))));
+ fclose($a);
+} catch (Exception $e) {
+ var_dump(get_class($e));
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/buildfromiterator.phar');
+__HALT_COMPILER();
+?>
+--EXPECTF--
+rewind
+valid
+current
+key
+next
+valid
+array(1) {
+ ["a"]=>
+ string(%d) "[stream]"
+}
+===DONE===
diff --git a/ext/phar/tests/zip/phar_commitwrite.phpt b/ext/phar/tests/zip/phar_commitwrite.phpt
new file mode 100644
index 0000000..4e18a6b
--- /dev/null
+++ b/ext/phar/tests/zip/phar_commitwrite.phpt
@@ -0,0 +1,47 @@
+--TEST--
+Phar::setStub()/stopBuffering() zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--ENV--
+TEMP=.
+TMP=.
+--FILE--
+<?php
+$p = new Phar(dirname(__FILE__) . '/brandnewphar.phar.zip', 0, 'brandnewphar.phar');
+$p['file1.txt'] = 'hi';
+$p->stopBuffering();
+var_dump($p->getStub());
+$p->setStub("<?php
+function __autoload(\$class)
+{
+ include 'phar://' . str_replace('_', '/', \$class);
+}
+Phar::mapPhar('brandnewphar.phar');
+include 'phar://brandnewphar.phar/startup.php';
+__HALT_COMPILER();
+?>");
+var_dump($p->getStub());
+var_dump($p->isFileFormat(Phar::ZIP));
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/brandnewphar.phar.zip');
+?>
+--EXPECT--
+string(60) "<?php // zip-based phar archive stub file
+__HALT_COMPILER();"
+string(200) "<?php
+function __autoload($class)
+{
+ include 'phar://' . str_replace('_', '/', $class);
+}
+Phar::mapPhar('brandnewphar.phar');
+include 'phar://brandnewphar.phar/startup.php';
+__HALT_COMPILER(); ?>
+"
+bool(true)
+===DONE===
diff --git a/ext/phar/tests/zip/phar_convert_phar.phpt b/ext/phar/tests/zip/phar_convert_phar.phpt
new file mode 100644
index 0000000..cad6d9f
--- /dev/null
+++ b/ext/phar/tests/zip/phar_convert_phar.phpt
@@ -0,0 +1,57 @@
+--TEST--
+Phar::convertToPhar() from zip
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar';
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '2.phar';
+$fname3 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.3.phar';
+
+$phar = new Phar($fname);
+$phar['a.txt'] = 'some text';
+$phar->stopBuffering();
+var_dump($phar->isFileFormat(Phar::ZIP));
+var_dump(strlen($phar->getStub()));
+
+$phar = $phar->convertToExecutable(Phar::ZIP);
+var_dump($phar->isFileFormat(Phar::ZIP));
+var_dump($phar->getStub());
+
+$phar['a'] = 'hi there';
+
+$phar = $phar->convertToExecutable(Phar::PHAR, Phar::NONE, '.3.phar');
+var_dump($phar->isFileFormat(Phar::PHAR));
+var_dump(strlen($phar->getStub()));
+
+copy($fname3, $fname2);
+
+$phar = new Phar($fname2);
+var_dump($phar->isFileFormat(Phar::PHAR));
+var_dump(strlen($phar->getStub()));
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '2.phar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.3.phar');
+__HALT_COMPILER();
+?>
+--EXPECT--
+bool(false)
+int(6683)
+bool(true)
+string(60) "<?php // zip-based phar archive stub file
+__HALT_COMPILER();"
+bool(true)
+int(6683)
+bool(true)
+int(6683)
+===DONE===
diff --git a/ext/phar/tests/zip/phar_copy.phpt b/ext/phar/tests/zip/phar_copy.phpt
new file mode 100644
index 0000000..14034c9
--- /dev/null
+++ b/ext/phar/tests/zip/phar_copy.phpt
@@ -0,0 +1,55 @@
+--TEST--
+Phar: copy() zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+--INI--
+phar.readonly=0
+phar.require_hash=1
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip.php';
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '2.phar.php';
+
+$pname = 'phar://'.$fname;
+$iname = '/file.txt';
+$ename = '/error/..';
+
+$p = new Phar($fname);
+
+try
+{
+ $p['a'] = 'hi';
+ $p->startBuffering();
+ $p->copy('a', 'b');
+ echo file_get_contents($p['b']->getPathName());
+ $p->copy('b', 'c');
+ $p->stopBuffering();
+ echo file_get_contents($p['c']->getPathName());
+ copy($fname, $fname2);
+ var_dump($p->isFileFormat(Phar::ZIP));
+ $p->copy('a', $ename);
+}
+catch(Exception $e)
+{
+ echo $e->getMessage() . "\n";
+}
+ini_set('phar.readonly',1);
+$p2 = new Phar($fname2);
+var_dump($p2->isFileFormat(Phar::ZIP));
+echo "\n";
+echo 'a: ' , file_get_contents($p2['a']->getPathName());
+echo 'b: ' ,file_get_contents($p2['b']->getPathName());
+echo 'c: ' ,file_get_contents($p2['c']->getPathName());
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip.php'); ?>
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '2.phar.php'); ?>
+--EXPECTF--
+hihibool(true)
+file "/error/.." contains invalid characters upper directory reference, cannot be copied from "a" in phar %s
+bool(true)
+
+a: hib: hic: hi===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/zip/phar_magic.phpt b/ext/phar/tests/zip/phar_magic.phpt
new file mode 100644
index 0000000..694f927
--- /dev/null
+++ b/ext/phar/tests/zip/phar_magic.phpt
@@ -0,0 +1,44 @@
+--TEST--
+Phar: include/fopen magic zip-based
+--SKIPIF--
+<?php
+if (!extension_loaded("phar")) die("skip");
+if (version_compare(PHP_VERSION, "6.0", ">")) die("skip pre-unicode version of PHP required");
+?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip.php';
+$pname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip.php';
+$p = new Phar($fname);
+var_dump($p->isFileFormat(Phar::ZIP));
+$p['a'] = '<?php include "b/c.php";' . "\n";
+$p['b/c.php'] = '<?php echo "in b\n";$a = fopen("a", "r", true);echo stream_get_contents($a);fclose($a);include dirname(__FILE__) . "/../d";';
+$p['d'] = "in d\n";
+$p->setStub('<?php
+var_dump(__FILE__);
+var_dump(substr(__FILE__, 0, 4) != "phar");
+set_include_path("phar://" . __FILE__);
+if (version_compare(PHP_VERSION, "5.3", "<")) {
+Phar::interceptFileFuncs();
+}
+include "phar://" . __FILE__ . "/a";
+__HALT_COMPILER();');
+include $pname;
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip.php');
+__HALT_COMPILER();
+?>
+--EXPECTF--
+bool(true)
+string(%d) "%sphar_magic.phar.zip.php"
+bool(true)
+in b
+<?php include "b/c.php";
+in d
+===DONE===
diff --git a/ext/phar/tests/zip/phar_magicU.phpt b/ext/phar/tests/zip/phar_magicU.phpt
new file mode 100644
index 0000000..f034e4e
--- /dev/null
+++ b/ext/phar/tests/zip/phar_magicU.phpt
@@ -0,0 +1,41 @@
+--TEST--
+Phar: include/fopen magic zip-based
+--SKIPIF--
+<?php
+if (!extension_loaded("phar")) die("skip");
+if (version_compare(PHP_VERSION, "6.0", "<")) die("skip Unicode support required");
+?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip.php';
+$pname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip.php';
+$p = new Phar($fname);
+var_dump($p->isFileFormat(Phar::ZIP));
+$p['a'] = '<?php include "b/c.php";' . "\n";
+$p['b/c.php'] = '<?php echo "in b\n";$a = fopen("a", "r", true);echo stream_get_contents($a);fclose($a);include dirname(__FILE__) . "/../d";';
+$p['d'] = "in d\n";
+$p->setStub('<?php
+var_dump(__FILE__);
+var_dump(substr(__FILE__, 0, 4) != "phar");
+set_include_path("phar://" . __FILE__);
+include "phar://" . __FILE__ . "/a";
+__HALT_COMPILER();');
+include $pname;
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip.php');
+__HALT_COMPILER();
+?>
+--EXPECTF--
+bool(true)
+unicode(%d) "%sphar_magicU.phar.zip.php"
+bool(true)
+in b
+<?php include "b/c.php";
+in d
+===DONE===
diff --git a/ext/phar/tests/zip/phar_oo_compressallbz2.phpt b/ext/phar/tests/zip/phar_oo_compressallbz2.phpt
new file mode 100644
index 0000000..d6b0a8f
--- /dev/null
+++ b/ext/phar/tests/zip/phar_oo_compressallbz2.phpt
@@ -0,0 +1,70 @@
+--TEST--
+Phar::compressFiles(Phar::BZ2) zip format
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("bz2")) die("skip bz2 not present"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip.php';
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip';
+$pname = 'phar://' . $fname;
+$pname2 = 'phar://' . $fname2;
+
+$phar = new Phar($fname);
+$phar['a'] = 'a';
+$phar['b'] = 'b';
+$phar['c'] = 'c';
+
+var_dump(file_get_contents($pname . '/a'));
+var_dump($phar['a']->isCompressed());
+var_dump(file_get_contents($pname . '/b'));
+var_dump($phar['b']->isCompressed());
+var_dump(file_get_contents($pname . '/c'));
+var_dump($phar['c']->isCompressed());
+
+$phar->compressFiles(Phar::BZ2);
+var_dump(file_get_contents($pname . '/a'));
+var_dump($phar['a']->isCompressed(Phar::GZ));
+var_dump($phar['a']->isCompressed(Phar::BZ2));
+var_dump(file_get_contents($pname . '/b'));
+var_dump($phar['b']->isCompressed(Phar::GZ));
+var_dump($phar['b']->isCompressed(Phar::BZ2));
+var_dump(file_get_contents($pname . '/c'));
+var_dump($phar['c']->isCompressed(Phar::GZ));
+var_dump($phar['b']->isCompressed(Phar::BZ2));
+$phar['d'] = 'hi'; // increases code coverage by having ufp open
+copy($fname, $fname2);
+$c = new Phar($fname2);
+var_dump(file_get_contents($pname2 . '/a'));
+var_dump($c['a']->isCompressed(Phar::GZ));
+var_dump($c['a']->isCompressed(Phar::BZ2));
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip.php');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip');
+?>
+--EXPECTF--
+string(1) "a"
+bool(false)
+string(1) "b"
+bool(false)
+string(1) "c"
+bool(false)
+string(1) "a"
+bool(false)
+bool(true)
+string(1) "b"
+bool(false)
+bool(true)
+string(1) "c"
+bool(false)
+bool(true)
+string(1) "a"
+bool(false)
+bool(true)
+===DONE===
diff --git a/ext/phar/tests/zip/phar_oo_compressallgz.phpt b/ext/phar/tests/zip/phar_oo_compressallgz.phpt
new file mode 100644
index 0000000..47dddac
--- /dev/null
+++ b/ext/phar/tests/zip/phar_oo_compressallgz.phpt
@@ -0,0 +1,58 @@
+--TEST--
+Phar::compressFiles(Phar::GZ) zip format
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zlib")) die("skip zlib not present"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip.php';
+$pname = 'phar://' . $fname;
+
+$phar = new Phar($fname);
+$phar['a'] = 'a';
+$phar['b'] = 'b';
+$phar['c'] = 'c';
+
+var_dump(file_get_contents($pname . '/a'));
+var_dump($phar['a']->isCompressed());
+var_dump(file_get_contents($pname . '/b'));
+var_dump($phar['b']->isCompressed());
+var_dump(file_get_contents($pname . '/c'));
+var_dump($phar['c']->isCompressed());
+
+$phar->compressFiles(Phar::GZ);
+var_dump(file_get_contents($pname . '/a'));
+var_dump($phar['a']->isCompressed(Phar::BZ2));
+var_dump($phar['a']->isCompressed(Phar::GZ));
+var_dump(file_get_contents($pname . '/b'));
+var_dump($phar['b']->isCompressed(Phar::BZ2));
+var_dump($phar['b']->isCompressed(Phar::GZ));
+var_dump(file_get_contents($pname . '/c'));
+var_dump($phar['b']->isCompressed(Phar::BZ2));
+var_dump($phar['c']->isCompressed(Phar::GZ));
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip.php');
+?>
+--EXPECTF--
+string(1) "a"
+bool(false)
+string(1) "b"
+bool(false)
+string(1) "c"
+bool(false)
+string(1) "a"
+bool(false)
+bool(true)
+string(1) "b"
+bool(false)
+bool(true)
+string(1) "c"
+bool(false)
+bool(true)
+===DONE===
diff --git a/ext/phar/tests/zip/phar_setalias.phpt b/ext/phar/tests/zip/phar_setalias.phpt
new file mode 100644
index 0000000..1a39633
--- /dev/null
+++ b/ext/phar/tests/zip/phar_setalias.phpt
@@ -0,0 +1,62 @@
+--TEST--
+Phar::setAlias() zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zlib")) die("skip no zlib"); ?>
+<?php if (!extension_loaded("bz2")) die("skip no bz2"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip';
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '2.phar.zip';
+$fname3 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '3.phar.zip';
+
+$phar = new Phar($fname);
+$phar->setStub('<?php echo "first stub\n"; __HALT_COMPILER(); ?>');
+$phar->setAlias('hio');
+
+$files = array();
+
+$files['a'] = 'a';
+$files['b'] = 'b';
+$files['c'] = 'c';
+
+foreach ($files as $n => $file) {
+ $phar[$n] = $file;
+}
+$phar->stopBuffering();
+
+echo $phar->getAlias() . "\n";
+$phar->setAlias('test');
+echo $phar->getAlias() . "\n";
+
+// test compression
+
+$phar->compressFiles(Phar::GZ);
+copy($fname, $fname2);
+$phar->setAlias('unused');
+$p2 = new Phar($fname2);
+echo $p2->getAlias(), "\n";
+$p2->compressFiles(Phar::BZ2);
+copy($fname2, $fname3);
+$p2->setAlias('unused2');
+$p3 = new Phar($fname3);
+echo $p3->getAlias(), "\n";
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '2.phar.zip');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '3.phar.zip');
+__HALT_COMPILER();
+?>
+--EXPECT--
+hio
+test
+test
+test
+===DONE===
diff --git a/ext/phar/tests/zip/phar_setalias2.phpt b/ext/phar/tests/zip/phar_setalias2.phpt
new file mode 100644
index 0000000..c89f4c7
--- /dev/null
+++ b/ext/phar/tests/zip/phar_setalias2.phpt
@@ -0,0 +1,49 @@
+--TEST--
+Phar::setAlias() error zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip';
+
+$phar = new Phar($fname);
+$phar->setStub('<?php echo "first stub\n"; __HALT_COMPILER(); ?>');
+$phar->setAlias('hio');
+
+$files = array();
+
+$files['a'] = 'a';
+$files['b'] = 'b';
+$files['c'] = 'c';
+
+foreach ($files as $n => $file) {
+ $phar[$n] = $file;
+}
+$phar->stopBuffering();
+
+echo $phar->getAlias() . "\n";
+$phar->setAlias('test');
+echo $phar->getAlias() . "\n";
+$b = $phar;
+$phar = new Phar(dirname(__FILE__) . '/notphar.phar');
+try {
+ $phar->setAlias('test');
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip');
+__HALT_COMPILER();
+?>
+--EXPECTF--
+hio
+test
+alias "test" is already used for archive "%sphar_setalias2.phar.zip" and cannot be used for other archives
+===DONE===
diff --git a/ext/phar/tests/zip/phar_setdefaultstub.phpt b/ext/phar/tests/zip/phar_setdefaultstub.phpt
new file mode 100644
index 0000000..e21d764
--- /dev/null
+++ b/ext/phar/tests/zip/phar_setdefaultstub.phpt
@@ -0,0 +1,80 @@
+--TEST--
+Phar: Phar::setDefaultStub() with and without arg, zip-based phar
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip';
+
+$phar = new Phar($fname);
+$phar['a.php'] = '<php echo "this is a\n"; ?>';
+$phar['b.php'] = '<php echo "this is b\n"; ?>';
+$phar->setStub('<?php echo "Hello World\n"; __HALT_COMPILER(); ?>');
+
+var_dump($phar->getStub());
+
+echo "============================================================================\n";
+echo "============================================================================\n";
+
+try {
+ $phar->setDefaultStub();
+ $phar->stopBuffering();
+} catch(Exception $e) {
+ echo $e->getMessage(). "\n";
+}
+
+var_dump($phar->getStub());
+
+echo "============================================================================\n";
+echo "============================================================================\n";
+
+try {
+ $phar->setDefaultStub('my/custom/thingy.php');
+ $phar->stopBuffering();
+} catch(Exception $e) {
+ echo $e->getMessage(). "\n";
+}
+
+var_dump($phar->getStub());
+
+echo "============================================================================\n";
+echo "============================================================================\n";
+
+try {
+ $phar->setDefaultStub('my/custom/thingy.php', 'the/web.php');
+ $phar->stopBuffering();
+} catch(Exception $e) {
+ echo $e->getMessage(). "\n";
+}
+
+var_dump($phar->getStub());
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip');
+?>
+--EXPECTF--
+string(51) "<?php echo "Hello World\n"; __HALT_COMPILER(); ?>
+"
+============================================================================
+============================================================================
+string(60) "<?php // zip-based phar archive stub file
+__HALT_COMPILER();"
+============================================================================
+============================================================================
+
+Warning: Phar::setDefaultStub(): method accepts no arguments for a tar- or zip-based phar stub, 1 given in %sphar_setdefaultstub.php on line %d
+string(60) "<?php // zip-based phar archive stub file
+__HALT_COMPILER();"
+============================================================================
+============================================================================
+
+Warning: Phar::setDefaultStub(): method accepts no arguments for a tar- or zip-based phar stub, 2 given in %sphar_setdefaultstub.php on line %d
+string(60) "<?php // zip-based phar archive stub file
+__HALT_COMPILER();"
+===DONE===
diff --git a/ext/phar/tests/zip/phar_setsignaturealgo2.phpt b/ext/phar/tests/zip/phar_setsignaturealgo2.phpt
new file mode 100644
index 0000000..7d3730c
--- /dev/null
+++ b/ext/phar/tests/zip/phar_setsignaturealgo2.phpt
@@ -0,0 +1,115 @@
+--TEST--
+Phar::setSupportedSignatures() with hash, zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("hash")) die("skip extension hash required");
+$arr = Phar::getSupportedSignatures();
+if (!in_array("OpenSSL", $arr)) die("skip openssl support required");
+if (!in_array('SHA-256', $arr)) die("skip hash extension loaded shared"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip';
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.phar.zip';
+$fname3 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.3.phar.zip';
+$fname4 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.4.phar.zip';
+$fname5 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.5.phar.zip';
+$fname6 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.6.phar.zip';
+$p = new Phar($fname);
+$p['file1.txt'] = 'hi';
+var_dump($p->getSignature());
+$p->setSignatureAlgorithm(Phar::MD5);
+
+copy($fname, $fname2);
+$p = new Phar($fname2);
+var_dump($p->getSignature());
+
+$p->setSignatureAlgorithm(Phar::SHA1);
+
+copy($fname2, $fname3);
+$p = new Phar($fname3);
+var_dump($p->getSignature());
+
+try {
+$p->setSignatureAlgorithm(Phar::SHA256);
+copy($fname3, $fname4);
+$p = new Phar($fname4);
+var_dump($p->getSignature());
+} catch (Exception $e) {
+echo $e->getMessage();
+}
+try {
+$p->setSignatureAlgorithm(Phar::SHA512);
+copy($fname4, $fname5);
+$p = new Phar($fname5);
+var_dump($p->getSignature());
+} catch (Exception $e) {
+echo $e->getMessage();
+}
+try {
+$config = dirname(__FILE__) . '/../files/openssl.cnf';
+$config_arg = array('config' => $config);
+$keys=openssl_pkey_new($config_arg);
+openssl_pkey_export($keys, $privkey, NULL, $config_arg);
+$pubkey=openssl_pkey_get_details($keys);
+$p->setSignatureAlgorithm(Phar::OPENSSL, $privkey);
+
+copy($fname5, $fname6);
+file_put_contents($fname6 . '.pubkey', $pubkey['key']);
+$p = new Phar($fname6);
+var_dump($p->getSignature());
+} catch (Exception $e) {
+echo $e->getMessage();
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar.zip');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.3.phar.zip');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.4.phar.zip');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.5.phar.zip');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.6.phar.zip');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.6.phar.zip.pubkey');
+?>
+--EXPECTF--
+array(2) {
+ ["hash"]=>
+ string(%d) "%s"
+ ["hash_type"]=>
+ string(5) "SHA-1"
+}
+array(2) {
+ ["hash"]=>
+ string(%d) "%s"
+ ["hash_type"]=>
+ string(3) "MD5"
+}
+array(2) {
+ ["hash"]=>
+ string(%d) "%s"
+ ["hash_type"]=>
+ string(5) "SHA-1"
+}
+array(2) {
+ ["hash"]=>
+ string(%d) "%s"
+ ["hash_type"]=>
+ string(7) "SHA-256"
+}
+array(2) {
+ ["hash"]=>
+ string(%d) "%s"
+ ["hash_type"]=>
+ string(7) "SHA-512"
+}
+array(2) {
+ ["hash"]=>
+ string(%d) "%s"
+ ["hash_type"]=>
+ string(7) "OpenSSL"
+}
+===DONE===
diff --git a/ext/phar/tests/zip/phar_stub.phpt b/ext/phar/tests/zip/phar_stub.phpt
new file mode 100644
index 0000000..72c1f17
--- /dev/null
+++ b/ext/phar/tests/zip/phar_stub.phpt
@@ -0,0 +1,75 @@
+--TEST--
+Phar::setStub() (zip-based)
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.phar.zip.php';
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip.php';
+$pname = 'phar://' . $fname;
+$pname2 = 'phar://' . $fname2;
+
+$p = new Phar($pname2);
+$p->setStub('<?php echo "first stub\n"; __HALT_COMPILER(); ?>');
+$p['a'] = 'a';
+$p['b'] = 'b';
+$p['c'] = 'c';
+copy($fname2, $fname);
+
+$phar = new Phar($fname);
+echo $phar->getStub();
+
+$file = b'<?php echo "second stub\n"; __HALT_COMPILER(); ?>';
+
+//// 2
+$phar->setStub($file);
+echo $phar->getStub();
+
+$fname3 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phartmp.php';
+$file = b'<?php echo "third stub\n"; __HALT_COMPILER(); ?>';
+$fp = fopen($fname3, 'wb');
+fwrite($fp, $file);
+fclose($fp);
+$fp = fopen($fname3, 'rb');
+
+//// 3
+$phar->setStub($fp);
+fclose($fp);
+
+echo $phar->getStub();
+
+$fp = fopen($fname3, 'ab');
+fwrite($fp, b'booya');
+fclose($fp);
+echo file_get_contents($fname3) . "\n";
+
+$fp = fopen($fname3, 'rb');
+
+//// 4
+$phar->setStub($fp, strlen($file));
+fclose($fp);
+echo $phar->getStub();
+
+$phar['testing'] = 'hi';
+
+echo $phar->getStub();
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip.php');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar.zip.php');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phartmp.php');
+__HALT_COMPILER();
+?>
+--EXPECT--
+<?php echo "first stub\n"; __HALT_COMPILER(); ?>
+<?php echo "second stub\n"; __HALT_COMPILER(); ?>
+<?php echo "third stub\n"; __HALT_COMPILER(); ?>
+<?php echo "third stub\n"; __HALT_COMPILER(); ?>booya
+<?php echo "third stub\n"; __HALT_COMPILER(); ?>
+<?php echo "third stub\n"; __HALT_COMPILER(); ?>
+===DONE===
diff --git a/ext/phar/tests/zip/phar_stub_error.phpt b/ext/phar/tests/zip/phar_stub_error.phpt
new file mode 100644
index 0000000..dafb312
--- /dev/null
+++ b/ext/phar/tests/zip/phar_stub_error.phpt
@@ -0,0 +1,55 @@
+--TEST--
+Phar::setStub()/getStub() zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip';
+
+$phar = new Phar($fname);
+$phar->setStub($stub = '<?php echo "first stub\n"; __HALT_COMPILER(); ?>' . "\r\n");
+$phar->setAlias('hio');
+$phar['a'] = 'a';
+$phar->stopBuffering();
+
+var_dump($phar->getStub());
+var_dump($phar->getStub() == $stub);
+
+$newstub = '<?php echo "second stub\n"; _x_HALT_COMPILER(); ?>';
+try
+{
+ $phar->setStub($newstub);
+}
+catch(exception $e)
+{
+ echo 'Exception: ' . $e->getMessage() . "\n";
+}
+var_dump($phar->getStub());
+var_dump($phar->getStub() == $stub);
+$phar->stopBuffering();
+var_dump($phar->getStub());
+var_dump($phar->getStub() == $stub);
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip');
+__HALT_COMPILER();
+?>
+--EXPECTF--
+string(50) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>
+"
+bool(true)
+Exception: illegal stub for zip-based phar "%sphar_stub_error.phar.zip"
+string(50) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>
+"
+bool(true)
+string(50) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>
+"
+bool(true)
+===DONE===
diff --git a/ext/phar/tests/zip/refcount1.phpt b/ext/phar/tests/zip/refcount1.phpt
new file mode 100644
index 0000000..618e7fe
--- /dev/null
+++ b/ext/phar/tests/zip/refcount1.phpt
@@ -0,0 +1,70 @@
+--TEST--
+Phar: test that refcounting avoids problems with deleting a file zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+<?php if (version_compare(PHP_VERSION, "5.3", "<")) die("skip requires 5.3 or later"); ?>
+--INI--
+phar.readonly=0
+phar.require_hash=0
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip';
+$alias = 'phar://' . $fname;
+
+$phar = new Phar($fname);
+$phar->setStub("<?php __HALT_COMPILER(); ?>");
+$phar->setAlias('hio');
+
+$files = array();
+
+$files['a.php'] = '<?php echo "This is a\n"; ?>';
+$files['b.php'] = '<?php echo "This is b\n"; ?>';
+$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>';
+
+foreach ($files as $n => $file) {
+ $phar[$n] = $file;
+}
+$phar->stopBuffering();
+
+$fp = fopen($alias . '/b/c.php', 'wb');
+fwrite($fp, b"extra");
+fclose($fp);
+echo "===CLOSE===\n";
+$b = fopen($alias . '/b/c.php', 'rb');
+$a = $phar['b/c.php'];
+var_dump($a);
+var_dump(fread($b, 20));
+rewind($b);
+echo "===UNLINK===\n";
+unlink($alias . '/b/c.php');
+var_dump($a);
+var_dump(fread($b, 20));
+include $alias . '/b/c.php';
+?>
+
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip'); ?>
+--EXPECTF--
+===CLOSE===
+object(PharFileInfo)#%d (2) {
+ [%spathName":%sSplFileInfo":private]=>
+ string(%d) "phar://%srefcount1.phar.zip/b/c.php"
+ [%sfileName":%sSplFileInfo":private]=>
+ string(%d) "c.php"
+}
+string(5) "extra"
+===UNLINK===
+
+Warning: unlink(): phar error: "b/c.php" in phar "%srefcount1.phar.zip", has open file pointers, cannot unlink in %srefcount1.php on line %d
+object(PharFileInfo)#%d (2) {
+ [%spathName":%sSplFileInfo":private]=>
+ string(%d) "phar://%srefcount1.phar.zip/b/c.php"
+ [%sfileName":%sSplFileInfo":private]=>
+ string(%s) "c.php"
+}
+string(5) "extra"
+extra
+===DONE===
diff --git a/ext/phar/tests/zip/refcount1_5_2.phpt b/ext/phar/tests/zip/refcount1_5_2.phpt
new file mode 100644
index 0000000..f3b2771
--- /dev/null
+++ b/ext/phar/tests/zip/refcount1_5_2.phpt
@@ -0,0 +1,64 @@
+--TEST--
+Phar: test that refcounting avoids problems with deleting a file zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+<?php if (version_compare(PHP_VERSION, "5.3", ">")) die("skip requires 5.2 or earlier"); ?>
+--INI--
+phar.readonly=0
+phar.require_hash=0
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip';
+$alias = 'phar://' . $fname;
+
+$phar = new Phar($fname);
+$phar->setStub("<?php __HALT_COMPILER(); ?>");
+$phar->setAlias('hio');
+
+$files = array();
+
+$files['a.php'] = '<?php echo "This is a\n"; ?>';
+$files['b.php'] = '<?php echo "This is b\n"; ?>';
+$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>';
+
+foreach ($files as $n => $file) {
+ $phar[$n] = $file;
+}
+$phar->stopBuffering();
+
+$fp = fopen($alias . '/b/c.php', 'wb');
+fwrite($fp, "extra");
+fclose($fp);
+
+echo "===CLOSE===\n";
+
+$b = fopen($alias . '/b/c.php', 'rb');
+$a = $phar['b/c.php'];
+var_dump($a);
+var_dump(fread($b, 20));
+rewind($b);
+echo "===UNLINK===\n";
+unlink($alias . '/b/c.php');
+var_dump($a);
+var_dump(fread($b, 20));
+include $alias . '/b/c.php';
+?>
+
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip'); ?>
+--EXPECTF--
+===CLOSE===
+object(PharFileInfo)#%d (0) {
+}
+string(5) "extra"
+===UNLINK===
+
+Warning: unlink(): phar error: "b/c.php" in phar "%sefcount1_5_2.phar.zip", has open file pointers, cannot unlink in %sefcount1_5_2.php on line %d
+object(PharFileInfo)#%d (0) {
+}
+string(5) "extra"
+extra
+===DONE===
diff --git a/ext/phar/tests/zip/rename.phpt b/ext/phar/tests/zip/rename.phpt
new file mode 100644
index 0000000..9b1f5c9
--- /dev/null
+++ b/ext/phar/tests/zip/rename.phpt
@@ -0,0 +1,34 @@
+--TEST--
+Phar: rename test zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+phar.require_hash=0
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip';
+$alias = 'phar://' . $fname;
+
+$phar = new Phar($fname);
+$phar->setStub("<?php
+Phar::mapPhar('hio');
+__HALT_COMPILER(); ?>");
+$phar['a'] = 'a';
+$phar->stopBuffering();
+
+include $fname;
+
+echo file_get_contents($alias . '/a') . "\n";
+rename($alias . '/a', $alias . '/b');
+echo file_get_contents($alias . '/b') . "\n";
+echo file_get_contents($alias . '/a') . "\n";
+?>
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip'); ?>
+--EXPECTF--
+a
+a
+
+Warning: file_get_contents(phar://%srename.phar.zip/a): failed to open stream: phar error: "a" is not a file in phar "%srename.phar.zip" in %srename.php on line %d \ No newline at end of file
diff --git a/ext/phar/tests/zip/rename_dir.phpt b/ext/phar/tests/zip/rename_dir.phpt
new file mode 100644
index 0000000..bb03c7f
--- /dev/null
+++ b/ext/phar/tests/zip/rename_dir.phpt
@@ -0,0 +1,34 @@
+--TEST--
+Phar: rename_dir test zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+phar.require_hash=0
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip';
+$alias = 'phar://' . $fname;
+
+$phar = new Phar($fname);
+$phar->setStub("<?php
+Phar::mapPhar('hio');
+__HALT_COMPILER(); ?>");
+$phar['a/x'] = 'a';
+$phar->stopBuffering();
+
+include $fname;
+
+echo file_get_contents($alias . '/a/x') . "\n";
+rename($alias . '/a', $alias . '/b');
+echo file_get_contents($alias . '/b/x') . "\n";
+echo file_get_contents($alias . '/a/x') . "\n";
+?>
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip'); ?>
+--EXPECTF--
+a
+a
+
+Warning: file_get_contents(phar://%srename_dir.phar.zip/a/x): failed to open stream: phar error: "a/x" is not a file in phar "%srename_dir.phar.zip" in %srename_dir.php on line %d \ No newline at end of file
diff --git a/ext/phar/tests/zip/rmdir.phpt b/ext/phar/tests/zip/rmdir.phpt
new file mode 100644
index 0000000..c7ef9da
--- /dev/null
+++ b/ext/phar/tests/zip/rmdir.phpt
@@ -0,0 +1,38 @@
+--TEST--
+Phar: rmdir test zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+phar.require_hash=0
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip';
+$alias = 'phar://' . $fname;
+
+$phar = new Phar($fname);
+$phar->setStub("<?php
+Phar::mapPhar('hio');
+__HALT_COMPILER(); ?>");
+$phar->addEmptyDir('a');
+$phar['a/x'] = 'a';
+$phar->stopBuffering();
+
+include $fname;
+
+echo file_get_contents($alias . '/a/x') . "\n";
+var_dump(rmdir($alias . '/a'));
+echo file_get_contents($alias . '/a/x') . "\n";
+unlink($alias . '/a/x');
+var_dump(rmdir($alias . '/a'));
+?>
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip'); ?>
+--EXPECTF--
+a
+
+Warning: rmdir(): phar error: Directory not empty in %srmdir.php on line %d
+bool(false)
+a
+bool(true)
diff --git a/ext/phar/tests/zip/unixzip.phpt b/ext/phar/tests/zip/unixzip.phpt
new file mode 100644
index 0000000..e2b95be
--- /dev/null
+++ b/ext/phar/tests/zip/unixzip.phpt
@@ -0,0 +1,29 @@
+--TEST--
+Phar: test a zip archive created by unix "zip" command
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+--FILE--
+<?php
+$a = new PharData(dirname(__FILE__) . '/files/zip.zip');
+foreach ($a as $b) {
+ if ($b->isDir()) {
+ echo "dir " . $b->getPathName() . "\n";
+ } else {
+ echo $b->getPathName(), "\n";
+ echo file_get_contents($b->getPathName()), "\n";
+ }
+}
+if (isset($a['notempty/hi.txt'])) {
+ echo $a['notempty/hi.txt']->getPathName() . "\n";
+}
+?>
+===DONE===
+--EXPECTF--
+dir phar://%s/zip.zip%cempty
+phar://%s/zip.zip%chi.txt
+hi there
+
+dir phar://%s/zip.zip%cnotempty
+phar://%s/zip.zip/notempty%chi.txt
+===DONE===
diff --git a/ext/phar/tests/zip/zlib.phpt b/ext/phar/tests/zip/zlib.phpt
new file mode 100644
index 0000000..c7494e2
--- /dev/null
+++ b/ext/phar/tests/zip/zlib.phpt
@@ -0,0 +1,19 @@
+--TEST--
+Phar: process zlib-compressed zip alias
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+<?php if (!extension_loaded("zlib")) die("skip zlib not available"); ?>
+--FILE--
+<?php
+try {
+ $a = new Phar(dirname(__FILE__) . '/files/zlib_alias.phar.zip');
+ var_dump($a->getAlias());
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--EXPECT--
+string(175) "hitheresuperlongzipistoostupidtodowhatIsaysoIhavetousethisridiculouslylongaliasbecauseitisstupiddidImentionthatalreadythemadnessdoesnotstopIhateinfozipIhateinfozipIhateinfozip"
+===DONE===