summaryrefslogtreecommitdiff
path: root/ext/phar/tests
diff options
context:
space:
mode:
Diffstat (limited to 'ext/phar/tests')
-rw-r--r--ext/phar/tests/001.phpt12
-rw-r--r--ext/phar/tests/002.phpt17
-rw-r--r--ext/phar/tests/003.phpt13
-rwxr-xr-xext/phar/tests/003a.phpt14
-rw-r--r--ext/phar/tests/004.phpt14
-rw-r--r--ext/phar/tests/005.phpt14
-rw-r--r--ext/phar/tests/006.phpt14
-rw-r--r--ext/phar/tests/007.phpt14
-rw-r--r--ext/phar/tests/008.phpt21
-rw-r--r--ext/phar/tests/009.phpt23
-rw-r--r--ext/phar/tests/010.phpt29
-rw-r--r--ext/phar/tests/011.phpt30
-rw-r--r--ext/phar/tests/012.phpt28
-rw-r--r--ext/phar/tests/013.phpt23
-rw-r--r--ext/phar/tests/014.phpt23
-rw-r--r--ext/phar/tests/015.phpt23
-rwxr-xr-xext/phar/tests/015b.phpt23
-rw-r--r--ext/phar/tests/016.phpt39
-rwxr-xr-xext/phar/tests/016b.phpt24
-rw-r--r--ext/phar/tests/017.phpt26
-rw-r--r--ext/phar/tests/018.phpt33
-rw-r--r--ext/phar/tests/019.phpt34
-rwxr-xr-xext/phar/tests/019b.phpt65
-rwxr-xr-xext/phar/tests/019c.phpt73
-rw-r--r--ext/phar/tests/020.phpt136
-rw-r--r--ext/phar/tests/021.phpt85
-rw-r--r--ext/phar/tests/022.phpt110
-rwxr-xr-xext/phar/tests/023.phpt32
-rwxr-xr-xext/phar/tests/024.phpt32
-rwxr-xr-xext/phar/tests/025.phpt32
-rwxr-xr-xext/phar/tests/026.phpt34
-rwxr-xr-xext/phar/tests/027.phpt94
-rwxr-xr-xext/phar/tests/028.phpt47
-rwxr-xr-xext/phar/tests/029.phpt50
-rwxr-xr-xext/phar/tests/030.phpt38
-rwxr-xr-xext/phar/tests/031.phpt31
-rwxr-xr-xext/phar/tests/032.phpt29
-rw-r--r--ext/phar/tests/033.phpt47
-rw-r--r--ext/phar/tests/033a.phpt36
-rw-r--r--ext/phar/tests/addfuncs.phpt41
-rw-r--r--ext/phar/tests/alias_acrobatics.phpt46
-rw-r--r--ext/phar/tests/badparameters.phpt210
-rw-r--r--ext/phar/tests/bug13727.phpt4135
-rw-r--r--ext/phar/tests/bug13786.phpt32
-rwxr-xr-xext/phar/tests/create_new_and_modify.phpt48
-rw-r--r--ext/phar/tests/create_new_phar.phpt21
-rwxr-xr-xext/phar/tests/create_new_phar_b.phpt27
-rwxr-xr-xext/phar/tests/create_new_phar_c.phpt29
-rwxr-xr-xext/phar/tests/create_path_error.phpt62
-rw-r--r--ext/phar/tests/delete.phpt31
-rw-r--r--ext/phar/tests/delete_in_phar.phpt48
-rwxr-xr-xext/phar/tests/delete_in_phar_b.phpt46
-rw-r--r--ext/phar/tests/delete_in_phar_confirm.phpt51
-rw-r--r--ext/phar/tests/dir.phpt92
-rw-r--r--ext/phar/tests/fgc_edgecases.phpt95
-rw-r--r--ext/phar/tests/file_get_contents.phpt30
-rw-r--r--ext/phar/tests/files/extracted.inc1
-rw-r--r--ext/phar/tests/files/frontcontroller.pharbin0 -> 331 bytes
-rw-r--r--ext/phar/tests/files/frontcontroller.phar.inc13
-rw-r--r--ext/phar/tests/files/frontcontroller10.pharbin0 -> 591 bytes
-rw-r--r--ext/phar/tests/files/frontcontroller10.phar.inc20
-rw-r--r--ext/phar/tests/files/frontcontroller11.pharbin0 -> 578 bytes
-rw-r--r--ext/phar/tests/files/frontcontroller11.phar.inc20
-rw-r--r--ext/phar/tests/files/frontcontroller12.pharbin0 -> 581 bytes
-rw-r--r--ext/phar/tests/files/frontcontroller12.phar.inc20
-rw-r--r--ext/phar/tests/files/frontcontroller13.pharbin0 -> 330 bytes
-rw-r--r--ext/phar/tests/files/frontcontroller13.phar.inc14
-rw-r--r--ext/phar/tests/files/frontcontroller14.pharbin0 -> 448 bytes
-rw-r--r--ext/phar/tests/files/frontcontroller14.phar.inc19
-rw-r--r--ext/phar/tests/files/frontcontroller16.pharbin0 -> 330 bytes
-rw-r--r--ext/phar/tests/files/frontcontroller16.phar.inc16
-rw-r--r--ext/phar/tests/files/frontcontroller17.pharbin0 -> 315 bytes
-rw-r--r--ext/phar/tests/files/frontcontroller17.phar.inc16
-rw-r--r--ext/phar/tests/files/frontcontroller18.pharbin0 -> 331 bytes
-rw-r--r--ext/phar/tests/files/frontcontroller18.phar.inc19
-rw-r--r--ext/phar/tests/files/frontcontroller19.pharbin0 -> 560 bytes
-rw-r--r--ext/phar/tests/files/frontcontroller19.phar.inc25
-rw-r--r--ext/phar/tests/files/frontcontroller2.pharbin0 -> 297 bytes
-rw-r--r--ext/phar/tests/files/frontcontroller2.phar.inc12
-rw-r--r--ext/phar/tests/files/frontcontroller3.pharbin0 -> 446 bytes
-rw-r--r--ext/phar/tests/files/frontcontroller3.phar.inc18
-rw-r--r--ext/phar/tests/files/frontcontroller4.pharbin0 -> 442 bytes
-rw-r--r--ext/phar/tests/files/frontcontroller4.phar.inc18
-rw-r--r--ext/phar/tests/files/frontcontroller5.pharbin0 -> 327 bytes
-rw-r--r--ext/phar/tests/files/frontcontroller5.phar.inc12
-rw-r--r--ext/phar/tests/files/frontcontroller6.pharbin0 -> 329 bytes
-rw-r--r--ext/phar/tests/files/frontcontroller6.phar.inc12
-rw-r--r--ext/phar/tests/files/frontcontroller7.pharbin0 -> 330 bytes
-rw-r--r--ext/phar/tests/files/frontcontroller7.phar.inc12
-rw-r--r--ext/phar/tests/files/frontcontroller8.pharbin0 -> 8968 bytes
-rw-r--r--ext/phar/tests/files/frontcontroller8.phar.inc19
-rw-r--r--ext/phar/tests/files/frontcontroller9.pharbin0 -> 448 bytes
-rw-r--r--ext/phar/tests/files/frontcontroller9.phar.inc14
-rw-r--r--ext/phar/tests/files/md5.pharbin0 -> 107 bytes
-rw-r--r--ext/phar/tests/files/nophar.pharbin0 -> 7017 bytes
-rw-r--r--ext/phar/tests/files/nophar.phar.inc10
-rw-r--r--ext/phar/tests/files/phar_oo_test.inc49
-rw-r--r--ext/phar/tests/files/phar_test.inc76
-rw-r--r--ext/phar/tests/files/sha1.pharbin0 -> 111 bytes
-rw-r--r--ext/phar/tests/files/sha256.pharbin0 -> 123 bytes
-rw-r--r--ext/phar/tests/files/sha512.pharbin0 -> 155 bytes
-rw-r--r--ext/phar/tests/files/zfapp.tgzbin0 -> 1725 bytes
-rw-r--r--ext/phar/tests/fopen.phpt43
-rw-r--r--ext/phar/tests/fopen5.2.phpt43
-rw-r--r--ext/phar/tests/fopen_edgecases.phpt124
-rw-r--r--ext/phar/tests/fopen_edgecases2.phpt43
-rw-r--r--ext/phar/tests/frontcontroller1.phpt15
-rw-r--r--ext/phar/tests/frontcontroller10.phpt22
-rw-r--r--ext/phar/tests/frontcontroller11.phpt18
-rw-r--r--ext/phar/tests/frontcontroller12.phpt18
-rw-r--r--ext/phar/tests/frontcontroller13.phpt18
-rw-r--r--ext/phar/tests/frontcontroller14.phpt15
-rw-r--r--ext/phar/tests/frontcontroller15.phpt18
-rw-r--r--ext/phar/tests/frontcontroller16.phpt15
-rw-r--r--ext/phar/tests/frontcontroller17.phpt16
-rw-r--r--ext/phar/tests/frontcontroller18.phpt16
-rw-r--r--ext/phar/tests/frontcontroller19.phpt16
-rw-r--r--ext/phar/tests/frontcontroller2.phpt14
-rw-r--r--ext/phar/tests/frontcontroller20.phpt16
-rw-r--r--ext/phar/tests/frontcontroller21.phpt22
-rw-r--r--ext/phar/tests/frontcontroller22.phpt19
-rw-r--r--ext/phar/tests/frontcontroller23.phpt15
-rw-r--r--ext/phar/tests/frontcontroller24.phpt14
-rw-r--r--ext/phar/tests/frontcontroller25.phpt15
-rw-r--r--ext/phar/tests/frontcontroller26.phpt14
-rw-r--r--ext/phar/tests/frontcontroller27.phpt14
-rw-r--r--ext/phar/tests/frontcontroller28.phpt14
-rw-r--r--ext/phar/tests/frontcontroller29.phpt14
-rw-r--r--ext/phar/tests/frontcontroller3.phpt17
-rw-r--r--ext/phar/tests/frontcontroller30.phpt12
-rw-r--r--ext/phar/tests/frontcontroller31.phpt13
-rw-r--r--ext/phar/tests/frontcontroller32.phpt13
-rw-r--r--ext/phar/tests/frontcontroller33.phpt13
-rw-r--r--ext/phar/tests/frontcontroller34.phpt16
-rw-r--r--ext/phar/tests/frontcontroller4.phpt13
-rw-r--r--ext/phar/tests/frontcontroller5.phpt14
-rw-r--r--ext/phar/tests/frontcontroller6.phpt21
-rw-r--r--ext/phar/tests/frontcontroller7.phpt14
-rw-r--r--ext/phar/tests/frontcontroller8.phpt21
-rw-r--r--ext/phar/tests/frontcontroller9.phpt17
-rw-r--r--ext/phar/tests/include_path.phpt34
-rw-r--r--ext/phar/tests/ini_set.phpt28
-rw-r--r--ext/phar/tests/ini_set_off.phpt85
-rw-r--r--ext/phar/tests/invalid_alias.phpt45
-rw-r--r--ext/phar/tests/invalid_setstubalias.phpt47
-rw-r--r--ext/phar/tests/metadata_read.phpt61
-rwxr-xr-xext/phar/tests/metadata_write.phpt62
-rwxr-xr-xext/phar/tests/metadata_write_commit.phpt79
-rw-r--r--ext/phar/tests/mkdir.phpt41
-rw-r--r--ext/phar/tests/mounteddir.phpt109
-rw-r--r--ext/phar/tests/nophar.phpt14
-rw-r--r--ext/phar/tests/nophar_web.phpt11
-rw-r--r--ext/phar/tests/open_for_write_existing.phpt31
-rwxr-xr-xext/phar/tests/open_for_write_existing_b.phpt42
-rwxr-xr-xext/phar/tests/open_for_write_existing_c.phpt36
-rw-r--r--ext/phar/tests/open_for_write_newfile.phpt33
-rwxr-xr-xext/phar/tests/open_for_write_newfile_b.phpt49
-rwxr-xr-xext/phar/tests/open_for_write_newfile_c.phpt43
-rw-r--r--ext/phar/tests/opendir.phpt42
-rw-r--r--ext/phar/tests/opendir_edgecases.phpt46
-rwxr-xr-xext/phar/tests/phar_begin_setstub_commit.phpt50
-rw-r--r--ext/phar/tests/phar_buildfromdirectory1.phpt28
-rw-r--r--ext/phar/tests/phar_buildfromdirectory2.phpt27
-rw-r--r--ext/phar/tests/phar_buildfromdirectory3.phpt27
-rw-r--r--ext/phar/tests/phar_buildfromdirectory4.phpt50
-rw-r--r--ext/phar/tests/phar_buildfromdirectory5.phpt50
-rw-r--r--ext/phar/tests/phar_buildfromdirectory6.phpt40
-rw-r--r--ext/phar/tests/phar_buildfromiterator1.phpt28
-rw-r--r--ext/phar/tests/phar_buildfromiterator10.phpt98
-rw-r--r--ext/phar/tests/phar_buildfromiterator2.phpt26
-rw-r--r--ext/phar/tests/phar_buildfromiterator3.phpt54
-rw-r--r--ext/phar/tests/phar_buildfromiterator4.phpt64
-rw-r--r--ext/phar/tests/phar_buildfromiterator5.phpt59
-rw-r--r--ext/phar/tests/phar_buildfromiterator6.phpt60
-rw-r--r--ext/phar/tests/phar_buildfromiterator7.phpt60
-rw-r--r--ext/phar/tests/phar_buildfromiterator8.phpt96
-rw-r--r--ext/phar/tests/phar_buildfromiterator9.phpt65
-rw-r--r--ext/phar/tests/phar_bz2.phpt63
-rw-r--r--ext/phar/tests/phar_commitwrite.phpt42
-rw-r--r--ext/phar/tests/phar_convert_again.phpt218
-rw-r--r--ext/phar/tests/phar_convert_repeated.phpt149
-rw-r--r--ext/phar/tests/phar_convert_repeated_b.phpt117
-rw-r--r--ext/phar/tests/phar_convert_tar.phpt57
-rw-r--r--ext/phar/tests/phar_convert_tar2.phpt64
-rw-r--r--ext/phar/tests/phar_convert_tar3.phpt65
-rw-r--r--ext/phar/tests/phar_convert_zip.phpt56
-rw-r--r--ext/phar/tests/phar_copy.phpt72
-rw-r--r--ext/phar/tests/phar_create_in_cwd.phpt45
-rw-r--r--ext/phar/tests/phar_createdefaultstub.phpt929
-rw-r--r--ext/phar/tests/phar_ctx_001.phpt100
-rw-r--r--ext/phar/tests/phar_decompress.phpt69
-rw-r--r--ext/phar/tests/phar_dir_iterate.phpt32
-rw-r--r--ext/phar/tests/phar_extract.phpt131
-rw-r--r--ext/phar/tests/phar_get_supported_signatures_001.phpt22
-rw-r--r--ext/phar/tests/phar_get_supported_signatures_002.phpt26
-rw-r--r--ext/phar/tests/phar_get_supportedcomp1.phpt22
-rw-r--r--ext/phar/tests/phar_get_supportedcomp2.phpt20
-rw-r--r--ext/phar/tests/phar_get_supportedcomp3.phpt20
-rw-r--r--ext/phar/tests/phar_get_supportedcomp4.phpt16
-rw-r--r--ext/phar/tests/phar_gobyebye.phpt44
-rw-r--r--ext/phar/tests/phar_gzip.phpt54
-rw-r--r--ext/phar/tests/phar_isvalidpharfilename.phpt140
-rw-r--r--ext/phar/tests/phar_magic.phpt31
-rw-r--r--ext/phar/tests/phar_metadata_read.phpt95
-rw-r--r--ext/phar/tests/phar_metadata_write.phpt71
-rw-r--r--ext/phar/tests/phar_mount.phpt63
-rwxr-xr-xext/phar/tests/phar_offset_get_error.phpt37
-rwxr-xr-xext/phar/tests/phar_oo_001.phpt54
-rwxr-xr-xext/phar/tests/phar_oo_002.phpt137
-rwxr-xr-xext/phar/tests/phar_oo_003.phpt45
-rwxr-xr-xext/phar/tests/phar_oo_004.phpt126
-rwxr-xr-xext/phar/tests/phar_oo_005.phpt60
-rwxr-xr-xext/phar/tests/phar_oo_006.phpt52
-rwxr-xr-xext/phar/tests/phar_oo_007.phpt87
-rwxr-xr-xext/phar/tests/phar_oo_008.phpt119
-rwxr-xr-xext/phar/tests/phar_oo_009.phpt56
-rwxr-xr-xext/phar/tests/phar_oo_010.phpt55
-rw-r--r--ext/phar/tests/phar_oo_011.phpt34
-rwxr-xr-xext/phar/tests/phar_oo_011b.phpt39
-rw-r--r--ext/phar/tests/phar_oo_012.phpt37
-rw-r--r--ext/phar/tests/phar_oo_012_confirm.phpt40
-rwxr-xr-xext/phar/tests/phar_oo_012b.phpt42
-rw-r--r--ext/phar/tests/phar_oo_compressallbz2.phpt66
-rw-r--r--ext/phar/tests/phar_oo_compressallgz.phpt71
-rw-r--r--ext/phar/tests/phar_oo_compressed_001.phpt68
-rwxr-xr-xext/phar/tests/phar_oo_compressed_001b.phpt68
-rwxr-xr-xext/phar/tests/phar_oo_compressed_002.phpt73
-rwxr-xr-xext/phar/tests/phar_oo_compressed_002b.phpt73
-rw-r--r--ext/phar/tests/phar_oo_getcontents.phpt39
-rw-r--r--ext/phar/tests/phar_oo_getcontentsgz.phpt34
-rw-r--r--ext/phar/tests/phar_oo_getmodified.phpt36
-rw-r--r--ext/phar/tests/phar_oo_iswriteable.phpt84
-rw-r--r--ext/phar/tests/phar_oo_nosig.phpt24
-rw-r--r--ext/phar/tests/phar_oo_uncompressall.phpt80
-rw-r--r--ext/phar/tests/phar_running.phpt29
-rw-r--r--ext/phar/tests/phar_setalias.phpt36
-rw-r--r--ext/phar/tests/phar_setalias2.phpt51
-rw-r--r--ext/phar/tests/phar_setdefaultstub.phpt944
-rw-r--r--ext/phar/tests/phar_setsignaturealgo1.phpt69
-rw-r--r--ext/phar/tests/phar_setsignaturealgo2.phpt79
-rw-r--r--ext/phar/tests/phar_stub.phpt92
-rwxr-xr-xext/phar/tests/phar_stub_error.phpt56
-rwxr-xr-xext/phar/tests/phar_stub_write.phpt64
-rwxr-xr-xext/phar/tests/phar_stub_write_file.phpt65
-rw-r--r--ext/phar/tests/phar_unlinkarchive.phpt108
-rw-r--r--ext/phar/tests/pharfileinfo_chmod.phpt33
-rw-r--r--ext/phar/tests/pharfileinfo_compression.phpt94
-rw-r--r--ext/phar/tests/pharfileinfo_construct.phpt54
-rw-r--r--ext/phar/tests/pharfileinfo_destruct.phpt25
-rw-r--r--ext/phar/tests/pharfileinfo_getcrc32.phpt49
-rw-r--r--ext/phar/tests/pharfileinfo_setmetadata.phpt65
-rw-r--r--ext/phar/tests/phpinfo_001.phpt59
-rw-r--r--ext/phar/tests/phpinfo_002.phpt37
-rw-r--r--ext/phar/tests/phpinfo_003.phpt37
-rw-r--r--ext/phar/tests/phpinfo_004.phpt66
-rw-r--r--ext/phar/tests/readfile.phpt30
-rw-r--r--ext/phar/tests/readfile_edgecases.phpt62
-rw-r--r--ext/phar/tests/refcount1.phpt62
-rwxr-xr-xext/phar/tests/refcount1_5_2.phpt64
-rw-r--r--ext/phar/tests/rename.phpt32
-rw-r--r--ext/phar/tests/security.phpt36
-rw-r--r--ext/phar/tests/stat.phpt215
-rw-r--r--ext/phar/tests/stat2.phpt60
-rw-r--r--ext/phar/tests/stat2_5.3.phpt60
-rw-r--r--ext/phar/tests/tar/033.phpt50
-rw-r--r--ext/phar/tests/tar/033a.phpt45
-rw-r--r--ext/phar/tests/tar/alias_acrobatics.phpt46
-rw-r--r--ext/phar/tests/tar/badalias.phpt25
-rw-r--r--ext/phar/tests/tar/badchecksum.phpt30
-rw-r--r--ext/phar/tests/tar/bignames.phpt35
-rw-r--r--ext/phar/tests/tar/create_new_and_modify.phpt45
-rw-r--r--ext/phar/tests/tar/create_new_phar_b.phpt27
-rw-r--r--ext/phar/tests/tar/delete.phpt32
-rw-r--r--ext/phar/tests/tar/delete_in_phar.phpt49
-rw-r--r--ext/phar/tests/tar/delete_in_phar_b.phpt49
-rw-r--r--ext/phar/tests/tar/delete_in_phar_confirm.phpt52
-rw-r--r--ext/phar/tests/tar/dir.phpt43
-rw-r--r--ext/phar/tests/tar/exists_as_phar.phpt38
-rw-r--r--ext/phar/tests/tar/files/badalias1.phar.tarbin0 -> 3072 bytes
-rw-r--r--ext/phar/tests/tar/files/badalias2.phar.tarbin0 -> 3072 bytes
-rw-r--r--ext/phar/tests/tar/files/badalias3.phar.tarbin0 -> 3072 bytes
-rw-r--r--ext/phar/tests/tar/files/badalias4.phar.tarbin0 -> 3072 bytes
-rw-r--r--ext/phar/tests/tar/files/badalias5.phar.tarbin0 -> 3584 bytes
-rw-r--r--ext/phar/tests/tar/files/biglink.tarbin0 -> 10240 bytes
-rw-r--r--ext/phar/tests/tar/files/corrupt_tarmaker.php.inc177
-rw-r--r--ext/phar/tests/tar/files/frontcontroller.phar.inc13
-rw-r--r--ext/phar/tests/tar/files/frontcontroller.phar.tarbin0 -> 6144 bytes
-rw-r--r--ext/phar/tests/tar/files/frontcontroller10.phar.inc20
-rw-r--r--ext/phar/tests/tar/files/frontcontroller10.phar.tarbin0 -> 3072 bytes
-rw-r--r--ext/phar/tests/tar/files/frontcontroller11.phar.inc20
-rw-r--r--ext/phar/tests/tar/files/frontcontroller11.phar.tarbin0 -> 3072 bytes
-rw-r--r--ext/phar/tests/tar/files/frontcontroller12.phar.inc20
-rw-r--r--ext/phar/tests/tar/files/frontcontroller12.phar.tarbin0 -> 3072 bytes
-rw-r--r--ext/phar/tests/tar/files/frontcontroller2.phar.inc12
-rw-r--r--ext/phar/tests/tar/files/frontcontroller2.phar.tarbin0 -> 5120 bytes
-rw-r--r--ext/phar/tests/tar/files/frontcontroller3.phar.inc18
-rw-r--r--ext/phar/tests/tar/files/frontcontroller3.phar.tarbin0 -> 5120 bytes
-rw-r--r--ext/phar/tests/tar/files/frontcontroller4.phar.inc18
-rw-r--r--ext/phar/tests/tar/files/frontcontroller4.phar.tarbin0 -> 5120 bytes
-rw-r--r--ext/phar/tests/tar/files/frontcontroller5.phar.inc12
-rw-r--r--ext/phar/tests/tar/files/frontcontroller5.phar.tarbin0 -> 5120 bytes
-rw-r--r--ext/phar/tests/tar/files/frontcontroller6.phar.inc12
-rw-r--r--ext/phar/tests/tar/files/frontcontroller6.phar.tarbin0 -> 5120 bytes
-rw-r--r--ext/phar/tests/tar/files/frontcontroller7.phar.inc12
-rw-r--r--ext/phar/tests/tar/files/frontcontroller7.phar.tarbin0 -> 5120 bytes
-rw-r--r--ext/phar/tests/tar/files/frontcontroller8.phar.inc13
-rw-r--r--ext/phar/tests/tar/files/frontcontroller8.phar.tarbin0 -> 6144 bytes
-rw-r--r--ext/phar/tests/tar/files/frontcontroller9.phar.inc14
-rw-r--r--ext/phar/tests/tar/files/frontcontroller9.phar.tarbin0 -> 6144 bytes
-rw-r--r--ext/phar/tests/tar/files/links.tarbin0 -> 10240 bytes
-rw-r--r--ext/phar/tests/tar/files/make_invalid_tar.php.inc9
-rw-r--r--ext/phar/tests/tar/files/subdirlink.tarbin0 -> 10240 bytes
-rw-r--r--ext/phar/tests/tar/files/tarmaker.php.inc169
-rw-r--r--ext/phar/tests/tar/files/tinylink.tarbin0 -> 10240 bytes
-rw-r--r--ext/phar/tests/tar/files/trunc.tarbin0 -> 800 bytes
-rw-r--r--ext/phar/tests/tar/frontcontroller1.phar.phpt15
-rw-r--r--ext/phar/tests/tar/frontcontroller10.phar.phpt22
-rw-r--r--ext/phar/tests/tar/frontcontroller11.phar.phpt18
-rw-r--r--ext/phar/tests/tar/frontcontroller12.phar.phpt18
-rw-r--r--ext/phar/tests/tar/frontcontroller13.phar.phpt18
-rw-r--r--ext/phar/tests/tar/frontcontroller14.phar.phpt15
-rw-r--r--ext/phar/tests/tar/frontcontroller15.phar.phpt18
-rw-r--r--ext/phar/tests/tar/frontcontroller16.phar.phpt15
-rw-r--r--ext/phar/tests/tar/frontcontroller17.phar.phpt16
-rw-r--r--ext/phar/tests/tar/frontcontroller18.phar.phpt16
-rw-r--r--ext/phar/tests/tar/frontcontroller19.phar.phpt16
-rw-r--r--ext/phar/tests/tar/frontcontroller2.phar.phpt14
-rw-r--r--ext/phar/tests/tar/frontcontroller20.phar.phpt16
-rw-r--r--ext/phar/tests/tar/frontcontroller21.phar.phpt22
-rw-r--r--ext/phar/tests/tar/frontcontroller3.phar.phpt17
-rw-r--r--ext/phar/tests/tar/frontcontroller4.phar.phpt13
-rw-r--r--ext/phar/tests/tar/frontcontroller5.phar.phpt14
-rw-r--r--ext/phar/tests/tar/frontcontroller6.phar.phpt21
-rw-r--r--ext/phar/tests/tar/frontcontroller7.phar.phpt14
-rw-r--r--ext/phar/tests/tar/frontcontroller8.phar.phpt21
-rw-r--r--ext/phar/tests/tar/frontcontroller9.phar.phpt17
-rw-r--r--ext/phar/tests/tar/links.phpt33
-rw-r--r--ext/phar/tests/tar/links2.phpt35
-rw-r--r--ext/phar/tests/tar/links3.phpt19
-rw-r--r--ext/phar/tests/tar/links4.phpt19
-rw-r--r--ext/phar/tests/tar/links5.phpt19
-rw-r--r--ext/phar/tests/tar/open_for_write_existing.phpt42
-rwxr-xr-xext/phar/tests/tar/open_for_write_existing_b.phpt56
-rwxr-xr-xext/phar/tests/tar/open_for_write_existing_c.phpt50
-rw-r--r--ext/phar/tests/tar/open_for_write_newfile.phpt44
-rwxr-xr-xext/phar/tests/tar/open_for_write_newfile_b.phpt61
-rwxr-xr-xext/phar/tests/tar/open_for_write_newfile_c.phpt54
-rwxr-xr-xext/phar/tests/tar/phar_begin_setstub_commit.phpt51
-rw-r--r--ext/phar/tests/tar/phar_buildfromiterator4.phpt66
-rw-r--r--ext/phar/tests/tar/phar_buildfromiterator5.phpt59
-rw-r--r--ext/phar/tests/tar/phar_buildfromiterator6.phpt60
-rw-r--r--ext/phar/tests/tar/phar_buildfromiterator7.phpt60
-rw-r--r--ext/phar/tests/tar/phar_buildfromiterator8.phpt73
-rw-r--r--ext/phar/tests/tar/phar_buildfromiterator9.phpt65
-rw-r--r--ext/phar/tests/tar/phar_commitwrite.phpt44
-rw-r--r--ext/phar/tests/tar/phar_convert_phar.phpt58
-rw-r--r--ext/phar/tests/tar/phar_convert_phar2.phpt62
-rw-r--r--ext/phar/tests/tar/phar_convert_phar3.phpt62
-rw-r--r--ext/phar/tests/tar/phar_copy.phpt56
-rw-r--r--ext/phar/tests/tar/phar_magic.phpt33
-rw-r--r--ext/phar/tests/tar/phar_setalias.phpt51
-rw-r--r--ext/phar/tests/tar/phar_setalias2.phpt53
-rw-r--r--ext/phar/tests/tar/phar_setdefaultstub.phpt80
-rw-r--r--ext/phar/tests/tar/phar_stub.phpt75
-rwxr-xr-xext/phar/tests/tar/phar_stub_error.phpt57
-rw-r--r--ext/phar/tests/tar/refcount1.phpt74
-rwxr-xr-xext/phar/tests/tar/refcount1_5_2.phpt64
-rw-r--r--ext/phar/tests/tar/rename.phpt42
-rw-r--r--ext/phar/tests/tar/tar_001.phpt31
-rw-r--r--ext/phar/tests/tar/tar_002.phpt34
-rw-r--r--ext/phar/tests/tar/tar_003.phpt74
-rw-r--r--ext/phar/tests/tar/tar_004.phpt38
-rw-r--r--ext/phar/tests/tar/tar_bz2.phpt54
-rw-r--r--ext/phar/tests/tar/tar_gzip.phpt51
-rw-r--r--ext/phar/tests/tar/tar_makebz2.phpt40
-rw-r--r--ext/phar/tests/tar/tar_makegz.phpt41
-rw-r--r--ext/phar/tests/tar/tar_nostub.phpt48
-rw-r--r--ext/phar/tests/tar/truncated.phpt22
-rw-r--r--ext/phar/tests/test_alias_unset.phpt45
-rw-r--r--ext/phar/tests/test_signaturealgos.phpt30
-rw-r--r--ext/phar/tests/test_unset.phpt42
-rw-r--r--ext/phar/tests/webphar_compilefail.phpt17
-rw-r--r--ext/phar/tests/withphar.phpt14
-rw-r--r--ext/phar/tests/withphar_web.phpt14
-rw-r--r--ext/phar/tests/zf_test.phpt49
-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.phpt62
-rw-r--r--ext/phar/tests/zip/badalias.phpt25
-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/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/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/corrupt_count1.php.inc11
-rw-r--r--ext/phar/tests/zip/files/corrupt_zipmaker.php.inc317
-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/encrypted.zipbin0 -> 191 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 -> 625 bytes
-rw-r--r--ext/phar/tests/zip/files/frontcontroller10.phar.inc20
-rw-r--r--ext/phar/tests/zip/files/frontcontroller10.phar.zipbin0 -> 471 bytes
-rw-r--r--ext/phar/tests/zip/files/frontcontroller11.phar.inc20
-rw-r--r--ext/phar/tests/zip/files/frontcontroller11.phar.zipbin0 -> 461 bytes
-rw-r--r--ext/phar/tests/zip/files/frontcontroller12.phar.inc20
-rw-r--r--ext/phar/tests/zip/files/frontcontroller12.phar.zipbin0 -> 465 bytes
-rw-r--r--ext/phar/tests/zip/files/frontcontroller2.phar.inc12
-rw-r--r--ext/phar/tests/zip/files/frontcontroller2.phar.zipbin0 -> 531 bytes
-rw-r--r--ext/phar/tests/zip/files/frontcontroller3.phar.inc18
-rw-r--r--ext/phar/tests/zip/files/frontcontroller3.phar.zipbin0 -> 826 bytes
-rw-r--r--ext/phar/tests/zip/files/frontcontroller4.phar.inc18
-rw-r--r--ext/phar/tests/zip/files/frontcontroller4.phar.zipbin0 -> 822 bytes
-rw-r--r--ext/phar/tests/zip/files/frontcontroller5.phar.inc12
-rw-r--r--ext/phar/tests/zip/files/frontcontroller5.phar.zipbin0 -> 554 bytes
-rw-r--r--ext/phar/tests/zip/files/frontcontroller6.phar.inc12
-rw-r--r--ext/phar/tests/zip/files/frontcontroller6.phar.zipbin0 -> 559 bytes
-rw-r--r--ext/phar/tests/zip/files/frontcontroller7.phar.inc12
-rw-r--r--ext/phar/tests/zip/files/frontcontroller7.phar.zipbin0 -> 559 bytes
-rw-r--r--ext/phar/tests/zip/files/frontcontroller8.phar.inc13
-rw-r--r--ext/phar/tests/zip/files/frontcontroller8.phar.zipbin0 -> 684 bytes
-rw-r--r--ext/phar/tests/zip/files/frontcontroller9.phar.inc14
-rw-r--r--ext/phar/tests/zip/files/frontcontroller9.phar.zipbin0 -> 697 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/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/frontcontroller1.phar.phpt15
-rw-r--r--ext/phar/tests/zip/frontcontroller10.phar.phpt22
-rw-r--r--ext/phar/tests/zip/frontcontroller11.phar.phpt18
-rw-r--r--ext/phar/tests/zip/frontcontroller12.phar.phpt18
-rw-r--r--ext/phar/tests/zip/frontcontroller13.phar.phpt18
-rw-r--r--ext/phar/tests/zip/frontcontroller14.phar.phpt15
-rw-r--r--ext/phar/tests/zip/frontcontroller15.phar.phpt18
-rw-r--r--ext/phar/tests/zip/frontcontroller16.phar.phpt15
-rw-r--r--ext/phar/tests/zip/frontcontroller17.phar.phpt16
-rw-r--r--ext/phar/tests/zip/frontcontroller18.phar.phpt16
-rw-r--r--ext/phar/tests/zip/frontcontroller19.phar.phpt16
-rw-r--r--ext/phar/tests/zip/frontcontroller2.phar.phpt14
-rw-r--r--ext/phar/tests/zip/frontcontroller20.phar.phpt16
-rw-r--r--ext/phar/tests/zip/frontcontroller21.phar.phpt22
-rw-r--r--ext/phar/tests/zip/frontcontroller3.phar.phpt17
-rw-r--r--ext/phar/tests/zip/frontcontroller4.phar.phpt13
-rw-r--r--ext/phar/tests/zip/frontcontroller5.phar.phpt14
-rw-r--r--ext/phar/tests/zip/frontcontroller6.phar.phpt21
-rw-r--r--ext/phar/tests/zip/frontcontroller7.phar.phpt14
-rw-r--r--ext/phar/tests/zip/frontcontroller8.phar.phpt21
-rw-r--r--ext/phar/tests/zip/frontcontroller9.phar.phpt17
-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.phpt85
-rw-r--r--ext/phar/tests/zip/notphar.phpt23
-rw-r--r--ext/phar/tests/zip/odt.phpt34
-rw-r--r--ext/phar/tests/zip/open_for_write_existing.phpt39
-rwxr-xr-xext/phar/tests/zip/open_for_write_existing_b.phpt52
-rwxr-xr-xext/phar/tests/zip/open_for_write_existing_c.phpt46
-rw-r--r--ext/phar/tests/zip/open_for_write_newfile.phpt42
-rwxr-xr-xext/phar/tests/zip/open_for_write_newfile_b.phpt60
-rwxr-xr-xext/phar/tests/zip/open_for_write_newfile_c.phpt54
-rwxr-xr-xext/phar/tests/zip/phar_begin_setstub_commit.phpt68
-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.phpt44
-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.phpt33
-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_stub.phpt75
-rwxr-xr-xext/phar/tests/zip/phar_stub_error.phpt58
-rw-r--r--ext/phar/tests/zip/refcount1.phpt70
-rwxr-xr-xext/phar/tests/zip/refcount1_5_2.phpt64
-rw-r--r--ext/phar/tests/zip/rename.phpt34
-rw-r--r--ext/phar/tests/zip/unixzip.phpt26
521 files changed, 24264 insertions, 0 deletions
diff --git a/ext/phar/tests/001.phpt b/ext/phar/tests/001.phpt
new file mode 100644
index 0000000000..1205e4e1aa
--- /dev/null
+++ b/ext/phar/tests/001.phpt
@@ -0,0 +1,12 @@
+--TEST--
+Phar::apiVersion
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--FILE--
+<?php
+var_dump(Phar::apiVersion());
+?>
+===DONE===
+--EXPECT--
+string(5) "1.1.1"
+===DONE===
diff --git a/ext/phar/tests/002.phpt b/ext/phar/tests/002.phpt
new file mode 100644
index 0000000000..a7cf0cb2d2
--- /dev/null
+++ b/ext/phar/tests/002.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Phar::mapPhar truncated manifest/improper params
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--FILE--
+<?php
+try {
+Phar::mapPhar(5, 'hio', 'hi');
+
+Phar::mapPhar();
+} catch (Exception $e) {
+ echo $e->getMessage();
+}
+__HALT_COMPILER(); ?>
+--EXPECTF--
+Warning: Phar::mapPhar() expects at most 2 parameters, 3 given in %s002.php on line %d
+internal corruption of phar "%s002.php" (truncated manifest at manifest length) \ No newline at end of file
diff --git a/ext/phar/tests/003.phpt b/ext/phar/tests/003.phpt
new file mode 100644
index 0000000000..fcc95a8481
--- /dev/null
+++ b/ext/phar/tests/003.phpt
@@ -0,0 +1,13 @@
+--TEST--
+Phar::canCompress
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--FILE--
+<?php
+/* check this works and actually returns the boolean value */
+var_dump(Phar::canCompress() == (
+ extension_loaded("zlib") || extension_loaded("bz2")
+ ));
+?>
+--EXPECT--
+bool(true)
diff --git a/ext/phar/tests/003a.phpt b/ext/phar/tests/003a.phpt
new file mode 100755
index 0000000000..37e31072d4
--- /dev/null
+++ b/ext/phar/tests/003a.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Phar::canCompress, specific
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--FILE--
+<?php
+var_dump(Phar::canCompress(Phar::GZ) == extension_loaded("zlib"));
+var_dump(Phar::canCompress(Phar::BZ2) == extension_loaded("bz2"));
+?>
+===DONE===
+--EXPECT--
+bool(true)
+bool(true)
+===DONE===
diff --git a/ext/phar/tests/004.phpt b/ext/phar/tests/004.phpt
new file mode 100644
index 0000000000..963a9b45a0
--- /dev/null
+++ b/ext/phar/tests/004.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Phar::mapPhar no __HALT_COMPILER();
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");?>
+--FILE--
+<?php
+try {
+Phar::mapPhar('hio');
+} catch (Exception $e) {
+echo $e->getMessage();
+}
+?>
+--EXPECTF--
+__HALT_COMPILER(); must be declared in a phar
diff --git a/ext/phar/tests/005.phpt b/ext/phar/tests/005.phpt
new file mode 100644
index 0000000000..a6e3449016
--- /dev/null
+++ b/ext/phar/tests/005.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Phar::mapPhar truncated manifest (none)
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");?>
+--FILE--
+<?php
+try {
+Phar::mapPhar('hio');
+} catch (Exception $e) {
+echo $e->getMessage();
+}
+__HALT_COMPILER(); ?>()
+--EXPECTF--
+internal corruption of phar "%s" (truncated manifest at manifest length)
diff --git a/ext/phar/tests/006.phpt b/ext/phar/tests/006.phpt
new file mode 100644
index 0000000000..b2e8b29ef9
--- /dev/null
+++ b/ext/phar/tests/006.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Phar::mapPhar truncated manifest (manifest length truncated)
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");?>
+--FILE--
+<?php
+try {
+Phar::mapPhar('hio');
+} catch (Exception $e) {
+echo $e->getMessage();
+}
+__HALT_COMPILER(); ?>
+--EXPECTF--
+internal corruption of phar "%s" (truncated manifest at manifest length)
diff --git a/ext/phar/tests/007.phpt b/ext/phar/tests/007.phpt
new file mode 100644
index 0000000000..a13c2a452a
--- /dev/null
+++ b/ext/phar/tests/007.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Phar::mapPhar manifest too big
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");?>
+--FILE--
+<?php
+try {
+Phar::mapPhar('hio');
+} catch (Exception $e) {
+echo $e->getMessage();
+}
+__HALT_COMPILER(); ?>~~~~
+--EXPECTF--
+manifest cannot be larger than 100 MB in phar "%s"
diff --git a/ext/phar/tests/008.phpt b/ext/phar/tests/008.phpt
new file mode 100644
index 0000000000..664ffea5cb
--- /dev/null
+++ b/ext/phar/tests/008.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Phar::mapPhar truncated manifest (not enough for manifest length)
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");?>
+--FILE--
+<?php
+$file = "<?php
+Phar::mapPhar('hio');
+__HALT_COMPILER(); ?>";
+$file .= pack('V', 500) . 'notenough';
+file_put_contents(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php', $file);
+try {
+include dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+} catch (Exception $e) {
+echo $e->getMessage();
+}
+?>
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECTF--
+internal corruption of phar "%s" (truncated manifest header)
diff --git a/ext/phar/tests/009.phpt b/ext/phar/tests/009.phpt
new file mode 100644
index 0000000000..c80445d61b
--- /dev/null
+++ b/ext/phar/tests/009.phpt
@@ -0,0 +1,23 @@
+--TEST--
+Phar::mapPhar too many manifest entries
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");?>
+--INI--
+phar.require_hash=0
+--FILE--
+<?php
+$file = "<?php
+Phar::mapPhar('hio');
+__HALT_COMPILER(); ?>";
+$file .= pack('VVnVVV', 500, 500, 0x1000, 0x00000000, 0, 0) . str_repeat('A', 500);
+file_put_contents(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php', $file);
+try {
+include dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+} catch (Exception $e) {
+echo $e->getMessage();
+}
+?>
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECTF--
+internal corruption of phar "%s009.phar.php" (too many manifest entries for size of manifest)
diff --git a/ext/phar/tests/010.phpt b/ext/phar/tests/010.phpt
new file mode 100644
index 0000000000..3dce5f8f4c
--- /dev/null
+++ b/ext/phar/tests/010.phpt
@@ -0,0 +1,29 @@
+--TEST--
+Phar::mapPhar buffer overrun
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");?>
+--INI--
+phar.require_hash=0
+--FILE--
+<?php
+$file = "<?php
+Phar::mapPhar('hio');
+__HALT_COMPILER(); ?>";
+
+// this fails because the manifest length does not include the other 10 byte manifest data
+
+$manifest = pack('V', 1) . 'a' . pack('VVVVVV', 0, time(), 0, crc32(''), 0x00000000, 0);
+$file .= pack('VVnVV', strlen($manifest), 1, 0x1000, 0x00000000, 3) . 'hio' . pack('V', 0) . $manifest;
+
+file_put_contents(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php', $file);
+try {
+include dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+echo file_get_contents('phar://hio/a');
+} catch (Exception $e) {
+echo $e->getMessage();
+}
+?>
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECTF--
+internal corruption of phar "%s" (too many manifest entries for size of manifest)
diff --git a/ext/phar/tests/011.phpt b/ext/phar/tests/011.phpt
new file mode 100644
index 0000000000..4a1f0dd42c
--- /dev/null
+++ b/ext/phar/tests/011.phpt
@@ -0,0 +1,30 @@
+--TEST--
+Phar::mapPhar filesize too small in manifest
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");?>
+--INI--
+phar.require_hash=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$file = "<?php
+Phar::mapPhar('hio');
+__HALT_COMPILER(); ?>";
+
+// compressed file length does not match incompressed lentgh for an uncompressed file
+
+$files = array();
+$files['a'] = array('cont'=>'a','ulen'=>1,'clen'=>2);;
+include 'files/phar_test.inc';
+try {
+include $fname;
+echo file_get_contents('phar://hio/a');
+} catch (Exception $e) {
+echo $e->getMessage();
+}
+?>
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECTF--
+internal corruption of phar "%s" (compressed and uncompressed size does not match for uncompressed entry)
diff --git a/ext/phar/tests/012.phpt b/ext/phar/tests/012.phpt
new file mode 100644
index 0000000000..3246eff468
--- /dev/null
+++ b/ext/phar/tests/012.phpt
@@ -0,0 +1,28 @@
+--TEST--
+Phar::mapPhar valid file
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");?>
+--INI--
+phar.require_hash=0
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$file = "<?php
+Phar::mapPhar('hio');
+__HALT_COMPILER(); ?>";
+
+$files = array();
+$files['a'] = 'a';
+
+include 'files/phar_test.inc';
+include $fname;
+
+echo file_get_contents('phar://hio/a');
+
+?>
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECT--
+a
diff --git a/ext/phar/tests/013.phpt b/ext/phar/tests/013.phpt
new file mode 100644
index 0000000000..ae3ae72936
--- /dev/null
+++ b/ext/phar/tests/013.phpt
@@ -0,0 +1,23 @@
+--TEST--
+Phar::mapPhar filesize mismatch
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");?>
+--INI--
+phar.require_hash=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$file = "<?php __HALT_COMPILER(); ?>";
+// filesize should be 1, and is 2
+
+$files = array();
+$files['a'] = array('cont'=>'a', 'ulen'=>2, 'clen'=>2);
+include 'files/phar_test.inc';
+
+echo file_get_contents($pname.'/a');
+?>
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECTF--
+Warning: file_get_contents(phar://%s/a): failed to open stream: phar error: internal corruption of phar "%s" (%s file "a") in %s on line %d
diff --git a/ext/phar/tests/014.phpt b/ext/phar/tests/014.phpt
new file mode 100644
index 0000000000..d08e6550b6
--- /dev/null
+++ b/ext/phar/tests/014.phpt
@@ -0,0 +1,23 @@
+--TEST--
+Phar::mapPhar filesize mismatch
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");?>
+--INI--
+phar.require_hash=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$file = "<?php __HALT_COMPILER(); ?>";
+// wrong crc32
+
+$files = array();
+$files['a'] = array('cont'=>'a', 'crc32'=>crc32('aX'));
+include 'files/phar_test.inc';
+
+echo file_get_contents($pname.'/a');
+?>
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECTF--
+Warning: file_get_contents(phar://%s/a): failed to open stream: phar error: internal corruption of phar "%s" (crc32 mismatch on file "a") in %s on line %d
diff --git a/ext/phar/tests/015.phpt b/ext/phar/tests/015.phpt
new file mode 100644
index 0000000000..b93b77e9fb
--- /dev/null
+++ b/ext/phar/tests/015.phpt
@@ -0,0 +1,23 @@
+--TEST--
+Phar::mapPhar valid file (gzipped)
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zlib")) die("skip zlib not present"); ?>
+--INI--
+phar.require_hash=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$file = "<?php __HALT_COMPILER(); ?>";
+
+$files = array();
+$files['a'] = array('cont'=>'a','comp'=>chr(75) . chr(4) . chr(0) /* 'a' gzdeflated */, 'flags'=>0x00001000);
+include 'files/phar_test.inc';
+
+echo file_get_contents($pname .'/a');
+?>
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECT--
+a
diff --git a/ext/phar/tests/015b.phpt b/ext/phar/tests/015b.phpt
new file mode 100755
index 0000000000..08ead2d9c0
--- /dev/null
+++ b/ext/phar/tests/015b.phpt
@@ -0,0 +1,23 @@
+--TEST--
+Phar::mapPhar valid file (bzip2)
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");?>
+<?php if (!extension_loaded("bz2")) die("skip bz2 not present"); ?>
+--INI--
+phar.require_hash=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$file = "<?php __HALT_COMPILER(); ?>";
+
+$files = array();
+$files['a'] = array('cont'=>'Hello World', 'comp'=>pack('H*', '425a6834314159265359065c89da0000009780400000400080060490002000310c082031a916c41d41e2ee48a70a1200cb913b40'),'flags'=>0x00002000);
+include 'files/phar_test.inc';
+
+var_dump(file_get_contents($pname . '/a'));
+?>
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECT--
+string(11) "Hello World"
diff --git a/ext/phar/tests/016.phpt b/ext/phar/tests/016.phpt
new file mode 100644
index 0000000000..302d06d3cb
--- /dev/null
+++ b/ext/phar/tests/016.phpt
@@ -0,0 +1,39 @@
+--TEST--
+Phar::mapPhar invalid file (gzipped file length is too short)
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");?>
+<?php if (!extension_loaded("zlib")) die("skip zlib not present"); ?>
+--INI--
+phar.require_hash=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$file = "<?php __HALT_COMPILER(); ?>";
+// file length is too short
+
+$files = array();
+// "hi" gzdeflated
+$files['a'] = array('cont'=>'a','comp'=> pack('H*', 'cbc80400'),'flags'=>0x00001000, 'ulen' => 1, 'clen' => 4);
+$files['b'] = $files['a'];
+$files['c'] = array('cont'=>'*');
+$files['d'] = $files['a'];
+include 'files/phar_test.inc';
+
+var_dump(file_get_contents($pname . '/a'));
+var_dump(file_get_contents($pname . '/b'));
+var_dump(file_get_contents($pname . '/c'));
+var_dump(file_get_contents($pname . '/d'));
+?>
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECTF--
+Warning: file_get_contents(phar://%s/a): failed to open stream: phar error: internal corruption of phar "%s" (actual filesize mismatch on file "a") in %s on line %d
+bool(false)
+
+Warning: file_get_contents(phar://%s/b): failed to open stream: phar error: internal corruption of phar "%s" (actual filesize mismatch on file "b") in %s on line %d
+bool(false)
+string(1) "*"
+
+Warning: file_get_contents(phar://%s/d): failed to open stream: phar error: internal corruption of phar "%s" (actual filesize mismatch on file "d") in %s on line %d
+bool(false)
diff --git a/ext/phar/tests/016b.phpt b/ext/phar/tests/016b.phpt
new file mode 100755
index 0000000000..8fe66826d6
--- /dev/null
+++ b/ext/phar/tests/016b.phpt
@@ -0,0 +1,24 @@
+--TEST--
+Phar::mapPhar invalid file (gzipped file length is too short)
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");?>
+<?php if (!extension_loaded("zlib")) die("skip zlib not present"); ?>
+--INI--
+phar.require_hash=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$file = "<?php __HALT_COMPILER(); ?>";
+// file length is too short
+
+$files = array();
+$files['a'] = array('cont'=>'a','flags'=>0x00001000, 'clen' => 1);
+include 'files/phar_test.inc';
+
+echo file_get_contents($pname . '/a');
+?>
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECTF--
+Warning: file_get_contents(phar://%s/a): failed to open stream: phar error: internal corruption of phar "%s" (actual filesize mismatch on file "a") in %s on line %d
diff --git a/ext/phar/tests/017.phpt b/ext/phar/tests/017.phpt
new file mode 100644
index 0000000000..ec012eaa11
--- /dev/null
+++ b/ext/phar/tests/017.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Phar: opendir test - no dir specified at all
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$file = "<?php
+Phar::mapPhar('hio');
+__HALT_COMPILER(); ?>";
+
+$files = array();
+$files['a'] = 'abc';
+include 'files/phar_test.inc';
+
+include $fname;
+$dir = opendir('phar://hio');
+?>
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECTF--
+Warning: opendir(phar://hio): failed to open dir: phar error: no directory in "phar://hio", must have at least phar://hio/ for root directory (always use full path to a new phar)
+phar url "phar://hio" is unknown in %s017.php on line %d \ No newline at end of file
diff --git a/ext/phar/tests/018.phpt b/ext/phar/tests/018.phpt
new file mode 100644
index 0000000000..97cd323779
--- /dev/null
+++ b/ext/phar/tests/018.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Phar: opendir test, root directory
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$file = "<?php
+Phar::mapPhar('hio');
+__HALT_COMPILER(); ?>";
+
+$files = array();
+$files['a'] = 'a';
+$files['b/a'] = 'b';
+include 'files/phar_test.inc';
+
+include $fname;
+$dir = opendir('phar://hio/');
+while (false !== ($a = readdir($dir))) {
+ var_dump($a);
+ var_dump(is_dir('phar://hio/' . $a));
+}
+?>
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECT--
+string(1) "a"
+bool(false)
+string(1) "b"
+bool(true) \ No newline at end of file
diff --git a/ext/phar/tests/019.phpt b/ext/phar/tests/019.phpt
new file mode 100644
index 0000000000..3d00b5f8e9
--- /dev/null
+++ b/ext/phar/tests/019.phpt
@@ -0,0 +1,34 @@
+--TEST--
+Phar: opendir test, subdirectory
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$file = "<?php
+Phar::mapPhar('hio');
+__HALT_COMPILER(); ?>";
+
+$files = array();
+$files['a'] = 'a';
+$files['b/a'] = 'b';
+$files['b/c/d'] = 'c';
+$files['bad/c'] = 'd';
+include 'files/phar_test.inc';
+include $fname;
+$dir = opendir('phar://hio/b');
+while (false !== ($a = readdir($dir))) {
+ var_dump($a);
+ var_dump(is_dir('phar://hio/b/' . $a));
+}
+?>
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECT--
+string(1) "a"
+bool(false)
+string(1) "c"
+bool(true) \ No newline at end of file
diff --git a/ext/phar/tests/019b.phpt b/ext/phar/tests/019b.phpt
new file mode 100755
index 0000000000..574919b793
--- /dev/null
+++ b/ext/phar/tests/019b.phpt
@@ -0,0 +1,65 @@
+--TEST--
+Phar: opendir test, recurse into
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$file = "<?php
+Phar::mapPhar('hio');
+__HALT_COMPILER(); ?>";
+
+$files = array();
+$files['a'] = 'a';
+$files['b/a'] = 'b';
+$files['b/c/d'] = 'c';
+$files['bad/c'] = 'd';
+include 'files/phar_test.inc';
+include $fname;
+
+function dump($phar, $base)
+{
+ var_dump($phar . $base);
+ $dir = opendir($phar . $base);
+ if ($base == '/')
+ {
+ $base = '';
+ }
+ while (false !== ($entry = readdir($dir))) {
+ $entry = $base . '/' . $entry;
+ var_dump($entry);
+ var_dump(is_dir($phar . $entry));
+ if (is_dir($phar . $entry))
+ {
+ dump($phar, $entry);
+ }
+ }
+}
+
+dump('phar://hio', '/');
+
+?>
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECT--
+string(11) "phar://hio/"
+string(2) "/a"
+bool(false)
+string(2) "/b"
+bool(true)
+string(12) "phar://hio/b"
+string(4) "/b/a"
+bool(false)
+string(4) "/b/c"
+bool(true)
+string(14) "phar://hio/b/c"
+string(6) "/b/c/d"
+bool(false)
+string(4) "/bad"
+bool(true)
+string(14) "phar://hio/bad"
+string(6) "/bad/c"
+bool(false)
diff --git a/ext/phar/tests/019c.phpt b/ext/phar/tests/019c.phpt
new file mode 100755
index 0000000000..242b666871
--- /dev/null
+++ b/ext/phar/tests/019c.phpt
@@ -0,0 +1,73 @@
+--TEST--
+Phar: opendir test, recurse into
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$file = "<?php
+Phar::mapPhar('hio');
+__HALT_COMPILER(); ?>";
+
+$files = array();
+$files['a'] = 'a';
+$files['b/a'] = 'b';
+$files['b/c/d'] = 'c';
+$files['bad/c'] = 'd';
+include 'files/phar_test.inc';
+include $fname;
+
+function dump($phar, $base)
+{
+ var_dump($phar . $base);
+ $dir = opendir($phar . $base);
+ if ($base == '/')
+ {
+ $base = '';
+ }
+ while (false !== ($entry = readdir($dir))) {
+ $entry = $base . '/' . $entry;
+ var_dump($entry);
+ var_dump(is_dir($phar . $entry));
+ if (is_dir($phar . $entry))
+ {
+ dump($phar, $entry);
+ }
+ else
+ {
+ var_dump(file_get_contents($phar . $entry));
+ }
+ }
+}
+
+dump('phar://hio', '/');
+
+?>
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECT--
+string(11) "phar://hio/"
+string(2) "/a"
+bool(false)
+string(1) "a"
+string(2) "/b"
+bool(true)
+string(12) "phar://hio/b"
+string(4) "/b/a"
+bool(false)
+string(1) "b"
+string(4) "/b/c"
+bool(true)
+string(14) "phar://hio/b/c"
+string(6) "/b/c/d"
+bool(false)
+string(1) "c"
+string(4) "/bad"
+bool(true)
+string(14) "phar://hio/bad"
+string(6) "/bad/c"
+bool(false)
+string(1) "d"
diff --git a/ext/phar/tests/020.phpt b/ext/phar/tests/020.phpt
new file mode 100644
index 0000000000..b06cdbf731
--- /dev/null
+++ b/ext/phar/tests/020.phpt
@@ -0,0 +1,136 @@
+--TEST--
+Phar: url stat
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$file = "<?php
+Phar::mapPhar('hio');
+__HALT_COMPILER(); ?>";
+
+$pfile = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$files = array();
+$files['a'] = 'a';
+$files['b/a'] = 'b';
+$files['b/c/d'] = 'c';
+$files['bad/c'] = 'd';
+include 'files/phar_test.inc';
+include $fname;
+
+var_dump(stat('phar://hio/a'), stat('phar://hio/b'));
+?>
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECTF--
+array(26) {
+ [0]=>
+ int(12)
+ [1]=>
+ int(%d)
+ [2]=>
+ int(33060)
+ [3]=>
+ int(1)
+ [4]=>
+ int(0)
+ [5]=>
+ int(0)
+ [6]=>
+ int(-1)
+ [7]=>
+ int(1)
+ [8]=>
+ int(%d)
+ [9]=>
+ int(%d)
+ [10]=>
+ int(%d)
+ [11]=>
+ int(-1)
+ [12]=>
+ int(-1)
+ ["dev"]=>
+ int(12)
+ ["ino"]=>
+ int(%d)
+ ["mode"]=>
+ int(33060)
+ ["nlink"]=>
+ int(1)
+ ["uid"]=>
+ int(0)
+ ["gid"]=>
+ int(0)
+ ["rdev"]=>
+ int(-1)
+ ["size"]=>
+ int(1)
+ ["atime"]=>
+ int(%d)
+ ["mtime"]=>
+ int(%d)
+ ["ctime"]=>
+ int(%d)
+ ["blksize"]=>
+ int(-1)
+ ["blocks"]=>
+ int(-1)
+}
+array(26) {
+ [0]=>
+ int(12)
+ [1]=>
+ int(%d)
+ [2]=>
+ int(16749)
+ [3]=>
+ int(1)
+ [4]=>
+ int(0)
+ [5]=>
+ int(0)
+ [6]=>
+ int(-1)
+ [7]=>
+ int(0)
+ [8]=>
+ int(%d)
+ [9]=>
+ int(%d)
+ [10]=>
+ int(%d)
+ [11]=>
+ int(-1)
+ [12]=>
+ int(-1)
+ ["dev"]=>
+ int(12)
+ ["ino"]=>
+ int(%d)
+ ["mode"]=>
+ int(16749)
+ ["nlink"]=>
+ int(1)
+ ["uid"]=>
+ int(0)
+ ["gid"]=>
+ int(0)
+ ["rdev"]=>
+ int(-1)
+ ["size"]=>
+ int(0)
+ ["atime"]=>
+ int(%d)
+ ["mtime"]=>
+ int(%d)
+ ["ctime"]=>
+ int(%d)
+ ["blksize"]=>
+ int(-1)
+ ["blocks"]=>
+ int(-1)
+} \ No newline at end of file
diff --git a/ext/phar/tests/021.phpt b/ext/phar/tests/021.phpt
new file mode 100644
index 0000000000..9c9cd97568
--- /dev/null
+++ b/ext/phar/tests/021.phpt
@@ -0,0 +1,85 @@
+--TEST--
+Phar: stream stat
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$file = "<?php
+Phar::mapPhar('hio');
+__HALT_COMPILER(); ?>";
+
+$files = array();
+$files['a'] = 'a';
+$files['b/a'] = 'b';
+$files['b/c/d'] = 'c';
+$files['bad/c'] = 'd';
+
+include 'files/phar_test.inc';
+
+include $fname;
+
+$fp = fopen('phar://hio/a', 'r');
+var_dump(fstat($fp));
+fclose($fp);
+?>
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECTF--
+array(26) {
+ [0]=>
+ int(12)
+ [1]=>
+ int(%d)
+ [2]=>
+ int(33060)
+ [3]=>
+ int(1)
+ [4]=>
+ int(0)
+ [5]=>
+ int(0)
+ [6]=>
+ int(-1)
+ [7]=>
+ int(1)
+ [8]=>
+ int(%d)
+ [9]=>
+ int(%d)
+ [10]=>
+ int(%d)
+ [11]=>
+ int(-1)
+ [12]=>
+ int(-1)
+ ["dev"]=>
+ int(12)
+ ["ino"]=>
+ int(%d)
+ ["mode"]=>
+ int(33060)
+ ["nlink"]=>
+ int(1)
+ ["uid"]=>
+ int(0)
+ ["gid"]=>
+ int(0)
+ ["rdev"]=>
+ int(-1)
+ ["size"]=>
+ int(1)
+ ["atime"]=>
+ int(%d)
+ ["mtime"]=>
+ int(%d)
+ ["ctime"]=>
+ int(%d)
+ ["blksize"]=>
+ int(-1)
+ ["blocks"]=>
+ int(-1)
+} \ No newline at end of file
diff --git a/ext/phar/tests/022.phpt b/ext/phar/tests/022.phpt
new file mode 100644
index 0000000000..20c24a0214
--- /dev/null
+++ b/ext/phar/tests/022.phpt
@@ -0,0 +1,110 @@
+--TEST--
+Phar: stream stat
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$file = "<?php
+Phar::mapPhar('hio');
+__HALT_COMPILER(); ?>";
+
+$files = array();
+$files['a'] = 'abcdefg';
+
+include 'files/phar_test.inc';
+
+include $fname;
+
+$fp = fopen('phar://hio/a', 'r');
+var_dump(ftell($fp));
+echo 'fseek($fp, 1)';var_dump(fseek($fp, 1));
+var_dump(ftell($fp));
+echo 'fseek($fp, 1, SEEK_CUR)';var_dump(fseek($fp, 1, SEEK_CUR));
+var_dump(ftell($fp));
+echo 'fseek($fp, -1, SEEK_CUR)';var_dump(fseek($fp, -1, SEEK_CUR));
+var_dump(ftell($fp));
+echo 'fseek($fp, -1, SEEK_END)';var_dump(fseek($fp, -1, SEEK_END));
+var_dump(ftell($fp));
+echo 'fseek($fp, -8, SEEK_END)';var_dump(fseek($fp, -8, SEEK_END));
+var_dump(ftell($fp));
+echo 'fseek($fp, -7, SEEK_END)';var_dump(fseek($fp, -7, SEEK_END));
+var_dump(ftell($fp));
+echo 'fseek($fp, 0, SEEK_END)';var_dump(fseek($fp, 0, SEEK_END));
+var_dump(ftell($fp));
+echo 'fseek($fp, 1, SEEK_END)';var_dump(fseek($fp, 1, SEEK_END));
+var_dump(ftell($fp));
+echo 'fseek($fp, -8, SEEK_END)';var_dump(fseek($fp, -8, SEEK_END));
+var_dump(ftell($fp));
+echo 'fseek($fp, 6)';var_dump(fseek($fp, 6));
+var_dump(ftell($fp));
+echo 'fseek($fp, 8)';var_dump(fseek($fp, 8));
+var_dump(ftell($fp));
+echo 'fseek($fp, -1)';var_dump(fseek($fp, -1));
+var_dump(ftell($fp));
+echo "next\n";
+fseek($fp, 4);
+var_dump(ftell($fp));
+echo 'fseek($fp, -5, SEEK_CUR)';var_dump(fseek($fp, -5, SEEK_CUR));
+var_dump(ftell($fp));
+fseek($fp, 4);
+var_dump(ftell($fp));
+echo 'fseek($fp, 5, SEEK_CUR)';var_dump(fseek($fp, 5, SEEK_CUR));
+var_dump(ftell($fp));
+fseek($fp, 4);
+var_dump(ftell($fp));
+echo 'fseek($fp, -4, SEEK_CUR)';var_dump(fseek($fp, -4, SEEK_CUR));
+var_dump(ftell($fp));
+fseek($fp, 4);
+var_dump(ftell($fp));
+echo 'fseek($fp, 3, SEEK_CUR)';var_dump(fseek($fp, 3, SEEK_CUR));
+var_dump(ftell($fp));
+fclose($fp);
+?>
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php');
+exit(0);
+ ?>
+--EXPECT--
+int(0)
+fseek($fp, 1)int(0)
+int(1)
+fseek($fp, 1, SEEK_CUR)int(0)
+int(2)
+fseek($fp, -1, SEEK_CUR)int(0)
+int(1)
+fseek($fp, -1, SEEK_END)int(0)
+int(6)
+fseek($fp, -8, SEEK_END)int(-1)
+bool(false)
+fseek($fp, -7, SEEK_END)int(0)
+int(0)
+fseek($fp, 0, SEEK_END)int(0)
+int(7)
+fseek($fp, 1, SEEK_END)int(-1)
+bool(false)
+fseek($fp, -8, SEEK_END)int(-1)
+bool(false)
+fseek($fp, 6)int(0)
+int(6)
+fseek($fp, 8)int(-1)
+bool(false)
+fseek($fp, -1)int(-1)
+bool(false)
+next
+int(4)
+fseek($fp, -5, SEEK_CUR)int(-1)
+bool(false)
+int(4)
+fseek($fp, 5, SEEK_CUR)int(-1)
+bool(false)
+int(4)
+fseek($fp, -4, SEEK_CUR)int(0)
+int(0)
+int(4)
+fseek($fp, 3, SEEK_CUR)int(0)
+int(7)
diff --git a/ext/phar/tests/023.phpt b/ext/phar/tests/023.phpt
new file mode 100755
index 0000000000..808f91deae
--- /dev/null
+++ b/ext/phar/tests/023.phpt
@@ -0,0 +1,32 @@
+--TEST--
+Phar: phar:// file_get_contents
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$file = "<?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"; ?>';
+
+include 'files/phar_test.inc';
+
+var_dump(file_get_contents($pname . '/a.php'));
+var_dump(file_get_contents($pname . '/b.php'));
+var_dump(file_get_contents($pname . '/b/c.php'));
+
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECT--
+string(28) "<?php echo "This is a\n"; ?>"
+string(28) "<?php echo "This is b\n"; ?>"
+string(30) "<?php echo "This is b/c\n"; ?>"
+===DONE===
diff --git a/ext/phar/tests/024.phpt b/ext/phar/tests/024.phpt
new file mode 100755
index 0000000000..ad30d2644d
--- /dev/null
+++ b/ext/phar/tests/024.phpt
@@ -0,0 +1,32 @@
+--TEST--
+Phar: phar:// include
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$file = "<?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"; ?>';
+
+include 'files/phar_test.inc';
+
+include $pname . '/a.php';
+include $pname . '/b.php';
+include $pname . '/b/c.php';
+
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECT--
+This is a
+This is b
+This is b/c
+===DONE===
diff --git a/ext/phar/tests/025.phpt b/ext/phar/tests/025.phpt
new file mode 100755
index 0000000000..bbb5bc4e83
--- /dev/null
+++ b/ext/phar/tests/025.phpt
@@ -0,0 +1,32 @@
+--TEST--
+Phar: phar:// include (repeated names)
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$file = "<?php __HALT_COMPILER(); ?>";
+
+$files = array();
+$files['a'] = '<?php echo "This is a\n"; ?>';
+$files['b'] = '<?php echo "This is b\n"; ?>';
+$files['b/b'] = '<?php echo "This is b/b\n"; ?>';
+
+include 'files/phar_test.inc';
+
+include $pname . '/a';
+include $pname . '/b';
+include $pname . '/b/b';
+
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECT--
+This is a
+This is b
+This is b/b
+===DONE===
diff --git a/ext/phar/tests/026.phpt b/ext/phar/tests/026.phpt
new file mode 100755
index 0000000000..696fbcf415
--- /dev/null
+++ b/ext/phar/tests/026.phpt
@@ -0,0 +1,34 @@
+--TEST--
+Phar: phar:// require from within
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$file = "<?php __HALT_COMPILER(); ?>";
+
+$files = array();
+$files['a.php'] = '<?php echo "This is a\n"; require \''.$pname.'/b.php\'; ?>';
+$files['b.php'] = '<?php echo "This is b\n"; require \''.$pname.'/b/c.php\'; ?>';
+$files['b/c.php'] = '<?php echo "This is b/c\n"; require \''.$pname.'/b/d.php\'; ?>';
+$files['b/d.php'] = '<?php echo "This is b/d\n"; require \''.$pname.'/e.php\'; ?>';
+$files['e.php'] = '<?php echo "This is e\n"; ?>';
+
+include 'files/phar_test.inc';
+
+require $pname . '/a.php';
+
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECT--
+This is a
+This is b
+This is b/c
+This is b/d
+This is e
+===DONE===
diff --git a/ext/phar/tests/027.phpt b/ext/phar/tests/027.phpt
new file mode 100755
index 0000000000..679fefc2cd
--- /dev/null
+++ b/ext/phar/tests/027.phpt
@@ -0,0 +1,94 @@
+--TEST--
+Phar: phar:// opendir
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$file = "<?php __HALT_COMPILER(); ?>";
+
+$files = array();
+$files['a.php'] = '<?php echo "This is a\n"; require \''.$pname.'/b.php\'; ?>';
+$files['b.php'] = '<?php echo "This is b\n"; require \''.$pname.'/b/c.php\'; ?>';
+$files['b/c.php'] = '<?php echo "This is b/c\n"; require \''.$pname.'/b/d.php\'; ?>';
+$files['b/d.php'] = '<?php echo "This is b/d\n"; require \''.$pname.'/e.php\'; ?>';
+$files['e.php'] = '<?php echo "This is e\n"; ?>';
+
+include 'files/phar_test.inc';
+
+function dump($phar, $base)
+{
+ var_dump(str_replace(dirname(__FILE__), '*', $phar) . $base);
+ $dir = opendir($phar . $base);
+ if ($base == '/')
+ {
+ $base = '';
+ }
+ while (false !== ($entry = readdir($dir))) {
+ $entry = $base . '/' . $entry;
+ var_dump($entry);
+ var_dump(is_dir($phar . $entry));
+ if (is_dir($phar . $entry))
+ {
+ dump($phar, $entry);
+ }
+ }
+}
+
+dump($pname, '/');
+
+$a = opendir($pname);
+// this may stop working in future versions, but is here for code coverage purposes
+echo "fseek on dir handle\n";
+var_dump(fseek($a, 0, SEEK_END), ftell($a));
+var_dump(fseek($a, -1), ftell($a));
+var_dump(fseek($a, 1), ftell($a));
+echo "fwrite on dir handle\n";
+var_dump(fwrite($a, 'hi'));
+var_dump(fstat($a));
+closedir($a);
+echo "opendir edge cases\n";
+var_dump(opendir("phar://"));
+var_dump(opendir("phar://foo.phar/hi"));
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECTF--
+string(%d) "phar://*/027.phar.php/"
+string(6) "/a.php"
+bool(false)
+string(2) "/b"
+bool(true)
+string(%d) "phar://*/027.phar.php/b"
+string(8) "/b/c.php"
+bool(false)
+string(8) "/b/d.php"
+bool(false)
+string(6) "/b.php"
+bool(false)
+string(6) "/e.php"
+bool(false)
+fseek on dir handle
+int(0)
+int(4)
+int(-1)
+int(4)
+int(0)
+int(1)
+fwrite on dir handle
+int(0)
+bool(false)
+opendir edge cases
+
+Warning: opendir(phar://): failed to open dir: phar error: no directory in "phar://", must have at least phar:/// for root directory (always use full path to a new phar)
+phar url "phar://" is unknown in %s027.php on line %d
+bool(false)
+
+Warning: opendir(phar://foo.phar/hi): failed to open dir: phar error: invalid url or non-existent phar "phar://foo.phar/hi"
+phar url "phar://foo.phar/hi" is unknown in %s027.php on line %d
+bool(false)
+===DONE===
diff --git a/ext/phar/tests/028.phpt b/ext/phar/tests/028.phpt
new file mode 100755
index 0000000000..087f822777
--- /dev/null
+++ b/ext/phar/tests/028.phpt
@@ -0,0 +1,47 @@
+--TEST--
+Phar::loadPhar
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://hio';
+$file = '<?php include "' . $pname . '/a.php"; __HALT_COMPILER(); ?>';
+$alias = '';
+
+$files = array();
+$files['a.php'] = '<?php echo "This is a\n"; include "'.$pname.'/b.php"; ?>';
+$files['b.php'] = '<?php echo "This is b\n"; include "'.$pname.'/b/c.php"; ?>';
+$files['b/c.php'] = '<?php echo "This is b/c\n"; include "'.$pname.'/b/d.php"; ?>';
+$files['b/d.php'] = '<?php echo "This is b/d\n"; include "'.$pname.'/e.php"; ?>';
+$files['e.php'] = '<?php echo "This is e\n"; ?>';
+
+include 'files/phar_test.inc';
+
+Phar::loadPhar($fname, 'hio');
+
+include $fname;
+
+echo "======\n";
+
+include $pname . '/a.php';
+
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECTF--
+This is a
+This is b
+This is b/c
+This is b/d
+This is e
+======
+This is a
+This is b
+This is b/c
+This is b/d
+This is e
+===DONE===
diff --git a/ext/phar/tests/029.phpt b/ext/phar/tests/029.phpt
new file mode 100755
index 0000000000..41fcec03e7
--- /dev/null
+++ b/ext/phar/tests/029.phpt
@@ -0,0 +1,50 @@
+--TEST--
+Phar::loadPhar overloading alias names
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+--FILE--
+<?php
+$fname1 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.1.phar.php';
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.phar.php';
+$fname = $fname1;
+$alias = '';
+$pname = 'phar://hio';
+$file = '<?php include "' . $pname . '/a.php"; __HALT_COMPILER(); ?>';
+
+$files = array();
+$files['a.php'] = '<?php echo "This is a\n"; include "'.$pname.'/b.php"; ?>';
+$files['b.php'] = '<?php echo "This is b\n"; include "'.$pname.'/b/c.php"; ?>';
+$files['b/c.php'] = '<?php echo "This is b/c\n"; include "'.$pname.'/b/d.php"; ?>';
+$files['b/d.php'] = '<?php echo "This is b/d\n"; include "'.$pname.'/e.php"; ?>';
+$files['e.php'] = '<?php echo "This is e\n"; ?>';
+
+include 'files/phar_test.inc';
+
+copy($fname1, $fname2);
+
+var_dump(Phar::loadPhar($fname1, 'hio'));
+var_dump(Phar::loadPhar($fname1, 'copy'));
+$a = new Phar($fname1);
+try
+{
+ var_dump(Phar::loadPhar($fname2, 'copy'));
+}
+catch (Exception $e)
+{
+ echo $e->getMessage() . "\n";
+}
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.1.phar.php');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar.php');
+?>
+--EXPECTF--
+bool(true)
+bool(true)
+alias "copy" is already used for archive "%s029.1.phar.php" cannot be overloaded with "%s029.2.phar.php"
+===DONE===
diff --git a/ext/phar/tests/030.phpt b/ext/phar/tests/030.phpt
new file mode 100755
index 0000000000..afaeb1a802
--- /dev/null
+++ b/ext/phar/tests/030.phpt
@@ -0,0 +1,38 @@
+--TEST--
+Phar::loadPhar ignoring alias
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$file = '<?php include "' . $pname . '/a.php"; __HALT_COMPILER(); ?>';
+
+$files = array();
+$files['a.php'] = '<?php echo "This is a\n"; include \''.$pname.'/b.php\'; ?>';
+$files['b.php'] = '<?php echo "This is b\n"; include \''.$pname.'/b/c.php\'; ?>';
+$files['b/c.php'] = '<?php echo "This is b/c\n"; include \''.$pname.'/b/d.php\'; ?>';
+$files['b/d.php'] = '<?php echo "This is b/d\n"; include \''.$pname.'/e.php\'; ?>';
+$files['e.php'] = '<?php echo "This is e\n"; ?>';
+
+include 'files/phar_test.inc';
+
+Phar::loadPhar($fname);
+
+require $pname . '/a.php';
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php');
+?>
+--EXPECTF--
+This is a
+This is b
+This is b/c
+This is b/d
+This is e
+===DONE===
diff --git a/ext/phar/tests/031.phpt b/ext/phar/tests/031.phpt
new file mode 100755
index 0000000000..4d5988621d
--- /dev/null
+++ b/ext/phar/tests/031.phpt
@@ -0,0 +1,31 @@
+--TEST--
+Phar: include and parser error
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+--FILE--
+<?php
+
+$pharconfig = 3;
+
+require_once 'files/phar_oo_test.inc';
+
+Phar::loadPhar($fname);
+
+$pname = 'phar://' . $fname . '/a.php';
+
+var_dump(file_get_contents($pname));
+require $pname;
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/files/phar_oo_test.phar.php');
+__halt_compiler();
+?>
+--EXPECTF--
+string(25) "<?php echo new new class;"
+
+Parse error: %s in phar://%sphar_oo_test.phar.php/a.php on line %d
diff --git a/ext/phar/tests/032.phpt b/ext/phar/tests/032.phpt
new file mode 100755
index 0000000000..faf3dcbf58
--- /dev/null
+++ b/ext/phar/tests/032.phpt
@@ -0,0 +1,29 @@
+--TEST--
+Phar: require hash
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=1
+--FILE--
+<?php
+
+$pharconfig = 0;
+
+require_once 'files/phar_oo_test.inc';
+
+try {
+Phar::loadPhar($fname);
+} catch (Exception $e) {
+echo $e->getMessage();
+}
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/files/phar_oo_test.phar.php');
+__halt_compiler();
+?>
+--EXPECTF--
+
+phar "%sphar_oo_test.phar.php" does not have a signature===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/033.phpt b/ext/phar/tests/033.phpt
new file mode 100644
index 0000000000..d53c7f52fa
--- /dev/null
+++ b/ext/phar/tests/033.phpt
@@ -0,0 +1,47 @@
+--TEST--
+Phar::chmod
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+phar.require_hash=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.1.phar.php';
+$pname = 'phar://hio';
+$file = '<?php include "' . $pname . '/a.php"; __HALT_COMPILER(); ?>';
+
+$files = array();
+$files['a.php'] = '<?php echo "This is a\n"; include "'.$pname.'/b.php"; ?>';
+$files['dir/'] = '';
+$hasdir = 1;
+include 'files/phar_test.inc';
+$a = new Phar($fname);
+var_dump($a['a.php']->isExecutable());
+$a['a.php']->chmod(0777);
+var_dump($a['a.php']->isExecutable());
+$a['a.php']->chmod(0666);
+var_dump($a['a.php']->isExecutable());
+echo "test dir\n";
+var_dump($a['dir']->isDir());
+var_dump($a['dir']->isReadable());
+$a['dir']->chmod(000);
+var_dump($a['dir']->isReadable());
+$a['dir']->chmod(0666);
+var_dump($a['dir']->isReadable());
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.1.phar.php');
+?>
+--EXPECT--
+bool(false)
+bool(true)
+bool(false)
+test dir
+bool(true)
+bool(true)
+bool(false)
+bool(true)
+===DONE===
diff --git a/ext/phar/tests/033a.phpt b/ext/phar/tests/033a.phpt
new file mode 100644
index 0000000000..e8725bdda6
--- /dev/null
+++ b/ext/phar/tests/033a.phpt
@@ -0,0 +1,36 @@
+--TEST--
+Phar::chmod
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=1
+phar.require_hash=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.1.phar.php';
+$pname = 'phar://hio';
+$file = '<?php include "' . $pname . '/a.php"; __HALT_COMPILER(); ?>';
+
+$files = array();
+$files['a.php'] = '<?php echo "This is a\n"; include "'.$pname.'/b.php"; ?>';
+include 'files/phar_test.inc';
+try {
+ $a = new Phar($fname);
+ var_dump($a['a.php']->isExecutable());
+ $a['a.php']->chmod(0777);
+ var_dump($a['a.php']->isExecutable());
+ $a['a.php']->chmod(0666);
+ var_dump($a['a.php']->isExecutable());
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.1.phar.php');
+?>
+--EXPECTF--
+bool(false)
+Cannot modify permissions for file "a.php" in phar "%s033a.1.phar.php", write operations are prohibited
+===DONE===
diff --git a/ext/phar/tests/addfuncs.phpt b/ext/phar/tests/addfuncs.phpt
new file mode 100644
index 0000000000..d9a183fd68
--- /dev/null
+++ b/ext/phar/tests/addfuncs.phpt
@@ -0,0 +1,41 @@
+--TEST--
+Phar: addFile/addFromString
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$phar = new Phar($fname);
+$phar->addFromString('a', 'hi');
+echo file_get_contents($pname . '/a') . "\n";
+$phar->addFile($pname . '/a', 'b');
+echo file_get_contents($pname . '/b') . "\n";
+try {
+$phar->addFile($pname . '/a');
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+try {
+$phar->addFile($pname . '/a', 'a');
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+try {
+$phar->addFile(dirname(__FILE__) . '/does/not/exist');
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECTF--
+hi
+hi
+Entry phar://%saddfuncs.phar.php/a does not exist and cannot be created: phar error: invalid path "phar://%saddfuncs.phar.php/a" contains double slash
+Entry a does not exist and cannot be created: phar error: file "a" in phar "%saddfuncs.phar.php" cannot be opened for writing, readable file pointers are open
+phar error: unable to open file "%s/does/not/exist" to add to phar archive
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/alias_acrobatics.phpt b/ext/phar/tests/alias_acrobatics.phpt
new file mode 100644
index 0000000000..1bb20a4b3a
--- /dev/null
+++ b/ext/phar/tests/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';
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.phar';
+
+$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');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar');
+?>
+--EXPECTF--
+alias "foo" is already used for archive "%salias_acrobatics.phar" cannot be overloaded with "%salias_acrobatics.2.phar"
+2
+Cannot open archive "%salias_acrobatics.2.phar", alias is already in use by existing archive
+alias "another" is already used for archive "%salias_acrobatics.phar" cannot be overloaded with "%salias_acrobatics.phar"
+===DONE===
diff --git a/ext/phar/tests/badparameters.phpt b/ext/phar/tests/badparameters.phpt
new file mode 100644
index 0000000000..a6ce37b3f9
--- /dev/null
+++ b/ext/phar/tests/badparameters.phpt
@@ -0,0 +1,210 @@
+--TEST--
+Phar: bad parameters to various methods
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+ini_set('phar.readonly', 1);
+Phar::mungServer('hi');
+Phar::createDefaultStub(array());
+Phar::loadPhar(array());
+Phar::canCompress('hi');
+$a = new Phar(array());
+$a = new Phar(dirname(__FILE__) . '/files/frontcontroller10.phar');
+$a->convertToExecutable(array());
+$a->convertToData(array());
+$b = new PharData(dirname(__FILE__) . '/whatever.tar');
+$c = new PharData(dirname(__FILE__) . '/whatever.zip');
+$b->delete(array());
+try {
+$a->delete('oops');
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+try {
+$b->delete('oops');
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+echo $a->getPath() . "\n";
+try {
+$a->setAlias('oops');
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+try {
+$b->setAlias('oops');
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+ini_set('phar.readonly', 0);
+$a->setAlias(array());
+ini_set('phar.readonly', 1);
+try {
+$b->stopBuffering();
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+try {
+$a->setStub('oops');
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+try {
+$b->setStub('oops');
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+ini_set('phar.readonly', 0);
+$a->setStub(array());
+ini_set('phar.readonly', 1);
+try {
+$b->setDefaultStub('oops');
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+$a->setDefaultStub(array());
+try {
+$a->setDefaultStub('oops');
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+try {
+$a->setSignatureAlgorithm(Phar::MD5);
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+try {
+$b->setSignatureAlgorithm(Phar::MD5);
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+try {
+$c->setSignatureAlgorithm(Phar::MD5);
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+$a->compress(array());
+try {
+$a->compress(1);
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+$a->compressFiles(array());
+try {
+$a->decompressFiles();
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+$a->copy(array());
+try {
+$a->copy('a', 'b');
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+$a->offsetExists(array());
+$a->offsetGet(array());
+ini_set('phar.readonly', 0);
+$a->offsetSet(array());
+ini_set('phar.readonly', 1);
+$b->offsetUnset(array());
+try {
+$a->offsetUnset('a');
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+$a->addEmptyDir(array());
+$a->addFile(array());
+$a->addFromString(array());
+try {
+$a->setMetadata('a');
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+try {
+$b->setMetadata('a');
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+ini_set('phar.readonly', 0);
+$a->setMetadata(1,2);
+ini_set('phar.readonly', 1);
+try {
+$a->delMetadata();
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+try {
+$b->delMetadata();
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--EXPECTF--
+Warning: Phar::mungServer() expects parameter 1 to be array, string given in %sbadparameters.php on line %d
+
+Warning: Phar::createDefaultStub() expects parameter 1 to be string, array given in %sbadparameters.php on line %d
+
+Warning: Phar::loadPhar() expects parameter 1 to be string, array given in %sbadparameters.php on line %d
+
+Warning: Phar::canCompress() expects parameter 1 to be long, string given in %sbadparameters.php on line %d
+
+Warning: Phar::__construct() expects parameter 1 to be string, array given in %sbadparameters.php on line %d
+
+Warning: Phar::convertToExecutable() expects parameter 1 to be long, array given in %sbadparameters.php on line %d
+
+Warning: Phar::convertToData() expects parameter 1 to be long, array given in %sbadparameters.php on line %d
+
+Warning: PharData::delete() expects parameter 1 to be string, array given in %sbadparameters.php on line %d
+Cannot write out phar archive, phar is read-only
+Entry oops does not exist and cannot be deleted
+%sfiles/frontcontroller10.phar
+Cannot write out phar archive, phar is read-only
+A Phar alias cannot be set in a plain tar archive
+
+Warning: Phar::setAlias() expects parameter 1 to be string, array given in %sbadparameters.php on line %d
+Cannot change stub, phar is read-only
+A Phar stub cannot be set in a plain tar archive
+
+Warning: Phar::setStub() expects parameter 1 to be string, array given in %sbadparameters.php on line %d
+A Phar stub cannot be set in a plain tar archive
+
+Warning: Phar::setDefaultStub() expects parameter 1 to be string, array given in %sbadparameters.php on line %d
+Cannot change stub: phar.readonly=1
+Cannot set signature algorithm, phar is read-only
+Cannot set signature algorithm, not possible with tar-based phar archives
+Cannot set signature algorithm, not possible with zip-based phar archives
+
+Warning: Phar::compress() expects parameter 1 to be long, array given in %sbadparameters.php on line %d
+Cannot compress phar archive, phar is read-only
+
+Warning: Phar::compressFiles() expects parameter 1 to be long, array given in %sbadparameters.php on line %d
+Phar is readonly, cannot change compression
+
+Warning: Phar::copy() expects exactly 2 parameters, 1 given in %sbadparameters.php on line %d
+Cannot copy "a" to "b", phar is read-only
+
+Warning: Phar::offsetExists() expects parameter 1 to be string, array given in %sbadparameters.php on line %d
+
+Warning: Phar::offsetGet() expects parameter 1 to be string, array given in %sbadparameters.php on line %d
+
+Warning: Phar::offsetSet() expects exactly 2 parameters, 1 given in %sbadparameters.php on line %d
+
+Warning: PharData::offsetUnset() expects parameter 1 to be string, array given in %sbadparameters.php on line %d
+Write operations disabled by INI setting
+
+Warning: Phar::addEmptyDir() expects parameter 1 to be string, array given in %sbadparameters.php on line %d
+
+Warning: Phar::addFile() expects parameter 1 to be string, array given in %sbadparameters.php on line %d
+
+Warning: Phar::addFromString() expects exactly 2 parameters, 1 given in %sbadparameters.php on line %d
+Write operations disabled by INI setting
+Cannot set metadata, not possible with tar-based phar archives
+
+Warning: Phar::setMetadata() expects exactly 1 parameter, 2 given in %sbadparameters.php on line %d
+Write operations disabled by INI setting
+Cannot delete metadata, not possible with tar-based phar archives
+===DONE===
diff --git a/ext/phar/tests/bug13727.phpt b/ext/phar/tests/bug13727.phpt
new file mode 100644
index 0000000000..cc7fc19a6c
--- /dev/null
+++ b/ext/phar/tests/bug13727.phpt
@@ -0,0 +1,4135 @@
+--TEST--
+Phar: SLOW TEST bug #13727: "Number of files in the Phar" limited to 2042
+--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.php';
+$dirName = dirname(__FILE__);
+$pname = 'phar://' . $fname;
+$pArchive="DataArchive.phar";
+$p = new Phar($fname, 0, $pArchive);
+for ($i = 0; $i < 4*1024; $i++){
+ echo("$i\n");
+ if (!is_dir($fileDir="$dirName/test_data"))
+ mkdir($fileDir, 0777, true);
+ file_put_contents("$fileDir/$i", "");
+ $p->addFile("$fileDir/$i", "$dirName");
+}
+echo("\n Written Files($i)\n");
+?>
+===DONE===
+--CLEAN--
+<?php
+$dirName = dirname(__FILE__);
+$fileDir="$dirName/test_data";
+for ($i = 0; $i < 4*1024; $i++){
+ unlink("$fileDir/$i");
+}
+rmdir($fileDir);
+unlink($dirName . '/' . basename(__FILE__, '.clean.php') . '.phar.php');
+__HALT_COMPILER();
+?>
+--EXPECT--
+0
+1
+2
+3
+4
+5
+6
+7
+8
+9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+21
+22
+23
+24
+25
+26
+27
+28
+29
+30
+31
+32
+33
+34
+35
+36
+37
+38
+39
+40
+41
+42
+43
+44
+45
+46
+47
+48
+49
+50
+51
+52
+53
+54
+55
+56
+57
+58
+59
+60
+61
+62
+63
+64
+65
+66
+67
+68
+69
+70
+71
+72
+73
+74
+75
+76
+77
+78
+79
+80
+81
+82
+83
+84
+85
+86
+87
+88
+89
+90
+91
+92
+93
+94
+95
+96
+97
+98
+99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
+508
+509
+510
+511
+512
+513
+514
+515
+516
+517
+518
+519
+520
+521
+522
+523
+524
+525
+526
+527
+528
+529
+530
+531
+532
+533
+534
+535
+536
+537
+538
+539
+540
+541
+542
+543
+544
+545
+546
+547
+548
+549
+550
+551
+552
+553
+554
+555
+556
+557
+558
+559
+560
+561
+562
+563
+564
+565
+566
+567
+568
+569
+570
+571
+572
+573
+574
+575
+576
+577
+578
+579
+580
+581
+582
+583
+584
+585
+586
+587
+588
+589
+590
+591
+592
+593
+594
+595
+596
+597
+598
+599
+600
+601
+602
+603
+604
+605
+606
+607
+608
+609
+610
+611
+612
+613
+614
+615
+616
+617
+618
+619
+620
+621
+622
+623
+624
+625
+626
+627
+628
+629
+630
+631
+632
+633
+634
+635
+636
+637
+638
+639
+640
+641
+642
+643
+644
+645
+646
+647
+648
+649
+650
+651
+652
+653
+654
+655
+656
+657
+658
+659
+660
+661
+662
+663
+664
+665
+666
+667
+668
+669
+670
+671
+672
+673
+674
+675
+676
+677
+678
+679
+680
+681
+682
+683
+684
+685
+686
+687
+688
+689
+690
+691
+692
+693
+694
+695
+696
+697
+698
+699
+700
+701
+702
+703
+704
+705
+706
+707
+708
+709
+710
+711
+712
+713
+714
+715
+716
+717
+718
+719
+720
+721
+722
+723
+724
+725
+726
+727
+728
+729
+730
+731
+732
+733
+734
+735
+736
+737
+738
+739
+740
+741
+742
+743
+744
+745
+746
+747
+748
+749
+750
+751
+752
+753
+754
+755
+756
+757
+758
+759
+760
+761
+762
+763
+764
+765
+766
+767
+768
+769
+770
+771
+772
+773
+774
+775
+776
+777
+778
+779
+780
+781
+782
+783
+784
+785
+786
+787
+788
+789
+790
+791
+792
+793
+794
+795
+796
+797
+798
+799
+800
+801
+802
+803
+804
+805
+806
+807
+808
+809
+810
+811
+812
+813
+814
+815
+816
+817
+818
+819
+820
+821
+822
+823
+824
+825
+826
+827
+828
+829
+830
+831
+832
+833
+834
+835
+836
+837
+838
+839
+840
+841
+842
+843
+844
+845
+846
+847
+848
+849
+850
+851
+852
+853
+854
+855
+856
+857
+858
+859
+860
+861
+862
+863
+864
+865
+866
+867
+868
+869
+870
+871
+872
+873
+874
+875
+876
+877
+878
+879
+880
+881
+882
+883
+884
+885
+886
+887
+888
+889
+890
+891
+892
+893
+894
+895
+896
+897
+898
+899
+900
+901
+902
+903
+904
+905
+906
+907
+908
+909
+910
+911
+912
+913
+914
+915
+916
+917
+918
+919
+920
+921
+922
+923
+924
+925
+926
+927
+928
+929
+930
+931
+932
+933
+934
+935
+936
+937
+938
+939
+940
+941
+942
+943
+944
+945
+946
+947
+948
+949
+950
+951
+952
+953
+954
+955
+956
+957
+958
+959
+960
+961
+962
+963
+964
+965
+966
+967
+968
+969
+970
+971
+972
+973
+974
+975
+976
+977
+978
+979
+980
+981
+982
+983
+984
+985
+986
+987
+988
+989
+990
+991
+992
+993
+994
+995
+996
+997
+998
+999
+1000
+1001
+1002
+1003
+1004
+1005
+1006
+1007
+1008
+1009
+1010
+1011
+1012
+1013
+1014
+1015
+1016
+1017
+1018
+1019
+1020
+1021
+1022
+1023
+1024
+1025
+1026
+1027
+1028
+1029
+1030
+1031
+1032
+1033
+1034
+1035
+1036
+1037
+1038
+1039
+1040
+1041
+1042
+1043
+1044
+1045
+1046
+1047
+1048
+1049
+1050
+1051
+1052
+1053
+1054
+1055
+1056
+1057
+1058
+1059
+1060
+1061
+1062
+1063
+1064
+1065
+1066
+1067
+1068
+1069
+1070
+1071
+1072
+1073
+1074
+1075
+1076
+1077
+1078
+1079
+1080
+1081
+1082
+1083
+1084
+1085
+1086
+1087
+1088
+1089
+1090
+1091
+1092
+1093
+1094
+1095
+1096
+1097
+1098
+1099
+1100
+1101
+1102
+1103
+1104
+1105
+1106
+1107
+1108
+1109
+1110
+1111
+1112
+1113
+1114
+1115
+1116
+1117
+1118
+1119
+1120
+1121
+1122
+1123
+1124
+1125
+1126
+1127
+1128
+1129
+1130
+1131
+1132
+1133
+1134
+1135
+1136
+1137
+1138
+1139
+1140
+1141
+1142
+1143
+1144
+1145
+1146
+1147
+1148
+1149
+1150
+1151
+1152
+1153
+1154
+1155
+1156
+1157
+1158
+1159
+1160
+1161
+1162
+1163
+1164
+1165
+1166
+1167
+1168
+1169
+1170
+1171
+1172
+1173
+1174
+1175
+1176
+1177
+1178
+1179
+1180
+1181
+1182
+1183
+1184
+1185
+1186
+1187
+1188
+1189
+1190
+1191
+1192
+1193
+1194
+1195
+1196
+1197
+1198
+1199
+1200
+1201
+1202
+1203
+1204
+1205
+1206
+1207
+1208
+1209
+1210
+1211
+1212
+1213
+1214
+1215
+1216
+1217
+1218
+1219
+1220
+1221
+1222
+1223
+1224
+1225
+1226
+1227
+1228
+1229
+1230
+1231
+1232
+1233
+1234
+1235
+1236
+1237
+1238
+1239
+1240
+1241
+1242
+1243
+1244
+1245
+1246
+1247
+1248
+1249
+1250
+1251
+1252
+1253
+1254
+1255
+1256
+1257
+1258
+1259
+1260
+1261
+1262
+1263
+1264
+1265
+1266
+1267
+1268
+1269
+1270
+1271
+1272
+1273
+1274
+1275
+1276
+1277
+1278
+1279
+1280
+1281
+1282
+1283
+1284
+1285
+1286
+1287
+1288
+1289
+1290
+1291
+1292
+1293
+1294
+1295
+1296
+1297
+1298
+1299
+1300
+1301
+1302
+1303
+1304
+1305
+1306
+1307
+1308
+1309
+1310
+1311
+1312
+1313
+1314
+1315
+1316
+1317
+1318
+1319
+1320
+1321
+1322
+1323
+1324
+1325
+1326
+1327
+1328
+1329
+1330
+1331
+1332
+1333
+1334
+1335
+1336
+1337
+1338
+1339
+1340
+1341
+1342
+1343
+1344
+1345
+1346
+1347
+1348
+1349
+1350
+1351
+1352
+1353
+1354
+1355
+1356
+1357
+1358
+1359
+1360
+1361
+1362
+1363
+1364
+1365
+1366
+1367
+1368
+1369
+1370
+1371
+1372
+1373
+1374
+1375
+1376
+1377
+1378
+1379
+1380
+1381
+1382
+1383
+1384
+1385
+1386
+1387
+1388
+1389
+1390
+1391
+1392
+1393
+1394
+1395
+1396
+1397
+1398
+1399
+1400
+1401
+1402
+1403
+1404
+1405
+1406
+1407
+1408
+1409
+1410
+1411
+1412
+1413
+1414
+1415
+1416
+1417
+1418
+1419
+1420
+1421
+1422
+1423
+1424
+1425
+1426
+1427
+1428
+1429
+1430
+1431
+1432
+1433
+1434
+1435
+1436
+1437
+1438
+1439
+1440
+1441
+1442
+1443
+1444
+1445
+1446
+1447
+1448
+1449
+1450
+1451
+1452
+1453
+1454
+1455
+1456
+1457
+1458
+1459
+1460
+1461
+1462
+1463
+1464
+1465
+1466
+1467
+1468
+1469
+1470
+1471
+1472
+1473
+1474
+1475
+1476
+1477
+1478
+1479
+1480
+1481
+1482
+1483
+1484
+1485
+1486
+1487
+1488
+1489
+1490
+1491
+1492
+1493
+1494
+1495
+1496
+1497
+1498
+1499
+1500
+1501
+1502
+1503
+1504
+1505
+1506
+1507
+1508
+1509
+1510
+1511
+1512
+1513
+1514
+1515
+1516
+1517
+1518
+1519
+1520
+1521
+1522
+1523
+1524
+1525
+1526
+1527
+1528
+1529
+1530
+1531
+1532
+1533
+1534
+1535
+1536
+1537
+1538
+1539
+1540
+1541
+1542
+1543
+1544
+1545
+1546
+1547
+1548
+1549
+1550
+1551
+1552
+1553
+1554
+1555
+1556
+1557
+1558
+1559
+1560
+1561
+1562
+1563
+1564
+1565
+1566
+1567
+1568
+1569
+1570
+1571
+1572
+1573
+1574
+1575
+1576
+1577
+1578
+1579
+1580
+1581
+1582
+1583
+1584
+1585
+1586
+1587
+1588
+1589
+1590
+1591
+1592
+1593
+1594
+1595
+1596
+1597
+1598
+1599
+1600
+1601
+1602
+1603
+1604
+1605
+1606
+1607
+1608
+1609
+1610
+1611
+1612
+1613
+1614
+1615
+1616
+1617
+1618
+1619
+1620
+1621
+1622
+1623
+1624
+1625
+1626
+1627
+1628
+1629
+1630
+1631
+1632
+1633
+1634
+1635
+1636
+1637
+1638
+1639
+1640
+1641
+1642
+1643
+1644
+1645
+1646
+1647
+1648
+1649
+1650
+1651
+1652
+1653
+1654
+1655
+1656
+1657
+1658
+1659
+1660
+1661
+1662
+1663
+1664
+1665
+1666
+1667
+1668
+1669
+1670
+1671
+1672
+1673
+1674
+1675
+1676
+1677
+1678
+1679
+1680
+1681
+1682
+1683
+1684
+1685
+1686
+1687
+1688
+1689
+1690
+1691
+1692
+1693
+1694
+1695
+1696
+1697
+1698
+1699
+1700
+1701
+1702
+1703
+1704
+1705
+1706
+1707
+1708
+1709
+1710
+1711
+1712
+1713
+1714
+1715
+1716
+1717
+1718
+1719
+1720
+1721
+1722
+1723
+1724
+1725
+1726
+1727
+1728
+1729
+1730
+1731
+1732
+1733
+1734
+1735
+1736
+1737
+1738
+1739
+1740
+1741
+1742
+1743
+1744
+1745
+1746
+1747
+1748
+1749
+1750
+1751
+1752
+1753
+1754
+1755
+1756
+1757
+1758
+1759
+1760
+1761
+1762
+1763
+1764
+1765
+1766
+1767
+1768
+1769
+1770
+1771
+1772
+1773
+1774
+1775
+1776
+1777
+1778
+1779
+1780
+1781
+1782
+1783
+1784
+1785
+1786
+1787
+1788
+1789
+1790
+1791
+1792
+1793
+1794
+1795
+1796
+1797
+1798
+1799
+1800
+1801
+1802
+1803
+1804
+1805
+1806
+1807
+1808
+1809
+1810
+1811
+1812
+1813
+1814
+1815
+1816
+1817
+1818
+1819
+1820
+1821
+1822
+1823
+1824
+1825
+1826
+1827
+1828
+1829
+1830
+1831
+1832
+1833
+1834
+1835
+1836
+1837
+1838
+1839
+1840
+1841
+1842
+1843
+1844
+1845
+1846
+1847
+1848
+1849
+1850
+1851
+1852
+1853
+1854
+1855
+1856
+1857
+1858
+1859
+1860
+1861
+1862
+1863
+1864
+1865
+1866
+1867
+1868
+1869
+1870
+1871
+1872
+1873
+1874
+1875
+1876
+1877
+1878
+1879
+1880
+1881
+1882
+1883
+1884
+1885
+1886
+1887
+1888
+1889
+1890
+1891
+1892
+1893
+1894
+1895
+1896
+1897
+1898
+1899
+1900
+1901
+1902
+1903
+1904
+1905
+1906
+1907
+1908
+1909
+1910
+1911
+1912
+1913
+1914
+1915
+1916
+1917
+1918
+1919
+1920
+1921
+1922
+1923
+1924
+1925
+1926
+1927
+1928
+1929
+1930
+1931
+1932
+1933
+1934
+1935
+1936
+1937
+1938
+1939
+1940
+1941
+1942
+1943
+1944
+1945
+1946
+1947
+1948
+1949
+1950
+1951
+1952
+1953
+1954
+1955
+1956
+1957
+1958
+1959
+1960
+1961
+1962
+1963
+1964
+1965
+1966
+1967
+1968
+1969
+1970
+1971
+1972
+1973
+1974
+1975
+1976
+1977
+1978
+1979
+1980
+1981
+1982
+1983
+1984
+1985
+1986
+1987
+1988
+1989
+1990
+1991
+1992
+1993
+1994
+1995
+1996
+1997
+1998
+1999
+2000
+2001
+2002
+2003
+2004
+2005
+2006
+2007
+2008
+2009
+2010
+2011
+2012
+2013
+2014
+2015
+2016
+2017
+2018
+2019
+2020
+2021
+2022
+2023
+2024
+2025
+2026
+2027
+2028
+2029
+2030
+2031
+2032
+2033
+2034
+2035
+2036
+2037
+2038
+2039
+2040
+2041
+2042
+2043
+2044
+2045
+2046
+2047
+2048
+2049
+2050
+2051
+2052
+2053
+2054
+2055
+2056
+2057
+2058
+2059
+2060
+2061
+2062
+2063
+2064
+2065
+2066
+2067
+2068
+2069
+2070
+2071
+2072
+2073
+2074
+2075
+2076
+2077
+2078
+2079
+2080
+2081
+2082
+2083
+2084
+2085
+2086
+2087
+2088
+2089
+2090
+2091
+2092
+2093
+2094
+2095
+2096
+2097
+2098
+2099
+2100
+2101
+2102
+2103
+2104
+2105
+2106
+2107
+2108
+2109
+2110
+2111
+2112
+2113
+2114
+2115
+2116
+2117
+2118
+2119
+2120
+2121
+2122
+2123
+2124
+2125
+2126
+2127
+2128
+2129
+2130
+2131
+2132
+2133
+2134
+2135
+2136
+2137
+2138
+2139
+2140
+2141
+2142
+2143
+2144
+2145
+2146
+2147
+2148
+2149
+2150
+2151
+2152
+2153
+2154
+2155
+2156
+2157
+2158
+2159
+2160
+2161
+2162
+2163
+2164
+2165
+2166
+2167
+2168
+2169
+2170
+2171
+2172
+2173
+2174
+2175
+2176
+2177
+2178
+2179
+2180
+2181
+2182
+2183
+2184
+2185
+2186
+2187
+2188
+2189
+2190
+2191
+2192
+2193
+2194
+2195
+2196
+2197
+2198
+2199
+2200
+2201
+2202
+2203
+2204
+2205
+2206
+2207
+2208
+2209
+2210
+2211
+2212
+2213
+2214
+2215
+2216
+2217
+2218
+2219
+2220
+2221
+2222
+2223
+2224
+2225
+2226
+2227
+2228
+2229
+2230
+2231
+2232
+2233
+2234
+2235
+2236
+2237
+2238
+2239
+2240
+2241
+2242
+2243
+2244
+2245
+2246
+2247
+2248
+2249
+2250
+2251
+2252
+2253
+2254
+2255
+2256
+2257
+2258
+2259
+2260
+2261
+2262
+2263
+2264
+2265
+2266
+2267
+2268
+2269
+2270
+2271
+2272
+2273
+2274
+2275
+2276
+2277
+2278
+2279
+2280
+2281
+2282
+2283
+2284
+2285
+2286
+2287
+2288
+2289
+2290
+2291
+2292
+2293
+2294
+2295
+2296
+2297
+2298
+2299
+2300
+2301
+2302
+2303
+2304
+2305
+2306
+2307
+2308
+2309
+2310
+2311
+2312
+2313
+2314
+2315
+2316
+2317
+2318
+2319
+2320
+2321
+2322
+2323
+2324
+2325
+2326
+2327
+2328
+2329
+2330
+2331
+2332
+2333
+2334
+2335
+2336
+2337
+2338
+2339
+2340
+2341
+2342
+2343
+2344
+2345
+2346
+2347
+2348
+2349
+2350
+2351
+2352
+2353
+2354
+2355
+2356
+2357
+2358
+2359
+2360
+2361
+2362
+2363
+2364
+2365
+2366
+2367
+2368
+2369
+2370
+2371
+2372
+2373
+2374
+2375
+2376
+2377
+2378
+2379
+2380
+2381
+2382
+2383
+2384
+2385
+2386
+2387
+2388
+2389
+2390
+2391
+2392
+2393
+2394
+2395
+2396
+2397
+2398
+2399
+2400
+2401
+2402
+2403
+2404
+2405
+2406
+2407
+2408
+2409
+2410
+2411
+2412
+2413
+2414
+2415
+2416
+2417
+2418
+2419
+2420
+2421
+2422
+2423
+2424
+2425
+2426
+2427
+2428
+2429
+2430
+2431
+2432
+2433
+2434
+2435
+2436
+2437
+2438
+2439
+2440
+2441
+2442
+2443
+2444
+2445
+2446
+2447
+2448
+2449
+2450
+2451
+2452
+2453
+2454
+2455
+2456
+2457
+2458
+2459
+2460
+2461
+2462
+2463
+2464
+2465
+2466
+2467
+2468
+2469
+2470
+2471
+2472
+2473
+2474
+2475
+2476
+2477
+2478
+2479
+2480
+2481
+2482
+2483
+2484
+2485
+2486
+2487
+2488
+2489
+2490
+2491
+2492
+2493
+2494
+2495
+2496
+2497
+2498
+2499
+2500
+2501
+2502
+2503
+2504
+2505
+2506
+2507
+2508
+2509
+2510
+2511
+2512
+2513
+2514
+2515
+2516
+2517
+2518
+2519
+2520
+2521
+2522
+2523
+2524
+2525
+2526
+2527
+2528
+2529
+2530
+2531
+2532
+2533
+2534
+2535
+2536
+2537
+2538
+2539
+2540
+2541
+2542
+2543
+2544
+2545
+2546
+2547
+2548
+2549
+2550
+2551
+2552
+2553
+2554
+2555
+2556
+2557
+2558
+2559
+2560
+2561
+2562
+2563
+2564
+2565
+2566
+2567
+2568
+2569
+2570
+2571
+2572
+2573
+2574
+2575
+2576
+2577
+2578
+2579
+2580
+2581
+2582
+2583
+2584
+2585
+2586
+2587
+2588
+2589
+2590
+2591
+2592
+2593
+2594
+2595
+2596
+2597
+2598
+2599
+2600
+2601
+2602
+2603
+2604
+2605
+2606
+2607
+2608
+2609
+2610
+2611
+2612
+2613
+2614
+2615
+2616
+2617
+2618
+2619
+2620
+2621
+2622
+2623
+2624
+2625
+2626
+2627
+2628
+2629
+2630
+2631
+2632
+2633
+2634
+2635
+2636
+2637
+2638
+2639
+2640
+2641
+2642
+2643
+2644
+2645
+2646
+2647
+2648
+2649
+2650
+2651
+2652
+2653
+2654
+2655
+2656
+2657
+2658
+2659
+2660
+2661
+2662
+2663
+2664
+2665
+2666
+2667
+2668
+2669
+2670
+2671
+2672
+2673
+2674
+2675
+2676
+2677
+2678
+2679
+2680
+2681
+2682
+2683
+2684
+2685
+2686
+2687
+2688
+2689
+2690
+2691
+2692
+2693
+2694
+2695
+2696
+2697
+2698
+2699
+2700
+2701
+2702
+2703
+2704
+2705
+2706
+2707
+2708
+2709
+2710
+2711
+2712
+2713
+2714
+2715
+2716
+2717
+2718
+2719
+2720
+2721
+2722
+2723
+2724
+2725
+2726
+2727
+2728
+2729
+2730
+2731
+2732
+2733
+2734
+2735
+2736
+2737
+2738
+2739
+2740
+2741
+2742
+2743
+2744
+2745
+2746
+2747
+2748
+2749
+2750
+2751
+2752
+2753
+2754
+2755
+2756
+2757
+2758
+2759
+2760
+2761
+2762
+2763
+2764
+2765
+2766
+2767
+2768
+2769
+2770
+2771
+2772
+2773
+2774
+2775
+2776
+2777
+2778
+2779
+2780
+2781
+2782
+2783
+2784
+2785
+2786
+2787
+2788
+2789
+2790
+2791
+2792
+2793
+2794
+2795
+2796
+2797
+2798
+2799
+2800
+2801
+2802
+2803
+2804
+2805
+2806
+2807
+2808
+2809
+2810
+2811
+2812
+2813
+2814
+2815
+2816
+2817
+2818
+2819
+2820
+2821
+2822
+2823
+2824
+2825
+2826
+2827
+2828
+2829
+2830
+2831
+2832
+2833
+2834
+2835
+2836
+2837
+2838
+2839
+2840
+2841
+2842
+2843
+2844
+2845
+2846
+2847
+2848
+2849
+2850
+2851
+2852
+2853
+2854
+2855
+2856
+2857
+2858
+2859
+2860
+2861
+2862
+2863
+2864
+2865
+2866
+2867
+2868
+2869
+2870
+2871
+2872
+2873
+2874
+2875
+2876
+2877
+2878
+2879
+2880
+2881
+2882
+2883
+2884
+2885
+2886
+2887
+2888
+2889
+2890
+2891
+2892
+2893
+2894
+2895
+2896
+2897
+2898
+2899
+2900
+2901
+2902
+2903
+2904
+2905
+2906
+2907
+2908
+2909
+2910
+2911
+2912
+2913
+2914
+2915
+2916
+2917
+2918
+2919
+2920
+2921
+2922
+2923
+2924
+2925
+2926
+2927
+2928
+2929
+2930
+2931
+2932
+2933
+2934
+2935
+2936
+2937
+2938
+2939
+2940
+2941
+2942
+2943
+2944
+2945
+2946
+2947
+2948
+2949
+2950
+2951
+2952
+2953
+2954
+2955
+2956
+2957
+2958
+2959
+2960
+2961
+2962
+2963
+2964
+2965
+2966
+2967
+2968
+2969
+2970
+2971
+2972
+2973
+2974
+2975
+2976
+2977
+2978
+2979
+2980
+2981
+2982
+2983
+2984
+2985
+2986
+2987
+2988
+2989
+2990
+2991
+2992
+2993
+2994
+2995
+2996
+2997
+2998
+2999
+3000
+3001
+3002
+3003
+3004
+3005
+3006
+3007
+3008
+3009
+3010
+3011
+3012
+3013
+3014
+3015
+3016
+3017
+3018
+3019
+3020
+3021
+3022
+3023
+3024
+3025
+3026
+3027
+3028
+3029
+3030
+3031
+3032
+3033
+3034
+3035
+3036
+3037
+3038
+3039
+3040
+3041
+3042
+3043
+3044
+3045
+3046
+3047
+3048
+3049
+3050
+3051
+3052
+3053
+3054
+3055
+3056
+3057
+3058
+3059
+3060
+3061
+3062
+3063
+3064
+3065
+3066
+3067
+3068
+3069
+3070
+3071
+3072
+3073
+3074
+3075
+3076
+3077
+3078
+3079
+3080
+3081
+3082
+3083
+3084
+3085
+3086
+3087
+3088
+3089
+3090
+3091
+3092
+3093
+3094
+3095
+3096
+3097
+3098
+3099
+3100
+3101
+3102
+3103
+3104
+3105
+3106
+3107
+3108
+3109
+3110
+3111
+3112
+3113
+3114
+3115
+3116
+3117
+3118
+3119
+3120
+3121
+3122
+3123
+3124
+3125
+3126
+3127
+3128
+3129
+3130
+3131
+3132
+3133
+3134
+3135
+3136
+3137
+3138
+3139
+3140
+3141
+3142
+3143
+3144
+3145
+3146
+3147
+3148
+3149
+3150
+3151
+3152
+3153
+3154
+3155
+3156
+3157
+3158
+3159
+3160
+3161
+3162
+3163
+3164
+3165
+3166
+3167
+3168
+3169
+3170
+3171
+3172
+3173
+3174
+3175
+3176
+3177
+3178
+3179
+3180
+3181
+3182
+3183
+3184
+3185
+3186
+3187
+3188
+3189
+3190
+3191
+3192
+3193
+3194
+3195
+3196
+3197
+3198
+3199
+3200
+3201
+3202
+3203
+3204
+3205
+3206
+3207
+3208
+3209
+3210
+3211
+3212
+3213
+3214
+3215
+3216
+3217
+3218
+3219
+3220
+3221
+3222
+3223
+3224
+3225
+3226
+3227
+3228
+3229
+3230
+3231
+3232
+3233
+3234
+3235
+3236
+3237
+3238
+3239
+3240
+3241
+3242
+3243
+3244
+3245
+3246
+3247
+3248
+3249
+3250
+3251
+3252
+3253
+3254
+3255
+3256
+3257
+3258
+3259
+3260
+3261
+3262
+3263
+3264
+3265
+3266
+3267
+3268
+3269
+3270
+3271
+3272
+3273
+3274
+3275
+3276
+3277
+3278
+3279
+3280
+3281
+3282
+3283
+3284
+3285
+3286
+3287
+3288
+3289
+3290
+3291
+3292
+3293
+3294
+3295
+3296
+3297
+3298
+3299
+3300
+3301
+3302
+3303
+3304
+3305
+3306
+3307
+3308
+3309
+3310
+3311
+3312
+3313
+3314
+3315
+3316
+3317
+3318
+3319
+3320
+3321
+3322
+3323
+3324
+3325
+3326
+3327
+3328
+3329
+3330
+3331
+3332
+3333
+3334
+3335
+3336
+3337
+3338
+3339
+3340
+3341
+3342
+3343
+3344
+3345
+3346
+3347
+3348
+3349
+3350
+3351
+3352
+3353
+3354
+3355
+3356
+3357
+3358
+3359
+3360
+3361
+3362
+3363
+3364
+3365
+3366
+3367
+3368
+3369
+3370
+3371
+3372
+3373
+3374
+3375
+3376
+3377
+3378
+3379
+3380
+3381
+3382
+3383
+3384
+3385
+3386
+3387
+3388
+3389
+3390
+3391
+3392
+3393
+3394
+3395
+3396
+3397
+3398
+3399
+3400
+3401
+3402
+3403
+3404
+3405
+3406
+3407
+3408
+3409
+3410
+3411
+3412
+3413
+3414
+3415
+3416
+3417
+3418
+3419
+3420
+3421
+3422
+3423
+3424
+3425
+3426
+3427
+3428
+3429
+3430
+3431
+3432
+3433
+3434
+3435
+3436
+3437
+3438
+3439
+3440
+3441
+3442
+3443
+3444
+3445
+3446
+3447
+3448
+3449
+3450
+3451
+3452
+3453
+3454
+3455
+3456
+3457
+3458
+3459
+3460
+3461
+3462
+3463
+3464
+3465
+3466
+3467
+3468
+3469
+3470
+3471
+3472
+3473
+3474
+3475
+3476
+3477
+3478
+3479
+3480
+3481
+3482
+3483
+3484
+3485
+3486
+3487
+3488
+3489
+3490
+3491
+3492
+3493
+3494
+3495
+3496
+3497
+3498
+3499
+3500
+3501
+3502
+3503
+3504
+3505
+3506
+3507
+3508
+3509
+3510
+3511
+3512
+3513
+3514
+3515
+3516
+3517
+3518
+3519
+3520
+3521
+3522
+3523
+3524
+3525
+3526
+3527
+3528
+3529
+3530
+3531
+3532
+3533
+3534
+3535
+3536
+3537
+3538
+3539
+3540
+3541
+3542
+3543
+3544
+3545
+3546
+3547
+3548
+3549
+3550
+3551
+3552
+3553
+3554
+3555
+3556
+3557
+3558
+3559
+3560
+3561
+3562
+3563
+3564
+3565
+3566
+3567
+3568
+3569
+3570
+3571
+3572
+3573
+3574
+3575
+3576
+3577
+3578
+3579
+3580
+3581
+3582
+3583
+3584
+3585
+3586
+3587
+3588
+3589
+3590
+3591
+3592
+3593
+3594
+3595
+3596
+3597
+3598
+3599
+3600
+3601
+3602
+3603
+3604
+3605
+3606
+3607
+3608
+3609
+3610
+3611
+3612
+3613
+3614
+3615
+3616
+3617
+3618
+3619
+3620
+3621
+3622
+3623
+3624
+3625
+3626
+3627
+3628
+3629
+3630
+3631
+3632
+3633
+3634
+3635
+3636
+3637
+3638
+3639
+3640
+3641
+3642
+3643
+3644
+3645
+3646
+3647
+3648
+3649
+3650
+3651
+3652
+3653
+3654
+3655
+3656
+3657
+3658
+3659
+3660
+3661
+3662
+3663
+3664
+3665
+3666
+3667
+3668
+3669
+3670
+3671
+3672
+3673
+3674
+3675
+3676
+3677
+3678
+3679
+3680
+3681
+3682
+3683
+3684
+3685
+3686
+3687
+3688
+3689
+3690
+3691
+3692
+3693
+3694
+3695
+3696
+3697
+3698
+3699
+3700
+3701
+3702
+3703
+3704
+3705
+3706
+3707
+3708
+3709
+3710
+3711
+3712
+3713
+3714
+3715
+3716
+3717
+3718
+3719
+3720
+3721
+3722
+3723
+3724
+3725
+3726
+3727
+3728
+3729
+3730
+3731
+3732
+3733
+3734
+3735
+3736
+3737
+3738
+3739
+3740
+3741
+3742
+3743
+3744
+3745
+3746
+3747
+3748
+3749
+3750
+3751
+3752
+3753
+3754
+3755
+3756
+3757
+3758
+3759
+3760
+3761
+3762
+3763
+3764
+3765
+3766
+3767
+3768
+3769
+3770
+3771
+3772
+3773
+3774
+3775
+3776
+3777
+3778
+3779
+3780
+3781
+3782
+3783
+3784
+3785
+3786
+3787
+3788
+3789
+3790
+3791
+3792
+3793
+3794
+3795
+3796
+3797
+3798
+3799
+3800
+3801
+3802
+3803
+3804
+3805
+3806
+3807
+3808
+3809
+3810
+3811
+3812
+3813
+3814
+3815
+3816
+3817
+3818
+3819
+3820
+3821
+3822
+3823
+3824
+3825
+3826
+3827
+3828
+3829
+3830
+3831
+3832
+3833
+3834
+3835
+3836
+3837
+3838
+3839
+3840
+3841
+3842
+3843
+3844
+3845
+3846
+3847
+3848
+3849
+3850
+3851
+3852
+3853
+3854
+3855
+3856
+3857
+3858
+3859
+3860
+3861
+3862
+3863
+3864
+3865
+3866
+3867
+3868
+3869
+3870
+3871
+3872
+3873
+3874
+3875
+3876
+3877
+3878
+3879
+3880
+3881
+3882
+3883
+3884
+3885
+3886
+3887
+3888
+3889
+3890
+3891
+3892
+3893
+3894
+3895
+3896
+3897
+3898
+3899
+3900
+3901
+3902
+3903
+3904
+3905
+3906
+3907
+3908
+3909
+3910
+3911
+3912
+3913
+3914
+3915
+3916
+3917
+3918
+3919
+3920
+3921
+3922
+3923
+3924
+3925
+3926
+3927
+3928
+3929
+3930
+3931
+3932
+3933
+3934
+3935
+3936
+3937
+3938
+3939
+3940
+3941
+3942
+3943
+3944
+3945
+3946
+3947
+3948
+3949
+3950
+3951
+3952
+3953
+3954
+3955
+3956
+3957
+3958
+3959
+3960
+3961
+3962
+3963
+3964
+3965
+3966
+3967
+3968
+3969
+3970
+3971
+3972
+3973
+3974
+3975
+3976
+3977
+3978
+3979
+3980
+3981
+3982
+3983
+3984
+3985
+3986
+3987
+3988
+3989
+3990
+3991
+3992
+3993
+3994
+3995
+3996
+3997
+3998
+3999
+4000
+4001
+4002
+4003
+4004
+4005
+4006
+4007
+4008
+4009
+4010
+4011
+4012
+4013
+4014
+4015
+4016
+4017
+4018
+4019
+4020
+4021
+4022
+4023
+4024
+4025
+4026
+4027
+4028
+4029
+4030
+4031
+4032
+4033
+4034
+4035
+4036
+4037
+4038
+4039
+4040
+4041
+4042
+4043
+4044
+4045
+4046
+4047
+4048
+4049
+4050
+4051
+4052
+4053
+4054
+4055
+4056
+4057
+4058
+4059
+4060
+4061
+4062
+4063
+4064
+4065
+4066
+4067
+4068
+4069
+4070
+4071
+4072
+4073
+4074
+4075
+4076
+4077
+4078
+4079
+4080
+4081
+4082
+4083
+4084
+4085
+4086
+4087
+4088
+4089
+4090
+4091
+4092
+4093
+4094
+4095
+
+ Written Files(4096)
+===DONE===
diff --git a/ext/phar/tests/bug13786.phpt b/ext/phar/tests/bug13786.phpt
new file mode 100644
index 0000000000..572d1eb9aa
--- /dev/null
+++ b/ext/phar/tests/bug13786.phpt
@@ -0,0 +1,32 @@
+--TEST--
+Phar: bug #13786: "PHP crashes on phar recreate after unlink"
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+
+try {
+for ($i = 0; $i < 2; $i++) {
+ $fname = "DataArchive.phar";
+ $path = dirname(__FILE__) . DIRECTORY_SEPARATOR . $fname;
+ $phar = new Phar($path);
+ $phar->addFromString($i, "file $i in $fname");
+ var_dump(file_get_contents($phar[$i]));
+ unset($phar);
+ unlink($path);
+}
+
+echo("\nWritten files: $i\n");
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+
+?>
+===DONE===
+--EXPECTF--
+string(26) "file 0 in DataArchive.phar"
+unable to seek to start of file "0" while creating new phar "%sDataArchive.phar"
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/create_new_and_modify.phpt b/ext/phar/tests/create_new_and_modify.phpt
new file mode 100755
index 0000000000..66587de023
--- /dev/null
+++ b/ext/phar/tests/create_new_and_modify.phpt
@@ -0,0 +1,48 @@
+--TEST--
+Phar: create and modify phar
+--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.php';
+$pname = 'phar://' . $fname;
+
+@unlink($fname);
+
+file_put_contents($pname . '/a.php', "brand new!\n");
+
+$phar = new Phar($fname);
+$sig1 = $phar->getSignature();
+
+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 = $phar->getSignature();
+
+var_dump($sig1['hash']);
+var_dump($sig2['hash']);
+var_dump($sig1['hash'] != $sig2['hash']);
+
+include $pname . '/a.php';
+include $pname . '/b.php';
+
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECTF--
+brand new!
+string(40) "%s"
+string(40) "%s"
+bool(true)
+modified!
+another!
+===DONE===
diff --git a/ext/phar/tests/create_new_phar.phpt b/ext/phar/tests/create_new_phar.phpt
new file mode 100644
index 0000000000..ec57c27217
--- /dev/null
+++ b/ext/phar/tests/create_new_phar.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Phar: create a completely new phar
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+phar.require_hash=1
+--FILE--
+<?php
+
+file_put_contents('phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php/a.php',
+ 'brand new!');
+include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php/a.php';
+?>
+
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECT--
+brand new!
+===DONE===
diff --git a/ext/phar/tests/create_new_phar_b.phpt b/ext/phar/tests/create_new_phar_b.phpt
new file mode 100755
index 0000000000..8f1298245c
--- /dev/null
+++ b/ext/phar/tests/create_new_phar_b.phpt
@@ -0,0 +1,27 @@
+--TEST--
+Phar: create a completely new 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.php/a.php',
+ 'brand new!');
+include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php/a.php';
+?>
+
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECTF--
+
+Warning: file_put_contents(phar://%screate_new_phar_b.phar.php/a.php): failed to open stream: phar error: write operations disabled by INI setting in %screate_new_phar_b.php on line %d
+
+Warning: include(phar://%screate_new_phar_b.phar.php/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.php/a.php' for inclusion (include_path='%s') in %screate_new_phar_b.php on line %d
+
+===DONE===
diff --git a/ext/phar/tests/create_new_phar_c.phpt b/ext/phar/tests/create_new_phar_c.phpt
new file mode 100755
index 0000000000..6beaa2eb61
--- /dev/null
+++ b/ext/phar/tests/create_new_phar_c.phpt
@@ -0,0 +1,29 @@
+--TEST--
+Phar: create a completely new phar
+--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
+
+file_put_contents('phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php/a.php',
+ 'brand new!');
+
+$phar = new Phar(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php');
+
+var_dump($phar->getSignature());
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECTF--
+array(2) {
+ ["hash"]=>
+ string(40) "%s"
+ ["hash_type"]=>
+ string(5) "SHA-1"
+}
+===DONE===
diff --git a/ext/phar/tests/create_path_error.phpt b/ext/phar/tests/create_path_error.phpt
new file mode 100755
index 0000000000..d3fc035860
--- /dev/null
+++ b/ext/phar/tests/create_path_error.phpt
@@ -0,0 +1,62 @@
+--TEST--
+Phar: create with illegal path
+--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.php';
+$pname = 'phar://' . $fname;
+
+@unlink($fname);
+
+file_put_contents($pname . '/a.php?', "query");
+file_put_contents($pname . '/b.php?bla', "query");
+
+var_dump(file_get_contents($pname . '/a.php'));
+var_dump(file_get_contents($pname . '/b.php'));
+
+function error_handler($errno, $errmsg)
+{
+ echo "Error: $errmsg\n";
+}
+
+set_error_handler('error_handler');
+
+$checks = array('/', '.', '../', 'a/..', 'a/', 'b//a.php');
+foreach($checks as $check)
+{
+ file_put_contents($pname . '/' . $check, "error");
+}
+
+$phar = new Phar($fname);
+$checks = array("a\0");
+foreach($checks as $check)
+{
+ try
+ {
+ $phar[$check] = 'error';
+ }
+ catch(Exception $e)
+ {
+ echo 'Exception: ' . $e->getMessage() . "\n";
+ }
+}
+
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECTF--
+string(5) "query"
+string(5) "query"
+Error: file_put_contents(phar://%s//): failed to open stream: phar error: file "" in phar "%s" cannot be empty
+Error: file_put_contents(phar://%s/.): failed to open stream: phar error: file "" in phar "%s" cannot be empty
+Error: file_put_contents(phar://%s/../): failed to open stream: phar error: file "" in phar "%s" cannot be empty
+Error: file_put_contents(phar://%s/a/..): failed to open stream: phar error: file "" in phar "%s" cannot be empty
+Exception: Entry a does not exist and cannot be created: phar error: invalid path "a" contains illegal character
+===DONE===
diff --git a/ext/phar/tests/delete.phpt b/ext/phar/tests/delete.phpt
new file mode 100644
index 0000000000..1d98509064
--- /dev/null
+++ b/ext/phar/tests/delete.phpt
@@ -0,0 +1,31 @@
+--TEST--
+Phar: delete test
+--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.php';
+$pname = 'phar://' . $fname;
+$file = "<?php
+Phar::mapPhar('hio');
+__HALT_COMPILER(); ?>";
+
+$files = array();
+$files['a'] = 'a';
+include 'files/phar_test.inc';
+include $fname;
+$phar = new Phar($fname);
+
+echo file_get_contents($pname . '/a') . "\n";
+$phar->delete('a');
+echo file_get_contents($pname . '/a') . "\n";
+?>
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECTF--
+a
+
+Warning: file_get_contents(phar://%sdelete.phar.php/a): failed to open stream: phar error: "a" is not a file in phar "%sdelete.phar.php" in %sdelete.php on line 16 \ No newline at end of file
diff --git a/ext/phar/tests/delete_in_phar.phpt b/ext/phar/tests/delete_in_phar.phpt
new file mode 100644
index 0000000000..4842d27913
--- /dev/null
+++ b/ext/phar/tests/delete_in_phar.phpt
@@ -0,0 +1,48 @@
+--TEST--
+Phar: delete a file within a .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.php';
+$pname = 'phar://' . $fname;
+$file = "<?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"; ?>';
+include 'files/phar_test.inc';
+
+include $pname . '/a.php';
+include $pname . '/b.php';
+include $pname . '/b/c.php';
+unlink($pname . '/b/c.php');
+?>
+===AFTER===
+<?php
+include $pname . '/a.php';
+include $pname . '/b.php';
+include $pname . '/b/c.php';
+?>
+
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECTF--
+This is a
+This is b
+This is b/c
+===AFTER===
+This is a
+This is b
+
+Warning: include(%sdelete_in_phar.phar.php/b/c.php): failed to open stream: phar error: "b/c.php" is not a file in phar "%sdelete_in_phar.phar.php" in %sdelete_in_phar.php on line %d
+
+Warning: include(): Failed opening 'phar://%sdelete_in_phar.phar.php/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/delete_in_phar_b.phpt b/ext/phar/tests/delete_in_phar_b.phpt
new file mode 100755
index 0000000000..d26f51cbf1
--- /dev/null
+++ b/ext/phar/tests/delete_in_phar_b.phpt
@@ -0,0 +1,46 @@
+--TEST--
+Phar: delete a file within a .phar
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=1
+phar.require_hash=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$file = "<?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"; ?>';
+include 'files/phar_test.inc';
+
+include $pname . '/a.php';
+include $pname . '/b.php';
+include $pname . '/b/c.php';
+unlink($pname . '/b/c.php');
+?>
+===AFTER===
+<?php
+include $pname . '/a.php';
+include $pname . '/b.php';
+include $pname . '/b/c.php';
+?>
+
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECTF--
+This is a
+This is b
+This is b/c
+
+Warning: unlink(): phar error: write operations disabled by INI setting 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/delete_in_phar_confirm.phpt b/ext/phar/tests/delete_in_phar_confirm.phpt
new file mode 100644
index 0000000000..13a8d0db29
--- /dev/null
+++ b/ext/phar/tests/delete_in_phar_confirm.phpt
@@ -0,0 +1,51 @@
+--TEST--
+Phar: delete a file within a .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.php';
+$pname = 'phar://' . $fname;
+$file = "<?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"; ?>';
+include 'files/phar_test.inc';
+
+include $pname . '/a.php';
+include $pname . '/b.php';
+include $pname . '/b/c.php';
+$md5 = md5_file($fname);
+unlink($pname . '/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.php/a.php';
+include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php/b.php';
+include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php/b/c.php';
+?>
+
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--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.php/b/c.php): failed to open stream: phar error: "b/c.php" is not a file in phar "%sdelete_in_phar_confirm.phar.php" in %sdelete_in_phar_confirm.php on line %d
+
+Warning: include(): Failed opening 'phar://%sdelete_in_phar_confirm.phar.php/b/c.php' for inclusion (include_path='%s') in %sdelete_in_phar_confirm.php on line %d
+
+===DONE===
diff --git a/ext/phar/tests/dir.phpt b/ext/phar/tests/dir.phpt
new file mode 100644
index 0000000000..a8f9d3f889
--- /dev/null
+++ b/ext/phar/tests/dir.phpt
@@ -0,0 +1,92 @@
+--TEST--
+Phar: mkdir/rmdir test
+--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.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::PHAR));
+
+$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/'));
+ini_set('phar.readonly', 1);
+mkdir($pname . '/fails');
+ini_set('phar.readonly', 0);
+// create new phar by mkdir
+mkdir('phar://' . dirname(__FILE__) . '/ok.phar/fails');
+mkdir('phar://' . dirname(__FILE__) . '/ok.phar/fails');
+file_put_contents('phar://' . dirname(__FILE__) . '/ok.phar/sub/directory.txt', 'hi');
+mkdir('phar://' . dirname(__FILE__) . '/ok.phar/sub');
+mkdir('phar://' . dirname(__FILE__) . '/ok.phar/sub/directory.txt');
+file_put_contents(dirname(__FILE__) . '/oops.phar', '<?php this should screw em up __HALT_COMPILER();');
+mkdir('phar://' . dirname(__FILE__) . '/oops.phar/fails');
+
+mkdir('phar://');
+rmdir('phar://');
+rmdir('phar://' . dirname(__FILE__) . '/unknown.phar/hi');
+ini_set('phar.readonly', 1);
+rmdir($pname . '/another/dir');
+ini_set('phar.readonly', 0);
+rmdir($pname);
+rmdir($pname . '/');
+mkdir($pname . '/');
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+<?php unlink(dirname(__FILE__) . '/ok.phar'); ?>
+<?php unlink(dirname(__FILE__) . '/oops.phar'); ?>
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.1.phar.php'); ?>
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar.php'); ?>
+--EXPECTF--
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(false)
+bool(true)
+bool(false)
+
+Warning: mkdir(): phar error: cannot create directory "phar://%sdir.phar.php/fails", write operations disabled in %sdir.php on line %d
+
+Warning: mkdir(): phar error: cannot create directory "fails" in phar "%sok.phar", directory already exists in %sdir.php on line %d
+
+Warning: mkdir(): phar error: cannot create directory "sub" in phar "%sok.phar", directory already exists in %sdir.php on line %d
+
+Warning: mkdir(): phar error: cannot create directory "sub/directory.txt" in phar "%sok.phar", phar error: path "sub/directory.txt" exists and is a not a directory in %sdir.php on line %d
+
+Warning: mkdir(): internal corruption of phar "%soops.phar" (truncated manifest at stub end) in %sdir.php on line %d
+
+Warning: mkdir(): phar error: cannot create directory "phar://", no phar archive specified in %sdir.php on line %d
+
+Warning: rmdir(): phar error: cannot remove directory "phar://", no phar archive specified, or phar archive does not exist in %sdir.php on line %d
+
+Warning: rmdir(): phar error: cannot remove directory "hi" in phar "%sunknown.phar", directory does not exist in %sdir.php on line %d
+
+Warning: rmdir(): phar error: cannot rmdir directory "phar://%sdir.phar.php/another/dir", write operations disabled in %sdir.php on line %d
+
+Warning: rmdir(): phar error: cannot remove directory "" in phar "%sdir.phar.php", directory does not exist in %sdir.php on line %d
+
+Warning: rmdir(): phar error: cannot remove directory "" in phar "%sdir.phar.php", directory does not exist in %sdir.php on line %d
+
+Warning: mkdir(): phar error: cannot create directory "" in phar "%sdir.phar.php", phar error: invalid path "" must not be empty in %sdir.php on line %d
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/fgc_edgecases.phpt b/ext/phar/tests/fgc_edgecases.phpt
new file mode 100644
index 0000000000..e899604e95
--- /dev/null
+++ b/ext/phar/tests/fgc_edgecases.phpt
@@ -0,0 +1,95 @@
+--TEST--
+Phar: test edge cases of file_get_contents() function interception
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+Phar::interceptFileFuncs();
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+
+file_get_contents(array());
+chdir(dirname(__FILE__));
+file_put_contents($fname, "blah\n");
+file_put_contents("foob", "test\n");
+echo file_get_contents($fname);
+unlink($fname);
+mkdir($pname . '/oops');
+file_put_contents($pname . '/foo/hi', '<?php
+echo file_get_contents("foo/" . basename(__FILE__));
+$context = stream_context_create();
+file_get_contents("./hi", 0, $context, 0, -1);
+echo file_get_contents("foob");
+set_include_path("' . addslashes(dirname(__FILE__)) . '");
+echo file_get_contents("foob", true);
+echo file_get_contents("./hi", 0, $context);
+echo file_get_contents("../oops");
+echo file_get_contents("./hi", 0, $context, 50000);
+ini_set("magic_quotes_runtime", 1);
+echo file_get_contents("./hi");
+echo file_get_contents("./hi", 0, $context, 0, 0);
+?>
+');
+include $pname . '/foo/hi';
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+<?php rmdir(dirname(__FILE__) . '/poo'); ?>
+<?php unlink(dirname(__FILE__) . '/foob'); ?>
+--EXPECTF--
+Warning: file_get_contents() expects parameter 1 to be string, array given in %sfgc_edgecases.php on line %d
+blah
+<?php
+echo file_get_contents("foo/" . basename(__FILE__));
+$context = stream_context_create();
+file_get_contents("./hi", 0, $context, 0, -1);
+echo file_get_contents("foob");
+set_include_path("%stests");
+echo file_get_contents("foob", true);
+echo file_get_contents("./hi", 0, $context);
+echo file_get_contents("../oops");
+echo file_get_contents("./hi", 0, $context, 50000);
+ini_set("magic_quotes_runtime", 1);
+echo file_get_contents("./hi");
+echo file_get_contents("./hi", 0, $context, 0, 0);
+?>
+
+Warning: file_get_contents(): length must be greater than or equal to zero in phar://%sfgc_edgecases.phar.php/foo/hi on line %d
+test
+test
+<?php
+echo file_get_contents("foo/" . basename(__FILE__));
+$context = stream_context_create();
+file_get_contents("./hi", 0, $context, 0, -1);
+echo file_get_contents("foob");
+set_include_path("%stests");
+echo file_get_contents("foob", true);
+echo file_get_contents("./hi", 0, $context);
+echo file_get_contents("../oops");
+echo file_get_contents("./hi", 0, $context, 50000);
+ini_set("magic_quotes_runtime", 1);
+echo file_get_contents("./hi");
+echo file_get_contents("./hi", 0, $context, 0, 0);
+?>
+
+Warning: file_get_contents(phar://%sfgc_edgecases.phar.php/oops): failed to open stream: phar error: path "oops" is a directory in phar://%sfgc_edgecases.phar.php/foo/hi on line %d
+
+Warning: file_get_contents(): Failed to seek to position 50000 in the stream in phar://%sfgc_edgecases.phar.php/foo/hi on line %d
+<?php
+echo file_get_contents(\"foo/\" . basename(__FILE__));
+$context = stream_context_create();
+file_get_contents(\"./hi\", 0, $context, 0, -1);
+echo file_get_contents(\"foob\");
+set_include_path(\"%stests\");
+echo file_get_contents(\"foob\", true);
+echo file_get_contents(\"./hi\", 0, $context);
+echo file_get_contents(\"../oops\");
+echo file_get_contents(\"./hi\", 0, $context, 50000);
+ini_set(\"magic_quotes_runtime\", 1);
+echo file_get_contents(\"./hi\");
+echo file_get_contents(\"./hi\", 0, $context, 0, 0);
+?>
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/file_get_contents.phpt b/ext/phar/tests/file_get_contents.phpt
new file mode 100644
index 0000000000..fcc9d64655
--- /dev/null
+++ b/ext/phar/tests/file_get_contents.phpt
@@ -0,0 +1,30 @@
+--TEST--
+Phar: test file_get_contents() interception
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");?>
+--INI--
+phar.require_hash=1
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$a = new Phar($fname);
+$a['index.php'] = '<?php
+echo file_get_contents("dir/file1.txt");
+echo file_get_contents("file1.txt", true);
+?>';
+$a['dir/file1.txt'] = 'hi';
+$a['dir/file2.txt'] = 'hi2';
+$a['dir/file3.txt'] = 'hi3';
+$a->setStub('<?php
+Phar::interceptFileFuncs();
+set_include_path("phar://" . __FILE__ . "/dir" . PATH_SEPARATOR . "phar://" . __FILE__);
+include "index.php";
+__HALT_COMPILER();');
+include $fname;
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECT--
+hihi===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/files/extracted.inc b/ext/phar/tests/files/extracted.inc
new file mode 100644
index 0000000000..a6e52246a3
--- /dev/null
+++ b/ext/phar/tests/files/extracted.inc
@@ -0,0 +1 @@
+<?php var_dump(__FILE__); ?>
diff --git a/ext/phar/tests/files/frontcontroller.phar b/ext/phar/tests/files/frontcontroller.phar
new file mode 100644
index 0000000000..626bf48acf
--- /dev/null
+++ b/ext/phar/tests/files/frontcontroller.phar
Binary files differ
diff --git a/ext/phar/tests/files/frontcontroller.phar.inc b/ext/phar/tests/files/frontcontroller.phar.inc
new file mode 100644
index 0000000000..80d42e886b
--- /dev/null
+++ b/ext/phar/tests/files/frontcontroller.phar.inc
@@ -0,0 +1,13 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller.phar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller.phar');
+$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/files/frontcontroller10.phar b/ext/phar/tests/files/frontcontroller10.phar
new file mode 100644
index 0000000000..078ce75b2c
--- /dev/null
+++ b/ext/phar/tests/files/frontcontroller10.phar
Binary files differ
diff --git a/ext/phar/tests/files/frontcontroller10.phar.inc b/ext/phar/tests/files/frontcontroller10.phar.inc
new file mode 100644
index 0000000000..4c139db58b
--- /dev/null
+++ b/ext/phar/tests/files/frontcontroller10.phar.inc
@@ -0,0 +1,20 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller10.phar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller10.phar');
+$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/files/frontcontroller11.phar b/ext/phar/tests/files/frontcontroller11.phar
new file mode 100644
index 0000000000..61ea843222
--- /dev/null
+++ b/ext/phar/tests/files/frontcontroller11.phar
Binary files differ
diff --git a/ext/phar/tests/files/frontcontroller11.phar.inc b/ext/phar/tests/files/frontcontroller11.phar.inc
new file mode 100644
index 0000000000..086350800b
--- /dev/null
+++ b/ext/phar/tests/files/frontcontroller11.phar.inc
@@ -0,0 +1,20 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller11.phar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller11.phar');
+$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/files/frontcontroller12.phar b/ext/phar/tests/files/frontcontroller12.phar
new file mode 100644
index 0000000000..9e45587610
--- /dev/null
+++ b/ext/phar/tests/files/frontcontroller12.phar
Binary files differ
diff --git a/ext/phar/tests/files/frontcontroller12.phar.inc b/ext/phar/tests/files/frontcontroller12.phar.inc
new file mode 100644
index 0000000000..ba17df37e1
--- /dev/null
+++ b/ext/phar/tests/files/frontcontroller12.phar.inc
@@ -0,0 +1,20 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller12.phar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller12.phar');
+$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"));
+Phar::webPhar();
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
diff --git a/ext/phar/tests/files/frontcontroller13.phar b/ext/phar/tests/files/frontcontroller13.phar
new file mode 100644
index 0000000000..750ff27a8e
--- /dev/null
+++ b/ext/phar/tests/files/frontcontroller13.phar
Binary files differ
diff --git a/ext/phar/tests/files/frontcontroller13.phar.inc b/ext/phar/tests/files/frontcontroller13.phar.inc
new file mode 100644
index 0000000000..0bfef46853
--- /dev/null
+++ b/ext/phar/tests/files/frontcontroller13.phar.inc
@@ -0,0 +1,14 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller13.phar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller13.phar');
+$a['index.php'] = '<?php
+var_dump("test");
+include "oof/test.php";';
+$a['oof/test.php'] = '<?php
+var_dump("oof/test.php");
+include "./hi.php";';
+$a['oof/hi.php'] = '<?php
+var_dump("hi");';
+$a->setStub('<?php
+Phar::webPhar();
+__HALT_COMPILER();'); \ No newline at end of file
diff --git a/ext/phar/tests/files/frontcontroller14.phar b/ext/phar/tests/files/frontcontroller14.phar
new file mode 100644
index 0000000000..78a42a999f
--- /dev/null
+++ b/ext/phar/tests/files/frontcontroller14.phar
Binary files differ
diff --git a/ext/phar/tests/files/frontcontroller14.phar.inc b/ext/phar/tests/files/frontcontroller14.phar.inc
new file mode 100644
index 0000000000..d0ebd9a45a
--- /dev/null
+++ b/ext/phar/tests/files/frontcontroller14.phar.inc
@@ -0,0 +1,19 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller14.phar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller14.phar');
+$a['html/index.php'] = '<?php
+var_dump($_SERVER["PATH_INFO"]);
+var_dump($_SERVER["PATH_TRANSLATED"]);
+';
+$a->setStub('<?php
+function s($a)
+{
+ return "/html/index.php";
+}
+Phar::interceptFileFuncs();
+Phar::mungServer(array("PHP_SELF", "REQUEST_URI"));
+Phar::webPhar("whatever", "/html/index.php", null, array(), "s");
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
diff --git a/ext/phar/tests/files/frontcontroller16.phar b/ext/phar/tests/files/frontcontroller16.phar
new file mode 100644
index 0000000000..cce5db5bb5
--- /dev/null
+++ b/ext/phar/tests/files/frontcontroller16.phar
Binary files differ
diff --git a/ext/phar/tests/files/frontcontroller16.phar.inc b/ext/phar/tests/files/frontcontroller16.phar.inc
new file mode 100644
index 0000000000..3c9986da00
--- /dev/null
+++ b/ext/phar/tests/files/frontcontroller16.phar.inc
@@ -0,0 +1,16 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller16.phar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller16.phar');
+$a['index.php'] = '<?php
+echo "hi";
+';
+$a->setStub('<?php
+try {
+Phar::webPhar("test.phar", "/index.php", null, array(), array("fail", "here"));
+} catch (Exception $e) {
+die($e->getMessage() . "\n");
+}
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
diff --git a/ext/phar/tests/files/frontcontroller17.phar b/ext/phar/tests/files/frontcontroller17.phar
new file mode 100644
index 0000000000..b83d41fd5b
--- /dev/null
+++ b/ext/phar/tests/files/frontcontroller17.phar
Binary files differ
diff --git a/ext/phar/tests/files/frontcontroller17.phar.inc b/ext/phar/tests/files/frontcontroller17.phar.inc
new file mode 100644
index 0000000000..85b8729f31
--- /dev/null
+++ b/ext/phar/tests/files/frontcontroller17.phar.inc
@@ -0,0 +1,16 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller17.phar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller17.phar');
+$a['index.php'] = '<?php
+echo "hi";
+';
+$a->setStub('<?php
+try {
+Phar::webPhar("test.phar", "/index.php", null, array(), "sort");
+} catch (Exception $e) {
+die($e->getMessage() . "\n");
+}
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
diff --git a/ext/phar/tests/files/frontcontroller18.phar b/ext/phar/tests/files/frontcontroller18.phar
new file mode 100644
index 0000000000..c447f397ac
--- /dev/null
+++ b/ext/phar/tests/files/frontcontroller18.phar
Binary files differ
diff --git a/ext/phar/tests/files/frontcontroller18.phar.inc b/ext/phar/tests/files/frontcontroller18.phar.inc
new file mode 100644
index 0000000000..847a713ba3
--- /dev/null
+++ b/ext/phar/tests/files/frontcontroller18.phar.inc
@@ -0,0 +1,19 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller18.phar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller18.phar');
+$a['index.php'] = '<?php
+echo "hi";
+';
+$a->setStub('<?php
+function s($a)
+{
+}
+try {
+Phar::webPhar("test.phar", "/index.php", null, array(), "s");
+} catch (Exception $e) {
+die($e->getMessage() . "\n");
+}
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
diff --git a/ext/phar/tests/files/frontcontroller19.phar b/ext/phar/tests/files/frontcontroller19.phar
new file mode 100644
index 0000000000..bdf8ee13c2
--- /dev/null
+++ b/ext/phar/tests/files/frontcontroller19.phar
Binary files differ
diff --git a/ext/phar/tests/files/frontcontroller19.phar.inc b/ext/phar/tests/files/frontcontroller19.phar.inc
new file mode 100644
index 0000000000..ba84ac410a
--- /dev/null
+++ b/ext/phar/tests/files/frontcontroller19.phar.inc
@@ -0,0 +1,25 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller19.phar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller19.phar');
+$a['start/index.php'] = '<?php
+echo "start/index.php\n";
+include "./another.php";
+';
+$a['start/another.php'] = '<?php
+echo "start/another.php\n";
+include "../another.php";
+?>';
+$a['another.php'] = '<?php
+echo "another.php\n";
+?>';
+$a->setStub('<?php
+set_include_path("phar://" . __FILE__);
+try {
+Phar::webPhar("test.phar", "/start/index.php");
+} catch (Exception $e) {
+die($e->getMessage() . "\n");
+}
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
diff --git a/ext/phar/tests/files/frontcontroller2.phar b/ext/phar/tests/files/frontcontroller2.phar
new file mode 100644
index 0000000000..0dd0e7f695
--- /dev/null
+++ b/ext/phar/tests/files/frontcontroller2.phar
Binary files differ
diff --git a/ext/phar/tests/files/frontcontroller2.phar.inc b/ext/phar/tests/files/frontcontroller2.phar.inc
new file mode 100644
index 0000000000..653c79691d
--- /dev/null
+++ b/ext/phar/tests/files/frontcontroller2.phar.inc
@@ -0,0 +1,12 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller2.phar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller2.phar');
+$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/files/frontcontroller3.phar b/ext/phar/tests/files/frontcontroller3.phar
new file mode 100644
index 0000000000..afcf03af35
--- /dev/null
+++ b/ext/phar/tests/files/frontcontroller3.phar
Binary files differ
diff --git a/ext/phar/tests/files/frontcontroller3.phar.inc b/ext/phar/tests/files/frontcontroller3.phar.inc
new file mode 100644
index 0000000000..2759d9ee45
--- /dev/null
+++ b/ext/phar/tests/files/frontcontroller3.phar.inc
@@ -0,0 +1,18 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller3.phar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller3.phar');
+$a['a.php'] = 'hio';
+$a['a.jpg'] = 'hio';
+$a['a.phps'] = '<?php function hio(){}';
+$a->setStub('<?php
+function s($a)
+{
+ static $b = array("/hi" => "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/files/frontcontroller4.phar b/ext/phar/tests/files/frontcontroller4.phar
new file mode 100644
index 0000000000..4c9a92a197
--- /dev/null
+++ b/ext/phar/tests/files/frontcontroller4.phar
Binary files differ
diff --git a/ext/phar/tests/files/frontcontroller4.phar.inc b/ext/phar/tests/files/frontcontroller4.phar.inc
new file mode 100644
index 0000000000..5c6a43f954
--- /dev/null
+++ b/ext/phar/tests/files/frontcontroller4.phar.inc
@@ -0,0 +1,18 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller4.phar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller4.phar');
+$a['a.php'] = 'hio';
+$a['a.jpg'] = 'hio';
+$a['a.phps'] = '<?php function hio(){}';
+$a->setStub('<?php
+function s($a)
+{
+ static $b = array("/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/files/frontcontroller5.phar b/ext/phar/tests/files/frontcontroller5.phar
new file mode 100644
index 0000000000..f206b5996d
--- /dev/null
+++ b/ext/phar/tests/files/frontcontroller5.phar
Binary files differ
diff --git a/ext/phar/tests/files/frontcontroller5.phar.inc b/ext/phar/tests/files/frontcontroller5.phar.inc
new file mode 100644
index 0000000000..d2d810c367
--- /dev/null
+++ b/ext/phar/tests/files/frontcontroller5.phar.inc
@@ -0,0 +1,12 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller5.phar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller5.phar');
+$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/files/frontcontroller6.phar b/ext/phar/tests/files/frontcontroller6.phar
new file mode 100644
index 0000000000..e3b6bb86a1
--- /dev/null
+++ b/ext/phar/tests/files/frontcontroller6.phar
Binary files differ
diff --git a/ext/phar/tests/files/frontcontroller6.phar.inc b/ext/phar/tests/files/frontcontroller6.phar.inc
new file mode 100644
index 0000000000..5c900eb603
--- /dev/null
+++ b/ext/phar/tests/files/frontcontroller6.phar.inc
@@ -0,0 +1,12 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller6.phar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller6.phar');
+$a['a.php'] = 'hio';
+$a['a.jpg'] = 'hio';
+$a['a.phps'] = '<?php function hio(){}';
+$a->setStub('<?php
+Phar::webPhar("whatever", "index.php", null, array("blah" => 100));
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
diff --git a/ext/phar/tests/files/frontcontroller7.phar b/ext/phar/tests/files/frontcontroller7.phar
new file mode 100644
index 0000000000..79672809b4
--- /dev/null
+++ b/ext/phar/tests/files/frontcontroller7.phar
Binary files differ
diff --git a/ext/phar/tests/files/frontcontroller7.phar.inc b/ext/phar/tests/files/frontcontroller7.phar.inc
new file mode 100644
index 0000000000..684970263e
--- /dev/null
+++ b/ext/phar/tests/files/frontcontroller7.phar.inc
@@ -0,0 +1,12 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller7.phar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller7.phar');
+$a['a.php'] = 'hio';
+$a['a.jpg'] = 'hio';
+$a['a.phps'] = '<?php function hio(){}';
+$a->setStub('<?php
+Phar::webPhar("whatever", "index.php", null, array("blah" => null));
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
diff --git a/ext/phar/tests/files/frontcontroller8.phar b/ext/phar/tests/files/frontcontroller8.phar
new file mode 100644
index 0000000000..ec05ceafb0
--- /dev/null
+++ b/ext/phar/tests/files/frontcontroller8.phar
Binary files differ
diff --git a/ext/phar/tests/files/frontcontroller8.phar.inc b/ext/phar/tests/files/frontcontroller8.phar.inc
new file mode 100644
index 0000000000..1dfb654a03
--- /dev/null
+++ b/ext/phar/tests/files/frontcontroller8.phar.inc
@@ -0,0 +1,19 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller8.phar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller8.phar');
+$a['a.phps'] = 'hio1';
+$a['a1.phps'] = '<?php var_dump($_SERVER["REQUEST_URI"], $_SERVER["PATH_INFO"]);';
+$a['a.jpg'] = 'hio2';
+$a['a.php'] = '<?php function hio(){}';
+$a['fronk.gronk'] = 'hio3';
+$a['404.php'] = 'My 404 is rawesome';
+$a['noext'] = 'hi';
+$a['unknown.ext'] = '<?php var_dump("hi");';
+$a['bigfile.txt'] = str_repeat('a', 8193);
+$a['fatalerror.phps'] = '<?php oopsie_daisy();';
+$a->setStub('<?php
+Phar::webPhar("whatever", "index.php", "404.php", 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/files/frontcontroller9.phar b/ext/phar/tests/files/frontcontroller9.phar
new file mode 100644
index 0000000000..39ca28c96c
--- /dev/null
+++ b/ext/phar/tests/files/frontcontroller9.phar
Binary files differ
diff --git a/ext/phar/tests/files/frontcontroller9.phar.inc b/ext/phar/tests/files/frontcontroller9.phar.inc
new file mode 100644
index 0000000000..00861f6420
--- /dev/null
+++ b/ext/phar/tests/files/frontcontroller9.phar.inc
@@ -0,0 +1,14 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller9.phar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller9.phar');
+$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/files/md5.phar b/ext/phar/tests/files/md5.phar
new file mode 100644
index 0000000000..8ca2f84dac
--- /dev/null
+++ b/ext/phar/tests/files/md5.phar
Binary files differ
diff --git a/ext/phar/tests/files/nophar.phar b/ext/phar/tests/files/nophar.phar
new file mode 100644
index 0000000000..f1c5252018
--- /dev/null
+++ b/ext/phar/tests/files/nophar.phar
Binary files differ
diff --git a/ext/phar/tests/files/nophar.phar.inc b/ext/phar/tests/files/nophar.phar.inc
new file mode 100644
index 0000000000..36d5628762
--- /dev/null
+++ b/ext/phar/tests/files/nophar.phar.inc
@@ -0,0 +1,10 @@
+<?php
+$fname = dirname(__FILE__) . '/nophar.phar';
+@unlink($fname);
+$p = new Phar($fname);
+$p['index.php'] = '<?php include "b/c.php";' . "\n";
+$p['web.php'] = '<?php echo "web\n";';
+$p['b/c.php'] = '<?php echo "in b\n";$a = fopen("index.php", "r", true);echo stream_get_contents($a);fclose($a);include dirname(__FILE__) . "/../d";';
+$p['d'] = "in d\n";
+$p->setStub($p->createDefaultStub('index.php', 'web.php'));
+?> \ No newline at end of file
diff --git a/ext/phar/tests/files/phar_oo_test.inc b/ext/phar/tests/files/phar_oo_test.inc
new file mode 100644
index 0000000000..9863e8da93
--- /dev/null
+++ b/ext/phar/tests/files/phar_oo_test.inc
@@ -0,0 +1,49 @@
+<?php
+
+ini_set('date.timezone', 'GMT');
+
+$fname = dirname(__FILE__) . '/phar_oo_test.phar.php';
+$pname = 'phar://' . $fname;
+$file = '<?php include "' . $pname . '/a.php"; __HALT_COMPILER(); ?>';
+
+$files = array();
+
+if (!isset($pharconfig)) $pharconfig = 0;
+
+switch($pharconfig)
+{
+ default:
+ case 0:
+ $files['a.php'] = '<?php echo "This is a.php\n"; ?>';
+ $files['b.php'] = '<?php echo "This is b.php\n"; ?>';
+ $files['b/c.php'] = '<?php echo "This is b/c.php\n"; ?>';
+ $files['b/d.php'] = '<?php echo "This is b/d.php\n"; ?>';
+ $files['e.php'] = '<?php echo "This is e.php\n"; ?>';
+ break;
+ case 1:
+ $files['a.csv'] =<<<EOF
+1,2,3
+2,a,b
+3,"c","'e'"
+EOF;
+ break;
+ case 2:
+ $files['a.csv'] =<<<EOF
+1,2,3
+2,a,b
+3,"c","'e'"
+4
+5,5
+
+7,777
+EOF;
+ break;
+ case 3:
+ $files['a.php'] = '<?php echo new new class;';
+ break;
+}
+
+$ftime = mktime(12, 0, 0, 3, 1, 2006);
+include 'phar_test.inc';
+
+?> \ No newline at end of file
diff --git a/ext/phar/tests/files/phar_test.inc b/ext/phar/tests/files/phar_test.inc
new file mode 100644
index 0000000000..a5e9d3fdc8
--- /dev/null
+++ b/ext/phar/tests/files/phar_test.inc
@@ -0,0 +1,76 @@
+<?php
+
+if (function_exists('date_default_timezone_set')) {
+ date_default_timezone_set('UTC');
+}
+
+$manifest = '';
+$glags = 0;
+
+foreach($files as $name => $cont)
+{
+ global $gflags, $files;
+
+ $comp = NULL;
+ $crc32= NULL;
+ $clen = NULL;
+ $ulen = NULL;
+ $time = isset($ftime) ? $ftime : @mktime(12, 0, 0, 3, 1, 2006);
+ $flags= 0;
+ $perm = 0x000001B6;
+ $meta = NULL;
+
+ // overwrite if array
+ if (is_array($cont))
+ {
+ foreach(array('comp','crc32','clen','ulen','time','flags','perm','meta','cont') as $what)
+ {
+ if (isset($cont[$what]))
+ {
+ $$what = $cont[$what];
+ }
+ }
+ }
+
+ // create if not yet done
+ if (empty($comp)) $comp = $cont;
+ if (empty($ulen)) $ulen = strlen($cont);
+ if (empty($clen)) $clen = strlen($comp);
+ if (empty($crc32))$crc32= crc32($cont);
+ if (isset($meta)) $meta = serialize($meta);
+
+ // write manifest entry
+ $manifest .= pack('V', strlen($name)) . $name;
+ $manifest .= pack('VVVVVV', $ulen, $time, $clen, $crc32, $flags|$perm, strlen($meta)) . $meta;
+
+ // globals
+ $gflags |= $flags;
+ $files[$name] = $comp;
+}
+
+if (!isset($alias)) $alias = 'hio';
+
+if (isset($pmeta)) $pmeta = serialize($pmeta); else $pmeta = '';
+$manifest = pack('VnVV', count($files), isset($hasdir) ? 0x1110 : 0x1000, $gflags, strlen($alias)) . $alias . pack('V', strlen($pmeta)) . $pmeta . $manifest;
+$file .= pack('V', strlen($manifest)) . $manifest;
+
+foreach($files as $cont)
+{
+ $file .= $cont;
+}
+
+file_put_contents($fname, $file);
+
+if (@$gzip) {
+ $fp = gzopen($fname, 'w');
+ fwrite($fp, $file);
+ fclose($fp);
+}
+
+if (@$bz2) {
+ $fp = bzopen($fname, 'w');
+ fwrite($fp, $file);
+ fclose($fp);
+}
+
+?> \ No newline at end of file
diff --git a/ext/phar/tests/files/sha1.phar b/ext/phar/tests/files/sha1.phar
new file mode 100644
index 0000000000..c7e9e7e6a2
--- /dev/null
+++ b/ext/phar/tests/files/sha1.phar
Binary files differ
diff --git a/ext/phar/tests/files/sha256.phar b/ext/phar/tests/files/sha256.phar
new file mode 100644
index 0000000000..81459eef0f
--- /dev/null
+++ b/ext/phar/tests/files/sha256.phar
Binary files differ
diff --git a/ext/phar/tests/files/sha512.phar b/ext/phar/tests/files/sha512.phar
new file mode 100644
index 0000000000..a7473819aa
--- /dev/null
+++ b/ext/phar/tests/files/sha512.phar
Binary files differ
diff --git a/ext/phar/tests/files/zfapp.tgz b/ext/phar/tests/files/zfapp.tgz
new file mode 100644
index 0000000000..fcaec86d65
--- /dev/null
+++ b/ext/phar/tests/files/zfapp.tgz
Binary files differ
diff --git a/ext/phar/tests/fopen.phpt b/ext/phar/tests/fopen.phpt
new file mode 100644
index 0000000000..5b694d6e2d
--- /dev/null
+++ b/ext/phar/tests/fopen.phpt
@@ -0,0 +1,43 @@
+--TEST--
+Phar: test fopen() interception
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");?>
+<?php if (substr(phpversion(), 0, 3) == '5.2') die("skip PHP >= 5.3 required for this test");?>
+--INI--
+phar.require_hash=1
+phar.readonly=0
+--FILE--
+<?php
+Phar::interceptFileFuncs();
+$a = fopen(__FILE__, 'rb'); // this satisfies 1 line of code coverage
+fclose($a);
+$a = fopen(); // this satisfies another line of code coverage
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$a = new Phar($fname);
+$a['index.php'] = '<?php
+$a = fopen("dir/file1.txt", "r");
+echo fread($a, 2);
+fclose($a);
+$a = fopen("file1.txt", "r", true);
+echo fread($a, 2);
+fclose($a);
+$a = fopen("notfound.txt", "r", true);
+?>';
+$a['dir/file1.txt'] = 'hi';
+$a['dir/file2.txt'] = 'hi2';
+$a['dir/file3.txt'] = 'hi3';
+$a->setStub('<?php
+set_include_path("phar://" . __FILE__ . "/dir" . PATH_SEPARATOR . "phar://" . __FILE__);
+include "index.php";
+__HALT_COMPILER();');
+include $fname;
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECTF--
+Warning: fopen() expects at least 2 parameters, 0 given in %sfopen.php on line %d
+hihi
+Warning: fopen(notfound.txt): failed to open stream: No such file or directory in phar://%sfopen.phar.php/index.php on line %d
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/fopen5.2.phpt b/ext/phar/tests/fopen5.2.phpt
new file mode 100644
index 0000000000..aa064f1662
--- /dev/null
+++ b/ext/phar/tests/fopen5.2.phpt
@@ -0,0 +1,43 @@
+--TEST--
+Phar: test fopen() interception
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");?>
+<?php if (substr(phpversion(), 0, 3) != '5.2') die("skip PHP 5.2 required for this test");?>
+--INI--
+phar.require_hash=1
+phar.readonly=0
+--FILE--
+<?php
+Phar::interceptFileFuncs();
+$a = fopen(__FILE__, 'rb'); // this satisfies 1 line of code coverage
+fclose($a);
+$a = fopen(); // this satisfies another line of code coverage
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$a = new Phar($fname);
+$a['index.php'] = '<?php
+$a = fopen("dir/file1.txt", "r");
+echo fread($a, 2);
+fclose($a);
+$a = fopen("file1.txt", "r", true);
+echo fread($a, 2);
+fclose($a);
+$a = fopen("notfound.txt", "r", true);
+?>';
+$a['dir/file1.txt'] = 'hi';
+$a['dir/file2.txt'] = 'hi2';
+$a['dir/file3.txt'] = 'hi3';
+$a->setStub('<?php
+set_include_path("phar://" . __FILE__ . "/dir" . PATH_SEPARATOR . "phar://" . __FILE__);
+include "index.php";
+__HALT_COMPILER();');
+include $fname;
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECTF--
+Warning: fopen() expects at least 2 parameters, 0 given in %sfopen5.2.php on line %d
+hihi
+Warning: fopen(phar://%sfopen5.2.phar.php/notfound.txt): failed to open stream: phar error: "notfound.txt" is not a file in phar "%sfopen5.2.phar.php" in phar://%sfopen5.2.phar.php/index.php on line %d
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/fopen_edgecases.phpt b/ext/phar/tests/fopen_edgecases.phpt
new file mode 100644
index 0000000000..4c28ff31a1
--- /dev/null
+++ b/ext/phar/tests/fopen_edgecases.phpt
@@ -0,0 +1,124 @@
+--TEST--
+Phar: fopen/stat/fseek/unlink/rename edge cases
+--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.php';
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.phar.php';
+$fname3 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.3.phar.php';
+$pname = 'phar://' . $fname;
+$pname2 = 'phar://' . $fname2;
+$pname3 = 'phar://' . $fname3;
+
+// create in cwd
+chdir(dirname(__FILE__));
+file_put_contents('phar://fopen_edgetest.phar/hi', 'hi');
+// append
+$a = fopen($pname . '/b/c.php', 'a');
+// invalid pharname
+$a = fopen($pname . '.phar.gz', 'r');
+// test phar_open_url() with quiet stat for code coverage
+var_dump(file_exists($pname . '.phar.gz/hi'));
+// test open for write with new phar
+$a = fopen($pname . '/hi', 'w');
+fclose($a);
+// test open for write with corrupted phar
+file_put_contents($fname2, '<?php oh crap __HALT_COMPILER();');
+$a = fopen($pname2 . '/hi', 'w');
+$a = fopen('phar://', 'r');
+$a = fopen('phar://foo.phar', 'r');
+
+file_put_contents($pname . '/hi', 'hi');
+$a = fopen($pname . '/hi', 'r');
+var_dump(fseek($a, 1), ftell($a));
+var_dump(fseek($a, 1, SEEK_CUR), ftell($a));
+fclose($a);
+
+var_dump(stat('phar://'));
+var_dump(stat('phar://foo.phar'));
+var_dump(is_dir($pname));
+
+// this tests coverage of the case where the phar exists and has no files
+$phar = new Phar($fname3);
+var_dump(file_exists($pname3 . '/test'));
+
+unlink($pname2 . '/hi');
+unlink('phar://');
+unlink('phar://foo.phar');
+unlink($pname . '/oops');
+
+rename('phar://', 'phar://');
+rename($pname . '/hi', 'phar://');
+rename('phar://foo.phar/hi', 'phar://');
+rename($pname . '/hi', 'phar://foo.phar/hi');
+
+ini_set('phar.readonly', 1);
+rename($pname . '/hi', $pname . '/there');
+ini_set('phar.readonly', 0);
+Phar::unlinkArchive($fname);
+file_put_contents($pname . '/test.php', '<?php
+$a = fopen("./notfound.php", "r");
+?>');
+include $pname . '/test.php';
+?>
+
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar.php'); ?>
+<?php unlink(dirname(__FILE__) . '/fopen_edgetest.phar');
+--EXPECTF--
+Warning: fopen(phar://%sfopen_edgecases.phar.php/b/c.php): failed to open stream: phar error: open mode append not supported in %sfopen_edgecases.php on line %d
+
+Warning: fopen(phar://%sfopen_edgecases.phar.php.phar.gz): failed to open stream: phar error: invalid url or non-existent phar "phar://%sfopen_edgecases.phar.php.phar.gz" in %sfopen_edgecases.php on line %d
+bool(false)
+
+Warning: fopen(phar://%sfopen_edgecases.2.phar.php/hi): failed to open stream: internal corruption of phar "%sfopen_edgecases.2.phar.php" (truncated manifest at stub end) in %sfopen_edgecases.php on line %d
+
+Warning: fopen(phar://): failed to open stream: phar error: no directory in "phar://", must have at least phar:/// for root directory (always use full path to a new phar) in %sfopen_edgecases.php on line %d
+
+Warning: fopen(phar://foo.phar): failed to open stream: %s in %sfopen_edgecases.php on line %d
+int(0)
+int(1)
+int(0)
+int(2)
+
+Warning: stat(): stat failed for phar:// in %sfopen_edgecases.php on line %d
+bool(false)
+
+Warning: stat(): stat failed for phar://foo.phar in %sfopen_edgecases.php on line %d
+bool(false)
+bool(true)
+bool(false)
+
+Warning: unlink(): internal corruption of phar "%sfopen_edgecases.2.phar.php" (truncated manifest at stub end) in %sfopen_edgecases.php on line %d
+
+Warning: unlink(): phar error: unlink failed in %sfopen_edgecases.php on line %d
+
+Warning: unlink(): phar error: no directory in "phar://", must have at least phar:/// for root directory (always use full path to a new phar) in %sfopen_edgecases.php on line %d
+
+Warning: unlink(): phar error: unlink failed in %sfopen_edgecases.php on line %d
+
+Warning: unlink(): phar error: invalid url or non-existent phar "phar://foo.phar" in %sfopen_edgecases.php on line %d
+
+Warning: unlink(): phar error: unlink failed in %sfopen_edgecases.php on line %d
+
+Warning: unlink(): unlink of "phar://%sfopen_edgecases.phar.php/oops" failed, file does not exist in %sfopen_edgecases.php on line %d
+
+Warning: rename(): phar error: cannot rename "phar://" to "phar://": invalid or non-writable url "phar://" in %sfopen_edgecases.php on line %d
+
+Warning: rename(): phar error: cannot rename "phar://%sfopen_edgecases.phar.php/hi" to "phar://": invalid or non-writable url "phar://" in %sfopen_edgecases.php on line %d
+
+Warning: rename(): phar error: cannot rename "phar://foo.phar/hi" to "phar://": invalid or non-writable url "phar://" in %sfopen_edgecases.php on line %d
+
+Warning: rename(): phar error: cannot rename "phar://%sfopen_edgecases.phar.php/hi" to "phar://foo.phar/hi", not within the same phar archive in %sfopen_edgecases.php on line %d
+
+Warning: rename(): phar error: cannot rename "phar://%sfopen_edgecases.phar.php/hi" to "phar://%sfopen_edgecases.phar.php/there": invalid or non-writable url "phar://%sfopen_edgecases.phar.php/hi" in %sfopen_edgecases.php on line %d
+
+Warning: fopen(./notfound.php): failed to open stream: No such file or directory in phar://%sfopen_edgecases.phar.php/test.php on line %d
+
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/fopen_edgecases2.phpt b/ext/phar/tests/fopen_edgecases2.phpt
new file mode 100644
index 0000000000..3579a2c221
--- /dev/null
+++ b/ext/phar/tests/fopen_edgecases2.phpt
@@ -0,0 +1,43 @@
+--TEST--
+Phar: test edge cases of fopen() function interception #2
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+Phar::interceptFileFuncs();
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+
+fopen(array(), 'r');
+chdir(dirname(__FILE__));
+file_put_contents($fname, "blah\n");
+file_put_contents("foob", "test\n");
+$a = fopen($fname, 'rb');
+echo fread($a, 1000);
+fclose($a);
+unlink($fname);
+mkdir($pname . '/oops');
+file_put_contents($pname . '/foo/hi', '<?php
+$context = stream_context_create();
+$a = fopen("foob", "rb", false, $context);
+echo fread($a, 1000);
+fclose($a);
+fopen("../oops", "r");
+?>
+');
+include $pname . '/foo/hi';
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+<?php rmdir(dirname(__FILE__) . '/poo'); ?>
+<?php unlink(dirname(__FILE__) . '/foob'); ?>
+--EXPECTF--
+Warning: fopen() expects parameter 1 to be string, array given in %sfopen_edgecases2.php on line %d
+blah
+test
+
+Warning: fopen(phar://%sfopen_edgecases2.phar.php/oops): failed to open stream: phar error: path "oops" is a directory in phar://%sfopen_edgecases2.phar.php/foo/hi on line %d
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/frontcontroller1.phpt b/ext/phar/tests/frontcontroller1.phpt
new file mode 100644
index 0000000000..7093323617
--- /dev/null
+++ b/ext/phar/tests/frontcontroller1.phpt
@@ -0,0 +1,15 @@
+--TEST--
+Phar front controller other
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller1.php
+REQUEST_URI=/frontcontroller1.php/a.jpg
+PATH_INFO=/a.jpg
+--FILE_EXTERNAL--
+files/frontcontroller.phar
+--EXPECTHEADERS--
+Content-type: image/jpeg
+Content-length: 3
+--EXPECT--
+hio
diff --git a/ext/phar/tests/frontcontroller10.phpt b/ext/phar/tests/frontcontroller10.phpt
new file mode 100644
index 0000000000..2dbf1cbed8
--- /dev/null
+++ b/ext/phar/tests/frontcontroller10.phpt
@@ -0,0 +1,22 @@
+--TEST--
+Phar front controller rewrite access denied
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller10.php
+REQUEST_URI=/frontcontroller10.php/hi
+PATH_INFO=/hi
+--FILE_EXTERNAL--
+files/frontcontroller4.phar
+--EXPECTHEADERS--
+Content-type: text/html
+Status: 403 Access Denied
+--EXPECT--
+<html>
+ <head>
+ <title>Access Denied</title>
+ </head>
+ <body>
+ <h1>403 - File /hi Access Denied</h1>
+ </body>
+</html>
diff --git a/ext/phar/tests/frontcontroller11.phpt b/ext/phar/tests/frontcontroller11.phpt
new file mode 100644
index 0000000000..3823fec191
--- /dev/null
+++ b/ext/phar/tests/frontcontroller11.phpt
@@ -0,0 +1,18 @@
+--TEST--
+Phar front controller mime type extension is not a string
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller11.php
+REQUEST_URI=/frontcontroller11.php/a.php
+PATH_INFO=/a.php
+--FILE_EXTERNAL--
+files/frontcontroller5.phar
+--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.php:2
+Stack trace:
+#0 %sfrontcontroller11.php(2): Phar::webPhar('whatever', 'index.php', '', Array)
+#1 {main}
+ thrown in %sfrontcontroller11.php on line 2 \ No newline at end of file
diff --git a/ext/phar/tests/frontcontroller12.phpt b/ext/phar/tests/frontcontroller12.phpt
new file mode 100644
index 0000000000..e07876a41b
--- /dev/null
+++ b/ext/phar/tests/frontcontroller12.phpt
@@ -0,0 +1,18 @@
+--TEST--
+Phar front controller mime type unknown int
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller12.php
+REQUEST_URI=/frontcontroller12.php/a.php
+PATH_INFO=/a.php
+--FILE_EXTERNAL--
+files/frontcontroller6.phar
+--EXPECTHEADERS--
+Content-type: text/html
+--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.php:2
+Stack trace:
+#0 %sfrontcontroller12.php(2): Phar::webPhar('whatever', 'index.php', '', Array)
+#1 {main}
+ thrown in %sfrontcontroller12.php on line 2 \ No newline at end of file
diff --git a/ext/phar/tests/frontcontroller13.phpt b/ext/phar/tests/frontcontroller13.phpt
new file mode 100644
index 0000000000..74ed0e1b75
--- /dev/null
+++ b/ext/phar/tests/frontcontroller13.phpt
@@ -0,0 +1,18 @@
+--TEST--
+Phar front controller mime type not string/int
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller13.php
+REQUEST_URI=/frontcontroller13.php/a.php
+PATH_INFO=/a.php
+--FILE_EXTERNAL--
+files/frontcontroller7.phar
+--EXPECTHEADERS--
+Content-type: text/html
+--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.php:2
+Stack trace:
+#0 %sfrontcontroller13.php(2): Phar::webPhar('whatever', 'index.php', '', Array)
+#1 {main}
+ thrown in %sfrontcontroller13.php on line 2 \ No newline at end of file
diff --git a/ext/phar/tests/frontcontroller14.phpt b/ext/phar/tests/frontcontroller14.phpt
new file mode 100644
index 0000000000..2bdb145c6e
--- /dev/null
+++ b/ext/phar/tests/frontcontroller14.phpt
@@ -0,0 +1,15 @@
+--TEST--
+Phar front controller mime type override, other
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller14.php
+REQUEST_URI=/frontcontroller14.php/a.jpg
+PATH_INFO=/a.jpg
+--FILE_EXTERNAL--
+files/frontcontroller8.phar
+--EXPECTHEADERS--
+Content-type: foo/bar
+Content-length: 4
+--EXPECT--
+hio2
diff --git a/ext/phar/tests/frontcontroller15.phpt b/ext/phar/tests/frontcontroller15.phpt
new file mode 100644
index 0000000000..eb69ede8f5
--- /dev/null
+++ b/ext/phar/tests/frontcontroller15.phpt
@@ -0,0 +1,18 @@
+--TEST--
+Phar front controller mime type override, Phar::PHPS
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller15.php
+REQUEST_URI=/frontcontroller15.php/a.php
+PATH_INFO=/a.php
+--FILE_EXTERNAL--
+files/frontcontroller8.phar
+--EXPECTHEADERS--
+Content-type: text/html
+--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/frontcontroller16.phpt b/ext/phar/tests/frontcontroller16.phpt
new file mode 100644
index 0000000000..5c6a03e16a
--- /dev/null
+++ b/ext/phar/tests/frontcontroller16.phpt
@@ -0,0 +1,15 @@
+--TEST--
+Phar front controller mime type override, Phar::PHP
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller16.php
+REQUEST_URI=/frontcontroller16.php/a.phps
+PATH_INFO=/a.phps
+--FILE_EXTERNAL--
+files/frontcontroller8.phar
+--EXPECTHEADERS--
+Content-type: text/html
+--EXPECT--
+hio1
+
diff --git a/ext/phar/tests/frontcontroller17.phpt b/ext/phar/tests/frontcontroller17.phpt
new file mode 100644
index 0000000000..233e2e2a49
--- /dev/null
+++ b/ext/phar/tests/frontcontroller17.phpt
@@ -0,0 +1,16 @@
+--TEST--
+Phar front controller mime type unknown
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller17.php
+REQUEST_URI=/frontcontroller17.php/fronk.gronk
+PATH_INFO=/fronk.gronk
+--FILE_EXTERNAL--
+files/frontcontroller8.phar
+--EXPECTHEADERS--
+Content-type: application/octet-stream
+Content-length: 4
+--EXPECT--
+hio3
+
diff --git a/ext/phar/tests/frontcontroller18.phpt b/ext/phar/tests/frontcontroller18.phpt
new file mode 100644
index 0000000000..19aea45563
--- /dev/null
+++ b/ext/phar/tests/frontcontroller18.phpt
@@ -0,0 +1,16 @@
+--TEST--
+Phar front controller $_SERVER munging failure
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller18.php
+REQUEST_URI=/frontcontroller18.php/fronk.gronk
+PATH_INFO=/fronk.gronk
+--FILE_EXTERNAL--
+files/frontcontroller9.phar
+--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.php:2
+Stack trace:
+#0 %sfrontcontroller18.php(2): Phar::mungServer(Array)
+#1 {main}
+ thrown in %sfrontcontroller18.php on line 2
diff --git a/ext/phar/tests/frontcontroller19.phpt b/ext/phar/tests/frontcontroller19.phpt
new file mode 100644
index 0000000000..9adafa2b30
--- /dev/null
+++ b/ext/phar/tests/frontcontroller19.phpt
@@ -0,0 +1,16 @@
+--TEST--
+Phar front controller $_SERVER munging failure 2
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller19.php
+REQUEST_URI=/frontcontroller19.php/
+PATH_INFO=/
+--FILE_EXTERNAL--
+files/frontcontroller10.phar
+--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.php:2
+Stack trace:
+#0 %sfrontcontroller19.php(2): Phar::mungServer(Array)
+#1 {main}
+ thrown in %sfrontcontroller19.php on line 2
diff --git a/ext/phar/tests/frontcontroller2.phpt b/ext/phar/tests/frontcontroller2.phpt
new file mode 100644
index 0000000000..4b1652c461
--- /dev/null
+++ b/ext/phar/tests/frontcontroller2.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Phar front controller PHP test
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller2.php
+REQUEST_URI=/frontcontroller2.php/a.php
+PATH_INFO=/a.php
+--FILE_EXTERNAL--
+files/frontcontroller.phar
+--EXPECTHEADERS--
+Content-type: text/html
+--EXPECT--
+hio
diff --git a/ext/phar/tests/frontcontroller20.phpt b/ext/phar/tests/frontcontroller20.phpt
new file mode 100644
index 0000000000..45e2bfc25e
--- /dev/null
+++ b/ext/phar/tests/frontcontroller20.phpt
@@ -0,0 +1,16 @@
+--TEST--
+Phar front controller $_SERVER munging failure 3
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller20.php
+REQUEST_URI=/frontcontroller20.php/
+PATH_INFO=/
+--FILE_EXTERNAL--
+files/frontcontroller11.phar
+--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.php:2
+Stack trace:
+#0 %sfrontcontroller20.php(2): Phar::mungServer(Array)
+#1 {main}
+ thrown in %sfrontcontroller20.php on line 2
diff --git a/ext/phar/tests/frontcontroller21.phpt b/ext/phar/tests/frontcontroller21.phpt
new file mode 100644
index 0000000000..70d3508496
--- /dev/null
+++ b/ext/phar/tests/frontcontroller21.phpt
@@ -0,0 +1,22 @@
+--TEST--
+Phar front controller $_SERVER munging success
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller21.php
+REQUEST_URI=/frontcontroller21.php/index.php?test=hi
+PATH_INFO=/index.php
+QUERY_STRING=test=hi
+--FILE_EXTERNAL--
+files/frontcontroller12.phar
+--EXPECTHEADERS--
+Content-type: text/html
+--EXPECTF--
+string(10) "/index.php"
+string(10) "/index.php"
+string(%d) "phar://%sfrontcontroller21.php/index.php"
+string(18) "/index.php?test=hi"
+string(32) "/frontcontroller21.php/index.php"
+string(22) "/frontcontroller21.php"
+string(%d) "%sfrontcontroller21.php"
+string(40) "/frontcontroller21.php/index.php?test=hi" \ No newline at end of file
diff --git a/ext/phar/tests/frontcontroller22.phpt b/ext/phar/tests/frontcontroller22.phpt
new file mode 100644
index 0000000000..9925ba16d3
--- /dev/null
+++ b/ext/phar/tests/frontcontroller22.phpt
@@ -0,0 +1,19 @@
+--TEST--
+Phar front controller include from cwd test 1
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller22.php
+REQUEST_URI=/frontcontroller22.php/index.php
+PATH_INFO=/index.php
+--FILE_EXTERNAL--
+files/frontcontroller13.phar
+--EXPECTHEADERS--
+Content-type: text/html
+--EXPECTF--
+string(4) "test"
+string(12) "oof/test.php"
+
+Warning: include(./hi.php): failed to open stream: No such file or directory in phar://%s/oof/test.php on line %d
+
+Warning: include(): Failed opening './hi.php' for inclusion (include_path='%s') in phar://%soof/test.php on line %d \ No newline at end of file
diff --git a/ext/phar/tests/frontcontroller23.phpt b/ext/phar/tests/frontcontroller23.phpt
new file mode 100644
index 0000000000..14f32dd6db
--- /dev/null
+++ b/ext/phar/tests/frontcontroller23.phpt
@@ -0,0 +1,15 @@
+--TEST--
+Phar front controller with generic action router test
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller23.php
+REQUEST_URI=/frontcontroller23.php/hi/there
+PATH_INFO=/hi/there
+--FILE_EXTERNAL--
+files/frontcontroller14.phar
+--EXPECTHEADERS--
+Content-type: text/html
+--EXPECTF--
+string(9) "/hi/there"
+string(%d) "phar://%sfrontcontroller23.php/html/index.php" \ No newline at end of file
diff --git a/ext/phar/tests/frontcontroller24.phpt b/ext/phar/tests/frontcontroller24.phpt
new file mode 100644
index 0000000000..dca5a693cd
--- /dev/null
+++ b/ext/phar/tests/frontcontroller24.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Phar front controller with custom 404 php script
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller24.php
+REQUEST_URI=/frontcontroller24.php/unknown/file
+PATH_INFO=/unknown/file
+--FILE_EXTERNAL--
+files/frontcontroller8.phar
+--EXPECTHEADERS--
+Content-type: text/html
+--EXPECTF--
+My 404 is rawesome \ No newline at end of file
diff --git a/ext/phar/tests/frontcontroller25.phpt b/ext/phar/tests/frontcontroller25.phpt
new file mode 100644
index 0000000000..4d0475b078
--- /dev/null
+++ b/ext/phar/tests/frontcontroller25.phpt
@@ -0,0 +1,15 @@
+--TEST--
+Phar front controller with extra path_info
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller25.php
+REQUEST_URI=/frontcontroller25.php/a1.phps/extra/stuff
+PATH_INFO=/a1.phps/extra/stuff
+--FILE_EXTERNAL--
+files/frontcontroller8.phar
+--EXPECTHEADERS--
+Content-type: text/html
+--EXPECTF--
+string(42) "/frontcontroller25.php/a1.phps/extra/stuff"
+string(12) "/extra/stuff" \ No newline at end of file
diff --git a/ext/phar/tests/frontcontroller26.phpt b/ext/phar/tests/frontcontroller26.phpt
new file mode 100644
index 0000000000..a8097b0886
--- /dev/null
+++ b/ext/phar/tests/frontcontroller26.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Phar front controller with unknown extension mime type
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller26.php
+REQUEST_URI=/frontcontroller26.php/unknown.ext
+PATH_INFO=/unknown.ext
+--FILE_EXTERNAL--
+files/frontcontroller8.phar
+--EXPECTHEADERS--
+Content-type: application/octet-stream
+--EXPECTF--
+<?php var_dump("hi"); \ No newline at end of file
diff --git a/ext/phar/tests/frontcontroller27.phpt b/ext/phar/tests/frontcontroller27.phpt
new file mode 100644
index 0000000000..78c9536410
--- /dev/null
+++ b/ext/phar/tests/frontcontroller27.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Phar front controller with no extension
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller27.php
+REQUEST_URI=/frontcontroller27.php/noext
+PATH_INFO=/noext
+--FILE_EXTERNAL--
+files/frontcontroller8.phar
+--EXPECTHEADERS--
+Content-type: text/plain
+--EXPECTF--
+hi \ No newline at end of file
diff --git a/ext/phar/tests/frontcontroller28.phpt b/ext/phar/tests/frontcontroller28.phpt
new file mode 100644
index 0000000000..59311120b4
--- /dev/null
+++ b/ext/phar/tests/frontcontroller28.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Phar front controller with huge file
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller28.php
+REQUEST_URI=/frontcontroller28.php/bigfile.txt
+PATH_INFO=/bigfile.txt
+--FILE_EXTERNAL--
+files/frontcontroller8.phar
+--EXPECTHEADERS--
+Content-type: text/plain
+--EXPECT--
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
diff --git a/ext/phar/tests/frontcontroller29.phpt b/ext/phar/tests/frontcontroller29.phpt
new file mode 100644
index 0000000000..64674b5a28
--- /dev/null
+++ b/ext/phar/tests/frontcontroller29.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Phar front controller with fatal error in php file
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller29.php
+REQUEST_URI=/frontcontroller29.php/fatalerror.phps
+PATH_INFO=/fatalerror.phps
+--FILE_EXTERNAL--
+files/frontcontroller8.phar
+--EXPECTHEADERS--
+Content-type: text/html
+--EXPECTF--
+Fatal error: Call to undefined function oopsie_daisy() in phar://%sfatalerror.phps on line 1 \ No newline at end of file
diff --git a/ext/phar/tests/frontcontroller3.phpt b/ext/phar/tests/frontcontroller3.phpt
new file mode 100644
index 0000000000..1b8093542f
--- /dev/null
+++ b/ext/phar/tests/frontcontroller3.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Phar front controller phps
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller3.php
+REQUEST_URI=/frontcontroller3.php/a.phps
+PATH_INFO=/a.phps
+--FILE_EXTERNAL--
+files/frontcontroller.phar
+--EXPECTHEADERS--
+Content-type: text/html
+--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/frontcontroller30.phpt b/ext/phar/tests/frontcontroller30.phpt
new file mode 100644
index 0000000000..de6960c244
--- /dev/null
+++ b/ext/phar/tests/frontcontroller30.phpt
@@ -0,0 +1,12 @@
+--TEST--
+Phar front controller with weird SCRIPT_NAME
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/huh?
+REQUEST_URI=/huh?
+--FILE_EXTERNAL--
+files/frontcontroller8.phar
+--EXPECTF--
+oops did not run
+%a \ No newline at end of file
diff --git a/ext/phar/tests/frontcontroller31.phpt b/ext/phar/tests/frontcontroller31.phpt
new file mode 100644
index 0000000000..6ec7ca1b6f
--- /dev/null
+++ b/ext/phar/tests/frontcontroller31.phpt
@@ -0,0 +1,13 @@
+--TEST--
+Phar front controller with invalid callback for rewrites
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller31.php
+REQUEST_URI=/frontcontroller31.php
+--EXPECTHEADERS--
+Content-type: text/html
+--FILE_EXTERNAL--
+files/frontcontroller16.phar
+--EXPECT--
+phar error: invalid rewrite callback \ No newline at end of file
diff --git a/ext/phar/tests/frontcontroller32.phpt b/ext/phar/tests/frontcontroller32.phpt
new file mode 100644
index 0000000000..da9a4ef256
--- /dev/null
+++ b/ext/phar/tests/frontcontroller32.phpt
@@ -0,0 +1,13 @@
+--TEST--
+Phar front controller with valid callback that is not good
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller32.php
+REQUEST_URI=/frontcontroller32.php
+--EXPECTHEADERS--
+Content-type: text/html
+--FILE_EXTERNAL--
+files/frontcontroller17.phar
+--EXPECTF--
+%ahar error: failed to call rewrite callback \ No newline at end of file
diff --git a/ext/phar/tests/frontcontroller33.phpt b/ext/phar/tests/frontcontroller33.phpt
new file mode 100644
index 0000000000..e1bc2a79fb
--- /dev/null
+++ b/ext/phar/tests/frontcontroller33.phpt
@@ -0,0 +1,13 @@
+--TEST--
+Phar front controller with valid callback that does not return any value
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller33.php
+REQUEST_URI=/frontcontroller33.php
+--EXPECTHEADERS--
+Content-type: text/html
+--FILE_EXTERNAL--
+files/frontcontroller18.phar
+--EXPECTF--
+phar error: rewrite callback must return a string or false \ No newline at end of file
diff --git a/ext/phar/tests/frontcontroller34.phpt b/ext/phar/tests/frontcontroller34.phpt
new file mode 100644
index 0000000000..636667032a
--- /dev/null
+++ b/ext/phar/tests/frontcontroller34.phpt
@@ -0,0 +1,16 @@
+--TEST--
+Phar front controller with cwd
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller34.php
+REQUEST_URI=/frontcontroller34.php/start/index.php
+PATH_INFO=/start/index.php
+--EXPECTHEADERS--
+Content-type: text/html
+--FILE_EXTERNAL--
+files/frontcontroller19.phar
+--EXPECT--
+start/index.php
+start/another.php
+another.php
diff --git a/ext/phar/tests/frontcontroller4.phpt b/ext/phar/tests/frontcontroller4.phpt
new file mode 100644
index 0000000000..f2482b9219
--- /dev/null
+++ b/ext/phar/tests/frontcontroller4.phpt
@@ -0,0 +1,13 @@
+--TEST--
+Phar front controller index.php relocate (no /)
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller4.php
+REQUEST_URI=/frontcontroller4.php
+--FILE_EXTERNAL--
+files/frontcontroller.phar
+--EXPECTHEADERS--
+Status: 301 Moved Permanently
+Location: /frontcontroller4.php/index.php
+--EXPECT--
diff --git a/ext/phar/tests/frontcontroller5.phpt b/ext/phar/tests/frontcontroller5.phpt
new file mode 100644
index 0000000000..1990a2b008
--- /dev/null
+++ b/ext/phar/tests/frontcontroller5.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Phar front controller index.php relocate
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller5.php
+REQUEST_URI=/frontcontroller5.php/
+PATH_INFO=/
+--FILE_EXTERNAL--
+files/frontcontroller.phar
+--EXPECTHEADERS--
+Status: 301 Moved Permanently
+Location: /frontcontroller5.php/index.php
+--EXPECT--
diff --git a/ext/phar/tests/frontcontroller6.phpt b/ext/phar/tests/frontcontroller6.phpt
new file mode 100644
index 0000000000..1a2cc2cd23
--- /dev/null
+++ b/ext/phar/tests/frontcontroller6.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Phar front controller 404
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller6.php
+REQUEST_URI=/frontcontroller6.php/notfound.php
+PATH_INFO=/notfound.php
+--FILE_EXTERNAL--
+files/frontcontroller.phar
+--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/frontcontroller7.phpt b/ext/phar/tests/frontcontroller7.phpt
new file mode 100644
index 0000000000..aff2087522
--- /dev/null
+++ b/ext/phar/tests/frontcontroller7.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Phar front controller alternate index file
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller7.php
+REQUEST_URI=/frontcontroller7.php/
+PATH_INFO=/
+--FILE_EXTERNAL--
+files/frontcontroller2.phar
+--EXPECTHEADERS--
+Status: 301 Moved Permanently
+Location: /frontcontroller7.php/a.php
+--EXPECT--
diff --git a/ext/phar/tests/frontcontroller8.phpt b/ext/phar/tests/frontcontroller8.phpt
new file mode 100644
index 0000000000..36e3206d66
--- /dev/null
+++ b/ext/phar/tests/frontcontroller8.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Phar front controller no index file 404
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller8.php
+REQUEST_URI=/frontcontroller8.php/
+PATH_INFO=/
+--FILE_EXTERNAL--
+files/frontcontroller3.phar
+--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/frontcontroller9.phpt b/ext/phar/tests/frontcontroller9.phpt
new file mode 100644
index 0000000000..b7af364853
--- /dev/null
+++ b/ext/phar/tests/frontcontroller9.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Phar front controller rewrite array
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller9.php
+REQUEST_URI=/frontcontroller9.php/hi
+PATH_INFO=/hi
+--FILE_EXTERNAL--
+files/frontcontroller3.phar
+--EXPECTHEADERS--
+Content-type: text/html
+--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/include_path.phpt b/ext/phar/tests/include_path.phpt
new file mode 100644
index 0000000000..5f9462c260
--- /dev/null
+++ b/ext/phar/tests/include_path.phpt
@@ -0,0 +1,34 @@
+--TEST--
+Phar: include_path with phar:// wrapper
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/tempmanifest1.phar.php';
+$a = new Phar($fname);
+$a['file1.php'] = 'file1.php
+';
+$a['test/file1.php'] = 'test/file1.php
+';
+unset($a);
+set_include_path('.' . PATH_SEPARATOR . 'phar://' . $fname);
+include 'file1.php';
+set_include_path('.' . PATH_SEPARATOR . 'phar://' . $fname . '/test');
+include 'file1.php';
+include 'file2.php';
+?>
+===DONE===
+--CLEAN--
+<?php
+@unlink(dirname(__FILE__) . '/tempmanifest1.phar.php');
+?>
+--EXPECTF--
+file1.php
+test/file1.php
+
+Warning: include(file2.php): failed to open stream: No such file or directory in %sinclude_path.php on line %d
+
+Warning: include(): Failed opening 'file2.php' for inclusion (include_path='%sphar://%stempmanifest1.phar.php/test') in %sinclude_path.php on line %d
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/ini_set.phpt b/ext/phar/tests/ini_set.phpt
new file mode 100644
index 0000000000..588cd4a74b
--- /dev/null
+++ b/ext/phar/tests/ini_set.phpt
@@ -0,0 +1,28 @@
+--TEST--
+Phar: test ini_set with readonly and require_hash enabled
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");?>
+--INI--
+phar.require_hash=1
+phar.readonly=1
+--FILE--
+<?php
+var_dump(ini_set('phar.require_hash', 1));
+var_dump(ini_set('phar.readonly', 1));
+var_dump(ini_get('phar.require_hash'));
+var_dump(ini_get('phar.readonly'));
+var_dump(ini_set('phar.require_hash', 0));
+var_dump(ini_set('phar.readonly', 0));
+var_dump(ini_get('phar.require_hash'));
+var_dump(ini_get('phar.readonly'));
+__HALT_COMPILER();
+?>
+--EXPECT--
+string(1) "1"
+string(1) "1"
+string(1) "1"
+string(1) "1"
+string(1) "1"
+string(1) "1"
+string(1) "1"
+string(1) "1"
diff --git a/ext/phar/tests/ini_set_off.phpt b/ext/phar/tests/ini_set_off.phpt
new file mode 100644
index 0000000000..7da07c5d8d
--- /dev/null
+++ b/ext/phar/tests/ini_set_off.phpt
@@ -0,0 +1,85 @@
+--TEST--
+Phar: test ini_set with readonly and require_hash disabled
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+var_dump(ini_set('phar.require_hash', 1));
+var_dump(ini_set('phar.readonly', 1));
+var_dump(ini_get('phar.require_hash'));
+var_dump(ini_get('phar.readonly'));
+ini_set('phar.require_hash', 0);
+ini_set('phar.readonly', 0);
+var_dump(Phar::canWrite());
+?>
+yes
+<?php
+var_dump(ini_set('phar.require_hash', 'yes'));
+var_dump(ini_set('phar.readonly', 'yes'));
+var_dump(ini_get('phar.require_hash'));
+var_dump(ini_get('phar.readonly'));
+var_dump(Phar::canWrite());
+ini_set('phar.require_hash', 0);
+ini_set('phar.readonly', 0);
+?>
+on
+<?php
+var_dump(ini_set('phar.require_hash', 'on'));
+var_dump(ini_set('phar.readonly', 'on'));
+var_dump(ini_get('phar.require_hash'));
+var_dump(ini_get('phar.readonly'));
+var_dump(Phar::canWrite());
+ini_set('phar.require_hash', 0);
+ini_set('phar.readonly', 0);
+?>
+true
+<?php
+var_dump(ini_set('phar.require_hash', 'true'));
+var_dump(ini_set('phar.readonly', 'true'));
+var_dump(Phar::canWrite());
+var_dump(ini_get('phar.require_hash'));
+var_dump(ini_get('phar.readonly'));
+?>
+0
+<?php
+var_dump(ini_set('phar.require_hash', 0));
+var_dump(ini_set('phar.readonly', 0));
+var_dump(Phar::canWrite());
+var_dump(ini_get('phar.require_hash'));
+var_dump(ini_get('phar.readonly'));
+?>
+===DONE===
+--EXPECT--
+string(1) "0"
+string(1) "0"
+string(1) "1"
+string(1) "1"
+bool(true)
+yes
+string(1) "0"
+string(1) "0"
+string(3) "yes"
+string(3) "yes"
+bool(false)
+on
+string(1) "0"
+string(1) "0"
+string(2) "on"
+string(2) "on"
+bool(false)
+true
+string(1) "0"
+string(1) "0"
+bool(false)
+string(4) "true"
+string(4) "true"
+0
+string(4) "true"
+string(4) "true"
+bool(true)
+string(1) "0"
+string(1) "0"
+===DONE===
diff --git a/ext/phar/tests/invalid_alias.phpt b/ext/phar/tests/invalid_alias.phpt
new file mode 100644
index 0000000000..dc0c71ed11
--- /dev/null
+++ b/ext/phar/tests/invalid_alias.phpt
@@ -0,0 +1,45 @@
+--TEST--
+Phar: set alias with invalid alias containing / \ : or ;
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar';
+
+$p = new Phar($fname);
+try {
+ $p->setAlias('hi/');
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+try {
+ $p->setAlias('hi\\l');
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+
+try {
+ $p->setAlias('hil;');
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+
+try {
+ $p->setAlias(':hil');
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar');
+?>
+--EXPECTF--
+Invalid alias "hi/" specified for phar "%sinvalid_alias.phar"
+Invalid alias "hi\l" specified for phar "%sinvalid_alias.phar"
+Invalid alias "hil;" specified for phar "%sinvalid_alias.phar"
+Invalid alias ":hil" specified for phar "%sinvalid_alias.phar"
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/invalid_setstubalias.phpt b/ext/phar/tests/invalid_setstubalias.phpt
new file mode 100644
index 0000000000..04cb779ddb
--- /dev/null
+++ b/ext/phar/tests/invalid_setstubalias.phpt
@@ -0,0 +1,47 @@
+--TEST--
+Phar: invalid set alias or stub via array access
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar';
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip';
+
+$p = new Phar($fname);
+try {
+ $p['.phar/stub.php'] = 'hi';
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+try {
+ $p['.phar/alias.txt'] = 'hi';
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+$p = new Phar($fname2);
+try {
+ $p['.phar/stub.php'] = 'hi';
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+try {
+ $p['.phar/alias.txt'] = 'hi';
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip');
+?>
+--EXPECTF--
+Cannot set stub ".phar/stub.php" directly in phar "%sinvalid_setstubalias.phar.tar", use setStub
+Cannot set alias ".phar/alias.txt" directly in phar "%sinvalid_setstubalias.phar.tar", use setAlias
+Cannot set stub ".phar/stub.php" directly in phar "%sinvalid_setstubalias.phar.zip", use setStub
+Cannot set alias ".phar/alias.txt" directly in phar "%sinvalid_setstubalias.phar.zip", use setAlias
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/metadata_read.phpt b/ext/phar/tests/metadata_read.phpt
new file mode 100644
index 0000000000..c3d12d6fbd
--- /dev/null
+++ b/ext/phar/tests/metadata_read.phpt
@@ -0,0 +1,61 @@
+--TEST--
+Phar with meta-data (read)
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");?>
+--INI--
+phar.require_hash=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$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'));
+include 'files/phar_test.inc';
+
+foreach($files as $name => $cont) {
+ var_dump(file_get_contents($pname.'/'.$name));
+}
+
+$phar = new Phar($fname);
+foreach($files as $name => $cont) {
+ var_dump($phar[$name]->getMetadata());
+}
+
+unset($phar);
+
+foreach($files as $name => $cont) {
+ var_dump(file_get_contents($pname.'/'.$name));
+}
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECT--
+string(1) "a"
+string(1) "b"
+string(1) "c"
+string(1) "d"
+NULL
+string(8) "hi there"
+array(2) {
+ [0]=>
+ string(2) "hi"
+ [1]=>
+ string(5) "there"
+}
+array(2) {
+ ["hi"]=>
+ string(5) "there"
+ ["foo"]=>
+ string(3) "bar"
+}
+string(1) "a"
+string(1) "b"
+string(1) "c"
+string(1) "d"
+===DONE===
diff --git a/ext/phar/tests/metadata_write.phpt b/ext/phar/tests/metadata_write.phpt
new file mode 100755
index 0000000000..4b9930b693
--- /dev/null
+++ b/ext/phar/tests/metadata_write.phpt
@@ -0,0 +1,62 @@
+--TEST--
+Phar with meta-data (write)
+--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.php';
+$pname = 'phar://' . $fname;
+$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'));
+include 'files/phar_test.inc';
+
+foreach($files as $name => $cont) {
+ var_dump(file_get_contents($pname.'/'.$name));
+}
+
+$phar = new Phar($fname);
+$phar['a']->setMetadata(42);
+$phar['b']->setMetadata(NULL);
+$phar['c']->setMetadata(array(25, 'foo'=>'bar'));
+$phar['d']->setMetadata(true);
+
+foreach($files as $name => $cont) {
+ var_dump($phar[$name]->getMetadata());
+}
+
+unset($phar);
+
+foreach($files as $name => $cont) {
+ var_dump(file_get_contents($pname.'/'.$name));
+}
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.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"
+===DONE===
diff --git a/ext/phar/tests/metadata_write_commit.phpt b/ext/phar/tests/metadata_write_commit.phpt
new file mode 100755
index 0000000000..0d0a5e56ad
--- /dev/null
+++ b/ext/phar/tests/metadata_write_commit.phpt
@@ -0,0 +1,79 @@
+--TEST--
+Phar with meta-data (write)
+--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.php';
+$pname = 'phar://' . $fname;
+$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'));
+include 'files/phar_test.inc';
+
+foreach($files as $name => $cont) {
+ var_dump(file_get_contents($pname.'/'.$name));
+}
+
+$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);
+
+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());
+}
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.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)
+===DONE===
diff --git a/ext/phar/tests/mkdir.phpt b/ext/phar/tests/mkdir.phpt
new file mode 100644
index 0000000000..af8bceb32c
--- /dev/null
+++ b/ext/phar/tests/mkdir.phpt
@@ -0,0 +1,41 @@
+--TEST--
+phar: mkdir/rmdir edge cases
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+Phar::interceptFileFuncs();
+mkdir('phar://');
+mkdir('phar://foo.phar');
+$a = new Phar($fname);
+$a['a'] = 'hi';
+mkdir($pname . '/a');
+rmdir('phar://');
+rmdir('phar://foo.phar');
+rmdir($pname . '/a');
+$a->addEmptyDir('bb');
+$a->addEmptyDir('bb');
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php');
+__HALT_COMPILER();
+?>
+--EXPECTF--
+Warning: mkdir(): phar error: cannot create directory "phar://", no phar archive specified in %smkdir.php on line %d
+
+Warning: mkdir(): phar error: cannot create directory "" in phar "foo.phar", phar error: invalid path "" must not be empty in %smkdir.php on line %d
+
+Warning: mkdir(): phar error: cannot create directory "a" in phar "%smkdir.phar.php", phar error: path "a" exists and is a not a directory in %smkdir.php on line %d
+
+Warning: rmdir(): phar error: cannot remove directory "phar://", no phar archive specified, or phar archive does not exist in %smkdir.php on line %d
+
+Warning: rmdir(): phar error: cannot remove directory "" in phar "foo.phar", directory does not exist in %smkdir.php on line %d
+
+Warning: rmdir(): phar error: cannot remove directory "a" in phar "%smkdir.phar.php", phar error: path "a" exists and is a not a directory in %smkdir.php on line %d
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/mounteddir.phpt b/ext/phar/tests/mounteddir.phpt
new file mode 100644
index 0000000000..c438eefb1d
--- /dev/null
+++ b/ext/phar/tests/mounteddir.phpt
@@ -0,0 +1,109 @@
+--TEST--
+Phar: mounted manifest directory test
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/tempmanifest1.phar.php';
+$pname = 'phar://' . $fname;
+
+$a = new Phar($fname);
+$a['index.php'] = '<?php
+Phar::mount("testit", dirname(Phar::running(0)) . "/testit");
+echo file_get_contents(Phar::running(1) . "/testit/extfile.php"), "\n";
+echo file_get_contents(Phar::running(1) . "/testit/directory"), "\n";
+echo file_get_contents(Phar::running(1) . "/testit/existing.txt"), "\n";
+include "testit/extfile.php";
+include "testit/extfile2.php";
+?>';
+$a['testit/existing.txt'] = 'oops';
+$a->setStub('<?php
+set_include_path("phar://" . __FILE__);
+include "index.php";
+__HALT_COMPILER();');
+unset($a);
+mkdir(dirname(__FILE__) . '/testit');
+mkdir(dirname(__FILE__) . '/testit/directory');
+file_put_contents(dirname(__FILE__) . '/testit/extfile.php', '<?php
+var_dump(__FILE__);
+?>');
+file_put_contents(dirname(__FILE__) . '/testit/extfile2.php', '<?php
+var_dump(__FILE__);
+?>');
+include dirname(__FILE__) . '/testit/extfile.php';
+include $fname;
+
+$a = opendir($pname . '/testit');
+$out = array();
+while (false !== ($b = readdir($a))) {
+ $out[] = $b;
+}
+sort($out);
+foreach ($out as $b) {
+ echo "$b\n";
+}
+$out = array();
+foreach (new Phar($pname . '/testit') as $b) {
+ $out[] = $b->getPathName();
+}
+sort($out);
+foreach ($out as $b) {
+ echo "$b\n";
+}
+try {
+Phar::mount($pname . '/testit', 'another\\..\\mistake');
+} catch (Exception $e) {
+echo $e->getMessage(), "\n";
+}
+try {
+Phar::mount($pname . '/notfound', dirname(__FILE__) . '/this/does/not/exist');
+} catch (Exception $e) {
+echo $e->getMessage(), "\n";
+}
+try {
+Phar::mount($pname . '/testit', dirname(__FILE__));
+} catch (Exception $e) {
+echo $e->getMessage(), "\n";
+}
+try {
+Phar::mount($pname . '/testit/extfile.php', dirname(__FILE__));
+} catch (Exception $e) {
+echo $e->getMessage(), "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+@unlink(dirname(__FILE__) . '/tempmanifest1.phar.php');
+@unlink(dirname(__FILE__) . '/testit/extfile.php');
+@unlink(dirname(__FILE__) . '/testit/extfile2.php');
+@rmdir(dirname(__FILE__) . '/testit/directory');
+@rmdir(dirname(__FILE__) . '/testit');
+
+?>
+--EXPECTF--
+string(%d) "%sextfile.php"
+<?php
+var_dump(__FILE__);
+?>
+
+Warning: file_get_contents(phar://%stempmanifest1.phar.php/testit/directory): failed to open stream: phar error: path "testit/directory" is a directory in phar://%stempmanifest1.phar.php/index.php on line %d
+
+oops
+string(%d) "phar://%sextfile.php"
+string(%d) "phar://%sextfile2.php"
+.
+..
+directory
+extfile.php
+extfile2.php
+phar://%stempmanifest1.phar.php/testit%cdirectory
+phar://%stempmanifest1.phar.php/testit%cextfile.php
+phar://%stempmanifest1.phar.php/testit%cextfile2.php
+Mounting of /testit to another\..\mistake within phar %stempmanifest1.phar.php failed
+Mounting of /notfound to %stests/this/does/not/exist within phar %stempmanifest1.phar.php failed
+Mounting of /testit to %stests within phar %stests/tempmanifest1.phar.php failed
+Mounting of /testit/extfile.php to %stests within phar %stests/tempmanifest1.phar.php failed
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/nophar.phpt b/ext/phar/tests/nophar.phpt
new file mode 100644
index 0000000000..d97df8af2e
--- /dev/null
+++ b/ext/phar/tests/nophar.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Phar: phar run without pecl/phar with default stub
+--SKIPIF--
+<?php if (extension_loaded("phar")) die("skip Phar extension must be disabled for this test"); ?>
+--FILE--
+<?php
+include dirname(__FILE__) . '/files/nophar.phar';
+?>
+===DONE===
+--EXPECT--
+in b
+<?php include "b/c.php";
+in d
+===DONE===
diff --git a/ext/phar/tests/nophar_web.phpt b/ext/phar/tests/nophar_web.phpt
new file mode 100644
index 0000000000..7ee67b4546
--- /dev/null
+++ b/ext/phar/tests/nophar_web.phpt
@@ -0,0 +1,11 @@
+--TEST--
+Phar: default web stub, no phar extension
+--SKIPIF--
+<?php if (extension_loaded("phar")) die("skip Phar extension must be disabled for this test"); ?>
+--ENV--
+SCRIPT_NAME=/nophar.phar
+REQUEST_URI=/nophar.phar
+--FILE_EXTERNAL--
+files/nophar.phar
+--EXPECT--
+web
diff --git a/ext/phar/tests/open_for_write_existing.phpt b/ext/phar/tests/open_for_write_existing.phpt
new file mode 100644
index 0000000000..2a3ec8b824
--- /dev/null
+++ b/ext/phar/tests/open_for_write_existing.phpt
@@ -0,0 +1,31 @@
+--TEST--
+Phar: fopen a .phar for writing (existing file)
+--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.php';
+$pname = 'phar://' . $fname;
+$file = "<?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"; ?>';
+include 'files/phar_test.inc';
+
+$fp = fopen($pname . '/b/c.php', 'wb');
+fwrite($fp, 'extra');
+fclose($fp);
+include $pname . '/b/c.php';
+?>
+
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECTF--
+extra
+===DONE===
diff --git a/ext/phar/tests/open_for_write_existing_b.phpt b/ext/phar/tests/open_for_write_existing_b.phpt
new file mode 100755
index 0000000000..6c3cd3e986
--- /dev/null
+++ b/ext/phar/tests/open_for_write_existing_b.phpt
@@ -0,0 +1,42 @@
+--TEST--
+Phar: fopen a .phar for writing (existing file)
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=1
+phar.require_hash=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$file = "<?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"; ?>';
+include 'files/phar_test.inc';
+
+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($pname . '/b/c.php', 'wb');
+fwrite($fp, 'extra');
+fclose($fp);
+include $pname . '/b/c.php';
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECTF--
+
+Warning: fopen(phar://%sopen_for_write_existing_b.phar.php/b/c.php): failed to open stream: phar error: write operations disabled by INI setting in %sopen_for_write_existing_b.php on line %d
+
+Warning: fwrite(): supplied argument is not a valid stream resource in %spen_for_write_existing_b.php on line %d
+
+Warning: fclose(): supplied argument is not a valid stream resource in %spen_for_write_existing_b.php on line %d
+This is b/c
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/open_for_write_existing_c.phpt b/ext/phar/tests/open_for_write_existing_c.phpt
new file mode 100755
index 0000000000..9bbaaae92a
--- /dev/null
+++ b/ext/phar/tests/open_for_write_existing_c.phpt
@@ -0,0 +1,36 @@
+--TEST--
+Phar: fopen a .phar for writing (existing file)
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=1
+phar.require_hash=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$file = "<?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"; ?>';
+include 'files/phar_test.inc';
+
+$fp = fopen($pname . '/b/c.php', 'wb');
+fwrite($fp, 'extra');
+fclose($fp);
+include $pname . '/b/c.php';
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECTF--
+
+Warning: fopen(phar://%sopen_for_write_existing_c.phar.php/b/c.php): failed to open stream: phar error: write operations disabled by INI setting in %sopen_for_write_existing_c.php on line %d
+
+Warning: fwrite(): supplied argument is not a valid stream resource in %sopen_for_write_existing_c.php on line %d
+
+Warning: fclose(): supplied argument is not a valid stream resource in %sopen_for_write_existing_c.php on line %d
+This is b/c
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/open_for_write_newfile.phpt b/ext/phar/tests/open_for_write_newfile.phpt
new file mode 100644
index 0000000000..13114072da
--- /dev/null
+++ b/ext/phar/tests/open_for_write_newfile.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Phar: fopen a .phar for writing (new file)
+--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.php';
+$pname = 'phar://' . $fname;
+$file = "<?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"; ?>';
+include 'files/phar_test.inc';
+
+$fp = fopen($pname . '/b/new.php', 'wb');
+fwrite($fp, 'extra');
+fclose($fp);
+include $pname . '/b/c.php';
+include $pname . '/b/new.php';
+?>
+
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECT--
+This is b/c
+extra
+===DONE===
diff --git a/ext/phar/tests/open_for_write_newfile_b.phpt b/ext/phar/tests/open_for_write_newfile_b.phpt
new file mode 100755
index 0000000000..1c136ff1d5
--- /dev/null
+++ b/ext/phar/tests/open_for_write_newfile_b.phpt
@@ -0,0 +1,49 @@
+--TEST--
+Phar: fopen a .phar for writing (new file)
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=1
+phar.require_hash=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$file = "<?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"; ?>';
+include 'files/phar_test.inc';
+
+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($pname . '/b/new.php', 'wb');
+fwrite($fp, 'extra');
+fclose($fp);
+include $pname . '/b/c.php';
+include $pname . '/b/new.php';
+?>
+
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECTF--
+
+Warning: fopen(phar://%sopen_for_write_newfile_b.phar.php/b/new.php): failed to open stream: phar error: write operations disabled by INI setting in %sopen_for_write_newfile_b.php on line %d
+
+Warning: fwrite(): supplied argument is not a valid stream resource in %sopen_for_write_newfile_b.php on line %d
+
+Warning: fclose(): supplied argument is not a valid stream resource in %sopen_for_write_newfile_b.php on line 20
+This is b/c
+
+Warning: include(phar://%sopen_for_write_newfile_b.phar.php/b/new.php): failed to open stream: phar error: "b/new.php" is not a file in phar "%sopen_for_write_newfile_b.phar.php" in %sopen_for_write_newfile_b.php on line 22
+
+Warning: include(): Failed opening 'phar://%sopen_for_write_newfile_b.phar.php/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/open_for_write_newfile_c.phpt b/ext/phar/tests/open_for_write_newfile_c.phpt
new file mode 100755
index 0000000000..59b4339eb9
--- /dev/null
+++ b/ext/phar/tests/open_for_write_newfile_c.phpt
@@ -0,0 +1,43 @@
+--TEST--
+Phar: fopen a .phar for writing (new file)
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=1
+phar.require_hash=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$file = "<?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"; ?>';
+include 'files/phar_test.inc';
+
+$fp = fopen($pname . '/b/new.php', 'wb');
+fwrite($fp, 'extra');
+fclose($fp);
+include $pname . '/b/c.php';
+include $pname . '/b/new.php';
+?>
+
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECTF--
+
+Warning: fopen(phar://%sopen_for_write_newfile_c.phar.php/b/new.php): failed to open stream: phar error: write operations disabled by INI setting in %sopen_for_write_newfile_c.php on line %d
+
+Warning: fwrite(): supplied argument is not a valid stream resource in %sopen_for_write_newfile_c.php on line %d
+
+Warning: fclose(): supplied argument is not a valid stream resource in %sopen_for_write_newfile_c.php on line %d
+This is b/c
+
+Warning: include(phar://%sopen_for_write_newfile_c.phar.php/b/new.php): failed to open stream: phar error: "b/new.php" is not a file in phar "%sopen_for_write_newfile_c.phar.php" in %sopen_for_write_newfile_c.php on line %d
+
+Warning: include(): Failed opening 'phar://%sopen_for_write_newfile_c.phar.php/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/opendir.phpt b/ext/phar/tests/opendir.phpt
new file mode 100644
index 0000000000..46ab7c9682
--- /dev/null
+++ b/ext/phar/tests/opendir.phpt
@@ -0,0 +1,42 @@
+--TEST--
+Phar: test opendir() interception
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");?>
+--INI--
+phar.require_hash=1
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$a = new Phar($fname);
+$a['index.php'] = '<?php
+$a = opendir("dir");
+while (false !== ($e = readdir($a))) {
+ echo $e;
+}
+?>';
+$a['dir/file1.txt'] = 'hi';
+$a['dir/file2.txt'] = 'hi2';
+$a['dir/file3.txt'] = 'hi3';
+$a->setStub('<?php
+Phar::interceptFileFuncs();
+set_include_path("phar://" . __FILE__);
+include "index.php";
+__HALT_COMPILER();');
+include $fname;
+echo "\n";
+opendir('phar://');
+opendir('phar://hi.phar');
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECTF--
+file1.txtfile2.txtfile3.txt
+
+Warning: opendir(phar://): failed to open dir: phar error: no directory in "phar://", must have at least phar:/// for root directory (always use full path to a new phar)
+phar url "phar://" is unknown in %sopendir.php on line %d
+
+Warning: opendir(phar://hi.phar): failed to open dir: phar error: invalid url or non-existent phar "phar://hi.phar"
+phar url "phar://hi.phar" is unknown in %sopendir.php on line %d
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/opendir_edgecases.phpt b/ext/phar/tests/opendir_edgecases.phpt
new file mode 100644
index 0000000000..d330d27ff3
--- /dev/null
+++ b/ext/phar/tests/opendir_edgecases.phpt
@@ -0,0 +1,46 @@
+--TEST--
+Phar: test edge cases of opendir() function interception
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+Phar::interceptFileFuncs();
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+opendir(array());
+mkdir(dirname(__FILE__) . '/poo');
+chdir(dirname(__FILE__));
+$a = opendir('poo');
+while (false !== ($b = readdir($a))) {
+echo "$b\n";
+}
+closedir($a);
+file_put_contents($pname . '/foo', '<?php
+$context = stream_context_create();
+$a = opendir(".", $context);
+$res = array();
+while (false !== ($b = readdir($a))) {
+$res[] = $b;
+}
+sort($res);
+foreach ($res as $b) {
+echo "$b\n";
+}
+opendir("oops");
+?>');
+include $pname . '/foo';
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+<?php rmdir(dirname(__FILE__) . '/poo');
+--EXPECTF--
+Warning: opendir() expects parameter 1 to be string, array given in %sopendir_edgecases.php on line %d
+.
+..
+foo
+
+Warning: opendir(phar://%sopendir_edgecases.phar.php/oops): failed to open dir: %s in phar://%sopendir_edgecases.phar.php/foo on line %d
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/phar_begin_setstub_commit.phpt b/ext/phar/tests/phar_begin_setstub_commit.phpt
new file mode 100755
index 0000000000..d36865ddc5
--- /dev/null
+++ b/ext/phar/tests/phar_begin_setstub_commit.phpt
@@ -0,0 +1,50 @@
+--TEST--
+Phar::startBuffering()/setStub()/stopBuffering()
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+$p = new Phar(dirname(__FILE__) . '/brandnewphar.phar', 0, 'brandnewphar.phar');
+//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());
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/brandnewphar.phar');
+?>
+--EXPECT--
+bool(true)
+bool(false)
+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(true)
+string(5) "Hello"
+string(5) "World"
+string(85) "<?php var_dump("Second"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>
+"
+===DONE===
diff --git a/ext/phar/tests/phar_buildfromdirectory1.phpt b/ext/phar/tests/phar_buildfromdirectory1.phpt
new file mode 100644
index 0000000000..505b15036f
--- /dev/null
+++ b/ext/phar/tests/phar_buildfromdirectory1.phpt
@@ -0,0 +1,28 @@
+--TEST--
+Phar::buildFromDirectory() - readonly
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+$phar = new Phar(dirname(__FILE__) . '/buildfromdirectory.phar');
+try {
+ ini_set('phar.readonly', 1);
+ $phar->buildFromDirectory(1);
+} catch (Exception $e) {
+ var_dump(get_class($e));
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/buildfromdirectory.phar');
+__HALT_COMPILER();
+?>
+--EXPECT--
+string(24) "UnexpectedValueException"
+Cannot write to archive - write operations restricted by INI setting
+===DONE===
diff --git a/ext/phar/tests/phar_buildfromdirectory2.phpt b/ext/phar/tests/phar_buildfromdirectory2.phpt
new file mode 100644
index 0000000000..fcad4725a7
--- /dev/null
+++ b/ext/phar/tests/phar_buildfromdirectory2.phpt
@@ -0,0 +1,27 @@
+--TEST--
+Phar::buildFromDirectory() - non-directory passed as first parameter
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+try {
+ $phar = new Phar(dirname(__FILE__) . '/buildfromdirectory.phar');
+ $phar->buildFromDirectory(1);
+} catch (Exception $e) {
+ var_dump(get_class($e));
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/buildfromdirectory.phar');
+__HALT_COMPILER();
+?>
+--EXPECT--
+string(24) "UnexpectedValueException"
+RecursiveDirectoryIterator::__construct(1): failed to open dir: No such file or directory
+===DONE===
diff --git a/ext/phar/tests/phar_buildfromdirectory3.phpt b/ext/phar/tests/phar_buildfromdirectory3.phpt
new file mode 100644
index 0000000000..435bbdfba6
--- /dev/null
+++ b/ext/phar/tests/phar_buildfromdirectory3.phpt
@@ -0,0 +1,27 @@
+--TEST--
+Phar::buildFromDirectory() - object passed as second parameter
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+
+try {
+ $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar');
+ $phar->buildFromDirectory('files', new stdClass);
+} catch (Exception $e) {
+ var_dump(get_class($e));
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/buildfromiterator.phar');
+__HALT_COMPILER();
+?>
+--EXPECTF--
+Warning: Phar::buildFromDirectory() expects parameter 2 to be string, object given in %sphar_buildfromdirectory3.php on line %d
+===DONE===
diff --git a/ext/phar/tests/phar_buildfromdirectory4.phpt b/ext/phar/tests/phar_buildfromdirectory4.phpt
new file mode 100644
index 0000000000..cf11d62af6
--- /dev/null
+++ b/ext/phar/tests/phar_buildfromdirectory4.phpt
@@ -0,0 +1,50 @@
+--TEST--
+Phar::buildFromDirectory(), directory exists
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+
+mkdir(dirname(__FILE__).'/testdir');
+foreach(range(1, 4) as $i) {
+ file_put_contents(dirname(__FILE__)."/testdir/file$i.txt", "some content for file $i");
+}
+
+try {
+ $phar = new Phar(dirname(__FILE__) . '/buildfromdirectory.phar');
+ $a = $phar->buildFromDirectory(dirname(__FILE__) . '/testdir');
+ asort($a);
+ var_dump($a);
+} catch (Exception $e) {
+ var_dump(get_class($e));
+ echo $e->getMessage() . "\n";
+}
+
+var_dump(file_exists(dirname(__FILE__) . '/buildfromdirectory.phar'));
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/buildfromdirectory.phar');
+foreach(range(1, 4) as $i) {
+ unlink(dirname(__FILE__) . "/testdir/file$i.txt");
+}
+rmdir(dirname(__FILE__) . '/testdir');
+?>
+--EXPECTF--
+array(4) {
+ ["file1.txt"]=>
+ string(%d) "%stestdir%cfile1.txt"
+ ["file2.txt"]=>
+ string(%d) "%stestdir%cfile2.txt"
+ ["file3.txt"]=>
+ string(%d) "%stestdir%cfile3.txt"
+ ["file4.txt"]=>
+ string(%d) "%stestdir%cfile4.txt"
+}
+bool(true)
+===DONE===
diff --git a/ext/phar/tests/phar_buildfromdirectory5.phpt b/ext/phar/tests/phar_buildfromdirectory5.phpt
new file mode 100644
index 0000000000..51e5cec691
--- /dev/null
+++ b/ext/phar/tests/phar_buildfromdirectory5.phpt
@@ -0,0 +1,50 @@
+--TEST--
+Phar::buildFromDirectory() with matching regex
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+
+mkdir(dirname(__FILE__).'/testdir');
+foreach(range(1, 4) as $i) {
+ file_put_contents(dirname(__FILE__)."/testdir/file$i.txt", "some content for file $i");
+}
+
+try {
+ $phar = new Phar(dirname(__FILE__) . '/buildfromdirectory.phar');
+ $a = $phar->buildFromDirectory(dirname(__FILE__) . '/testdir', '/\.txt/');
+ asort($a);
+ var_dump($a);
+} catch (Exception $e) {
+ var_dump(get_class($e));
+ echo $e->getMessage() . "\n";
+}
+
+var_dump(file_exists(dirname(__FILE__) . '/buildfromdirectory.phar'));
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/buildfromdirectory.phar');
+foreach(range(1, 4) as $i) {
+ unlink(dirname(__FILE__) . "/testdir/file$i.txt");
+}
+rmdir(dirname(__FILE__) . '/testdir');
+?>
+--EXPECTF--
+array(4) {
+ ["file1.txt"]=>
+ string(%d) "%stestdir%cfile1.txt"
+ ["file2.txt"]=>
+ string(%d) "%stestdir%cfile2.txt"
+ ["file3.txt"]=>
+ string(%d) "%stestdir%cfile3.txt"
+ ["file4.txt"]=>
+ string(%d) "%stestdir%cfile4.txt"
+}
+bool(true)
+===DONE===
diff --git a/ext/phar/tests/phar_buildfromdirectory6.phpt b/ext/phar/tests/phar_buildfromdirectory6.phpt
new file mode 100644
index 0000000000..2edd0962f1
--- /dev/null
+++ b/ext/phar/tests/phar_buildfromdirectory6.phpt
@@ -0,0 +1,40 @@
+--TEST--
+Phar::buildFromDirectory() with non-matching regex
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+
+mkdir(dirname(__FILE__).'/testdir', 0777);
+foreach(range(1, 4) as $i) {
+ file_put_contents(dirname(__FILE__)."/testdir/file$i.txt", "some content for file $i");
+}
+
+try {
+ $phar = new Phar(dirname(__FILE__) . '/buildfromdirectory.phar');
+ var_dump($phar->buildFromDirectory(dirname(__FILE__) . '/testdir', '/\.php/'));
+} catch (Exception $e) {
+ var_dump(get_class($e));
+ echo $e->getMessage() . "\n";
+}
+
+var_dump(file_exists(dirname(__FILE__) . '/buildfromdirectory.phar'));
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/buildfromdirectory.phar');
+foreach(range(1, 4) as $i) {
+ unlink(dirname(__FILE__) . "/testdir/file$i.txt");
+}
+rmdir(dirname(__FILE__) . '/testdir');
+?>
+--EXPECT--
+array(0) {
+}
+bool(false)
+===DONE===
diff --git a/ext/phar/tests/phar_buildfromiterator1.phpt b/ext/phar/tests/phar_buildfromiterator1.phpt
new file mode 100644
index 0000000000..f75823f94c
--- /dev/null
+++ b/ext/phar/tests/phar_buildfromiterator1.phpt
@@ -0,0 +1,28 @@
+--TEST--
+Phar::buildFromIterator() readonly
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+$phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar');
+try {
+ ini_set('phar.readonly', 1);
+ $phar->buildFromIterator(1);
+} catch (Exception $e) {
+ var_dump(get_class($e));
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/buildfromiterator.phar');
+__HALT_COMPILER();
+?>
+--EXPECT--
+string(24) "UnexpectedValueException"
+Cannot write out phar archive, phar is read-only
+===DONE===
diff --git a/ext/phar/tests/phar_buildfromiterator10.phpt b/ext/phar/tests/phar_buildfromiterator10.phpt
new file mode 100644
index 0000000000..3f03245727
--- /dev/null
+++ b/ext/phar/tests/phar_buildfromiterator10.phpt
@@ -0,0 +1,98 @@
+--TEST--
+Phar::buildFromIterator() RegexIterator(RecursiveIteratorIterator), SplFileInfo as current
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+try {
+ chdir(dirname(__FILE__));
+ $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar');
+ $dir = new RecursiveDirectoryIterator('.');
+ $iter = new RecursiveIteratorIterator($dir);
+ $a = $phar->buildFromIterator(new RegexIterator($iter, '/_\d{3}\.phpt$/'), dirname(__FILE__) . DIRECTORY_SEPARATOR);
+ asort($a);
+ var_dump($a);
+} catch (Exception $e) {
+ var_dump(get_class($e));
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/buildfromiterator.phar');
+__HALT_COMPILER();
+?>
+--EXPECTF--
+array(33) {
+ ["phar_ctx_001.phpt"]=>
+ string(%d) "%sphar_ctx_001.phpt"
+ ["phar_get_supported_signatures_001.phpt"]=>
+ string(%d) "%sphar_get_supported_signatures_001.phpt"
+ ["phar_get_supported_signatures_002.phpt"]=>
+ string(%d) "%sphar_get_supported_signatures_002.phpt"
+ ["phar_oo_001.phpt"]=>
+ string(%d) "%sphar_oo_001.phpt"
+ ["phar_oo_002.phpt"]=>
+ string(%d) "%sphar_oo_002.phpt"
+ ["phar_oo_003.phpt"]=>
+ string(%d) "%sphar_oo_003.phpt"
+ ["phar_oo_004.phpt"]=>
+ string(%d) "%sphar_oo_004.phpt"
+ ["phar_oo_005.phpt"]=>
+ string(%d) "%sphar_oo_005.phpt"
+ ["phar_oo_006.phpt"]=>
+ string(%d) "%sphar_oo_006.phpt"
+ ["phar_oo_007.phpt"]=>
+ string(%d) "%sphar_oo_007.phpt"
+ ["phar_oo_008.phpt"]=>
+ string(%d) "%sphar_oo_008.phpt"
+ ["phar_oo_009.phpt"]=>
+ string(%d) "%sphar_oo_009.phpt"
+ ["phar_oo_010.phpt"]=>
+ string(%d) "%sphar_oo_010.phpt"
+ ["phar_oo_011.phpt"]=>
+ string(%d) "%sphar_oo_011.phpt"
+ ["phar_oo_012.phpt"]=>
+ string(%d) "%sphar_oo_012.phpt"
+ ["phar_oo_compressed_001.phpt"]=>
+ string(%d) "%sphar_oo_compressed_001.phpt"
+ ["phar_oo_compressed_002.phpt"]=>
+ string(%d) "%sphar_oo_compressed_002.phpt"
+ ["phpinfo_001.phpt"]=>
+ string(%d) "%sphpinfo_001.phpt"
+ ["phpinfo_002.phpt"]=>
+ string(%d) "%sphpinfo_002.phpt"
+ ["phpinfo_003.phpt"]=>
+ string(%d) "%sphpinfo_003.phpt"
+ ["phpinfo_004.phpt"]=>
+ string(%d) "%sphpinfo_004.phpt"
+ ["tar/tar_001.phpt"]=>
+ string(%d) "%star%ctar_001.phpt"
+ ["tar/tar_002.phpt"]=>
+ string(%d) "%star%ctar_002.phpt"
+ ["tar/tar_003.phpt"]=>
+ string(%d) "%star%ctar_003.phpt"
+ ["tar/tar_004.phpt"]=>
+ string(%d) "%star%ctar_004.phpt"
+ ["zip/corrupt_001.phpt"]=>
+ string(%d) "%szip%ccorrupt_001.phpt"
+ ["zip/corrupt_002.phpt"]=>
+ string(%d) "%szip%ccorrupt_002.phpt"
+ ["zip/corrupt_003.phpt"]=>
+ string(%d) "%szip%ccorrupt_003.phpt"
+ ["zip/corrupt_004.phpt"]=>
+ string(%d) "%szip%ccorrupt_004.phpt"
+ ["zip/corrupt_005.phpt"]=>
+ string(%d) "%szip%ccorrupt_005.phpt"
+ ["zip/corrupt_006.phpt"]=>
+ string(%d) "%szip%ccorrupt_006.phpt"
+ ["zip/corrupt_007.phpt"]=>
+ string(%d) "%szip%ccorrupt_007.phpt"
+ ["zip/corrupt_008.phpt"]=>
+ string(%d) "%szip%ccorrupt_008.phpt"
+}
+===DONE===
diff --git a/ext/phar/tests/phar_buildfromiterator2.phpt b/ext/phar/tests/phar_buildfromiterator2.phpt
new file mode 100644
index 0000000000..cdc2df1050
--- /dev/null
+++ b/ext/phar/tests/phar_buildfromiterator2.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Phar::buildFromIterator() wrong object
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+try {
+ $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar');
+ $phar->buildFromIterator(new stdClass);
+} catch (Exception $e) {
+ var_dump(get_class($e));
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/buildfromiterator.phar');
+__HALT_COMPILER();
+?>
+--EXPECTF--
+Warning: Phar::buildFromIterator() expects parameter 1 to be Traversable, object given in %sphar_buildfromiterator2.php on line %d
+===DONE===
diff --git a/ext/phar/tests/phar_buildfromiterator3.phpt b/ext/phar/tests/phar_buildfromiterator3.phpt
new file mode 100644
index 0000000000..5fca706041
--- /dev/null
+++ b/ext/phar/tests/phar_buildfromiterator3.phpt
@@ -0,0 +1,54 @@
+--TEST--
+Phar::buildFromIterator() iterator, but object passed
+--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 {
+ $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar');
+ $phar->buildFromIterator(new myIterator(array()), new stdClass);
+} catch (Exception $e) {
+ var_dump(get_class($e));
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/buildfromiterator.phar');
+__HALT_COMPILER();
+?>
+--EXPECTF--
+Warning: Phar::buildFromIterator() expects parameter 2 to be string, object given in %sphar_buildfromiterator3.php on line %d
+===DONE===
diff --git a/ext/phar/tests/phar_buildfromiterator4.phpt b/ext/phar/tests/phar_buildfromiterator4.phpt
new file mode 100644
index 0000000000..3c20460d53
--- /dev/null
+++ b/ext/phar/tests/phar_buildfromiterator4.phpt
@@ -0,0 +1,64 @@
+--TEST--
+Phar::buildFromIterator() iterator, 1 file 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' => basename(__FILE__, 'php') . 'phpt'))));
+} 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) "%sphar_buildfromiterator4.phpt"
+}
+===DONE===
diff --git a/ext/phar/tests/phar_buildfromiterator5.phpt b/ext/phar/tests/phar_buildfromiterator5.phpt
new file mode 100644
index 0000000000..3bd2cec78c
--- /dev/null
+++ b/ext/phar/tests/phar_buildfromiterator5.phpt
@@ -0,0 +1,59 @@
+--TEST--
+Phar::buildFromIterator() iterator, iterator returns non-string
+--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' => new stdClass))));
+} 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
+string(24) "UnexpectedValueException"
+Iterator myIterator returned an invalid value (must return a string)
+===DONE===
diff --git a/ext/phar/tests/phar_buildfromiterator6.phpt b/ext/phar/tests/phar_buildfromiterator6.phpt
new file mode 100644
index 0000000000..ae73bbd479
--- /dev/null
+++ b/ext/phar/tests/phar_buildfromiterator6.phpt
@@ -0,0 +1,60 @@
+--TEST--
+Phar::buildFromIterator() iterator, key is int
+--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(basename(__FILE__, 'php') . 'phpt'))));
+} 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
+string(24) "UnexpectedValueException"
+Iterator myIterator returned an invalid key (must return a string)
+===DONE===
diff --git a/ext/phar/tests/phar_buildfromiterator7.phpt b/ext/phar/tests/phar_buildfromiterator7.phpt
new file mode 100644
index 0000000000..38d2e1a5f2
--- /dev/null
+++ b/ext/phar/tests/phar_buildfromiterator7.phpt
@@ -0,0 +1,60 @@
+--TEST--
+Phar::buildFromIterator() iterator, file can't be opened
+--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' => 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');
+__HALT_COMPILER();
+?>
+--EXPECT--
+rewind
+valid
+current
+key
+string(24) "UnexpectedValueException"
+Iterator myIterator returned a file that could not be opened "phar_buildfromiterator7./oopsie/there.phpt"
+===DONE===
diff --git a/ext/phar/tests/phar_buildfromiterator8.phpt b/ext/phar/tests/phar_buildfromiterator8.phpt
new file mode 100644
index 0000000000..d382b82ee0
--- /dev/null
+++ b/ext/phar/tests/phar_buildfromiterator8.phpt
@@ -0,0 +1,96 @@
+--TEST--
+Phar::buildFromIterator() RegexIterator(DirectoryIterator), SplFileInfo as current
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+try {
+ chdir(dirname(__FILE__));
+ $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar');
+ $a = $phar->buildFromIterator(new RegexIterator(new DirectoryIterator('.'), '/^\d{0,3}\.phpt\\z|^\.\\z|^\.\.\\z/'), dirname(__FILE__) . DIRECTORY_SEPARATOR);
+ asort($a);
+ var_dump($a);
+} catch (Exception $e) {
+ var_dump(get_class($e));
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/buildfromiterator.phar');
+__HALT_COMPILER();
+?>
+--EXPECTF--
+array(33) {
+ ["001.phpt"]=>
+ string(%d) "%s001.phpt"
+ ["002.phpt"]=>
+ string(%d) "%s002.phpt"
+ ["003.phpt"]=>
+ string(%d) "%s003.phpt"
+ ["004.phpt"]=>
+ string(%d) "%s004.phpt"
+ ["005.phpt"]=>
+ string(%d) "%s005.phpt"
+ ["006.phpt"]=>
+ string(%d) "%s006.phpt"
+ ["007.phpt"]=>
+ string(%d) "%s007.phpt"
+ ["008.phpt"]=>
+ string(%d) "%s008.phpt"
+ ["009.phpt"]=>
+ string(%d) "%s009.phpt"
+ ["010.phpt"]=>
+ string(%d) "%s010.phpt"
+ ["011.phpt"]=>
+ string(%d) "%s011.phpt"
+ ["012.phpt"]=>
+ string(%d) "%s012.phpt"
+ ["013.phpt"]=>
+ string(%d) "%s013.phpt"
+ ["014.phpt"]=>
+ string(%d) "%s014.phpt"
+ ["015.phpt"]=>
+ string(%d) "%s015.phpt"
+ ["016.phpt"]=>
+ string(%d) "%s016.phpt"
+ ["017.phpt"]=>
+ string(%d) "%s017.phpt"
+ ["018.phpt"]=>
+ string(%d) "%s018.phpt"
+ ["019.phpt"]=>
+ string(%d) "%s019.phpt"
+ ["020.phpt"]=>
+ string(%d) "%s020.phpt"
+ ["021.phpt"]=>
+ string(%d) "%s021.phpt"
+ ["022.phpt"]=>
+ string(%d) "%s022.phpt"
+ ["023.phpt"]=>
+ string(%d) "%s023.phpt"
+ ["024.phpt"]=>
+ string(%d) "%s024.phpt"
+ ["025.phpt"]=>
+ string(%d) "%s025.phpt"
+ ["026.phpt"]=>
+ string(%d) "%s026.phpt"
+ ["027.phpt"]=>
+ string(%d) "%s027.phpt"
+ ["028.phpt"]=>
+ string(%d) "%s028.phpt"
+ ["029.phpt"]=>
+ string(%d) "%s029.phpt"
+ ["030.phpt"]=>
+ string(%d) "%s030.phpt"
+ ["031.phpt"]=>
+ string(%d) "%s031.phpt"
+ ["032.phpt"]=>
+ string(%d) "%s032.phpt"
+ ["033.phpt"]=>
+ string(%d) "%s033.phpt"
+}
+===DONE===
diff --git a/ext/phar/tests/phar_buildfromiterator9.phpt b/ext/phar/tests/phar_buildfromiterator9.phpt
new file mode 100644
index 0000000000..0b56307545
--- /dev/null
+++ b/ext/phar/tests/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/phar_bz2.phpt b/ext/phar/tests/phar_bz2.phpt
new file mode 100644
index 0000000000..71b10f9092
--- /dev/null
+++ b/ext/phar/tests/phar_bz2.phpt
@@ -0,0 +1,63 @@
+--TEST--
+Phar: bzipped phar
+--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"); ?>
+--INI--
+phar.readonly=0
+phar.require_hash=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/phar_bz2.phar';
+$pname = 'phar://' . $fname;
+$fname2 = dirname(__FILE__) . '/phar_bz2.2.phar';
+$pname2 = 'phar://' . $fname2;
+
+$file = '<?php
+Phar::mapPhar();
+var_dump("it worked");
+include "phar://" . __FILE__ . "/tar_004.php";
+__HALT_COMPILER();';
+
+$files = array();
+$files['tar_004.php'] = '<?php var_dump(__FILE__);';
+$files['internal/file/here'] = "hi there!\n";
+$files['internal/dir/'] = '';
+$files['dir/'] = '';
+$bz2 = true;
+
+include 'files/phar_test.inc';
+
+include $fname;
+
+$a = new Phar($fname);
+$a['test'] = 'hi';
+copy($fname, $fname2);
+$a->setAlias('another');
+$b = new Phar($fname2);
+var_dump($b->isFileFormat(Phar::PHAR));
+var_dump($b->isCompressed() == Phar::BZ2);
+// additional code coverage
+$b->isFileFormat(array());
+try {
+$b->isFileFormat(25);
+} catch (Exception $e) {
+echo $e->getMessage(),"\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+@unlink(dirname(__FILE__) . '/phar_bz2.phar');
+@unlink(dirname(__FILE__) . '/phar_bz2.2.phar');
+?>
+--EXPECTF--
+string(9) "it worked"
+string(%d) "phar://%sphar_bz2.phar/tar_004.php"
+bool(true)
+bool(true)
+
+Warning: Phar::isFileFormat() expects parameter 1 to be long, array given in %sphar_bz2.php on line %d
+Unknown file format specified
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/phar_commitwrite.phpt b/ext/phar/tests/phar_commitwrite.phpt
new file mode 100644
index 0000000000..63878355b0
--- /dev/null
+++ b/ext/phar/tests/phar_commitwrite.phpt
@@ -0,0 +1,42 @@
+--TEST--
+Phar::setStub()/stopBuffering()
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+$p = new Phar(dirname(__FILE__) . '/brandnewphar.phar', 0, 'brandnewphar.phar');
+$p['file1.txt'] = 'hi';
+$p->stopBuffering();
+var_dump(strlen($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());
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/brandnewphar.phar');
+__HALT_COMPILER();
+?>
+--EXPECT--
+int(6651)
+string(200) "<?php
+function __autoload($class)
+{
+ include 'phar://' . str_replace('_', '/', $class);
+}
+Phar::mapPhar('brandnewphar.phar');
+include 'phar://brandnewphar.phar/startup.php';
+__HALT_COMPILER(); ?>
+"
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/phar_convert_again.phpt b/ext/phar/tests/phar_convert_again.phpt
new file mode 100644
index 0000000000..4543a238d5
--- /dev/null
+++ b/ext/phar/tests/phar_convert_again.phpt
@@ -0,0 +1,218 @@
+--TEST--
+Phar::conversion to other formats
+--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';
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '2.tbz';
+$pname = 'phar://' . $fname;
+$stub = '<?php echo "first stub\n"; __HALT_COMPILER(); ?>';
+$file = $stub;
+
+$files = array();
+$files['a'] = 'a';
+$files['b'] = 'b';
+$files['c'] = 'c';
+
+include 'files/phar_test.inc';
+
+$phar = new Phar($fname);
+$zip = $phar->convertToData(Phar::ZIP);
+echo $zip->getPath() . "\n";
+$tgz = $phar->convertToData(Phar::TAR, Phar::GZ);
+echo $tgz->getPath() . "\n";
+$tbz = $phar->convertToData(Phar::TAR, Phar::BZ2);
+echo $tbz->getPath() . "\n";
+try {
+$phar = $tbz->convertToExecutable(Phar::PHAR, Phar::NONE);
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+copy($tbz->getPath(), $fname2);
+$tbz = new PharData($fname2);
+$phar = $tbz->convertToExecutable(Phar::PHAR, Phar::NONE);
+echo $phar->getPath() . "\n";
+$phar['a'] = 'hi';
+$phar['a']->setMetadata('hi');
+$zip = $phar->convertToExecutable(Phar::ZIP);
+echo $zip->getPath() . "\n";
+echo $zip['a']->getMetadata() . "\n";
+$data = $zip->convertToData();
+echo $data->getPath() . "\n";
+// extra code coverage
+try {
+$data->setStub('hi');
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+try {
+$data->setDefaultStub();
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+try {
+$data->setAlias('hi');
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+try {
+$data->setSignatureAlgorithm(Phar::MD5);
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+$tar = $phar->convertToExecutable(Phar::TAR);
+echo $tar->getPath() . "\n";
+$data = $tar->convertToData();
+echo $data->getPath() . "\n";
+$tgz = $tar->convertToExecutable(null, Phar::GZ);
+echo $tgz->getPath() . "\n";
+try {
+$tgz->convertToExecutable(25);
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+try {
+$tgz->convertToExecutable(Phar::ZIP, Phar::GZ);
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+try {
+$tgz->convertToExecutable(Phar::ZIP, Phar::BZ2);
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+try {
+$phar->convertToData();
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+try {
+$tgz->convertToData(Phar::PHAR);
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+try {
+$tgz->convertToData(25);
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+try {
+$tgz->convertToData(Phar::ZIP, Phar::GZ);
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+try {
+$tgz->convertToData(Phar::ZIP, Phar::BZ2);
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+try {
+$tgz->convertToExecutable(Phar::TAR, 25);
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+try {
+$tgz->convertToData(Phar::TAR, 25);
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+// extra code coverage
+try {
+$data->setStub('hi');
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+try {
+$data->setAlias('hi');
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+try {
+$data->setDefaultStub();
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+try {
+$data->setSignatureAlgorithm(Phar::MD5);
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+
+try {
+$tgz->convertToData(Phar::TAR, Phar::GZ, '.phar.tgz.oops');
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+
+try {
+$phar->convertToExecutable(Phar::TAR, Phar::GZ, '.tgz.oops');
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+
+try {
+$tgz->convertToData(Phar::TAR, Phar::GZ, '.phar/.tgz.oops');
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar.gz');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.zip');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.tar.gz');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.tar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.tar.bz2');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '2.tbz');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '2.phar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '2.phar.tar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '2.tar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '2.phar.zip');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '2.zip');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '2.phar.tar.gz');
+__HALT_COMPILER();
+?>
+--EXPECTF--
+%sphar_convert_again.zip
+%sphar_convert_again.tar.gz
+%sphar_convert_again.tar.bz2
+Unable to add newly converted phar "%sphar_convert_again.phar" to the list of phars, a phar with that name already exists
+%sphar_convert_again2.phar
+%sphar_convert_again2.phar.zip
+hi
+%sphar_convert_again2.zip
+A Phar stub cannot be set in a plain zip archive
+A Phar stub cannot be set in a plain zip archive
+A Phar alias cannot be set in a plain zip archive
+Cannot set signature algorithm, not possible with zip-based phar archives
+%sphar_convert_again2.phar.tar
+%sphar_convert_again2.tar
+%sphar_convert_again2.phar.tar.gz
+Unknown file format specified, please pass one of Phar::PHAR, Phar::TAR or Phar::ZIP
+Cannot compress entire archive with gzip, zip archives do not support whole-archive compression
+Cannot compress entire archive with bz2, zip archives do not support whole-archive compression
+Cannot write out data phar archive, use Phar::TAR or Phar::ZIP
+Cannot write out data phar archive, use Phar::TAR or Phar::ZIP
+Unknown file format specified, please pass one of Phar::TAR or Phar::ZIP
+Cannot compress entire archive with gzip, zip archives do not support whole-archive compression
+Cannot compress entire archive with bz2, zip archives do not support whole-archive compression
+Unknown compression specified, please pass one of Phar::GZ or Phar::BZ2
+Unknown compression specified, please pass one of Phar::GZ or Phar::BZ2
+A Phar stub cannot be set in a plain tar archive
+A Phar alias cannot be set in a plain tar archive
+A Phar stub cannot be set in a plain tar archive
+Cannot set signature algorithm, not possible with tar-based phar archives
+data phar "%sphar_convert_again2.phar.tgz.oops" has invalid extension phar.tgz.oops
+phar "%sphar_convert_again2.tgz.oops" has invalid extension tgz.oops
+data phar "%sphar_convert_again2.phar/.tgz.oops" has invalid extension phar/.tgz.oops
+===DONE===
diff --git a/ext/phar/tests/phar_convert_repeated.phpt b/ext/phar/tests/phar_convert_repeated.phpt
new file mode 100644
index 0000000000..b2ef195ea7
--- /dev/null
+++ b/ext/phar/tests/phar_convert_repeated.phpt
@@ -0,0 +1,149 @@
+--TEST--
+Phar::convertToZip|Tar|Phar() repeated (phar_based archives)
+--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';
+$pname = 'phar://' . $fname;
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip';
+$fname3 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar';
+$stub = '<?php echo "first stub\n"; __HALT_COMPILER(); ?>';
+$file = $stub;
+
+$files = array();
+$files['a'] = 'a';
+$files['b'] = 'b';
+$files['c'] = 'c';
+
+include 'files/phar_test.inc';
+
+echo "=================== new Phar() =======================\n";
+$phar = new Phar($fname);
+var_dump($phar->isFileFormat(Phar::PHAR));
+var_dump($phar->isFileFormat(Phar::TAR));
+var_dump($phar->isFileFormat(Phar::ZIP));
+var_dump($phar->getStub());
+var_dump($phar->getAlias());
+
+echo "================= convertToTar() =====================\n";
+
+$phar = $phar->convertToExecutable(Phar::TAR);
+var_dump($phar->isFileFormat(Phar::PHAR));
+var_dump($phar->isFileFormat(Phar::TAR));
+var_dump($phar->isFileFormat(Phar::ZIP));
+var_dump($phar->getStub());
+var_dump($phar->getAlias());
+
+echo "================= convertToZip() =====================\n";
+
+$phar = $phar->convertToExecutable(Phar::ZIP);
+var_dump($phar->isFileFormat(Phar::PHAR));
+var_dump($phar->isFileFormat(Phar::TAR));
+var_dump($phar->isFileFormat(Phar::ZIP));
+var_dump($phar->getStub());
+var_dump($phar->getAlias());
+
+echo "================= convertToPhar() ====================\n";
+
+$phar = $phar->convertToExecutable(Phar::PHAR, Phar::NONE, '.2.phar');
+var_dump($phar->isFileFormat(Phar::PHAR));
+var_dump($phar->isFileFormat(Phar::TAR));
+var_dump($phar->isFileFormat(Phar::ZIP));
+var_dump(strlen($phar->getStub()));
+var_dump($phar->getAlias());
+
+echo "================= convertToZip() =====================\n";
+
+$phar = $phar->convertToExecutable(Phar::ZIP, Phar::NONE, '.2.phar.zip');
+var_dump($phar->isFileFormat(Phar::PHAR));
+var_dump($phar->isFileFormat(Phar::TAR));
+var_dump($phar->isFileFormat(Phar::ZIP));
+var_dump($phar->getStub());
+var_dump($phar->getAlias());
+
+echo "================= convertToTar() =====================\n";
+
+$phar = $phar->convertToExecutable(Phar::TAR, Phar::NONE, '2.phar.tar');
+var_dump($phar->isFileFormat(Phar::PHAR));
+var_dump($phar->isFileFormat(Phar::TAR));
+var_dump($phar->isFileFormat(Phar::ZIP));
+var_dump($phar->getStub());
+var_dump($phar->getAlias());
+
+echo "================= convertToZip() =====================\n";
+
+$phar = $phar->convertToExecutable(Phar::ZIP, Phar::NONE, '3.phar.zip');
+var_dump($phar->isFileFormat(Phar::PHAR));
+var_dump($phar->isFileFormat(Phar::TAR));
+var_dump($phar->isFileFormat(Phar::ZIP));
+var_dump($phar->getStub());
+var_dump($phar->getAlias());
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar.zip');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar.tar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.3.phar.zip');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.3.phar.tar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.3.phar');
+?>
+--EXPECTF--
+=================== new Phar() =======================
+bool(true)
+bool(false)
+bool(false)
+string(48) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>"
+string(3) "hio"
+================= convertToTar() =====================
+bool(false)
+bool(true)
+bool(false)
+string(60) "<?php // tar-based phar archive stub file
+__HALT_COMPILER();"
+string(%d) "%sphar_convert_repeated.phar.tar"
+================= convertToZip() =====================
+bool(false)
+bool(false)
+bool(true)
+string(60) "<?php // zip-based phar archive stub file
+__HALT_COMPILER();"
+NULL
+================= convertToPhar() ====================
+bool(true)
+bool(false)
+bool(false)
+int(6651)
+NULL
+================= convertToZip() =====================
+bool(false)
+bool(false)
+bool(true)
+string(60) "<?php // zip-based phar archive stub file
+__HALT_COMPILER();"
+NULL
+================= convertToTar() =====================
+bool(false)
+bool(true)
+bool(false)
+string(60) "<?php // tar-based phar archive stub file
+__HALT_COMPILER();"
+NULL
+================= convertToZip() =====================
+bool(false)
+bool(false)
+bool(true)
+string(60) "<?php // zip-based phar archive stub file
+__HALT_COMPILER();"
+NULL
+===DONE===
diff --git a/ext/phar/tests/phar_convert_repeated_b.phpt b/ext/phar/tests/phar_convert_repeated_b.phpt
new file mode 100644
index 0000000000..3d958927bb
--- /dev/null
+++ b/ext/phar/tests/phar_convert_repeated_b.phpt
@@ -0,0 +1,117 @@
+--TEST--
+PharData::convertToZip|Tar|Phar() repeated (phardata_based archives)
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=1
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.zip';
+
+echo "=================== new PharData() ==================\n";
+$phar = new PharData($fname);
+$phar['a'] = 'a';
+$phar['b'] = 'b';
+$phar['c'] = 'c';
+
+var_dump($phar->isFileFormat(Phar::PHAR));
+var_dump($phar->isFileFormat(Phar::TAR));
+var_dump($phar->isFileFormat(Phar::ZIP));
+var_dump($phar->getStub());
+var_dump($phar->getAlias());
+
+echo "================= convertToTar() =====================\n";
+
+$phar = $phar->convertToData(Phar::TAR);
+var_dump($phar->isFileFormat(Phar::PHAR));
+var_dump($phar->isFileFormat(Phar::TAR));
+var_dump($phar->isFileFormat(Phar::ZIP));
+var_dump($phar->getStub());
+var_dump($phar->getAlias());
+
+echo "================= convertToZip() =====================\n";
+
+$phar = $phar->convertToData(Phar::ZIP, Phar::NONE, '.1.zip');
+var_dump($phar->isFileFormat(Phar::PHAR));
+var_dump($phar->isFileFormat(Phar::TAR));
+var_dump($phar->isFileFormat(Phar::ZIP));
+var_dump($phar->getStub());
+var_dump($phar->getAlias());
+
+echo "================= convertToPhar() ====================\n";
+
+try {
+ $phar = $phar->convertToExecutable(Phar::PHAR);
+ var_dump($phar->isFileFormat(Phar::PHAR));
+ var_dump($phar->isFileFormat(Phar::TAR));
+ var_dump($phar->isFileFormat(Phar::ZIP));
+ var_dump(strlen($phar->getStub()));
+ var_dump($phar->getAlias());
+} catch(Exception $e) {
+ echo $e->getMessage()."\n";
+}
+
+echo "================ convertToTar(GZ) ====================\n";
+
+$phar = $phar->convertToData(Phar::TAR, Phar::GZ, '.2.tar');
+var_dump($phar->isFileFormat(Phar::PHAR));
+var_dump($phar->isFileFormat(Phar::TAR));
+var_dump($phar->isFileFormat(Phar::ZIP));
+var_dump($phar->getStub());
+var_dump($phar->getAlias());
+
+echo "================= convertToPhar() ====================\n";
+
+try {
+ $phar = $phar->convertToExecutable(Phar::PHAR);
+ var_dump($phar->isFileFormat(Phar::PHAR));
+ var_dump($phar->isFileFormat(Phar::TAR));
+ var_dump($phar->isFileFormat(Phar::ZIP));
+ var_dump(strlen($phar->getStub()));
+ var_dump($phar->getAlias());
+} catch(Exception $e) {
+ echo $e->getMessage()."\n";
+}
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.gz');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.tar.gz');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.tar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.tar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.zip');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.1.zip');
+?>
+--EXPECT--
+=================== new PharData() ==================
+bool(false)
+bool(false)
+bool(true)
+string(0) ""
+NULL
+================= convertToTar() =====================
+bool(false)
+bool(true)
+bool(false)
+string(0) ""
+NULL
+================= convertToZip() =====================
+bool(false)
+bool(false)
+bool(true)
+string(0) ""
+NULL
+================= convertToPhar() ====================
+Cannot write out executable phar archive, phar is read-only
+================ convertToTar(GZ) ====================
+bool(false)
+bool(true)
+bool(false)
+string(0) ""
+NULL
+================= convertToPhar() ====================
+Cannot write out executable phar archive, phar is read-only
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/phar_convert_tar.phpt b/ext/phar/tests/phar_convert_tar.phpt
new file mode 100644
index 0000000000..d4031ec32f
--- /dev/null
+++ b/ext/phar/tests/phar_convert_tar.phpt
@@ -0,0 +1,57 @@
+--TEST--
+Phar::convertToTar()
+--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';
+$pname = 'phar://' . $fname;
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar';
+$fname3 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.phar.tar';
+$stub = '<?php echo "first stub\n"; __HALT_COMPILER(); ?>';
+$file = $stub;
+
+$files = array();
+$files['a'] = 'a';
+$files['b'] = 'b';
+$files['c'] = 'c';
+
+include 'files/phar_test.inc';
+
+$phar = new Phar($fname);
+var_dump($phar->isFileFormat(Phar::TAR));
+var_dump($phar->getStub());
+
+$phar = $phar->convertToExecutable(Phar::TAR);
+var_dump($phar->isFileFormat(Phar::TAR));
+var_dump($phar->getStub());
+
+copy($fname2, $fname3);
+
+$phar = new Phar($fname3);
+var_dump($phar->isFileFormat(Phar::TAR));
+var_dump($phar->getStub());
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar.tar');
+__HALT_COMPILER();
+?>
+--EXPECT--
+bool(false)
+string(48) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>"
+bool(true)
+string(60) "<?php // tar-based phar archive stub file
+__HALT_COMPILER();"
+bool(true)
+string(60) "<?php // tar-based phar archive stub file
+__HALT_COMPILER();"
+===DONE===
diff --git a/ext/phar/tests/phar_convert_tar2.phpt b/ext/phar/tests/phar_convert_tar2.phpt
new file mode 100644
index 0000000000..f0f0f69825
--- /dev/null
+++ b/ext/phar/tests/phar_convert_tar2.phpt
@@ -0,0 +1,64 @@
+--TEST--
+Phar::convertToTar() gzip compressed
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zlib")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar.gz';
+$fname3 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.phar.tar';
+$stub = '<?php echo "first stub\n"; __HALT_COMPILER(); ?>';
+$file = $stub;
+
+$files = array();
+$files['a'] = 'a';
+$files['b'] = 'b';
+$files['c'] = 'c';
+
+include 'files/phar_test.inc';
+
+$phar = new Phar($fname);
+var_dump($phar->isFileFormat(Phar::TAR));
+var_dump($phar->isCompressed());
+var_dump($phar->getStub());
+
+$phar = $phar->convertToExecutable(Phar::TAR, Phar::GZ);
+var_dump($phar->isFileFormat(Phar::TAR));
+var_dump($phar->isCompressed());
+var_dump($phar->getStub());
+
+copy($fname2, $fname3);
+
+$phar = new Phar($fname3);
+var_dump($phar->isFileFormat(Phar::TAR));
+var_dump($phar->isCompressed() == Phar::GZ);
+var_dump($phar->getStub());
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar.gz');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar.tar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php');
+?>
+--EXPECT--
+bool(false)
+bool(false)
+string(48) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>"
+bool(true)
+int(4096)
+string(60) "<?php // tar-based phar archive stub file
+__HALT_COMPILER();"
+bool(true)
+bool(true)
+string(60) "<?php // tar-based phar archive stub file
+__HALT_COMPILER();"
+===DONE===
diff --git a/ext/phar/tests/phar_convert_tar3.phpt b/ext/phar/tests/phar_convert_tar3.phpt
new file mode 100644
index 0000000000..52fd0f555a
--- /dev/null
+++ b/ext/phar/tests/phar_convert_tar3.phpt
@@ -0,0 +1,65 @@
+--TEST--
+Phar::convertToTar() bz2 compressed
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("bz2")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar';
+$fname3 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.phar.tar';
+$stub = '<?php echo "first stub\n"; __HALT_COMPILER(); ?>';
+$file = $stub;
+
+$files = array();
+$files['a'] = 'a';
+$files['b'] = 'b';
+$files['c'] = 'c';
+
+include 'files/phar_test.inc';
+
+$phar = new Phar($fname);
+var_dump($phar->isFileFormat(Phar::TAR));
+var_dump($phar->isCompressed());
+var_dump($phar->getStub());
+
+$phar = $phar->convertToExecutable(Phar::TAR, Phar::BZ2);
+var_dump($phar->isFileFormat(Phar::TAR));
+var_dump($phar->isCompressed());
+var_dump($phar->getStub());
+
+copy($fname2 . '.bz2', $fname3);
+
+$phar = new Phar($fname3);
+var_dump($phar->isFileFormat(Phar::TAR));
+var_dump($phar->isCompressed() == Phar::BZ2);
+var_dump($phar->getStub());
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar.bz2');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar.tar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php');
+__HALT_COMPILER();
+?>
+--EXPECT--
+bool(false)
+bool(false)
+string(48) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>"
+bool(true)
+int(8192)
+string(60) "<?php // tar-based phar archive stub file
+__HALT_COMPILER();"
+bool(true)
+bool(true)
+string(60) "<?php // tar-based phar archive stub file
+__HALT_COMPILER();"
+===DONE===
diff --git a/ext/phar/tests/phar_convert_zip.phpt b/ext/phar/tests/phar_convert_zip.phpt
new file mode 100644
index 0000000000..734551ee9c
--- /dev/null
+++ b/ext/phar/tests/phar_convert_zip.phpt
@@ -0,0 +1,56 @@
+--TEST--
+Phar::convertToZip()
+--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';
+$pname = 'phar://' . $fname;
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip';
+$fname3 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.phar.zip';
+$stub = '<?php echo "first stub\n"; __HALT_COMPILER(); ?>';
+$file = $stub;
+
+$files = array();
+$files['a'] = 'a';
+$files['b'] = 'b';
+$files['c'] = 'c';
+
+include 'files/phar_test.inc';
+
+$phar = new Phar($fname);
+var_dump($phar->isFileFormat(Phar::ZIP));
+var_dump($phar->getStub());
+
+$phar = $phar->convertToExecutable(Phar::ZIP);
+var_dump($phar->isFileFormat(Phar::ZIP));
+var_dump($phar->getStub());
+
+copy($fname2, $fname3);
+
+$phar = new Phar($fname3);
+var_dump($phar->isFileFormat(Phar::ZIP));
+var_dump($phar->getStub());
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar.zip');
+__HALT_COMPILER();
+?>
+--EXPECT--
+bool(false)
+string(48) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>"
+bool(true)
+string(60) "<?php // zip-based phar archive stub file
+__HALT_COMPILER();"
+bool(true)
+string(60) "<?php // zip-based phar archive stub file
+__HALT_COMPILER();"
+===DONE===
diff --git a/ext/phar/tests/phar_copy.phpt b/ext/phar/tests/phar_copy.phpt
new file mode 100644
index 0000000000..0a43947bd1
--- /dev/null
+++ b/ext/phar/tests/phar_copy.phpt
@@ -0,0 +1,72 @@
+--TEST--
+Phar: copy()
+--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"); ?>
+--INI--
+phar.readonly=0
+phar.require_hash=1
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.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['a']->compress(Phar::GZ);
+ $p['b']->setMetadata('a');
+ $p->copy('b', 'c');
+ $p->stopBuffering();
+ echo file_get_contents($p['c']->getPathName());
+ copy($fname, $fname2);
+ $p->copy('a', $ename);
+}
+catch(Exception $e)
+{
+ echo $e->getMessage() . "\n";
+}
+ini_set('phar.readonly',1);
+$p2 = new Phar($fname2);
+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()), $p2['c']->getMetaData(), "\n";
+ini_set('phar.readonly', 0);
+try {
+$p2->copy('notexisting', 'another');
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+try {
+$p2->copy('a', 'b');
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+$p2['a']->compress(Phar::GZ);
+$p2->copy('a', 'd');
+echo $p2['d']->getContent() . "\n";
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '2.phar.php'); ?>
+--EXPECTF--
+hihifile "/error/.." contains invalid characters upper directory reference, cannot be copied from "a" in phar %s
+
+a: hib: hic: hia
+file "notexisting" cannot be copied to file "another", file does not exist in %sphar_copy2.phar.php
+file "a" cannot be copied to file "b", file must not already exist in phar %sphar_copy2.phar.php
+hi
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/phar_create_in_cwd.phpt b/ext/phar/tests/phar_create_in_cwd.phpt
new file mode 100644
index 0000000000..83de7bed28
--- /dev/null
+++ b/ext/phar/tests/phar_create_in_cwd.phpt
@@ -0,0 +1,45 @@
+--TEST--
+Phar: attempt to create a Phar with relative path
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+chdir(dirname(__FILE__));
+try {
+ $p = new Phar('brandnewphar.phar');
+ $p['file1.txt'] = 'hi';
+ var_dump(strlen($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());
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/brandnewphar.phar');
+?>
+--EXPECT--
+int(6651)
+string(200) "<?php
+function __autoload($class)
+{
+ include 'phar://' . str_replace('_', '/', $class);
+}
+Phar::mapPhar('brandnewphar.phar');
+include 'phar://brandnewphar.phar/startup.php';
+__HALT_COMPILER(); ?>
+"
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/phar_createdefaultstub.phpt b/ext/phar/tests/phar_createdefaultstub.phpt
new file mode 100644
index 0000000000..a8648dc311
--- /dev/null
+++ b/ext/phar/tests/phar_createdefaultstub.phpt
@@ -0,0 +1,929 @@
+--TEST--
+Phar: Phar::createDefaultStub() with and without arg
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--FILE--
+<?php
+try {
+var_dump(Phar::createDefaultStub());
+echo "============================================================================\n";
+echo "============================================================================\n";
+var_dump(Phar::createDefaultStub('my/custom/thingy.php'));
+echo "============================================================================\n";
+echo "============================================================================\n";
+var_dump(strlen(Phar::createDefaultStub(str_repeat('a', 400))));
+echo "============================================================================\n";
+echo "============================================================================\n";
+var_dump(Phar::createDefaultStub(str_repeat('a', 401)));
+} catch(Exception $e) {
+echo $e->getMessage() . "\n";
+}
+echo "============================================================================\n";
+echo "============================================================================\n";
+echo "============================================================================\n";
+echo "============================================================================\n";
+try {
+var_dump(Phar::createDefaultStub('my/custom/thingy.php', 'the/web.php'));
+echo "============================================================================\n";
+echo "============================================================================\n";
+var_dump(strlen(Phar::createDefaultStub('index.php', str_repeat('a', 400))));
+var_dump(Phar::createDefaultStub('hio', str_repeat('a', 401)));
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--EXPECT--
+string(6651) "<?php
+
+$web = 'index.php';
+
+if (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) {
+Phar::interceptFileFuncs();
+set_include_path('phar://' . __FILE__ . PATH_SEPARATOR . get_include_path());
+Phar::webPhar(null, $web);
+include 'phar://' . __FILE__ . '/' . Extract_Phar::START;
+return;
+}
+
+if (@(isset($_SERVER['REQUEST_URI']) && isset($_SERVER['REQUEST_METHOD']) && ($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'POST'))) {
+Extract_Phar::go(true);
+$mimes = array(
+'phps' => 2,
+'c' => 'text/plain',
+'cc' => 'text/plain',
+'cpp' => 'text/plain',
+'c++' => 'text/plain',
+'dtd' => 'text/plain',
+'h' => 'text/plain',
+'log' => 'text/plain',
+'rng' => 'text/plain',
+'txt' => 'text/plain',
+'xsd' => 'text/plain',
+'php' => 1,
+'inc' => 1,
+'avi' => 'video/avi',
+'bmp' => 'image/bmp',
+'css' => 'text/css',
+'gif' => 'image/gif',
+'htm' => 'text/html',
+'html' => 'text/html',
+'htmls' => 'text/html',
+'ico' => 'image/x-ico',
+'jpe' => 'image/jpeg',
+'jpg' => 'image/jpeg',
+'jpeg' => 'image/jpeg',
+'js' => 'application/x-javascript',
+'midi' => 'audio/midi',
+'mid' => 'audio/midi',
+'mod' => 'audio/mod',
+'mov' => 'movie/quicktime',
+'mp3' => 'audio/mp3',
+'mpg' => 'video/mpeg',
+'mpeg' => 'video/mpeg',
+'pdf' => 'application/pdf',
+'png' => 'image/png',
+'swf' => 'application/shockwave-flash',
+'tif' => 'image/tiff',
+'tiff' => 'image/tiff',
+'wav' => 'audio/wav',
+'xbm' => 'image/xbm',
+'xml' => 'text/xml',
+);
+
+header("Cache-Control: no-cache, must-revalidate");
+header("Pragma: no-cache");
+
+$basename = basename(__FILE__);
+if (!strpos($_SERVER['REQUEST_URI'], $basename)) {
+chdir(Extract_Phar::$temp);
+include $web;
+return;
+}
+$pt = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], $basename) + strlen($basename));
+if (!$pt || $pt == '/') {
+$pt = $web;
+header('HTTP/1.1 301 Moved Permanently');
+header('Location: ' . $_SERVER['REQUEST_URI'] . '/' . $pt);
+exit;
+}
+$a = realpath(Extract_Phar::$temp . DIRECTORY_SEPARATOR . $pt);
+if (!$a || strlen(dirname($a)) < strlen(Extract_Phar::$temp)) {
+header('HTTP/1.0 404 Not Found');
+echo "<html>\n <head>\n <title>File Not Found<title>\n </head>\n <body>\n <h1>404 - File ", $pt, " Not Found</h1>\n </body>\n</html>";
+exit;
+}
+$b = pathinfo($a);
+if (!isset($b['extension'])) {
+header('Content-Type: text/plain');
+header('Content-Length: ' . filesize($a));
+readfile($a);
+exit;
+}
+if (isset($mimes[$b['extension']])) {
+if ($mimes[$b['extension']] === 1) {
+include $a;
+exit;
+}
+if ($mimes[$b['extension']] === 2) {
+highlight_file($a);
+exit;
+}
+header('Content-Type: ' .$mimes[$b['extension']]);
+header('Content-Length: ' . filesize($a));
+readfile($a);
+exit;
+}
+}
+
+class Extract_Phar
+{
+static $temp;
+static $origdir;
+const GZ = 0x1000;
+const BZ2 = 0x2000;
+const MASK = 0x3000;
+const START = 'index.php';
+const LEN = 6653;
+
+static function go($return = false)
+{
+$fp = fopen(__FILE__, 'rb');
+fseek($fp, self::LEN);
+$L = unpack('V', $a = fread($fp, 4));
+$m = '';
+
+do {
+$read = 8192;
+if ($L[1] - strlen($m) < 8192) {
+$read = $L[1] - strlen($m);
+}
+$last = fread($fp, $read);
+$m .= $last;
+} while (strlen($last) && strlen($m) < $L[1]);
+
+if (strlen($m) < $L[1]) {
+die('ERROR: manifest length read was "' .
+strlen($m) .'" should be "' .
+$L[1] . '"');
+}
+
+$info = self::_unpack($m);
+$f = $info['c'];
+
+if ($f & self::GZ) {
+if (!function_exists('gzinflate')) {
+die('Error: zlib extension is not enabled -' .
+' gzinflate() function needed for zlib-compressed .phars');
+}
+}
+
+if ($f & self::BZ2) {
+if (!function_exists('bzdecompress')) {
+die('Error: bzip2 extension is not enabled -' .
+' bzdecompress() function needed for bz2-compressed .phars');
+}
+}
+
+$temp = self::tmpdir();
+
+if (!$temp || !is_writable($temp)) {
+$sessionpath = session_save_path();
+if (strpos ($sessionpath, ";") !== false)
+$sessionpath = substr ($sessionpath, strpos ($sessionpath, ";")+1);
+if (!file_exists($sessionpath) || !is_dir($sessionpath)) {
+die('Could not locate temporary directory to extract phar');
+}
+$temp = $sessionpath;
+}
+
+$temp .= '/pharextract/'.basename(__FILE__, '.phar');
+self::$temp = $temp;
+self::$origdir = getcwd();
+@mkdir($temp, 0777, true);
+$temp = realpath($temp);
+
+if (!file_exists($temp . DIRECTORY_SEPARATOR . md5_file(__FILE__))) {
+self::_removeTmpFiles($temp, getcwd());
+@mkdir($temp, 0777, true);
+@file_put_contents($temp . '/' . md5_file(__FILE__), '');
+
+foreach ($info['m'] as $path => $file) {
+$a = !file_exists(dirname($temp . '/' . $path));
+@mkdir(dirname($temp . '/' . $path), 0777, true);
+clearstatcache();
+
+if ($path[strlen($path) - 1] == '/') {
+@mkdir($temp . '/' . $path, 0777);
+} else {
+file_put_contents($temp . '/' . $path, self::extractFile($path, $file, $fp));
+@chmod($temp . '/' . $path, 0666);
+}
+}
+}
+
+chdir($temp);
+
+if (!$return) {
+include self::START;
+}
+}
+
+static function tmpdir()
+{
+if (strpos(PHP_OS, 'WIN') !== false) {
+if ($var = getenv('TMP') ? getenv('TMP') : getenv('TEMP')) {
+return $var;
+}
+if (is_dir('/temp') || mkdir('/temp')) {
+return realpath('/temp');
+}
+return false;
+}
+if ($var = getenv('TMPDIR')) {
+return $var;
+}
+return realpath('/tmp');
+}
+
+static function _unpack($m)
+{
+$info = unpack('V', substr($m, 0, 4));
+ $l = unpack('V', substr($m, 10, 4));
+$m = substr($m, 14 + $l[1]);
+$s = unpack('V', substr($m, 0, 4));
+$o = 0;
+$start = 4 + $s[1];
+$ret['c'] = 0;
+
+for ($i = 0; $i < $info[1]; $i++) {
+ $len = unpack('V', substr($m, $start, 4));
+$start += 4;
+ $savepath = substr($m, $start, $len[1]);
+$start += $len[1];
+ $ret['m'][$savepath] = array_values(unpack('Va/Vb/Vc/Vd/Ve/Vf', substr($m, $start, 24)));
+$ret['m'][$savepath][3] = sprintf('%u', $ret['m'][$savepath][3]
+& 0xffffffff);
+$ret['m'][$savepath][7] = $o;
+$o += $ret['m'][$savepath][2];
+$start += 24 + $ret['m'][$savepath][5];
+$ret['c'] |= $ret['m'][$savepath][4] & self::MASK;
+}
+return $ret;
+}
+
+static function extractFile($path, $entry, $fp)
+{
+$data = '';
+$c = $entry[2];
+
+while ($c) {
+if ($c < 8192) {
+$data .= @fread($fp, $c);
+$c = 0;
+} else {
+$c -= 8192;
+$data .= @fread($fp, 8192);
+}
+}
+
+if ($entry[4] & self::GZ) {
+$data = gzinflate($data);
+} elseif ($entry[4] & self::BZ2) {
+$data = bzdecompress($data);
+}
+
+if (strlen($data) != $entry[0]) {
+die("Invalid internal .phar file (size error " . strlen($data) . " != " .
+$stat[7] . ")");
+}
+
+if ($entry[3] != sprintf("%u", crc32($data) & 0xffffffff)) {
+die("Invalid internal .phar file (checksum error)");
+}
+
+return $data;
+}
+
+static function _removeTmpFiles($temp, $origdir)
+{
+chdir($temp);
+
+foreach (glob('*') as $f) {
+if (file_exists($f)) {
+is_dir($f) ? @rmdir($f) : @unlink($f);
+if (file_exists($f) && is_dir($f)) {
+self::_removeTmpFiles($f, getcwd());
+}
+}
+}
+
+@rmdir($temp);
+clearstatcache();
+chdir($origdir);
+}
+}
+
+Extract_Phar::go();
+__HALT_COMPILER(); ?>"
+============================================================================
+============================================================================
+string(6662) "<?php
+
+$web = 'index.php';
+
+if (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) {
+Phar::interceptFileFuncs();
+set_include_path('phar://' . __FILE__ . PATH_SEPARATOR . get_include_path());
+Phar::webPhar(null, $web);
+include 'phar://' . __FILE__ . '/' . Extract_Phar::START;
+return;
+}
+
+if (@(isset($_SERVER['REQUEST_URI']) && isset($_SERVER['REQUEST_METHOD']) && ($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'POST'))) {
+Extract_Phar::go(true);
+$mimes = array(
+'phps' => 2,
+'c' => 'text/plain',
+'cc' => 'text/plain',
+'cpp' => 'text/plain',
+'c++' => 'text/plain',
+'dtd' => 'text/plain',
+'h' => 'text/plain',
+'log' => 'text/plain',
+'rng' => 'text/plain',
+'txt' => 'text/plain',
+'xsd' => 'text/plain',
+'php' => 1,
+'inc' => 1,
+'avi' => 'video/avi',
+'bmp' => 'image/bmp',
+'css' => 'text/css',
+'gif' => 'image/gif',
+'htm' => 'text/html',
+'html' => 'text/html',
+'htmls' => 'text/html',
+'ico' => 'image/x-ico',
+'jpe' => 'image/jpeg',
+'jpg' => 'image/jpeg',
+'jpeg' => 'image/jpeg',
+'js' => 'application/x-javascript',
+'midi' => 'audio/midi',
+'mid' => 'audio/midi',
+'mod' => 'audio/mod',
+'mov' => 'movie/quicktime',
+'mp3' => 'audio/mp3',
+'mpg' => 'video/mpeg',
+'mpeg' => 'video/mpeg',
+'pdf' => 'application/pdf',
+'png' => 'image/png',
+'swf' => 'application/shockwave-flash',
+'tif' => 'image/tiff',
+'tiff' => 'image/tiff',
+'wav' => 'audio/wav',
+'xbm' => 'image/xbm',
+'xml' => 'text/xml',
+);
+
+header("Cache-Control: no-cache, must-revalidate");
+header("Pragma: no-cache");
+
+$basename = basename(__FILE__);
+if (!strpos($_SERVER['REQUEST_URI'], $basename)) {
+chdir(Extract_Phar::$temp);
+include $web;
+return;
+}
+$pt = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], $basename) + strlen($basename));
+if (!$pt || $pt == '/') {
+$pt = $web;
+header('HTTP/1.1 301 Moved Permanently');
+header('Location: ' . $_SERVER['REQUEST_URI'] . '/' . $pt);
+exit;
+}
+$a = realpath(Extract_Phar::$temp . DIRECTORY_SEPARATOR . $pt);
+if (!$a || strlen(dirname($a)) < strlen(Extract_Phar::$temp)) {
+header('HTTP/1.0 404 Not Found');
+echo "<html>\n <head>\n <title>File Not Found<title>\n </head>\n <body>\n <h1>404 - File ", $pt, " Not Found</h1>\n </body>\n</html>";
+exit;
+}
+$b = pathinfo($a);
+if (!isset($b['extension'])) {
+header('Content-Type: text/plain');
+header('Content-Length: ' . filesize($a));
+readfile($a);
+exit;
+}
+if (isset($mimes[$b['extension']])) {
+if ($mimes[$b['extension']] === 1) {
+include $a;
+exit;
+}
+if ($mimes[$b['extension']] === 2) {
+highlight_file($a);
+exit;
+}
+header('Content-Type: ' .$mimes[$b['extension']]);
+header('Content-Length: ' . filesize($a));
+readfile($a);
+exit;
+}
+}
+
+class Extract_Phar
+{
+static $temp;
+static $origdir;
+const GZ = 0x1000;
+const BZ2 = 0x2000;
+const MASK = 0x3000;
+const START = 'my/custom/thingy.php';
+const LEN = 6664;
+
+static function go($return = false)
+{
+$fp = fopen(__FILE__, 'rb');
+fseek($fp, self::LEN);
+$L = unpack('V', $a = fread($fp, 4));
+$m = '';
+
+do {
+$read = 8192;
+if ($L[1] - strlen($m) < 8192) {
+$read = $L[1] - strlen($m);
+}
+$last = fread($fp, $read);
+$m .= $last;
+} while (strlen($last) && strlen($m) < $L[1]);
+
+if (strlen($m) < $L[1]) {
+die('ERROR: manifest length read was "' .
+strlen($m) .'" should be "' .
+$L[1] . '"');
+}
+
+$info = self::_unpack($m);
+$f = $info['c'];
+
+if ($f & self::GZ) {
+if (!function_exists('gzinflate')) {
+die('Error: zlib extension is not enabled -' .
+' gzinflate() function needed for zlib-compressed .phars');
+}
+}
+
+if ($f & self::BZ2) {
+if (!function_exists('bzdecompress')) {
+die('Error: bzip2 extension is not enabled -' .
+' bzdecompress() function needed for bz2-compressed .phars');
+}
+}
+
+$temp = self::tmpdir();
+
+if (!$temp || !is_writable($temp)) {
+$sessionpath = session_save_path();
+if (strpos ($sessionpath, ";") !== false)
+$sessionpath = substr ($sessionpath, strpos ($sessionpath, ";")+1);
+if (!file_exists($sessionpath) || !is_dir($sessionpath)) {
+die('Could not locate temporary directory to extract phar');
+}
+$temp = $sessionpath;
+}
+
+$temp .= '/pharextract/'.basename(__FILE__, '.phar');
+self::$temp = $temp;
+self::$origdir = getcwd();
+@mkdir($temp, 0777, true);
+$temp = realpath($temp);
+
+if (!file_exists($temp . DIRECTORY_SEPARATOR . md5_file(__FILE__))) {
+self::_removeTmpFiles($temp, getcwd());
+@mkdir($temp, 0777, true);
+@file_put_contents($temp . '/' . md5_file(__FILE__), '');
+
+foreach ($info['m'] as $path => $file) {
+$a = !file_exists(dirname($temp . '/' . $path));
+@mkdir(dirname($temp . '/' . $path), 0777, true);
+clearstatcache();
+
+if ($path[strlen($path) - 1] == '/') {
+@mkdir($temp . '/' . $path, 0777);
+} else {
+file_put_contents($temp . '/' . $path, self::extractFile($path, $file, $fp));
+@chmod($temp . '/' . $path, 0666);
+}
+}
+}
+
+chdir($temp);
+
+if (!$return) {
+include self::START;
+}
+}
+
+static function tmpdir()
+{
+if (strpos(PHP_OS, 'WIN') !== false) {
+if ($var = getenv('TMP') ? getenv('TMP') : getenv('TEMP')) {
+return $var;
+}
+if (is_dir('/temp') || mkdir('/temp')) {
+return realpath('/temp');
+}
+return false;
+}
+if ($var = getenv('TMPDIR')) {
+return $var;
+}
+return realpath('/tmp');
+}
+
+static function _unpack($m)
+{
+$info = unpack('V', substr($m, 0, 4));
+ $l = unpack('V', substr($m, 10, 4));
+$m = substr($m, 14 + $l[1]);
+$s = unpack('V', substr($m, 0, 4));
+$o = 0;
+$start = 4 + $s[1];
+$ret['c'] = 0;
+
+for ($i = 0; $i < $info[1]; $i++) {
+ $len = unpack('V', substr($m, $start, 4));
+$start += 4;
+ $savepath = substr($m, $start, $len[1]);
+$start += $len[1];
+ $ret['m'][$savepath] = array_values(unpack('Va/Vb/Vc/Vd/Ve/Vf', substr($m, $start, 24)));
+$ret['m'][$savepath][3] = sprintf('%u', $ret['m'][$savepath][3]
+& 0xffffffff);
+$ret['m'][$savepath][7] = $o;
+$o += $ret['m'][$savepath][2];
+$start += 24 + $ret['m'][$savepath][5];
+$ret['c'] |= $ret['m'][$savepath][4] & self::MASK;
+}
+return $ret;
+}
+
+static function extractFile($path, $entry, $fp)
+{
+$data = '';
+$c = $entry[2];
+
+while ($c) {
+if ($c < 8192) {
+$data .= @fread($fp, $c);
+$c = 0;
+} else {
+$c -= 8192;
+$data .= @fread($fp, 8192);
+}
+}
+
+if ($entry[4] & self::GZ) {
+$data = gzinflate($data);
+} elseif ($entry[4] & self::BZ2) {
+$data = bzdecompress($data);
+}
+
+if (strlen($data) != $entry[0]) {
+die("Invalid internal .phar file (size error " . strlen($data) . " != " .
+$stat[7] . ")");
+}
+
+if ($entry[3] != sprintf("%u", crc32($data) & 0xffffffff)) {
+die("Invalid internal .phar file (checksum error)");
+}
+
+return $data;
+}
+
+static function _removeTmpFiles($temp, $origdir)
+{
+chdir($temp);
+
+foreach (glob('*') as $f) {
+if (file_exists($f)) {
+is_dir($f) ? @rmdir($f) : @unlink($f);
+if (file_exists($f) && is_dir($f)) {
+self::_removeTmpFiles($f, getcwd());
+}
+}
+}
+
+@rmdir($temp);
+clearstatcache();
+chdir($origdir);
+}
+}
+
+Extract_Phar::go();
+__HALT_COMPILER(); ?>"
+============================================================================
+============================================================================
+int(7042)
+============================================================================
+============================================================================
+Illegal filename passed in for stub creation, was 401 characters long, and only 400 or less is allowed
+============================================================================
+============================================================================
+============================================================================
+============================================================================
+string(6664) "<?php
+
+$web = 'the/web.php';
+
+if (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) {
+Phar::interceptFileFuncs();
+set_include_path('phar://' . __FILE__ . PATH_SEPARATOR . get_include_path());
+Phar::webPhar(null, $web);
+include 'phar://' . __FILE__ . '/' . Extract_Phar::START;
+return;
+}
+
+if (@(isset($_SERVER['REQUEST_URI']) && isset($_SERVER['REQUEST_METHOD']) && ($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'POST'))) {
+Extract_Phar::go(true);
+$mimes = array(
+'phps' => 2,
+'c' => 'text/plain',
+'cc' => 'text/plain',
+'cpp' => 'text/plain',
+'c++' => 'text/plain',
+'dtd' => 'text/plain',
+'h' => 'text/plain',
+'log' => 'text/plain',
+'rng' => 'text/plain',
+'txt' => 'text/plain',
+'xsd' => 'text/plain',
+'php' => 1,
+'inc' => 1,
+'avi' => 'video/avi',
+'bmp' => 'image/bmp',
+'css' => 'text/css',
+'gif' => 'image/gif',
+'htm' => 'text/html',
+'html' => 'text/html',
+'htmls' => 'text/html',
+'ico' => 'image/x-ico',
+'jpe' => 'image/jpeg',
+'jpg' => 'image/jpeg',
+'jpeg' => 'image/jpeg',
+'js' => 'application/x-javascript',
+'midi' => 'audio/midi',
+'mid' => 'audio/midi',
+'mod' => 'audio/mod',
+'mov' => 'movie/quicktime',
+'mp3' => 'audio/mp3',
+'mpg' => 'video/mpeg',
+'mpeg' => 'video/mpeg',
+'pdf' => 'application/pdf',
+'png' => 'image/png',
+'swf' => 'application/shockwave-flash',
+'tif' => 'image/tiff',
+'tiff' => 'image/tiff',
+'wav' => 'audio/wav',
+'xbm' => 'image/xbm',
+'xml' => 'text/xml',
+);
+
+header("Cache-Control: no-cache, must-revalidate");
+header("Pragma: no-cache");
+
+$basename = basename(__FILE__);
+if (!strpos($_SERVER['REQUEST_URI'], $basename)) {
+chdir(Extract_Phar::$temp);
+include $web;
+return;
+}
+$pt = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], $basename) + strlen($basename));
+if (!$pt || $pt == '/') {
+$pt = $web;
+header('HTTP/1.1 301 Moved Permanently');
+header('Location: ' . $_SERVER['REQUEST_URI'] . '/' . $pt);
+exit;
+}
+$a = realpath(Extract_Phar::$temp . DIRECTORY_SEPARATOR . $pt);
+if (!$a || strlen(dirname($a)) < strlen(Extract_Phar::$temp)) {
+header('HTTP/1.0 404 Not Found');
+echo "<html>\n <head>\n <title>File Not Found<title>\n </head>\n <body>\n <h1>404 - File ", $pt, " Not Found</h1>\n </body>\n</html>";
+exit;
+}
+$b = pathinfo($a);
+if (!isset($b['extension'])) {
+header('Content-Type: text/plain');
+header('Content-Length: ' . filesize($a));
+readfile($a);
+exit;
+}
+if (isset($mimes[$b['extension']])) {
+if ($mimes[$b['extension']] === 1) {
+include $a;
+exit;
+}
+if ($mimes[$b['extension']] === 2) {
+highlight_file($a);
+exit;
+}
+header('Content-Type: ' .$mimes[$b['extension']]);
+header('Content-Length: ' . filesize($a));
+readfile($a);
+exit;
+}
+}
+
+class Extract_Phar
+{
+static $temp;
+static $origdir;
+const GZ = 0x1000;
+const BZ2 = 0x2000;
+const MASK = 0x3000;
+const START = 'my/custom/thingy.php';
+const LEN = 6666;
+
+static function go($return = false)
+{
+$fp = fopen(__FILE__, 'rb');
+fseek($fp, self::LEN);
+$L = unpack('V', $a = fread($fp, 4));
+$m = '';
+
+do {
+$read = 8192;
+if ($L[1] - strlen($m) < 8192) {
+$read = $L[1] - strlen($m);
+}
+$last = fread($fp, $read);
+$m .= $last;
+} while (strlen($last) && strlen($m) < $L[1]);
+
+if (strlen($m) < $L[1]) {
+die('ERROR: manifest length read was "' .
+strlen($m) .'" should be "' .
+$L[1] . '"');
+}
+
+$info = self::_unpack($m);
+$f = $info['c'];
+
+if ($f & self::GZ) {
+if (!function_exists('gzinflate')) {
+die('Error: zlib extension is not enabled -' .
+' gzinflate() function needed for zlib-compressed .phars');
+}
+}
+
+if ($f & self::BZ2) {
+if (!function_exists('bzdecompress')) {
+die('Error: bzip2 extension is not enabled -' .
+' bzdecompress() function needed for bz2-compressed .phars');
+}
+}
+
+$temp = self::tmpdir();
+
+if (!$temp || !is_writable($temp)) {
+$sessionpath = session_save_path();
+if (strpos ($sessionpath, ";") !== false)
+$sessionpath = substr ($sessionpath, strpos ($sessionpath, ";")+1);
+if (!file_exists($sessionpath) || !is_dir($sessionpath)) {
+die('Could not locate temporary directory to extract phar');
+}
+$temp = $sessionpath;
+}
+
+$temp .= '/pharextract/'.basename(__FILE__, '.phar');
+self::$temp = $temp;
+self::$origdir = getcwd();
+@mkdir($temp, 0777, true);
+$temp = realpath($temp);
+
+if (!file_exists($temp . DIRECTORY_SEPARATOR . md5_file(__FILE__))) {
+self::_removeTmpFiles($temp, getcwd());
+@mkdir($temp, 0777, true);
+@file_put_contents($temp . '/' . md5_file(__FILE__), '');
+
+foreach ($info['m'] as $path => $file) {
+$a = !file_exists(dirname($temp . '/' . $path));
+@mkdir(dirname($temp . '/' . $path), 0777, true);
+clearstatcache();
+
+if ($path[strlen($path) - 1] == '/') {
+@mkdir($temp . '/' . $path, 0777);
+} else {
+file_put_contents($temp . '/' . $path, self::extractFile($path, $file, $fp));
+@chmod($temp . '/' . $path, 0666);
+}
+}
+}
+
+chdir($temp);
+
+if (!$return) {
+include self::START;
+}
+}
+
+static function tmpdir()
+{
+if (strpos(PHP_OS, 'WIN') !== false) {
+if ($var = getenv('TMP') ? getenv('TMP') : getenv('TEMP')) {
+return $var;
+}
+if (is_dir('/temp') || mkdir('/temp')) {
+return realpath('/temp');
+}
+return false;
+}
+if ($var = getenv('TMPDIR')) {
+return $var;
+}
+return realpath('/tmp');
+}
+
+static function _unpack($m)
+{
+$info = unpack('V', substr($m, 0, 4));
+ $l = unpack('V', substr($m, 10, 4));
+$m = substr($m, 14 + $l[1]);
+$s = unpack('V', substr($m, 0, 4));
+$o = 0;
+$start = 4 + $s[1];
+$ret['c'] = 0;
+
+for ($i = 0; $i < $info[1]; $i++) {
+ $len = unpack('V', substr($m, $start, 4));
+$start += 4;
+ $savepath = substr($m, $start, $len[1]);
+$start += $len[1];
+ $ret['m'][$savepath] = array_values(unpack('Va/Vb/Vc/Vd/Ve/Vf', substr($m, $start, 24)));
+$ret['m'][$savepath][3] = sprintf('%u', $ret['m'][$savepath][3]
+& 0xffffffff);
+$ret['m'][$savepath][7] = $o;
+$o += $ret['m'][$savepath][2];
+$start += 24 + $ret['m'][$savepath][5];
+$ret['c'] |= $ret['m'][$savepath][4] & self::MASK;
+}
+return $ret;
+}
+
+static function extractFile($path, $entry, $fp)
+{
+$data = '';
+$c = $entry[2];
+
+while ($c) {
+if ($c < 8192) {
+$data .= @fread($fp, $c);
+$c = 0;
+} else {
+$c -= 8192;
+$data .= @fread($fp, 8192);
+}
+}
+
+if ($entry[4] & self::GZ) {
+$data = gzinflate($data);
+} elseif ($entry[4] & self::BZ2) {
+$data = bzdecompress($data);
+}
+
+if (strlen($data) != $entry[0]) {
+die("Invalid internal .phar file (size error " . strlen($data) . " != " .
+$stat[7] . ")");
+}
+
+if ($entry[3] != sprintf("%u", crc32($data) & 0xffffffff)) {
+die("Invalid internal .phar file (checksum error)");
+}
+
+return $data;
+}
+
+static function _removeTmpFiles($temp, $origdir)
+{
+chdir($temp);
+
+foreach (glob('*') as $f) {
+if (file_exists($f)) {
+is_dir($f) ? @rmdir($f) : @unlink($f);
+if (file_exists($f) && is_dir($f)) {
+self::_removeTmpFiles($f, getcwd());
+}
+}
+}
+
+@rmdir($temp);
+clearstatcache();
+chdir($origdir);
+}
+}
+
+Extract_Phar::go();
+__HALT_COMPILER(); ?>"
+============================================================================
+============================================================================
+int(7042)
+Illegal web filename passed in for stub creation, was 401 characters long, and only 400 or less is allowed
+===DONE===
diff --git a/ext/phar/tests/phar_ctx_001.phpt b/ext/phar/tests/phar_ctx_001.phpt
new file mode 100644
index 0000000000..13b4d6a781
--- /dev/null
+++ b/ext/phar/tests/phar_ctx_001.phpt
@@ -0,0 +1,100 @@
+--TEST--
+Phar context
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zlib")) die("skip zlib not present"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$file = '<?php __HALT_COMPILER(); ?>';
+
+$files = array();
+$files['a'] = 'a';
+$files['b'] = 'b';
+$files['c'] = 'c';
+
+include 'files/phar_test.inc';
+
+$phar = new Phar($fname);
+
+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());
+
+$context = stream_context_create(array('phar'=> array('compress'=>Phar::GZ, 'metadata' => array(2, 'hi' => 3))));
+$context2 = stream_context_create(array('phar' => array('metadata' => array(4))));
+
+file_put_contents($pname . '/a', 'new a', 0); // no compression
+file_put_contents($pname . '/b', 'new b', 0, $context);
+file_put_contents($pname . '/d', 'new d', 0, $context2);
+
+$phar = new Phar($fname);
+var_dump(file_get_contents($pname . '/a'));
+var_dump($phar['a']->isCompressed());
+var_dump($phar['a']->getMetaData());
+var_dump(file_get_contents($pname . '/b'));
+var_dump($phar['b']->isCompressed());
+var_dump($phar['b']->getMetaData());
+var_dump(file_get_contents($pname . '/c'));
+var_dump($phar['c']->isCompressed());
+var_dump($phar['c']->getMetaData());
+var_dump(file_get_contents($pname . '/d'));
+var_dump($phar['d']->isCompressed());
+var_dump($phar['d']->getMetaData());
+$context2 = stream_context_create(array('phar' => array('metadata' => array(4))));
+$fp = fopen($pname . '/b', 'r+', 0, $context2);
+fclose($fp);
+?>
+==AFTER==
+<?php
+var_dump(file_get_contents($pname . '/b'));
+var_dump($phar['b']->isCompressed());
+var_dump($phar['b']->getMetaData());
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php');
+?>
+--EXPECT--
+string(1) "a"
+bool(false)
+string(1) "b"
+bool(false)
+string(1) "c"
+bool(false)
+string(5) "new a"
+bool(false)
+NULL
+string(5) "new b"
+bool(true)
+array(2) {
+ [0]=>
+ int(2)
+ ["hi"]=>
+ int(3)
+}
+string(1) "c"
+bool(false)
+NULL
+string(5) "new d"
+bool(false)
+array(1) {
+ [0]=>
+ int(4)
+}
+==AFTER==
+string(5) "new b"
+bool(true)
+array(1) {
+ [0]=>
+ int(4)
+}
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/phar_decompress.phpt b/ext/phar/tests/phar_decompress.phpt
new file mode 100644
index 0000000000..ae199eb03b
--- /dev/null
+++ b/ext/phar/tests/phar_decompress.phpt
@@ -0,0 +1,69 @@
+--TEST--
+Phar::decompress()
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zlib")) die("skip zlib not present"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '2.phar.gz';
+$pname = 'phar://' . $fname;
+$file = '<?php __HALT_COMPILER(); ?>';
+
+$files = array();
+$files['a'] = 'a';
+$files['b'] = 'b';
+$files['c'] = 'c';
+
+include 'files/phar_test.inc';
+
+$phar = new Phar($fname);
+
+$gz = $phar->compress(Phar::GZ);
+copy($gz->getPath(), $fname2);
+$a = new Phar($fname2);
+var_dump($a->isCompressed());
+$unc = $a->compress(Phar::NONE);
+echo $unc->getPath() . "\n";
+$unc2 = $gz->decompress();
+echo $unc2->getPath() . "\n";
+$unc3 = $gz->decompress('hooba.phar');
+echo $unc3->getPath() . "\n";
+$gz->decompress(array());
+$zip = $phar->convertToData(Phar::ZIP);
+ini_set('phar.readonly', 1);
+try {
+$gz->decompress();
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+try {
+$zip->decompress();
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.zip');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.hooba.phar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.gz');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '2.phar.gz');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '2.phar');
+?>
+--EXPECTF--
+int(4096)
+%sphar_decompress2.phar
+%sphar_decompress.phar
+%sphar_decompress.hooba.phar
+
+Warning: Phar::decompress() expects parameter 1 to be string, array given in %sphar_decompress.php on line %d
+Cannot decompress phar archive, phar is read-only
+Cannot decompress zip-based archives with whole-archive compression
+===DONE===
diff --git a/ext/phar/tests/phar_dir_iterate.phpt b/ext/phar/tests/phar_dir_iterate.phpt
new file mode 100644
index 0000000000..2ee2cb5529
--- /dev/null
+++ b/ext/phar/tests/phar_dir_iterate.phpt
@@ -0,0 +1,32 @@
+--TEST--
+Phar object: iterate test with sub-directories and RecursiveIteratorIterator
+--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=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+
+$phar = new Phar($fname);
+$phar['top.txt'] = 'hi';
+$phar['sub/top.txt'] = 'there';
+$phar['another.file.txt'] = 'wowee';
+$newphar = new Phar($fname);
+foreach (new RecursiveIteratorIterator($newphar) as $path => $obj) {
+ var_dump($obj->getPathName());
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php');
+__halt_compiler();
+?>
+--EXPECTF--
+string(%d) "phar://%sphar_dir_iterate.phar.php%canother.file.txt"
+string(%d) "phar://%sphar_dir_iterate.phar.php%csub%ctop.txt"
+string(%d) "phar://%sphar_dir_iterate.phar.php%ctop.txt"
+===DONE===
diff --git a/ext/phar/tests/phar_extract.phpt b/ext/phar/tests/phar_extract.phpt
new file mode 100644
index 0000000000..82e5f8d191
--- /dev/null
+++ b/ext/phar/tests/phar_extract.phpt
@@ -0,0 +1,131 @@
+--TEST--
+Phar: Phar::extractTo()
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/tempmanifest1.phar.php';
+$pname = 'phar://' . $fname;
+
+$a = new Phar($fname);
+$a['file1.txt'] = 'hi';
+$a['file2.txt'] = 'hi2';
+$a['subdir/ectory/file.txt'] = 'hi3';
+$a->mount($pname . '/mount', __FILE__);
+$a->addEmptyDir('one/level');
+
+$a->extractTo(dirname(__FILE__) . '/extract', 'mount');
+$a->extractTo(dirname(__FILE__) . '/extract');
+$out = array();
+foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator(dirname(__FILE__) . '/extract'), RecursiveIteratorIterator::CHILD_FIRST) as $p => $b) {
+ $out[] = $p;
+}
+sort($out);
+foreach ($out as $b) {
+echo "$b\n";
+}
+
+$a->extractTo(dirname(__FILE__) . '/extract1', 'file1.txt');
+var_dump(file_get_contents(dirname(__FILE__) . '/extract1/file1.txt'));
+$a->extractTo(dirname(__FILE__) . '/extract1', 'subdir/ectory/file.txt');
+var_dump(file_get_contents(dirname(__FILE__) . '/extract1/subdir/ectory/file.txt'));
+
+$a->extractTo(dirname(__FILE__) . '/extract2', array('file2.txt', 'one/level'));
+var_dump(file_get_contents(dirname(__FILE__) . '/extract2/file2.txt'));
+var_dump(is_dir(dirname(__FILE__) . '/extract2/one/level'));
+try {
+$a->extractTo(dirname(__FILE__) . '/whatever', 134);
+} catch (Exception $e) {
+echo $e->getMessage(), "\n";
+}
+$a->extractTo(array());
+try {
+$a->extractTo('');
+} catch (Exception $e) {
+echo $e->getMessage(), "\n";
+}
+file_put_contents(dirname(__FILE__) . '/oops', 'I is file');
+try {
+$a->extractTo(dirname(__FILE__) . '/oops', 'file1.txt');
+} catch (Exception $e) {
+echo $e->getMessage(), "\n";
+}
+try {
+$a->extractTo(dirname(__FILE__) . '/oops1', array(array(), 'file1.txt'));
+} catch (Exception $e) {
+echo $e->getMessage(), "\n";
+}
+try {
+$a->extractTo(dirname(__FILE__) . '/extract', 'file1.txt');
+} catch (Exception $e) {
+echo $e->getMessage(), "\n";
+}
+file_put_contents(dirname(__FILE__) . '/extract/file1.txt', 'first');
+var_dump(file_get_contents(dirname(__FILE__) . '/extract/file1.txt'));
+$a->extractTo(dirname(__FILE__) . '/extract', 'file1.txt', true);
+var_dump(file_get_contents(dirname(__FILE__) . '/extract/file1.txt'));
+try {
+$a->extractTo(str_repeat('a', 20000), 'file1.txt');
+} catch (Exception $e) {
+echo $e->getMessage(), "\n";
+}
+$a[str_repeat('a', 20000)] = 'long';
+try {
+$a->extractTo(dirname(__FILE__) . '/extract', str_repeat('a', 20000));
+} catch (Exception $e) {
+echo $e->getMessage(), "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+@rmdir(dirname(__FILE__) . '/whatever');
+@unlink(dirname(__FILE__) . '/oops');
+@rmdir(dirname(__FILE__) . '/oops1');
+@unlink(dirname(__FILE__) . '/tempmanifest1.phar.php');
+$e = dirname(__FILE__) . '/extract/';
+@unlink($e . 'file1.txt');
+@unlink($e . 'file2.txt');
+@unlink($e . 'subdir/ectory/file.txt');
+@rmdir($e . 'subdir/ectory');
+@rmdir($e . 'subdir');
+@rmdir($e . 'one/level');
+@rmdir($e . 'one');
+@rmdir($e);
+$e = dirname(__FILE__) . '/extract1/';
+@unlink($e . 'file1.txt');
+@unlink($e . 'subdir/ectory/file.txt');
+@rmdir($e . 'subdir/ectory');
+@rmdir($e . 'subdir');
+@rmdir($e);
+$e = dirname(__FILE__) . '/extract2/';
+@unlink($e . 'file2.txt');
+@rmdir($e . 'one/level');
+@rmdir($e . 'one');
+@rmdir($e);
+?>
+--EXPECTF--
+%sextract%cfile1.txt
+%sextract%cfile2.txt
+%sextract%cone
+%sextract%csubdir
+%sextract%csubdir%cectory
+%sextract%csubdir%cectory%cfile.txt
+string(2) "hi"
+string(3) "hi3"
+string(3) "hi2"
+bool(false)
+Invalid argument, expected a filename (string) or array of filenames
+
+Warning: Phar::extractTo() expects parameter 1 to be string, array given in %sphar_extract.php on line %d
+Invalid argument, extraction path must be non-zero length
+Unable to use path "%soops" for extraction, it is a file, must be a directory
+Invalid argument, array of filenames to extract contains non-string value
+Extraction from phar "%stempmanifest1.phar.php" failed: Cannot extract "file1.txt" to "%sextract/file1.txt", path already exists
+string(5) "first"
+string(2) "hi"
+Cannot extract to "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...", destination directory is too long for filesystem
+Extraction from phar "%stempmanifest1.phar.php" failed: Cannot extract "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa..." to "%s...", extracted filename is too long for filesystem
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/phar_get_supported_signatures_001.phpt b/ext/phar/tests/phar_get_supported_signatures_001.phpt
new file mode 100644
index 0000000000..f672c0024b
--- /dev/null
+++ b/ext/phar/tests/phar_get_supported_signatures_001.phpt
@@ -0,0 +1,22 @@
+--TEST--
+Phar::getSupportedSignatures()
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (extension_loaded("hash")) die("skip extension hash conflicts"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+var_dump(Phar::getSupportedSignatures());
+?>
+===DONE===
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ string(3) "MD5"
+ [1]=>
+ string(5) "SHA-1"
+}
+===DONE===
diff --git a/ext/phar/tests/phar_get_supported_signatures_002.phpt b/ext/phar/tests/phar_get_supported_signatures_002.phpt
new file mode 100644
index 0000000000..ba86947d5d
--- /dev/null
+++ b/ext/phar/tests/phar_get_supported_signatures_002.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Phar::getSupportedSignatures()
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("hash")) die("skip extension hash required"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+var_dump(Phar::getSupportedSignatures());
+?>
+===DONE===
+?>
+--EXPECT--
+array(4) {
+ [0]=>
+ string(3) "MD5"
+ [1]=>
+ string(5) "SHA-1"
+ [2]=>
+ string(7) "SHA-256"
+ [3]=>
+ string(7) "SHA-512"
+}
+===DONE===
diff --git a/ext/phar/tests/phar_get_supportedcomp1.phpt b/ext/phar/tests/phar_get_supportedcomp1.phpt
new file mode 100644
index 0000000000..d32e12c0ab
--- /dev/null
+++ b/ext/phar/tests/phar_get_supportedcomp1.phpt
@@ -0,0 +1,22 @@
+--TEST--
+Phar::getSupportedCompression() (bz2 and zlib)
+--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"); ?>
+<?php if (!extension_loaded("zlib")) die("skip zlib not available"); ?>
+--INI--
+phar.require_hash=0
+--FILE--
+<?php
+var_dump(Phar::getSupportedCompression());
+?>
+===DONE===
+--EXPECT--
+array(2) {
+ [0]=>
+ string(2) "GZ"
+ [1]=>
+ string(5) "BZIP2"
+}
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/phar_get_supportedcomp2.phpt b/ext/phar/tests/phar_get_supportedcomp2.phpt
new file mode 100644
index 0000000000..c607724918
--- /dev/null
+++ b/ext/phar/tests/phar_get_supportedcomp2.phpt
@@ -0,0 +1,20 @@
+--TEST--
+Phar::getSupportedCompression() (bz2 only)
+--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"); ?>
+<?php if (extension_loaded("zlib")) die("skip zlib is available"); ?>
+--INI--
+phar.require_hash=0
+--FILE--
+<?php
+var_dump(Phar::getSupportedCompression());
+?>
+===DONE===
+--EXPECT--
+array(1) {
+ [0]=>
+ string(5) "BZIP2"
+}
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/phar_get_supportedcomp3.phpt b/ext/phar/tests/phar_get_supportedcomp3.phpt
new file mode 100644
index 0000000000..c300407f3f
--- /dev/null
+++ b/ext/phar/tests/phar_get_supportedcomp3.phpt
@@ -0,0 +1,20 @@
+--TEST--
+Phar::getSupportedCompression() (zlib only)
+--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 is available"); ?>
+<?php if (!extension_loaded("zlib")) die("skip zlib not available"); ?>
+--INI--
+phar.require_hash=0
+--FILE--
+<?php
+var_dump(Phar::getSupportedCompression());
+?>
+===DONE===
+--EXPECT--
+array(1) {
+ [0]=>
+ string(2) "GZ"
+}
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/phar_get_supportedcomp4.phpt b/ext/phar/tests/phar_get_supportedcomp4.phpt
new file mode 100644
index 0000000000..fba2c71bfc
--- /dev/null
+++ b/ext/phar/tests/phar_get_supportedcomp4.phpt
@@ -0,0 +1,16 @@
+--TEST--
+Phar::getSupportedCompression() (none)
+--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 is available"); ?>
+<?php if (extension_loaded("zlib")) die("skip zlib is available"); ?>
+--FILE--
+<?php
+var_dump(Phar::getSupportedCompression());
+?>
+===DONE===
+--EXPECT--
+array(0) {
+}
+===DONE===
diff --git a/ext/phar/tests/phar_gobyebye.phpt b/ext/phar/tests/phar_gobyebye.phpt
new file mode 100644
index 0000000000..d55bef0c30
--- /dev/null
+++ b/ext/phar/tests/phar_gobyebye.phpt
@@ -0,0 +1,44 @@
+--TEST--
+Phar: test edge cases of intercepted functions when the underlying phar archive has been unlinkArchive()d
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+Phar::interceptFileFuncs();
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.php';
+$pname = 'phar://' . $fname;
+file_put_contents($fname2, '<?php Phar::unlinkArchive("' . addslashes($fname) . '");');
+file_put_contents($pname . '/foo/hi', '<?php
+include "' . addslashes($fname2) . '";
+readfile("foo/hi");
+fopen("foo/hi", "r");
+echo file_get_contents("foo/hi");
+var_dump(is_file("foo/hi"),is_link("foo/hi"),is_dir("foo/hi"),file_exists("foo/hi"),stat("foo/hi"));
+opendir("foo/hi");
+?>
+');
+include $pname . '/foo/hi';
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.php'); ?>
+--EXPECTF--
+Warning: readfile(foo/hi): failed to open stream: No such file or directory in phar://%sphar_gobyebye.phar.php/foo/hi on line %d
+
+Warning: fopen(foo/hi): failed to open stream: No such file or directory in phar://%sphar_gobyebye.phar.php/foo/hi on line %d
+
+Warning: file_get_contents(foo/hi): failed to open stream: No such file or directory in phar://%sphar_gobyebye.phar.php/foo/hi on line %d
+
+Warning: stat(): stat failed for foo/hi in phar://%sphar_gobyebye.phar.php/foo/hi on line %d
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+
+Warning: opendir(foo/hi): failed to open dir: No such file or directory in phar://%sphar_gobyebye.phar.php/foo/hi on line %d
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/phar_gzip.phpt b/ext/phar/tests/phar_gzip.phpt
new file mode 100644
index 0000000000..f472949c05
--- /dev/null
+++ b/ext/phar/tests/phar_gzip.phpt
@@ -0,0 +1,54 @@
+--TEST--
+Phar: gzipped phar
+--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"); ?>
+<?php if (version_compare(phpversion(), '5.2.6', '<')) die("skip zlib is buggy in PHP < 5.2.6"); ?>
+--INI--
+phar.readonly=0
+phar.require_hash=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/phar_gzip.phar';
+$pname = 'phar://' . $fname;
+$fname2 = dirname(__FILE__) . '/phar_gzip.2.phar';
+$pname2 = 'phar://' . $fname2;
+
+$file = '<?php
+Phar::mapPhar();
+var_dump("it worked");
+include "phar://" . __FILE__ . "/tar_004.php";
+__HALT_COMPILER();';
+
+$files = array();
+$files['tar_004.php'] = '<?php var_dump(__FILE__);';
+$files['internal/file/here'] = "hi there!\n";
+$files['internal/dir/'] = '';
+$files['dir/'] = '';
+$gzip = true;
+
+include 'files/phar_test.inc';
+
+include $fname;
+
+$a = new Phar($fname);
+$a['test'] = 'hi';
+copy($fname, $fname2);
+$a->setAlias('another');
+$b = new Phar($fname2);
+var_dump($b->isFileFormat(Phar::PHAR));
+var_dump($b->isCompressed() == Phar::GZ);
+?>
+===DONE===
+--CLEAN--
+<?php
+@unlink(dirname(__FILE__) . '/phar_gzip.phar');
+@unlink(dirname(__FILE__) . '/phar_gzip.2.phar');
+?>
+--EXPECTF--
+string(9) "it worked"
+string(%d) "phar://%sphar_gzip.phar/tar_004.php"
+bool(true)
+bool(true)
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/phar_isvalidpharfilename.phpt b/ext/phar/tests/phar_isvalidpharfilename.phpt
new file mode 100644
index 0000000000..9c953ee88a
--- /dev/null
+++ b/ext/phar/tests/phar_isvalidpharfilename.phpt
@@ -0,0 +1,140 @@
+--TEST--
+Phar: Phar::isValidPharFilename()
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");?>
+--INI--
+phar.readonly=1
+--FILE--
+<?php
+chdir(dirname(__FILE__));
+Phar::isValidPharFilename(array());
+echo "*\n";
+var_dump(Phar::isValidPharFilename('*'));
+var_dump(Phar::isValidPharFilename('*', true));
+var_dump(Phar::isValidPharFilename('*', false));
+
+echo "\nboo.phar\n";
+var_dump(Phar::isValidPharFilename('boo.phar'));
+var_dump(Phar::isValidPharFilename('boo.phar', true));
+var_dump(Phar::isValidPharFilename('boo.phar', false));
+
+echo "\nboo.tar\n";
+var_dump(Phar::isValidPharFilename('boo.tar'));
+var_dump(Phar::isValidPharFilename('boo.tar', true));
+var_dump(Phar::isValidPharFilename('boo.tar', false));
+
+echo "\nboo.phar.tar\n";
+var_dump(Phar::isValidPharFilename('boo.phar.tar'));
+var_dump(Phar::isValidPharFilename('boo.phar.tar', true));
+var_dump(Phar::isValidPharFilename('boo.phar.tar', false));
+
+mkdir(dirname(__FILE__) . '/.phar');
+
+echo "\n.phar/boo.tar\n";
+var_dump(Phar::isValidPharFilename('.phar/boo.tar'));
+var_dump(Phar::isValidPharFilename('.phar/boo.tar', true));
+var_dump(Phar::isValidPharFilename('.phar/boo.tar', false));
+
+echo "\n.phar.tar\n";
+var_dump(Phar::isValidPharFilename('.phar.tar'));
+var_dump(Phar::isValidPharFilename('.phar.tar', true));
+var_dump(Phar::isValidPharFilename('.phar.tar', false));
+
+echo "\n.phar.phar\n";
+var_dump(Phar::isValidPharFilename('.phar.phar'));
+var_dump(Phar::isValidPharFilename('.phar.phar', true));
+var_dump(Phar::isValidPharFilename('.phar.phar', false));
+
+echo "\n.phar.phart\n";
+var_dump(Phar::isValidPharFilename('.phar.phart'));
+var_dump(Phar::isValidPharFilename('.phar.phart', true));
+var_dump(Phar::isValidPharFilename('.phar.phart', false));
+
+echo "\nmy.pharmy\n";
+var_dump(Phar::isValidPharFilename('my.pharmy'));
+var_dump(Phar::isValidPharFilename('my.pharmy', true));
+var_dump(Phar::isValidPharFilename('my.pharmy', false));
+
+echo "\nphar.zip\n";
+var_dump(Phar::isValidPharFilename('phar.zip'));
+var_dump(Phar::isValidPharFilename('phar.zip', true));
+var_dump(Phar::isValidPharFilename('phar.zip', false));
+
+echo "\nphar.zip.phar\n";
+var_dump(Phar::isValidPharFilename('phar.zip.phar'));
+var_dump(Phar::isValidPharFilename('phar.zip.phar', true));
+var_dump(Phar::isValidPharFilename('phar.zip.phar', false));
+
+echo "\ndir.phar.php\n";
+var_dump(Phar::isValidPharFilename('dir.phar.php'));
+var_dump(Phar::isValidPharFilename('dir.phar.php', true));
+var_dump(Phar::isValidPharFilename('dir.phar.php', false));
+
+?>
+===DONE===
+--CLEAN--
+<?php
+rmdir(dirname(__FILE__) . '/.phar');
+--EXPECTF--
+Warning: Phar::isValidPharFilename() expects parameter 1 to be string, array given in %sphar_isvalidpharfilename.php on line %d
+*
+bool(false)
+bool(false)
+bool(false)
+
+boo.phar
+bool(true)
+bool(true)
+bool(false)
+
+boo.tar
+bool(false)
+bool(false)
+bool(true)
+
+boo.phar.tar
+bool(true)
+bool(true)
+bool(false)
+
+.phar/boo.tar
+bool(false)
+bool(false)
+bool(true)
+
+.phar.tar
+bool(false)
+bool(false)
+bool(true)
+
+.phar.phar
+bool(true)
+bool(true)
+bool(false)
+
+.phar.phart
+bool(false)
+bool(false)
+bool(true)
+
+my.pharmy
+bool(false)
+bool(false)
+bool(true)
+
+phar.zip
+bool(false)
+bool(false)
+bool(true)
+
+phar.zip.phar
+bool(true)
+bool(true)
+bool(false)
+
+dir.phar.php
+bool(true)
+bool(true)
+bool(false)
+===DONE===
+
diff --git a/ext/phar/tests/phar_magic.phpt b/ext/phar/tests/phar_magic.phpt
new file mode 100644
index 0000000000..f6a0a675ef
--- /dev/null
+++ b/ext/phar/tests/phar_magic.phpt
@@ -0,0 +1,31 @@
+--TEST--
+Phar: include/fopen magic
+--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.php';
+$p = new Phar($fname);
+$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
+set_include_path("phar://" . __FILE__);
+include "phar://" . __FILE__ . "/a";
+__HALT_COMPILER();');
+include $fname;
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php');
+__HALT_COMPILER();
+?>
+--EXPECTF--
+in b
+<?php include "b/c.php";
+in d
+===DONE===
diff --git a/ext/phar/tests/phar_metadata_read.phpt b/ext/phar/tests/phar_metadata_read.phpt
new file mode 100644
index 0000000000..bda411f740
--- /dev/null
+++ b/ext/phar/tests/phar_metadata_read.phpt
@@ -0,0 +1,95 @@
+--TEST--
+Phar with metadata (read)
+--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.php';
+$pname = 'phar://' . $fname;
+$file = "<?php __HALT_COMPILER(); ?>";
+
+$files = array();
+$pmeta = 'hi there';
+$files['a'] = array('cont' => 'a');
+$files['b'] = array('cont' => 'b');
+$files['c'] = array('cont' => 'c', 'meta' => array('hi', 'there'));
+$files['d'] = array('cont' => 'd', 'meta' => array('hi'=>'there','foo'=>'bar'));
+include 'files/phar_test.inc';
+
+foreach($files as $name => $cont) {
+ var_dump(file_get_contents($pname.'/'.$name));
+}
+
+$phar = new Phar($fname);
+var_dump($phar->hasMetaData());
+var_dump($phar->getMetaData());
+var_dump($phar->delMetaData());
+var_dump($phar->getMetaData());
+var_dump($phar->delMetaData());
+var_dump($phar->getMetaData());
+foreach($files as $name => $cont) {
+ echo " meta $name\n";
+ var_dump($phar[$name]->hasMetadata());
+ var_dump($phar[$name]->getMetadata());
+ var_dump($phar[$name]->delMetadata());
+ var_dump($phar[$name]->getMetadata());
+}
+
+unset($phar);
+
+foreach($files as $name => $cont) {
+ var_dump(file_get_contents($pname.'/'.$name));
+}
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECT--
+string(1) "a"
+string(1) "b"
+string(1) "c"
+string(1) "d"
+bool(true)
+string(8) "hi there"
+bool(true)
+NULL
+bool(true)
+NULL
+ meta a
+bool(false)
+NULL
+bool(true)
+NULL
+ meta b
+bool(false)
+NULL
+bool(true)
+NULL
+ meta c
+bool(true)
+array(2) {
+ [0]=>
+ string(2) "hi"
+ [1]=>
+ string(5) "there"
+}
+bool(true)
+NULL
+ meta d
+bool(true)
+array(2) {
+ ["hi"]=>
+ string(5) "there"
+ ["foo"]=>
+ string(3) "bar"
+}
+bool(true)
+NULL
+string(1) "a"
+string(1) "b"
+string(1) "c"
+string(1) "d"
+===DONE===
diff --git a/ext/phar/tests/phar_metadata_write.phpt b/ext/phar/tests/phar_metadata_write.phpt
new file mode 100644
index 0000000000..6df7ba4faf
--- /dev/null
+++ b/ext/phar/tests/phar_metadata_write.phpt
@@ -0,0 +1,71 @@
+--TEST--
+Phar with metadata (write)
+--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.php';
+$pname = 'phar://' . $fname;
+$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'));
+include 'files/phar_test.inc';
+
+foreach($files as $name => $cont) {
+ var_dump(file_get_contents($pname.'/'.$name));
+}
+
+$phar = new Phar($fname);
+var_dump($phar->getMetadata());
+$phar->setMetadata(array('my' => 'friend'));
+$phar->setMetadata(array('my' => 'friend'));
+var_dump($phar->getMetadata());
+$phar['a']->setMetadata(42);
+$phar['b']->setMetadata(NULL);
+$phar['c']->setMetadata(array(25, 'foo'=>'bar'));
+$phar['d']->setMetadata(true);
+
+foreach($files as $name => $cont) {
+ var_dump($phar[$name]->getMetadata());
+}
+
+unset($phar);
+
+foreach($files as $name => $cont) {
+ var_dump(file_get_contents($pname.'/'.$name));
+}
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECT--
+string(1) "a"
+string(1) "b"
+string(1) "c"
+string(1) "d"
+NULL
+array(1) {
+ ["my"]=>
+ string(6) "friend"
+}
+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"
+===DONE===
diff --git a/ext/phar/tests/phar_mount.phpt b/ext/phar/tests/phar_mount.phpt
new file mode 100644
index 0000000000..80f8cda389
--- /dev/null
+++ b/ext/phar/tests/phar_mount.phpt
@@ -0,0 +1,63 @@
+--TEST--
+Phar: Phar::mount
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar';
+
+$a = new Phar($fname);
+$a['index.php'] = '<?php
+Phar::mount("testit", "' . addslashes(__FILE__) . '");
+try {
+Phar::mount("testit", "' . addslashes(__FILE__) . '");
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+try {
+Phar::mount("' . addslashes($pname) . '/testit1", "' . addslashes(__FILE__) . '");
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+?>';
+$a->setStub('<?php
+set_include_path("phar://" . __FILE__);
+include "index.php";
+__HALT_COMPILER();');
+Phar::mount($pname . '/testit1', __FILE__);
+include $fname;
+// test copying of a phar with mounted entries
+$b = $a->convertToExecutable(Phar::TAR);
+$b->setStub('<?php
+set_include_path("phar://" . __FILE__);
+include "index.php";
+__HALT_COMPILER();');
+try {
+include $fname2;
+} catch (Exception $e) {
+echo $e->getMessage(),"\n";
+}
+try {
+Phar::mount($pname . '/oops', '/home/oops/../../etc/passwd:');
+} catch (Exception $e) {
+echo $e->getMessage(),"\n";
+}
+Phar::mount($pname . '/testit2', $pname . '/testit1');
+echo substr($a['testit2']->getContent(),0, 50),"\n";
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); ?>
+--EXPECTF--
+Mounting of testit to %sphar_mount.php within phar %sphar_mount.phar.php failed
+Can only mount internal paths within a phar archive, use a relative path instead of "phar://%sphar_mount.phar.php/testit1"
+Mounting of testit to %sphar_mount.php within phar %sphar_mount.phar.tar failed
+Mounting of /oops to /home/oops/../../etc/passwd: within phar %sphar_mount.phar.php failed
+<?php
+$fname = dirname(__FILE__) . '/' . basename(
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/phar_offset_get_error.phpt b/ext/phar/tests/phar_offset_get_error.phpt
new file mode 100755
index 0000000000..ad0223697d
--- /dev/null
+++ b/ext/phar/tests/phar_offset_get_error.phpt
@@ -0,0 +1,37 @@
+--TEST--
+Phar: ignore filenames starting with / on offsetSet
+--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.php';
+$pname = 'phar://'.$fname;
+$iname = '/file.txt';
+$ename = '/error/..';
+
+$p = new Phar($fname);
+$p[$iname] = "foobar\n";
+
+try
+{
+ $p[$ename] = "foobar\n";
+}
+catch(Exception $e)
+{
+ echo $e->getMessage() . "\n";
+}
+
+include($pname . $iname);
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECT--
+Entry /error/.. does not exist and cannot be created: phar error: invalid path "/error/.." contains upper directory reference
+foobar
+===DONE===
diff --git a/ext/phar/tests/phar_oo_001.phpt b/ext/phar/tests/phar_oo_001.phpt
new file mode 100755
index 0000000000..81d57d1bfc
--- /dev/null
+++ b/ext/phar/tests/phar_oo_001.phpt
@@ -0,0 +1,54 @@
+--TEST--
+Phar object: basics
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+
+require_once 'files/phar_oo_test.inc';
+
+$phar = new Phar($fname);
+var_dump($phar->getVersion());
+var_dump(count($phar));
+
+class MyPhar extends Phar
+{
+ function __construct()
+ {
+ }
+}
+
+try
+{
+ $phar = new MyPhar();
+ var_dump($phar->getVersion());
+}
+catch (BadMethodCallException $e)
+{
+ var_dump($e->getMessage());
+}
+try {
+ $phar = new Phar('test.phar');
+ $phar->__construct('oops');
+} catch (BadMethodCallException $e)
+{
+ var_dump($e->getMessage());
+}
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/files/phar_oo_test.phar.php');
+__halt_compiler();
+?>
+--EXPECT--
+string(5) "1.0.0"
+int(5)
+string(50) "Cannot call method on an uninitialized Phar object"
+string(29) "Cannot call constructor twice"
+===DONE===
diff --git a/ext/phar/tests/phar_oo_002.phpt b/ext/phar/tests/phar_oo_002.phpt
new file mode 100755
index 0000000000..9bb28689d9
--- /dev/null
+++ b/ext/phar/tests/phar_oo_002.phpt
@@ -0,0 +1,137 @@
+--TEST--
+Phar object: iterator & entries
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+--INI--
+phar.readonly=1
+phar.require_hash=0
+--FILE--
+<?php
+
+require_once 'files/phar_oo_test.inc';
+
+$phar = new Phar($fname);
+$phar->setInfoClass('SplFileInfo');
+foreach($phar as $name => $ent)
+{
+ var_dump(str_replace(str_replace('\\', '/', dirname(__FILE__)), '*', $name));
+ var_dump($ent->getFilename());
+ var_dump($ent->getSize());
+ var_dump($ent->getType());
+ var_dump($ent->isWritable());
+ var_dump($ent->isReadable());
+ var_dump($ent->isExecutable());
+ var_dump($ent->isFile());
+ var_dump($ent->isDir());
+ var_dump($ent->isLink());
+ var_dump($ent->getCTime());
+ var_dump($ent->getMTime());
+ var_dump($ent->getATime());
+}
+
+echo "==RECURSIVE==\n";
+
+$phar = new Phar($fname);
+foreach(new RecursiveIteratorIterator($phar) as $name => $ent)
+{
+ var_dump(str_replace(str_replace('\\', '/', dirname(__FILE__)), '*', $name));
+ var_dump(str_replace('\\', '/', $ent->getFilename()));
+ var_dump($ent->getCompressedSize());
+ var_dump($ent->isCRCChecked());
+ var_dump($ent->isCRCChecked() ? $ent->getCRC32() : NULL);
+ var_dump($ent->getPharFlags());
+}
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/files/phar_oo_test.phar.php');
+__halt_compiler();
+?>
+--EXPECTF--
+string(42) "phar://*/files/phar_oo_test.phar.php%ca.php"
+string(5) "a.php"
+int(32)
+string(4) "file"
+bool(false)
+bool(true)
+bool(false)
+bool(true)
+bool(false)
+bool(false)
+int(1141214400)
+int(1141214400)
+int(1141214400)
+string(38) "phar://*/files/phar_oo_test.phar.php%cb"
+string(1) "b"
+int(0)
+string(3) "dir"
+bool(false)
+bool(true)
+bool(false)
+bool(false)
+bool(true)
+bool(false)
+int(1141214400)
+int(1141214400)
+int(1141214400)
+string(42) "phar://*/files/phar_oo_test.phar.php%cb.php"
+string(5) "b.php"
+int(32)
+string(4) "file"
+bool(false)
+bool(true)
+bool(false)
+bool(true)
+bool(false)
+bool(false)
+int(1141214400)
+int(1141214400)
+int(1141214400)
+string(42) "phar://*/files/phar_oo_test.phar.php%ce.php"
+string(5) "e.php"
+int(32)
+string(4) "file"
+bool(false)
+bool(true)
+bool(false)
+bool(true)
+bool(false)
+bool(false)
+int(1141214400)
+int(1141214400)
+int(1141214400)
+==RECURSIVE==
+string(42) "phar://*/files/phar_oo_test.phar.php%ca.php"
+string(5) "a.php"
+int(32)
+bool(false)
+NULL
+int(0)
+string(44) "phar://*/files/phar_oo_test.phar.php%cb%cc.php"
+string(5) "c.php"
+int(34)
+bool(false)
+NULL
+int(0)
+string(44) "phar://*/files/phar_oo_test.phar.php%cb%cd.php"
+string(5) "d.php"
+int(34)
+bool(false)
+NULL
+int(0)
+string(42) "phar://*/files/phar_oo_test.phar.php%cb.php"
+string(5) "b.php"
+int(32)
+bool(false)
+NULL
+int(0)
+string(42) "phar://*/files/phar_oo_test.phar.php%ce.php"
+string(5) "e.php"
+int(32)
+bool(false)
+NULL
+int(0)
+===DONE===
diff --git a/ext/phar/tests/phar_oo_003.phpt b/ext/phar/tests/phar_oo_003.phpt
new file mode 100755
index 0000000000..9d24b1919b
--- /dev/null
+++ b/ext/phar/tests/phar_oo_003.phpt
@@ -0,0 +1,45 @@
+--TEST--
+Phar object: entry & openFile()
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+--INI--
+phar.require_hash=0
+--FILE--
+<?php
+
+require_once 'files/phar_oo_test.inc';
+
+$phar = new Phar($fname);
+$phar->setInfoClass();
+foreach($phar as $name => $ent)
+{
+ var_dump($ent->getFilename());
+ if ($ent->isDir()) {
+ var_dump('DIR');
+ } else {
+ var_dump($ent->openFile()->fgets());
+ include $ent->getPathName();
+ }
+}
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/files/phar_oo_test.phar.php');
+__halt_compiler();
+?>
+--EXPECT--
+string(5) "a.php"
+string(32) "<?php echo "This is a.php\n"; ?>"
+This is a.php
+string(1) "b"
+string(3) "DIR"
+string(5) "b.php"
+string(32) "<?php echo "This is b.php\n"; ?>"
+This is b.php
+string(5) "e.php"
+string(32) "<?php echo "This is e.php\n"; ?>"
+This is e.php
+===DONE===
diff --git a/ext/phar/tests/phar_oo_004.phpt b/ext/phar/tests/phar_oo_004.phpt
new file mode 100755
index 0000000000..4f72b3678d
--- /dev/null
+++ b/ext/phar/tests/phar_oo_004.phpt
@@ -0,0 +1,126 @@
+--TEST--
+Phar and DirectoryIterator
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+--INI--
+phar.require_hash=0
+--FILE--
+<?php
+
+require_once 'files/phar_oo_test.inc';
+
+$it = new DirectoryIterator('phar://'.$fname);
+
+foreach($it as $name => $ent)
+{
+ var_dump($name);
+ var_dump($ent->getFilename());
+ var_dump($ent->isDir());
+ var_dump($ent->isDot());
+}
+
+?>
+===MANUAL===
+<?php
+
+class MyDirectoryIterator extends DirectoryIterator
+{
+ function __construct($dir)
+ {
+ echo __METHOD__ . "\n";
+ parent::__construct($dir);
+ }
+
+ function rewind()
+ {
+ echo __METHOD__ . "\n";
+ parent::rewind();
+ }
+
+ function valid()
+ {
+ echo __METHOD__ . "\n";
+ return parent::valid();
+ }
+
+ function key()
+ {
+ echo __METHOD__ . "\n";
+ return parent::key();
+ }
+
+ function current()
+ {
+ echo __METHOD__ . "\n";
+ return parent::current();
+ }
+
+ function next()
+ {
+ echo __METHOD__ . "\n";
+ parent::next();
+ }
+}
+
+$it = new MyDirectoryIterator('phar://'.$fname);
+
+foreach($it as $name => $ent)
+{
+ var_dump($name);
+ var_dump($ent->getFilename());
+}
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/files/phar_oo_test.phar.php');
+__halt_compiler();
+?>
+--EXPECT--
+int(0)
+string(5) "a.php"
+bool(false)
+bool(false)
+int(1)
+string(1) "b"
+bool(true)
+bool(false)
+int(2)
+string(5) "b.php"
+bool(false)
+bool(false)
+int(3)
+string(5) "e.php"
+bool(false)
+bool(false)
+===MANUAL===
+MyDirectoryIterator::__construct
+MyDirectoryIterator::rewind
+MyDirectoryIterator::valid
+MyDirectoryIterator::current
+MyDirectoryIterator::key
+int(0)
+string(5) "a.php"
+MyDirectoryIterator::next
+MyDirectoryIterator::valid
+MyDirectoryIterator::current
+MyDirectoryIterator::key
+int(1)
+string(1) "b"
+MyDirectoryIterator::next
+MyDirectoryIterator::valid
+MyDirectoryIterator::current
+MyDirectoryIterator::key
+int(2)
+string(5) "b.php"
+MyDirectoryIterator::next
+MyDirectoryIterator::valid
+MyDirectoryIterator::current
+MyDirectoryIterator::key
+int(3)
+string(5) "e.php"
+MyDirectoryIterator::next
+MyDirectoryIterator::valid
+===DONE===
diff --git a/ext/phar/tests/phar_oo_005.phpt b/ext/phar/tests/phar_oo_005.phpt
new file mode 100755
index 0000000000..687cf59d07
--- /dev/null
+++ b/ext/phar/tests/phar_oo_005.phpt
@@ -0,0 +1,60 @@
+--TEST--
+Phar and RecursiveDirectoryIterator
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+--INI--
+phar.require_hash=0
+--FILE--
+<?php
+
+require_once 'files/phar_oo_test.inc';
+$fname = str_replace('\\', '/', $fname);
+
+$it = new RecursiveDirectoryIterator('phar://'.$fname);
+$it = new RecursiveIteratorIterator($it);
+
+foreach($it as $name => $ent)
+{
+ var_dump(str_replace(array('\\', $fname), array('/', '*'), $name));
+ var_dump(str_replace(array('\\', $fname), array('/', '*'), $ent->getPathname()));
+ var_dump(str_replace('\\', '/', $it->getSubPath()));
+ var_dump(str_replace('\\', '/', $it->getSubPathName()));
+ $sub = $it->getPathInfo();
+ var_dump(str_replace('\\', '/', $sub->getFilename()));
+}
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/files/phar_oo_test.phar.php');
+__halt_compiler();
+?>
+--EXPECT--
+string(14) "phar://*/a.php"
+string(14) "phar://*/a.php"
+string(0) ""
+string(5) "a.php"
+string(21) "phar_oo_test.phar.php"
+string(16) "phar://*/b/c.php"
+string(16) "phar://*/b/c.php"
+string(1) "b"
+string(7) "b/c.php"
+string(1) "b"
+string(16) "phar://*/b/d.php"
+string(16) "phar://*/b/d.php"
+string(1) "b"
+string(7) "b/d.php"
+string(1) "b"
+string(14) "phar://*/b.php"
+string(14) "phar://*/b.php"
+string(0) ""
+string(5) "b.php"
+string(21) "phar_oo_test.phar.php"
+string(14) "phar://*/e.php"
+string(14) "phar://*/e.php"
+string(0) ""
+string(5) "e.php"
+string(21) "phar_oo_test.phar.php"
+===DONE===
diff --git a/ext/phar/tests/phar_oo_006.phpt b/ext/phar/tests/phar_oo_006.phpt
new file mode 100755
index 0000000000..556c98ce0b
--- /dev/null
+++ b/ext/phar/tests/phar_oo_006.phpt
@@ -0,0 +1,52 @@
+--TEST--
+Phar object: array access
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+--INI--
+phar.require_hash=0
+--FILE--
+<?php
+
+require_once 'files/phar_oo_test.inc';
+
+class MyFile extends SplFileObject
+{
+ function __construct($what)
+ {
+ echo __METHOD__ . "($what)\n";
+ parent::__construct($what);
+ }
+}
+
+$phar = new Phar($fname);
+try
+{
+ $phar->setFileClass('SplFileInfo');
+}
+catch (UnexpectedValueException $e)
+{
+ echo $e->getMessage() . "\n";
+}
+$phar->setInfoClass('MyFile');
+
+echo $phar['a.php']->getFilename() . "\n";
+echo $phar['b/c.php']->getFilename() . "\n";
+echo $phar['b.php']->getFilename() . "\n";
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/files/phar_oo_test.phar.php');
+__halt_compiler();
+?>
+--EXPECTF--
+SplFileInfo::setFileClass() expects parameter 1 to be a class name derived from SplFileObject, 'SplFileInfo' given
+MyFile::__construct(phar://%s/a.php)
+a.php
+MyFile::__construct(phar://%s/b/c.php)
+c.php
+MyFile::__construct(phar://%s/b.php)
+b.php
+===DONE===
diff --git a/ext/phar/tests/phar_oo_007.phpt b/ext/phar/tests/phar_oo_007.phpt
new file mode 100755
index 0000000000..48807660ff
--- /dev/null
+++ b/ext/phar/tests/phar_oo_007.phpt
@@ -0,0 +1,87 @@
+--TEST--
+Phar object: access through SplFileObject
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+--INI--
+phar.require_hash=0
+--FILE--
+<?php
+
+require_once 'files/phar_oo_test.inc';
+
+class MyFile extends SplFileObject
+{
+ function __construct($name)
+ {
+ echo __METHOD__ . "(" . str_replace(str_replace('\\', '/', dirname(__FILE__)), '*', $name) . ")\n";
+ parent::__construct($name);
+ }
+}
+
+$phar = new Phar($fname);
+$phar->setInfoClass('MyFile');
+
+$f = $phar['a.php'];
+
+$s = $f->fstat();
+
+var_dump($s['atime']);
+var_dump($s['ctime']);
+var_dump($s['mtime']);
+
+var_dump($f->ftell());
+var_dump($f->eof());
+var_dump($f->fgets());
+var_dump($f->eof());
+var_dump($f->fseek(20));
+var_dump($f->ftell());
+var_dump($f->fgets());
+var_dump($f->rewind());
+var_dump($f->ftell());
+var_dump($f->fgets());
+var_dump($f->ftell());
+
+?>
+===AGAIN===
+<?php
+
+$f = $phar['a.php'];
+
+var_dump($f->ftell());
+var_dump($f->eof());
+var_dump($f->fgets());
+var_dump($f->eof());
+
+//unset($f); without unset we check for working refcounting
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/files/phar_oo_test.phar.php');
+__halt_compiler();
+?>
+--EXPECTF--
+MyFile::__construct(phar://*/files/phar_oo_test.phar.php/a.php)
+int(1141214400)
+int(1141214400)
+int(1141214400)
+int(0)
+bool(false)
+string(32) "<?php echo "This is a.php\n"; ?>"
+bool(true)
+int(0)
+int(20)
+string(12) "a.php\n"; ?>"
+NULL
+int(0)
+string(32) "<?php echo "This is a.php\n"; ?>"
+int(32)
+===AGAIN===
+MyFile::__construct(phar://*/files/phar_oo_test.phar.php/a.php)
+int(0)
+bool(false)
+string(32) "<?php echo "This is a.php\n"; ?>"
+bool(true)
+===DONE===
diff --git a/ext/phar/tests/phar_oo_008.phpt b/ext/phar/tests/phar_oo_008.phpt
new file mode 100755
index 0000000000..80d1ece0ca
--- /dev/null
+++ b/ext/phar/tests/phar_oo_008.phpt
@@ -0,0 +1,119 @@
+--TEST--
+Phar object: iterating via SplFileObject
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+--INI--
+phar.require_hash=0
+--FILE--
+<?php
+
+$pharconfig = 1;
+
+require_once 'files/phar_oo_test.inc';
+
+$phar = new Phar($fname);
+$phar->setInfoClass('SplFileObject');
+
+$f = $phar['a.csv'];
+echo "===1===\n";
+foreach($f as $k => $v)
+{
+ echo "$k=>$v\n";
+}
+
+$f->setFlags(SplFileObject::DROP_NEW_LINE);
+
+echo "===2===\n";
+foreach($f as $k => $v)
+{
+ echo "$k=>$v\n";
+}
+
+class MyCSVFile extends SplFileObject
+{
+ function current()
+ {
+ return parent::fgetcsv(',', '"');
+ }
+}
+
+$phar->setInfoClass('MyCSVFile');
+$v = $phar['a.csv'];
+
+echo "===3===\n";
+while(!$v->eof())
+{
+ echo $v->key() . "=>" . join('|',$v->fgetcsv()) . "\n";
+}
+
+echo "===4===\n";
+$v->rewind();
+while(!$v->eof())
+{
+ $l = $v->fgetcsv();
+ echo $v->key() . "=>" . join('|',$l) . "\n";
+}
+
+echo "===5===\n";
+foreach($v as $k => $d)
+{
+ echo "$k=>" . join('|',$d) . "\n";
+}
+
+class MyCSVFile2 extends SplFileObject
+{
+ function getCurrentLine()
+ {
+ echo __METHOD__ . "\n";
+ return parent::fgetcsv(',', '"');
+ }
+}
+
+$phar->setInfoClass('MyCSVFile2');
+$v = $phar['a.csv'];
+
+echo "===6===\n";
+foreach($v as $k => $d)
+{
+ echo "$k=>" . join('|',$d) . "\n";
+}
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/files/phar_oo_test.phar.php');
+__halt_compiler();
+?>
+--EXPECTF--
+===1===
+0=>1,2,3
+
+1=>2,a,b
+
+2=>3,"c","'e'"
+===2===
+0=>1,2,3
+1=>2,a,b
+2=>3,"c","'e'"
+===3===
+0=>1|2|3
+0=>2|a|b
+1=>3|c|'e'
+===4===
+0=>1|2|3
+1=>2|a|b
+2=>3|c|'e'
+===5===
+0=>1|2|3
+1=>2|a|b
+2=>3|c|'e'
+===6===
+MyCSVFile2::getCurrentLine
+1=>1|2|3
+MyCSVFile2::getCurrentLine
+3=>2|a|b
+MyCSVFile2::getCurrentLine
+5=>3|c|'e'
+===DONE===
diff --git a/ext/phar/tests/phar_oo_009.phpt b/ext/phar/tests/phar_oo_009.phpt
new file mode 100755
index 0000000000..6abd03ee30
--- /dev/null
+++ b/ext/phar/tests/phar_oo_009.phpt
@@ -0,0 +1,56 @@
+--TEST--
+Phar object: iterating via SplFileObject and reading csv
+--SKIPIF--
+<?php if (!extension_loaded('phar')) die('skip'); ?>
+<?php if (!defined('SplFileObject::READ_CSV') || !defined('SplFileObject::SKIP_EMPTY')) die('skip newer SPL version is required'); ?>
+--INI--
+phar.require_hash=0
+--FILE--
+<?php
+
+$pharconfig = 2;
+
+require_once 'files/phar_oo_test.inc';
+
+$phar = new Phar($fname);
+$phar->setInfoClass('SplFileObject');
+
+$f = $phar['a.csv'];
+$f->setFlags(SplFileObject::SKIP_EMPTY | SplFileObject::DROP_NEW_LINE);
+foreach($f as $k => $v)
+{
+ echo "$k=>$v\n";
+}
+
+?>
+===CSV===
+<?php
+
+$f->setFlags(SplFileObject::SKIP_EMPTY | SplFileObject::DROP_NEW_LINE | SplFileObject::READ_CSV);
+foreach($f as $k => $v)
+{
+ echo "$k=>" . join('|', $v) . "\n";
+}
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/files/phar_oo_test.phar.php');
+__halt_compiler();
+?>
+--EXPECTF--
+0=>1,2,3
+1=>2,a,b
+2=>3,"c","'e'"
+3=>4
+4=>5,5
+5=>7,777
+===CSV===
+0=>1|2|3
+1=>2|a|b
+2=>3|c|'e'
+3=>4
+4=>5|5
+6=>7|777
+===DONE===
diff --git a/ext/phar/tests/phar_oo_010.phpt b/ext/phar/tests/phar_oo_010.phpt
new file mode 100755
index 0000000000..4e4435a7bb
--- /dev/null
+++ b/ext/phar/tests/phar_oo_010.phpt
@@ -0,0 +1,55 @@
+--TEST--
+Phar object: ArrayAccess and isset
+--SKIPIF--
+<?php if (!extension_loaded('phar')) die('skip'); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+--INI--
+phar.require_hash=0
+--FILE--
+<?php
+
+$pharconfig = 0;
+
+require_once 'files/phar_oo_test.inc';
+
+$phar = new Phar($fname);
+
+var_dump(isset($phar['a.php']));
+var_dump(isset($phar['b.php']));
+var_dump(isset($phar['b/c.php']));
+var_dump(isset($phar['b/d.php']));
+var_dump(isset($phar['e.php']));
+
+?>
+===DIR===
+<?php
+var_dump(isset($phar['b']));
+?>
+===NA===
+<?php
+var_dump(isset($phar['a']));
+var_dump(isset($phar['b/c']));
+var_dump(isset($phar[12]));
+var_dump(isset($phar['b']));
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/files/phar_oo_test.phar.php');
+__halt_compiler();
+?>
+--EXPECTF--
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+===DIR===
+bool(false)
+===NA===
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+===DONE===
diff --git a/ext/phar/tests/phar_oo_011.phpt b/ext/phar/tests/phar_oo_011.phpt
new file mode 100644
index 0000000000..236009b7e4
--- /dev/null
+++ b/ext/phar/tests/phar_oo_011.phpt
@@ -0,0 +1,34 @@
+--TEST--
+Phar object: add file
+--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=0
+--FILE--
+<?php
+
+$pharconfig = 0;
+
+require_once 'files/phar_oo_test.inc';
+
+$phar = new Phar($fname);
+$phar->setInfoClass('SplFileObject');
+
+$phar['f.php'] = 'hi';
+var_dump(isset($phar['f.php']));
+echo $phar['f.php'];
+echo "\n";
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/files/phar_oo_test.phar.php');
+__halt_compiler();
+?>
+--EXPECT--
+bool(true)
+hi
+===DONE===
diff --git a/ext/phar/tests/phar_oo_011b.phpt b/ext/phar/tests/phar_oo_011b.phpt
new file mode 100755
index 0000000000..37a0e570a5
--- /dev/null
+++ b/ext/phar/tests/phar_oo_011b.phpt
@@ -0,0 +1,39 @@
+--TEST--
+Phar object: add file
+--SKIPIF--
+<?php if (!extension_loaded('phar')) die('skip'); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+--INI--
+phar.readonly=1
+phar.require_hash=0
+--FILE--
+<?php
+
+try
+{
+ $pharconfig = 0;
+
+ require_once 'files/phar_oo_test.inc';
+
+ $phar = new Phar($fname);
+
+ $phar['f.php'] = 'hi';
+ var_dump(isset($phar['f.php']));
+ echo $phar['f.php'];
+ echo "\n";
+}
+catch (BadMethodCallException $e)
+{
+ echo "Exception: " . $e->getMessage() . "\n";
+}
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/files/phar_oo_test.phar.php');
+__halt_compiler();
+?>
+--EXPECTF--
+Exception: Write operations disabled by INI setting
+===DONE===
diff --git a/ext/phar/tests/phar_oo_012.phpt b/ext/phar/tests/phar_oo_012.phpt
new file mode 100644
index 0000000000..e79ac0960e
--- /dev/null
+++ b/ext/phar/tests/phar_oo_012.phpt
@@ -0,0 +1,37 @@
+--TEST--
+Phar object: unset file
+--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=0
+--FILE--
+<?php
+
+$pharconfig = 0;
+
+require_once 'files/phar_oo_test.inc';
+
+$phar = new Phar($fname);
+$phar->setInfoClass('SplFileObject');
+
+$phar['f.php'] = 'hi';
+var_dump(isset($phar['f.php']));
+echo $phar['f.php'];
+echo "\n";
+unset($phar['f.php']);
+var_dump(isset($phar['f.php']));
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/files/phar_oo_test.phar.php');
+__halt_compiler();
+?>
+--EXPECT--
+bool(true)
+hi
+bool(false)
+===DONE===
diff --git a/ext/phar/tests/phar_oo_012_confirm.phpt b/ext/phar/tests/phar_oo_012_confirm.phpt
new file mode 100644
index 0000000000..58a3be87b3
--- /dev/null
+++ b/ext/phar/tests/phar_oo_012_confirm.phpt
@@ -0,0 +1,40 @@
+--TEST--
+Phar object: unset file (confirm disk file is changed)
+--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=0
+--FILE--
+<?php
+
+$pharconfig = 0;
+
+require_once 'files/phar_oo_test.inc';
+
+$phar = new Phar($fname);
+$phar->setInfoClass('SplFileObject');
+
+$phar['f.php'] = 'hi';
+var_dump(isset($phar['f.php']));
+echo $phar['f.php'];
+echo "\n";
+$md5 = md5_file($fname);
+unset($phar['f.php']);
+$md52 = md5_file($fname);
+if ($md5 == $md52) echo 'File on disk has not changed';
+var_dump(isset($phar['f.php']));
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/files/phar_oo_test.phar.php');
+__halt_compiler();
+?>
+--EXPECT--
+bool(true)
+hi
+bool(false)
+===DONE===
diff --git a/ext/phar/tests/phar_oo_012b.phpt b/ext/phar/tests/phar_oo_012b.phpt
new file mode 100755
index 0000000000..01cf776986
--- /dev/null
+++ b/ext/phar/tests/phar_oo_012b.phpt
@@ -0,0 +1,42 @@
+--TEST--
+Phar object: unset file
+--SKIPIF--
+<?php if (!extension_loaded('phar')) die('skip'); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+--INI--
+phar.readonly=1
+phar.require_hash=0
+--FILE--
+<?php
+
+try
+{
+ $pharconfig = 0;
+
+ require_once 'files/phar_oo_test.inc';
+
+ $phar = new Phar($fname);
+ $phar->setInfoClass('SplFileObject');
+
+ $phar['f.php'] = 'hi';
+ var_dump(isset($phar['f.php']));
+ echo $phar['f.php'];
+ echo "\n";
+ unset($phar['f.php']);
+ var_dump(isset($phar['f.php']));
+}
+catch (BadMethodCallException $e)
+{
+ echo "Exception: " . $e->getMessage() . "\n";
+}
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/files/phar_oo_test.phar.php');
+__halt_compiler();
+?>
+--EXPECTF--
+Exception: Write operations disabled by INI setting
+===DONE===
diff --git a/ext/phar/tests/phar_oo_compressallbz2.phpt b/ext/phar/tests/phar_oo_compressallbz2.phpt
new file mode 100644
index 0000000000..3f52227194
--- /dev/null
+++ b/ext/phar/tests/phar_oo_compressallbz2.phpt
@@ -0,0 +1,66 @@
+--TEST--
+Phar::compressFiles(Phar::BZ2)
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("bz2")) die("skip bz2 not present"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$file = '<?php __HALT_COMPILER(); ?>';
+
+$files = array();
+$files['a'] = 'a';
+$files['b'] = 'b';
+$files['c'] = 'c';
+
+include 'files/phar_test.inc';
+
+$phar = new Phar($fname);
+
+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 = new Phar($fname);
+$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));
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.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/phar_oo_compressallgz.phpt b/ext/phar/tests/phar_oo_compressallgz.phpt
new file mode 100644
index 0000000000..55e7435f95
--- /dev/null
+++ b/ext/phar/tests/phar_oo_compressallgz.phpt
@@ -0,0 +1,71 @@
+--TEST--
+Phar::compressFiles(Phar::GZ)
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zlib")) die("skip zlib not present"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$file = '<?php __HALT_COMPILER(); ?>';
+
+$files = array();
+$files['a'] = 'a';
+$files['b'] = 'b';
+$files['c'] = 'c';
+
+include 'files/phar_test.inc';
+
+$phar = new Phar($fname);
+
+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 = new Phar($fname);
+$phar->compressFiles(Phar::GZ);
+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));
+try {
+$phar->compressFiles(25);
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php');
+?>
+--EXPECTF--
+string(1) "a"
+bool(false)
+string(1) "b"
+bool(false)
+string(1) "c"
+bool(false)
+string(1) "a"
+bool(true)
+bool(false)
+string(1) "b"
+bool(true)
+bool(false)
+string(1) "c"
+bool(true)
+bool(false)
+Unknown compression specified, please pass one of Phar::GZ or Phar::BZ2
+===DONE===
diff --git a/ext/phar/tests/phar_oo_compressed_001.phpt b/ext/phar/tests/phar_oo_compressed_001.phpt
new file mode 100644
index 0000000000..af02012573
--- /dev/null
+++ b/ext/phar/tests/phar_oo_compressed_001.phpt
@@ -0,0 +1,68 @@
+--TEST--
+Phar: PharFileInfo::compress(Phar::GZ)
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zlib")) die("skip zlib not present"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$file = '<?php __HALT_COMPILER(); ?>';
+
+$files = array();
+$files['a'] = 'a';
+$files['b'] = 'b';
+$files['c'] = 'c';
+
+include 'files/phar_test.inc';
+
+$phar = new Phar($fname);
+
+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['a'] = 'new a';
+$phar['a']->decompress();
+$phar['b'] = 'new b';
+$phar['b']->compress(Phar::GZ);
+$phar['d'] = 'new d';
+
+$phar = new Phar($fname);
+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());
+var_dump(file_get_contents($pname . '/d'));
+var_dump($phar['d']->isCompressed());
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php');
+?>
+--EXPECTF--
+string(1) "a"
+bool(false)
+string(1) "b"
+bool(false)
+string(1) "c"
+bool(false)
+string(5) "new a"
+bool(false)
+string(5) "new b"
+bool(true)
+string(1) "c"
+bool(false)
+string(5) "new d"
+bool(false)
+===DONE===
diff --git a/ext/phar/tests/phar_oo_compressed_001b.phpt b/ext/phar/tests/phar_oo_compressed_001b.phpt
new file mode 100755
index 0000000000..6d4c732862
--- /dev/null
+++ b/ext/phar/tests/phar_oo_compressed_001b.phpt
@@ -0,0 +1,68 @@
+--TEST--
+Phar: PharFileInfo::compress(Phar::BZ2)
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("bz2")) die("skip bz2 not present"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$file = '<?php __HALT_COMPILER(); ?>';
+
+$files = array();
+$files['a'] = 'a';
+$files['b'] = 'b';
+$files['c'] = 'c';
+
+include 'files/phar_test.inc';
+
+$phar = new Phar($fname);
+
+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['a'] = 'new a';
+$phar['a']->decompress();
+$phar['b'] = 'new b';
+$phar['b']->compress(Phar::BZ2);
+$phar['d'] = 'new d';
+
+$phar = new Phar($fname);
+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());
+var_dump(file_get_contents($pname . '/d'));
+var_dump($phar['d']->isCompressed());
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php');
+?>
+--EXPECTF--
+string(1) "a"
+bool(false)
+string(1) "b"
+bool(false)
+string(1) "c"
+bool(false)
+string(5) "new a"
+bool(false)
+string(5) "new b"
+bool(true)
+string(1) "c"
+bool(false)
+string(5) "new d"
+bool(false)
+===DONE===
diff --git a/ext/phar/tests/phar_oo_compressed_002.phpt b/ext/phar/tests/phar_oo_compressed_002.phpt
new file mode 100755
index 0000000000..d03d6f1a98
--- /dev/null
+++ b/ext/phar/tests/phar_oo_compressed_002.phpt
@@ -0,0 +1,73 @@
+--TEST--
+Phar: context/compress=GZ
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zlib")) die("skip zlib not present"); ?>
+--INI--
+phar.readonly=0
+phar.require_hash=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$file = '<?php __HALT_COMPILER(); ?>';
+
+$files = array();
+$files['a'] = 'a';
+$files['b'] = 'b';
+$files['c'] = 'c';
+
+include 'files/phar_test.inc';
+
+$phar = new Phar($fname);
+
+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());
+
+$context = stream_context_create(array('phar'=>array('compress'=>Phar::GZ)));
+
+file_put_contents($pname . '/b', 'new b');
+file_put_contents($pname . '/c', 'new c', 0, $context);
+file_put_contents($pname . '/d', 'new d');
+file_put_contents($pname . '/e', 'new e', 0, $context);
+
+$phar = new Phar($fname);
+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());
+var_dump(file_get_contents($pname . '/d'));
+var_dump($phar['d']->isCompressed());
+var_dump(file_get_contents($pname . '/e'));
+var_dump($phar['e']->isCompressed());
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php');
+?>
+--EXPECTF--
+string(1) "a"
+bool(false)
+string(1) "b"
+bool(false)
+string(1) "c"
+bool(false)
+string(1) "a"
+bool(false)
+string(5) "new b"
+bool(false)
+string(5) "new c"
+bool(true)
+string(5) "new d"
+bool(false)
+string(5) "new e"
+bool(true)
+===DONE===
diff --git a/ext/phar/tests/phar_oo_compressed_002b.phpt b/ext/phar/tests/phar_oo_compressed_002b.phpt
new file mode 100755
index 0000000000..0e167012b7
--- /dev/null
+++ b/ext/phar/tests/phar_oo_compressed_002b.phpt
@@ -0,0 +1,73 @@
+--TEST--
+Phar: context/compress=BZip2
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("bz2")) die("skip bz2 not present"); ?>
+--INI--
+phar.readonly=0
+phar.require_hash=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$file = '<?php __HALT_COMPILER(); ?>';
+
+$files = array();
+$files['a'] = 'a';
+$files['b'] = 'b';
+$files['c'] = 'c';
+
+include 'files/phar_test.inc';
+
+$phar = new Phar($fname);
+
+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());
+
+$context = stream_context_create(array('phar'=>array('compress'=>Phar::BZ2)));
+
+file_put_contents($pname . '/b', 'new b');
+file_put_contents($pname . '/c', 'new c', 0, $context);
+file_put_contents($pname . '/d', 'new d');
+file_put_contents($pname . '/e', 'new e', 0, $context);
+
+$phar = new Phar($fname);
+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());
+var_dump(file_get_contents($pname . '/d'));
+var_dump($phar['d']->isCompressed());
+var_dump(file_get_contents($pname . '/e'));
+var_dump($phar['e']->isCompressed());
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php');
+?>
+--EXPECTF--
+string(1) "a"
+bool(false)
+string(1) "b"
+bool(false)
+string(1) "c"
+bool(false)
+string(1) "a"
+bool(false)
+string(5) "new b"
+bool(false)
+string(5) "new c"
+bool(true)
+string(5) "new d"
+bool(false)
+string(5) "new e"
+bool(true)
+===DONE===
diff --git a/ext/phar/tests/phar_oo_getcontents.phpt b/ext/phar/tests/phar_oo_getcontents.phpt
new file mode 100644
index 0000000000..e42bca46fc
--- /dev/null
+++ b/ext/phar/tests/phar_oo_getcontents.phpt
@@ -0,0 +1,39 @@
+--TEST--
+Phar object: getContent()
+--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.php';
+
+$phar = new Phar($fname);
+$phar['a/b'] = 'file contents
+this works';
+$phar->addEmptyDir('hi');
+echo $phar['a/b']->getContent() . "\n";
+try {
+echo $phar['a']->getContent(), "\n";
+} catch (Exception $e) {
+echo $e->getMessage(), "\n";
+}
+try {
+echo $phar['hi']->getContent(), "\n";
+} catch (Exception $e) {
+echo $e->getMessage(), "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php');
+__halt_compiler();
+?>
+--EXPECTF--
+file contents
+this works
+Phar error: Cannot retrieve contents, "a" in phar "%sphar_oo_getcontents.phar.php" is a directory
+Phar error: Cannot retrieve contents, "hi" in phar "%sphar_oo_getcontents.phar.php" is a directory
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/phar_oo_getcontentsgz.phpt b/ext/phar/tests/phar_oo_getcontentsgz.phpt
new file mode 100644
index 0000000000..a480a69637
--- /dev/null
+++ b/ext/phar/tests/phar_oo_getcontentsgz.phpt
@@ -0,0 +1,34 @@
+--TEST--
+Phar object: getContent() (verify it works with compression)
+--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"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.phar.php';
+
+$phar = new Phar($fname);
+$phar['a'] = 'file contents
+this works';
+$phar['a']->compress(Phar::GZ);
+copy($fname, $fname2);
+$phar2 = new Phar($fname2);
+var_dump($phar2['a']->isCompressed());
+echo $phar2['a']->getContent() . "\n";
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar.php');
+__halt_compiler();
+?>
+--EXPECT--
+bool(true)
+file contents
+this works
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/phar_oo_getmodified.phpt b/ext/phar/tests/phar_oo_getmodified.phpt
new file mode 100644
index 0000000000..d531393281
--- /dev/null
+++ b/ext/phar/tests/phar_oo_getmodified.phpt
@@ -0,0 +1,36 @@
+--TEST--
+Phar::getModified()
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zlib")) die("skip zlib not present"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$file = '<?php __HALT_COMPILER(); ?>';
+
+$files = array();
+$files['a'] = 'a';
+$files['b'] = 'b';
+$files['c'] = 'c';
+
+include 'files/phar_test.inc';
+
+$phar = new Phar($fname);
+var_dump($phar->getModified());
+$phar->compressFiles(Phar::GZ);
+var_dump($phar->getModified());
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php');
+?>
+--EXPECTF--
+bool(false)
+bool(true)
+===DONE===
diff --git a/ext/phar/tests/phar_oo_iswriteable.phpt b/ext/phar/tests/phar_oo_iswriteable.phpt
new file mode 100644
index 0000000000..9fbca2c9ea
--- /dev/null
+++ b/ext/phar/tests/phar_oo_iswriteable.phpt
@@ -0,0 +1,84 @@
+--TEST--
+Phar::isWriteable
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+phar.require_hash=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.1.phar.php';
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.tar';
+$pname = 'phar://hio';
+$file = '<?php include "' . $pname . '/a.php"; __HALT_COMPILER(); ?>';
+
+$files = array();
+$files['a.php'] = '<?php echo "This is a\n"; include "'.$pname.'/b.php"; ?>';
+$files['dir/'] = '';
+$hasdir = 1;
+include 'files/phar_test.inc';
+$a = new Phar($fname);
+$b = new PharData($fname2);
+$b['test'] = 'hi';
+
+var_dump($a['a.php']->isWritable());
+var_dump($a['a.php']->isReadable());
+$a['a.php']->chmod(000);
+var_dump($a['a.php']->isWritable());
+var_dump($a['a.php']->isReadable());
+$a['a.php']->chmod(0666);
+var_dump($a['a.php']->isWritable());
+var_dump($a['a.php']->isReadable());
+ini_set('phar.readonly',1);
+clearstatcache();
+var_dump($a['a.php']->isWritable());
+var_dump($a['a.php']->isReadable());
+ini_set('phar.readonly',0);
+clearstatcache();
+var_dump($a['a.php']->isWritable());
+var_dump($a['a.php']->isReadable());
+?>
+archive
+<?php
+ini_set('phar.readonly',0);
+$p = new Phar('doesnotexisthere.phar');
+var_dump($p->isWritable());
+clearstatcache();
+var_dump($a->isWritable());
+var_dump($b->isWritable());
+ini_set('phar.readonly',1);
+clearstatcache();
+var_dump($a->isWritable());
+var_dump($b->isWritable());
+chmod($fname2, 000);
+clearstatcache();
+var_dump($a->isWritable());
+var_dump($b->isWritable());
+chmod($fname2, 0666);
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.1.phar.php');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.tar');
+?>
+--EXPECT--
+bool(true)
+bool(true)
+bool(false)
+bool(false)
+bool(true)
+bool(true)
+bool(false)
+bool(true)
+bool(true)
+bool(true)
+archive
+bool(true)
+bool(true)
+bool(true)
+bool(false)
+bool(true)
+bool(false)
+bool(false)
+===DONE===
diff --git a/ext/phar/tests/phar_oo_nosig.phpt b/ext/phar/tests/phar_oo_nosig.phpt
new file mode 100644
index 0000000000..d99222e12c
--- /dev/null
+++ b/ext/phar/tests/phar_oo_nosig.phpt
@@ -0,0 +1,24 @@
+--TEST--
+Phar::getSignature() no signature
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+--INI--
+phar.require_hash=0
+--FILE--
+<?php
+
+require_once 'files/phar_oo_test.inc';
+
+$phar = new Phar($fname);
+var_dump($phar->getSignature());
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/files/phar_oo_test.phar.php');
+__halt_compiler();
+?>
+--EXPECT--
+bool(false)
+===DONE===
diff --git a/ext/phar/tests/phar_oo_uncompressall.phpt b/ext/phar/tests/phar_oo_uncompressall.phpt
new file mode 100644
index 0000000000..19cf953197
--- /dev/null
+++ b/ext/phar/tests/phar_oo_uncompressall.phpt
@@ -0,0 +1,80 @@
+--TEST--
+Phar::decompressFiles()
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zlib")) die("skip zlib not present"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$file = '<?php __HALT_COMPILER(); ?>';
+
+$files = array();
+$files['a'] = 'a';
+$files['b'] = 'b';
+$files['c'] = 'c';
+
+include 'files/phar_test.inc';
+
+$phar = new Phar($fname);
+
+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 = new Phar($fname);
+$phar->compressFiles(Phar::GZ);
+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->decompressFiles();
+var_dump(file_get_contents($pname . '/a'));
+var_dump($phar['a']->isCompressed());
+var_dump(file_get_contents($pname . '/b'));
+var_dump($phar['a']->isCompressed());
+var_dump(file_get_contents($pname . '/c'));
+var_dump($phar['a']->isCompressed());
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php');
+?>
+--EXPECTF--
+string(1) "a"
+bool(false)
+string(1) "b"
+bool(false)
+string(1) "c"
+bool(false)
+string(1) "a"
+bool(true)
+bool(false)
+string(1) "b"
+bool(true)
+bool(false)
+string(1) "c"
+bool(true)
+bool(false)
+string(1) "a"
+bool(false)
+string(1) "b"
+bool(false)
+string(1) "c"
+bool(false)
+===DONE===
diff --git a/ext/phar/tests/phar_running.phpt b/ext/phar/tests/phar_running.phpt
new file mode 100644
index 0000000000..2d132b9ac7
--- /dev/null
+++ b/ext/phar/tests/phar_running.phpt
@@ -0,0 +1,29 @@
+--TEST--
+Phar: Phar::running()
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+
+$phar = new Phar($fname);
+$phar['index.php'] = '<?php
+Phar::running(array());
+var_dump(Phar::running());
+var_dump(Phar::running(false));
+?>';
+include $pname . '/index.php';
+var_dump(Phar::running());
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECTF--
+Warning: Phar::running() expects parameter 1 to be boolean, array given in phar://%sphar_running.phar.php/index.php on line 2
+string(%d) "phar://%sphar_running.phar.php"
+string(%d) "%sphar_running.phar.php"
+string(0) ""
+===DONE===
diff --git a/ext/phar/tests/phar_setalias.phpt b/ext/phar/tests/phar_setalias.phpt
new file mode 100644
index 0000000000..ef9fa283d5
--- /dev/null
+++ b/ext/phar/tests/phar_setalias.phpt
@@ -0,0 +1,36 @@
+--TEST--
+Phar::setAlias()
+--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.php';
+$pname = 'phar://' . $fname;
+$file = '<?php echo "first stub\n"; __HALT_COMPILER(); ?>';
+
+$files = array();
+$files['a'] = 'a';
+$files['b'] = 'b';
+$files['c'] = 'c';
+
+include 'files/phar_test.inc';
+
+$phar = new Phar($fname);
+echo $phar->getAlias() . "\n";
+$phar->setAlias('test');
+echo $phar->getAlias() . "\n";
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phartmp.php');
+__HALT_COMPILER();
+?>
+--EXPECT--
+hio
+test
+===DONE===
diff --git a/ext/phar/tests/phar_setalias2.phpt b/ext/phar/tests/phar_setalias2.phpt
new file mode 100644
index 0000000000..901e4d2ebd
--- /dev/null
+++ b/ext/phar/tests/phar_setalias2.phpt
@@ -0,0 +1,51 @@
+--TEST--
+Phar::setAlias() error
+--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.php';
+$pname = 'phar://' . $fname;
+$file = '<?php echo "first stub\n"; __HALT_COMPILER(); ?>';
+
+$files = array();
+$files['a'] = 'a';
+$files['b'] = 'b';
+$files['c'] = 'c';
+
+include 'files/phar_test.inc';
+
+$phar = new Phar($fname);
+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";
+}
+try {
+ $b = new Phar(dirname(__FILE__) . '/nope.phar', 0, 'test');
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phartmp.php');
+unlink(dirname(__FILE__) . '/notphar.phar');
+__HALT_COMPILER();
+?>
+--EXPECTF--
+hio
+test
+alias "test" is already used for archive "%sphar_setalias2.phar.php" and cannot be used for other archives
+alias "test" is already used for archive "%sphar_setalias2.phar.php" cannot be overloaded with "%snope.phar"
+===DONE===
diff --git a/ext/phar/tests/phar_setdefaultstub.phpt b/ext/phar/tests/phar_setdefaultstub.phpt
new file mode 100644
index 0000000000..a36c005eac
--- /dev/null
+++ b/ext/phar/tests/phar_setdefaultstub.phpt
@@ -0,0 +1,944 @@
+--TEST--
+Phar: Phar::setDefaultStub() with and without arg
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar';
+
+$phar = new Phar($fname);
+$phar['a.php'] = '<php echo "this is a\n"; ?>';
+$phar['b.php'] = '<php echo "this is b\n"; ?>';
+$phar->setDefaultStub();
+$phar->stopBuffering();
+
+var_dump($phar->getStub());
+
+echo "============================================================================\n";
+echo "============================================================================\n";
+
+$phar->setDefaultStub('my/custom/thingy.php');
+$phar->stopBuffering();
+var_dump($phar->getStub());
+
+echo "============================================================================\n";
+echo "============================================================================\n";
+
+$phar->setDefaultStub('my/custom/thingy.php', 'the/web.php');
+$phar->stopBuffering();
+var_dump($phar->getStub());
+
+echo "============================================================================\n";
+echo "============================================================================\n";
+
+try {
+ $phar->setDefaultStub(str_repeat('a', 400));
+ $phar->stopBuffering();
+ var_dump(strlen($phar->getStub()));
+
+ $phar->setDefaultStub(str_repeat('a', 401));
+ $phar->stopBuffering();
+ var_dump(strlen($phar->getStub()));
+
+} catch(Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar');
+?>
+--EXPECT--
+string(6653) "<?php
+
+$web = 'index.php';
+
+if (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) {
+Phar::interceptFileFuncs();
+set_include_path('phar://' . __FILE__ . PATH_SEPARATOR . get_include_path());
+Phar::webPhar(null, $web);
+include 'phar://' . __FILE__ . '/' . Extract_Phar::START;
+return;
+}
+
+if (@(isset($_SERVER['REQUEST_URI']) && isset($_SERVER['REQUEST_METHOD']) && ($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'POST'))) {
+Extract_Phar::go(true);
+$mimes = array(
+'phps' => 2,
+'c' => 'text/plain',
+'cc' => 'text/plain',
+'cpp' => 'text/plain',
+'c++' => 'text/plain',
+'dtd' => 'text/plain',
+'h' => 'text/plain',
+'log' => 'text/plain',
+'rng' => 'text/plain',
+'txt' => 'text/plain',
+'xsd' => 'text/plain',
+'php' => 1,
+'inc' => 1,
+'avi' => 'video/avi',
+'bmp' => 'image/bmp',
+'css' => 'text/css',
+'gif' => 'image/gif',
+'htm' => 'text/html',
+'html' => 'text/html',
+'htmls' => 'text/html',
+'ico' => 'image/x-ico',
+'jpe' => 'image/jpeg',
+'jpg' => 'image/jpeg',
+'jpeg' => 'image/jpeg',
+'js' => 'application/x-javascript',
+'midi' => 'audio/midi',
+'mid' => 'audio/midi',
+'mod' => 'audio/mod',
+'mov' => 'movie/quicktime',
+'mp3' => 'audio/mp3',
+'mpg' => 'video/mpeg',
+'mpeg' => 'video/mpeg',
+'pdf' => 'application/pdf',
+'png' => 'image/png',
+'swf' => 'application/shockwave-flash',
+'tif' => 'image/tiff',
+'tiff' => 'image/tiff',
+'wav' => 'audio/wav',
+'xbm' => 'image/xbm',
+'xml' => 'text/xml',
+);
+
+header("Cache-Control: no-cache, must-revalidate");
+header("Pragma: no-cache");
+
+$basename = basename(__FILE__);
+if (!strpos($_SERVER['REQUEST_URI'], $basename)) {
+chdir(Extract_Phar::$temp);
+include $web;
+return;
+}
+$pt = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], $basename) + strlen($basename));
+if (!$pt || $pt == '/') {
+$pt = $web;
+header('HTTP/1.1 301 Moved Permanently');
+header('Location: ' . $_SERVER['REQUEST_URI'] . '/' . $pt);
+exit;
+}
+$a = realpath(Extract_Phar::$temp . DIRECTORY_SEPARATOR . $pt);
+if (!$a || strlen(dirname($a)) < strlen(Extract_Phar::$temp)) {
+header('HTTP/1.0 404 Not Found');
+echo "<html>\n <head>\n <title>File Not Found<title>\n </head>\n <body>\n <h1>404 - File ", $pt, " Not Found</h1>\n </body>\n</html>";
+exit;
+}
+$b = pathinfo($a);
+if (!isset($b['extension'])) {
+header('Content-Type: text/plain');
+header('Content-Length: ' . filesize($a));
+readfile($a);
+exit;
+}
+if (isset($mimes[$b['extension']])) {
+if ($mimes[$b['extension']] === 1) {
+include $a;
+exit;
+}
+if ($mimes[$b['extension']] === 2) {
+highlight_file($a);
+exit;
+}
+header('Content-Type: ' .$mimes[$b['extension']]);
+header('Content-Length: ' . filesize($a));
+readfile($a);
+exit;
+}
+}
+
+class Extract_Phar
+{
+static $temp;
+static $origdir;
+const GZ = 0x1000;
+const BZ2 = 0x2000;
+const MASK = 0x3000;
+const START = 'index.php';
+const LEN = 6653;
+
+static function go($return = false)
+{
+$fp = fopen(__FILE__, 'rb');
+fseek($fp, self::LEN);
+$L = unpack('V', $a = fread($fp, 4));
+$m = '';
+
+do {
+$read = 8192;
+if ($L[1] - strlen($m) < 8192) {
+$read = $L[1] - strlen($m);
+}
+$last = fread($fp, $read);
+$m .= $last;
+} while (strlen($last) && strlen($m) < $L[1]);
+
+if (strlen($m) < $L[1]) {
+die('ERROR: manifest length read was "' .
+strlen($m) .'" should be "' .
+$L[1] . '"');
+}
+
+$info = self::_unpack($m);
+$f = $info['c'];
+
+if ($f & self::GZ) {
+if (!function_exists('gzinflate')) {
+die('Error: zlib extension is not enabled -' .
+' gzinflate() function needed for zlib-compressed .phars');
+}
+}
+
+if ($f & self::BZ2) {
+if (!function_exists('bzdecompress')) {
+die('Error: bzip2 extension is not enabled -' .
+' bzdecompress() function needed for bz2-compressed .phars');
+}
+}
+
+$temp = self::tmpdir();
+
+if (!$temp || !is_writable($temp)) {
+$sessionpath = session_save_path();
+if (strpos ($sessionpath, ";") !== false)
+$sessionpath = substr ($sessionpath, strpos ($sessionpath, ";")+1);
+if (!file_exists($sessionpath) || !is_dir($sessionpath)) {
+die('Could not locate temporary directory to extract phar');
+}
+$temp = $sessionpath;
+}
+
+$temp .= '/pharextract/'.basename(__FILE__, '.phar');
+self::$temp = $temp;
+self::$origdir = getcwd();
+@mkdir($temp, 0777, true);
+$temp = realpath($temp);
+
+if (!file_exists($temp . DIRECTORY_SEPARATOR . md5_file(__FILE__))) {
+self::_removeTmpFiles($temp, getcwd());
+@mkdir($temp, 0777, true);
+@file_put_contents($temp . '/' . md5_file(__FILE__), '');
+
+foreach ($info['m'] as $path => $file) {
+$a = !file_exists(dirname($temp . '/' . $path));
+@mkdir(dirname($temp . '/' . $path), 0777, true);
+clearstatcache();
+
+if ($path[strlen($path) - 1] == '/') {
+@mkdir($temp . '/' . $path, 0777);
+} else {
+file_put_contents($temp . '/' . $path, self::extractFile($path, $file, $fp));
+@chmod($temp . '/' . $path, 0666);
+}
+}
+}
+
+chdir($temp);
+
+if (!$return) {
+include self::START;
+}
+}
+
+static function tmpdir()
+{
+if (strpos(PHP_OS, 'WIN') !== false) {
+if ($var = getenv('TMP') ? getenv('TMP') : getenv('TEMP')) {
+return $var;
+}
+if (is_dir('/temp') || mkdir('/temp')) {
+return realpath('/temp');
+}
+return false;
+}
+if ($var = getenv('TMPDIR')) {
+return $var;
+}
+return realpath('/tmp');
+}
+
+static function _unpack($m)
+{
+$info = unpack('V', substr($m, 0, 4));
+ $l = unpack('V', substr($m, 10, 4));
+$m = substr($m, 14 + $l[1]);
+$s = unpack('V', substr($m, 0, 4));
+$o = 0;
+$start = 4 + $s[1];
+$ret['c'] = 0;
+
+for ($i = 0; $i < $info[1]; $i++) {
+ $len = unpack('V', substr($m, $start, 4));
+$start += 4;
+ $savepath = substr($m, $start, $len[1]);
+$start += $len[1];
+ $ret['m'][$savepath] = array_values(unpack('Va/Vb/Vc/Vd/Ve/Vf', substr($m, $start, 24)));
+$ret['m'][$savepath][3] = sprintf('%u', $ret['m'][$savepath][3]
+& 0xffffffff);
+$ret['m'][$savepath][7] = $o;
+$o += $ret['m'][$savepath][2];
+$start += 24 + $ret['m'][$savepath][5];
+$ret['c'] |= $ret['m'][$savepath][4] & self::MASK;
+}
+return $ret;
+}
+
+static function extractFile($path, $entry, $fp)
+{
+$data = '';
+$c = $entry[2];
+
+while ($c) {
+if ($c < 8192) {
+$data .= @fread($fp, $c);
+$c = 0;
+} else {
+$c -= 8192;
+$data .= @fread($fp, 8192);
+}
+}
+
+if ($entry[4] & self::GZ) {
+$data = gzinflate($data);
+} elseif ($entry[4] & self::BZ2) {
+$data = bzdecompress($data);
+}
+
+if (strlen($data) != $entry[0]) {
+die("Invalid internal .phar file (size error " . strlen($data) . " != " .
+$stat[7] . ")");
+}
+
+if ($entry[3] != sprintf("%u", crc32($data) & 0xffffffff)) {
+die("Invalid internal .phar file (checksum error)");
+}
+
+return $data;
+}
+
+static function _removeTmpFiles($temp, $origdir)
+{
+chdir($temp);
+
+foreach (glob('*') as $f) {
+if (file_exists($f)) {
+is_dir($f) ? @rmdir($f) : @unlink($f);
+if (file_exists($f) && is_dir($f)) {
+self::_removeTmpFiles($f, getcwd());
+}
+}
+}
+
+@rmdir($temp);
+clearstatcache();
+chdir($origdir);
+}
+}
+
+Extract_Phar::go();
+__HALT_COMPILER(); ?>
+"
+============================================================================
+============================================================================
+string(6664) "<?php
+
+$web = 'index.php';
+
+if (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) {
+Phar::interceptFileFuncs();
+set_include_path('phar://' . __FILE__ . PATH_SEPARATOR . get_include_path());
+Phar::webPhar(null, $web);
+include 'phar://' . __FILE__ . '/' . Extract_Phar::START;
+return;
+}
+
+if (@(isset($_SERVER['REQUEST_URI']) && isset($_SERVER['REQUEST_METHOD']) && ($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'POST'))) {
+Extract_Phar::go(true);
+$mimes = array(
+'phps' => 2,
+'c' => 'text/plain',
+'cc' => 'text/plain',
+'cpp' => 'text/plain',
+'c++' => 'text/plain',
+'dtd' => 'text/plain',
+'h' => 'text/plain',
+'log' => 'text/plain',
+'rng' => 'text/plain',
+'txt' => 'text/plain',
+'xsd' => 'text/plain',
+'php' => 1,
+'inc' => 1,
+'avi' => 'video/avi',
+'bmp' => 'image/bmp',
+'css' => 'text/css',
+'gif' => 'image/gif',
+'htm' => 'text/html',
+'html' => 'text/html',
+'htmls' => 'text/html',
+'ico' => 'image/x-ico',
+'jpe' => 'image/jpeg',
+'jpg' => 'image/jpeg',
+'jpeg' => 'image/jpeg',
+'js' => 'application/x-javascript',
+'midi' => 'audio/midi',
+'mid' => 'audio/midi',
+'mod' => 'audio/mod',
+'mov' => 'movie/quicktime',
+'mp3' => 'audio/mp3',
+'mpg' => 'video/mpeg',
+'mpeg' => 'video/mpeg',
+'pdf' => 'application/pdf',
+'png' => 'image/png',
+'swf' => 'application/shockwave-flash',
+'tif' => 'image/tiff',
+'tiff' => 'image/tiff',
+'wav' => 'audio/wav',
+'xbm' => 'image/xbm',
+'xml' => 'text/xml',
+);
+
+header("Cache-Control: no-cache, must-revalidate");
+header("Pragma: no-cache");
+
+$basename = basename(__FILE__);
+if (!strpos($_SERVER['REQUEST_URI'], $basename)) {
+chdir(Extract_Phar::$temp);
+include $web;
+return;
+}
+$pt = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], $basename) + strlen($basename));
+if (!$pt || $pt == '/') {
+$pt = $web;
+header('HTTP/1.1 301 Moved Permanently');
+header('Location: ' . $_SERVER['REQUEST_URI'] . '/' . $pt);
+exit;
+}
+$a = realpath(Extract_Phar::$temp . DIRECTORY_SEPARATOR . $pt);
+if (!$a || strlen(dirname($a)) < strlen(Extract_Phar::$temp)) {
+header('HTTP/1.0 404 Not Found');
+echo "<html>\n <head>\n <title>File Not Found<title>\n </head>\n <body>\n <h1>404 - File ", $pt, " Not Found</h1>\n </body>\n</html>";
+exit;
+}
+$b = pathinfo($a);
+if (!isset($b['extension'])) {
+header('Content-Type: text/plain');
+header('Content-Length: ' . filesize($a));
+readfile($a);
+exit;
+}
+if (isset($mimes[$b['extension']])) {
+if ($mimes[$b['extension']] === 1) {
+include $a;
+exit;
+}
+if ($mimes[$b['extension']] === 2) {
+highlight_file($a);
+exit;
+}
+header('Content-Type: ' .$mimes[$b['extension']]);
+header('Content-Length: ' . filesize($a));
+readfile($a);
+exit;
+}
+}
+
+class Extract_Phar
+{
+static $temp;
+static $origdir;
+const GZ = 0x1000;
+const BZ2 = 0x2000;
+const MASK = 0x3000;
+const START = 'my/custom/thingy.php';
+const LEN = 6664;
+
+static function go($return = false)
+{
+$fp = fopen(__FILE__, 'rb');
+fseek($fp, self::LEN);
+$L = unpack('V', $a = fread($fp, 4));
+$m = '';
+
+do {
+$read = 8192;
+if ($L[1] - strlen($m) < 8192) {
+$read = $L[1] - strlen($m);
+}
+$last = fread($fp, $read);
+$m .= $last;
+} while (strlen($last) && strlen($m) < $L[1]);
+
+if (strlen($m) < $L[1]) {
+die('ERROR: manifest length read was "' .
+strlen($m) .'" should be "' .
+$L[1] . '"');
+}
+
+$info = self::_unpack($m);
+$f = $info['c'];
+
+if ($f & self::GZ) {
+if (!function_exists('gzinflate')) {
+die('Error: zlib extension is not enabled -' .
+' gzinflate() function needed for zlib-compressed .phars');
+}
+}
+
+if ($f & self::BZ2) {
+if (!function_exists('bzdecompress')) {
+die('Error: bzip2 extension is not enabled -' .
+' bzdecompress() function needed for bz2-compressed .phars');
+}
+}
+
+$temp = self::tmpdir();
+
+if (!$temp || !is_writable($temp)) {
+$sessionpath = session_save_path();
+if (strpos ($sessionpath, ";") !== false)
+$sessionpath = substr ($sessionpath, strpos ($sessionpath, ";")+1);
+if (!file_exists($sessionpath) || !is_dir($sessionpath)) {
+die('Could not locate temporary directory to extract phar');
+}
+$temp = $sessionpath;
+}
+
+$temp .= '/pharextract/'.basename(__FILE__, '.phar');
+self::$temp = $temp;
+self::$origdir = getcwd();
+@mkdir($temp, 0777, true);
+$temp = realpath($temp);
+
+if (!file_exists($temp . DIRECTORY_SEPARATOR . md5_file(__FILE__))) {
+self::_removeTmpFiles($temp, getcwd());
+@mkdir($temp, 0777, true);
+@file_put_contents($temp . '/' . md5_file(__FILE__), '');
+
+foreach ($info['m'] as $path => $file) {
+$a = !file_exists(dirname($temp . '/' . $path));
+@mkdir(dirname($temp . '/' . $path), 0777, true);
+clearstatcache();
+
+if ($path[strlen($path) - 1] == '/') {
+@mkdir($temp . '/' . $path, 0777);
+} else {
+file_put_contents($temp . '/' . $path, self::extractFile($path, $file, $fp));
+@chmod($temp . '/' . $path, 0666);
+}
+}
+}
+
+chdir($temp);
+
+if (!$return) {
+include self::START;
+}
+}
+
+static function tmpdir()
+{
+if (strpos(PHP_OS, 'WIN') !== false) {
+if ($var = getenv('TMP') ? getenv('TMP') : getenv('TEMP')) {
+return $var;
+}
+if (is_dir('/temp') || mkdir('/temp')) {
+return realpath('/temp');
+}
+return false;
+}
+if ($var = getenv('TMPDIR')) {
+return $var;
+}
+return realpath('/tmp');
+}
+
+static function _unpack($m)
+{
+$info = unpack('V', substr($m, 0, 4));
+ $l = unpack('V', substr($m, 10, 4));
+$m = substr($m, 14 + $l[1]);
+$s = unpack('V', substr($m, 0, 4));
+$o = 0;
+$start = 4 + $s[1];
+$ret['c'] = 0;
+
+for ($i = 0; $i < $info[1]; $i++) {
+ $len = unpack('V', substr($m, $start, 4));
+$start += 4;
+ $savepath = substr($m, $start, $len[1]);
+$start += $len[1];
+ $ret['m'][$savepath] = array_values(unpack('Va/Vb/Vc/Vd/Ve/Vf', substr($m, $start, 24)));
+$ret['m'][$savepath][3] = sprintf('%u', $ret['m'][$savepath][3]
+& 0xffffffff);
+$ret['m'][$savepath][7] = $o;
+$o += $ret['m'][$savepath][2];
+$start += 24 + $ret['m'][$savepath][5];
+$ret['c'] |= $ret['m'][$savepath][4] & self::MASK;
+}
+return $ret;
+}
+
+static function extractFile($path, $entry, $fp)
+{
+$data = '';
+$c = $entry[2];
+
+while ($c) {
+if ($c < 8192) {
+$data .= @fread($fp, $c);
+$c = 0;
+} else {
+$c -= 8192;
+$data .= @fread($fp, 8192);
+}
+}
+
+if ($entry[4] & self::GZ) {
+$data = gzinflate($data);
+} elseif ($entry[4] & self::BZ2) {
+$data = bzdecompress($data);
+}
+
+if (strlen($data) != $entry[0]) {
+die("Invalid internal .phar file (size error " . strlen($data) . " != " .
+$stat[7] . ")");
+}
+
+if ($entry[3] != sprintf("%u", crc32($data) & 0xffffffff)) {
+die("Invalid internal .phar file (checksum error)");
+}
+
+return $data;
+}
+
+static function _removeTmpFiles($temp, $origdir)
+{
+chdir($temp);
+
+foreach (glob('*') as $f) {
+if (file_exists($f)) {
+is_dir($f) ? @rmdir($f) : @unlink($f);
+if (file_exists($f) && is_dir($f)) {
+self::_removeTmpFiles($f, getcwd());
+}
+}
+}
+
+@rmdir($temp);
+clearstatcache();
+chdir($origdir);
+}
+}
+
+Extract_Phar::go();
+__HALT_COMPILER(); ?>
+"
+============================================================================
+============================================================================
+string(6666) "<?php
+
+$web = 'the/web.php';
+
+if (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) {
+Phar::interceptFileFuncs();
+set_include_path('phar://' . __FILE__ . PATH_SEPARATOR . get_include_path());
+Phar::webPhar(null, $web);
+include 'phar://' . __FILE__ . '/' . Extract_Phar::START;
+return;
+}
+
+if (@(isset($_SERVER['REQUEST_URI']) && isset($_SERVER['REQUEST_METHOD']) && ($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'POST'))) {
+Extract_Phar::go(true);
+$mimes = array(
+'phps' => 2,
+'c' => 'text/plain',
+'cc' => 'text/plain',
+'cpp' => 'text/plain',
+'c++' => 'text/plain',
+'dtd' => 'text/plain',
+'h' => 'text/plain',
+'log' => 'text/plain',
+'rng' => 'text/plain',
+'txt' => 'text/plain',
+'xsd' => 'text/plain',
+'php' => 1,
+'inc' => 1,
+'avi' => 'video/avi',
+'bmp' => 'image/bmp',
+'css' => 'text/css',
+'gif' => 'image/gif',
+'htm' => 'text/html',
+'html' => 'text/html',
+'htmls' => 'text/html',
+'ico' => 'image/x-ico',
+'jpe' => 'image/jpeg',
+'jpg' => 'image/jpeg',
+'jpeg' => 'image/jpeg',
+'js' => 'application/x-javascript',
+'midi' => 'audio/midi',
+'mid' => 'audio/midi',
+'mod' => 'audio/mod',
+'mov' => 'movie/quicktime',
+'mp3' => 'audio/mp3',
+'mpg' => 'video/mpeg',
+'mpeg' => 'video/mpeg',
+'pdf' => 'application/pdf',
+'png' => 'image/png',
+'swf' => 'application/shockwave-flash',
+'tif' => 'image/tiff',
+'tiff' => 'image/tiff',
+'wav' => 'audio/wav',
+'xbm' => 'image/xbm',
+'xml' => 'text/xml',
+);
+
+header("Cache-Control: no-cache, must-revalidate");
+header("Pragma: no-cache");
+
+$basename = basename(__FILE__);
+if (!strpos($_SERVER['REQUEST_URI'], $basename)) {
+chdir(Extract_Phar::$temp);
+include $web;
+return;
+}
+$pt = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], $basename) + strlen($basename));
+if (!$pt || $pt == '/') {
+$pt = $web;
+header('HTTP/1.1 301 Moved Permanently');
+header('Location: ' . $_SERVER['REQUEST_URI'] . '/' . $pt);
+exit;
+}
+$a = realpath(Extract_Phar::$temp . DIRECTORY_SEPARATOR . $pt);
+if (!$a || strlen(dirname($a)) < strlen(Extract_Phar::$temp)) {
+header('HTTP/1.0 404 Not Found');
+echo "<html>\n <head>\n <title>File Not Found<title>\n </head>\n <body>\n <h1>404 - File ", $pt, " Not Found</h1>\n </body>\n</html>";
+exit;
+}
+$b = pathinfo($a);
+if (!isset($b['extension'])) {
+header('Content-Type: text/plain');
+header('Content-Length: ' . filesize($a));
+readfile($a);
+exit;
+}
+if (isset($mimes[$b['extension']])) {
+if ($mimes[$b['extension']] === 1) {
+include $a;
+exit;
+}
+if ($mimes[$b['extension']] === 2) {
+highlight_file($a);
+exit;
+}
+header('Content-Type: ' .$mimes[$b['extension']]);
+header('Content-Length: ' . filesize($a));
+readfile($a);
+exit;
+}
+}
+
+class Extract_Phar
+{
+static $temp;
+static $origdir;
+const GZ = 0x1000;
+const BZ2 = 0x2000;
+const MASK = 0x3000;
+const START = 'my/custom/thingy.php';
+const LEN = 6666;
+
+static function go($return = false)
+{
+$fp = fopen(__FILE__, 'rb');
+fseek($fp, self::LEN);
+$L = unpack('V', $a = fread($fp, 4));
+$m = '';
+
+do {
+$read = 8192;
+if ($L[1] - strlen($m) < 8192) {
+$read = $L[1] - strlen($m);
+}
+$last = fread($fp, $read);
+$m .= $last;
+} while (strlen($last) && strlen($m) < $L[1]);
+
+if (strlen($m) < $L[1]) {
+die('ERROR: manifest length read was "' .
+strlen($m) .'" should be "' .
+$L[1] . '"');
+}
+
+$info = self::_unpack($m);
+$f = $info['c'];
+
+if ($f & self::GZ) {
+if (!function_exists('gzinflate')) {
+die('Error: zlib extension is not enabled -' .
+' gzinflate() function needed for zlib-compressed .phars');
+}
+}
+
+if ($f & self::BZ2) {
+if (!function_exists('bzdecompress')) {
+die('Error: bzip2 extension is not enabled -' .
+' bzdecompress() function needed for bz2-compressed .phars');
+}
+}
+
+$temp = self::tmpdir();
+
+if (!$temp || !is_writable($temp)) {
+$sessionpath = session_save_path();
+if (strpos ($sessionpath, ";") !== false)
+$sessionpath = substr ($sessionpath, strpos ($sessionpath, ";")+1);
+if (!file_exists($sessionpath) || !is_dir($sessionpath)) {
+die('Could not locate temporary directory to extract phar');
+}
+$temp = $sessionpath;
+}
+
+$temp .= '/pharextract/'.basename(__FILE__, '.phar');
+self::$temp = $temp;
+self::$origdir = getcwd();
+@mkdir($temp, 0777, true);
+$temp = realpath($temp);
+
+if (!file_exists($temp . DIRECTORY_SEPARATOR . md5_file(__FILE__))) {
+self::_removeTmpFiles($temp, getcwd());
+@mkdir($temp, 0777, true);
+@file_put_contents($temp . '/' . md5_file(__FILE__), '');
+
+foreach ($info['m'] as $path => $file) {
+$a = !file_exists(dirname($temp . '/' . $path));
+@mkdir(dirname($temp . '/' . $path), 0777, true);
+clearstatcache();
+
+if ($path[strlen($path) - 1] == '/') {
+@mkdir($temp . '/' . $path, 0777);
+} else {
+file_put_contents($temp . '/' . $path, self::extractFile($path, $file, $fp));
+@chmod($temp . '/' . $path, 0666);
+}
+}
+}
+
+chdir($temp);
+
+if (!$return) {
+include self::START;
+}
+}
+
+static function tmpdir()
+{
+if (strpos(PHP_OS, 'WIN') !== false) {
+if ($var = getenv('TMP') ? getenv('TMP') : getenv('TEMP')) {
+return $var;
+}
+if (is_dir('/temp') || mkdir('/temp')) {
+return realpath('/temp');
+}
+return false;
+}
+if ($var = getenv('TMPDIR')) {
+return $var;
+}
+return realpath('/tmp');
+}
+
+static function _unpack($m)
+{
+$info = unpack('V', substr($m, 0, 4));
+ $l = unpack('V', substr($m, 10, 4));
+$m = substr($m, 14 + $l[1]);
+$s = unpack('V', substr($m, 0, 4));
+$o = 0;
+$start = 4 + $s[1];
+$ret['c'] = 0;
+
+for ($i = 0; $i < $info[1]; $i++) {
+ $len = unpack('V', substr($m, $start, 4));
+$start += 4;
+ $savepath = substr($m, $start, $len[1]);
+$start += $len[1];
+ $ret['m'][$savepath] = array_values(unpack('Va/Vb/Vc/Vd/Ve/Vf', substr($m, $start, 24)));
+$ret['m'][$savepath][3] = sprintf('%u', $ret['m'][$savepath][3]
+& 0xffffffff);
+$ret['m'][$savepath][7] = $o;
+$o += $ret['m'][$savepath][2];
+$start += 24 + $ret['m'][$savepath][5];
+$ret['c'] |= $ret['m'][$savepath][4] & self::MASK;
+}
+return $ret;
+}
+
+static function extractFile($path, $entry, $fp)
+{
+$data = '';
+$c = $entry[2];
+
+while ($c) {
+if ($c < 8192) {
+$data .= @fread($fp, $c);
+$c = 0;
+} else {
+$c -= 8192;
+$data .= @fread($fp, 8192);
+}
+}
+
+if ($entry[4] & self::GZ) {
+$data = gzinflate($data);
+} elseif ($entry[4] & self::BZ2) {
+$data = bzdecompress($data);
+}
+
+if (strlen($data) != $entry[0]) {
+die("Invalid internal .phar file (size error " . strlen($data) . " != " .
+$stat[7] . ")");
+}
+
+if ($entry[3] != sprintf("%u", crc32($data) & 0xffffffff)) {
+die("Invalid internal .phar file (checksum error)");
+}
+
+return $data;
+}
+
+static function _removeTmpFiles($temp, $origdir)
+{
+chdir($temp);
+
+foreach (glob('*') as $f) {
+if (file_exists($f)) {
+is_dir($f) ? @rmdir($f) : @unlink($f);
+if (file_exists($f) && is_dir($f)) {
+self::_removeTmpFiles($f, getcwd());
+}
+}
+}
+
+@rmdir($temp);
+clearstatcache();
+chdir($origdir);
+}
+}
+
+Extract_Phar::go();
+__HALT_COMPILER(); ?>
+"
+============================================================================
+============================================================================
+int(7044)
+Illegal filename passed in for stub creation, was 401 characters long, and only 400 or less is allowed
+===DONE===
diff --git a/ext/phar/tests/phar_setsignaturealgo1.phpt b/ext/phar/tests/phar_setsignaturealgo1.phpt
new file mode 100644
index 0000000000..edc032e7be
--- /dev/null
+++ b/ext/phar/tests/phar_setsignaturealgo1.phpt
@@ -0,0 +1,69 @@
+--TEST--
+Phar::setSignatureAlgorithm()
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if ( extension_loaded("hash")) die("skip extension hash conflicts"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+$p = new Phar(dirname(__FILE__) . '/brandnewphar.phar', 0, 'brandnewphar.phar');
+$p['file1.txt'] = 'hi';
+var_dump($p->getSignature());
+$p->setSignatureAlgorithm(Phar::MD5);
+var_dump($p->getSignature());
+$p->setSignatureAlgorithm(Phar::SHA1);
+var_dump($p->getSignature());
+try {
+$p->setSignatureAlgorithm(Phar::SHA256);
+var_dump($p->getSignature());
+} catch (Exception $e) {
+echo $e->getMessage();
+}
+try {
+$p->setSignatureAlgorithm(Phar::SHA512);
+var_dump($p->getSignature());
+} catch (Exception $e) {
+echo $e->getMessage();
+}
+try {
+$p->setSignatureAlgorithm(Phar::PGP);
+var_dump($p->getSignature());
+} catch (Exception $e) {
+echo $e->getMessage();
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/brandnewphar.phar');
+?>
+--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"
+}
+string (82) "SHA-256 and SHA-512 signatures are only supported if the hash extension is enabled"
+string (82) "SHA-256 and SHA-512 signatures are only supported if the hash extension is enabled"
+array(2) {
+ ["hash"]=>
+ string(%d) "%s"
+ ["hash_type"]=>
+ string(5) "SHA-1"
+}
+===DONE===
diff --git a/ext/phar/tests/phar_setsignaturealgo2.phpt b/ext/phar/tests/phar_setsignaturealgo2.phpt
new file mode 100644
index 0000000000..cc83281b22
--- /dev/null
+++ b/ext/phar/tests/phar_setsignaturealgo2.phpt
@@ -0,0 +1,79 @@
+--TEST--
+Phar::setSupportedSignatures() with hash
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("hash")) die("skip extension hash required"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+$p = new Phar(dirname(__FILE__) . '/brandnewphar.phar', 0, 'brandnewphar.phar');
+$p['file1.txt'] = 'hi';
+var_dump($p->getSignature());
+$p->setSignatureAlgorithm(Phar::MD5);
+var_dump($p->getSignature());
+$p->setSignatureAlgorithm(Phar::SHA1);
+var_dump($p->getSignature());
+try {
+$p->setSignatureAlgorithm(Phar::SHA256);
+var_dump($p->getSignature());
+} catch (Exception $e) {
+echo $e->getMessage();
+}
+try {
+$p->setSignatureAlgorithm(Phar::SHA512);
+var_dump($p->getSignature());
+} catch (Exception $e) {
+echo $e->getMessage();
+}
+try {
+$p->setSignatureAlgorithm(Phar::PGP);
+var_dump($p->getSignature());
+} catch (Exception $e) {
+echo $e->getMessage();
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/brandnewphar.phar');
+?>
+--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(5) "SHA-1"
+}
+===DONE===
diff --git a/ext/phar/tests/phar_stub.phpt b/ext/phar/tests/phar_stub.phpt
new file mode 100644
index 0000000000..ed306816e2
--- /dev/null
+++ b/ext/phar/tests/phar_stub.phpt
@@ -0,0 +1,92 @@
+--TEST--
+Phar::setStub()
+--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.php';
+$pname = 'phar://' . $fname;
+$file = '<?php echo "first stub\n"; __HALT_COMPILER(); ?>';
+
+$files = array();
+$files['a'] = 'a';
+$files['b'] = 'b';
+$files['c'] = 'c';
+
+include 'files/phar_test.inc';
+
+$file = '<?php echo "first stub\n"; __HALT_COMPILER(); ?>';
+$fp = fopen($fname, 'rb');
+//// 1
+echo fread($fp, strlen($file)) . "\n";
+fclose($fp);
+$phar = new Phar($fname);
+$file = '<?php echo "second stub\n"; __HALT_COMPILER(); ?>';
+
+//// 2
+$phar->setStub($file);
+$fp = fopen($fname, 'rb');
+echo fread($fp, strlen($file)) . "\n";
+fclose($fp);
+
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phartmp.php';
+$file = '<?php echo "third stub\n"; __HALT_COMPILER(); ?>';
+$fp = fopen($fname2, 'wb');
+fwrite($fp, $file);
+fclose($fp);
+$fp = fopen($fname2, 'rb');
+
+//// 3
+$phar->setStub($fp);
+fclose($fp);
+
+$fp = fopen($fname, 'rb');
+echo fread($fp, strlen($file)) . "\n";
+fclose($fp);
+
+$fp = fopen($fname2, 'ab');
+fwrite($fp, 'booya');
+fclose($fp);
+echo file_get_contents($fname2) . "\n";
+
+$fp = fopen($fname2, 'rb');
+
+//// 4
+$phar->setStub($fp, strlen($file));
+fclose($fp);
+
+$fp = fopen($fname, 'rb');
+echo fread($fp, strlen($file)) . "\n";
+if (fread($fp, strlen('booya')) == 'booya') {
+ echo 'failed - copied booya';
+}
+fclose($fp);
+$phar['testing'] = 'hi';
+
+// ensure stub is not overwritten
+$fp = fopen($fname, 'rb');
+echo fread($fp, strlen($file)) . "\n";
+if (fread($fp, strlen('booya')) == 'booya') {
+ echo 'failed - copied booya';
+}
+fclose($fp);
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.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/phar_stub_error.phpt b/ext/phar/tests/phar_stub_error.phpt
new file mode 100755
index 0000000000..99f313bc2f
--- /dev/null
+++ b/ext/phar/tests/phar_stub_error.phpt
@@ -0,0 +1,56 @@
+--TEST--
+Phar::setStub()/getStub()
+--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.php';
+$pname = 'phar://' . $fname;
+$stub = '<?php echo "first stub\n"; __HALT_COMPILER(); ?>';
+$file = $stub;
+
+$files = array();
+$files['a'] = 'a';
+
+include 'files/phar_test.inc';
+
+$phar = new Phar($fname);
+var_dump($stub);
+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.php');
+__HALT_COMPILER();
+?>
+--EXPECTF--
+string(48) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>"
+string(48) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>"
+bool(true)
+Exception: illegal stub for phar "%sphar_stub_error.phar.php"
+string(48) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>"
+bool(true)
+string(48) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>"
+bool(true)
+===DONE===
diff --git a/ext/phar/tests/phar_stub_write.phpt b/ext/phar/tests/phar_stub_write.phpt
new file mode 100755
index 0000000000..9e5d6d5635
--- /dev/null
+++ b/ext/phar/tests/phar_stub_write.phpt
@@ -0,0 +1,64 @@
+--TEST--
+Phar::setStub()/getStub()
+--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.php';
+$pname = 'phar://' . $fname;
+$stub = '<?php echo "first stub\n"; __HALT_COMPILER(); ?>';
+$file = $stub;
+
+$files = array();
+$files['a'] = 'a';
+$files['b'] = 'b';
+$files['c'] = 'c';
+
+include 'files/phar_test.inc';
+
+$phar = new Phar($fname);
+var_dump($stub);
+var_dump($phar->getStub());
+var_dump($phar->getStub() == $stub);
+
+$stub = '<?php echo "second stub\n"; __HALT_COMPILER(); ?>';
+$sexp = $stub . "\r\n";
+
+$phar->setStub($stub);
+var_dump($phar->getStub());
+var_dump($phar->getStub() == $stub);
+var_dump($phar->getStub() == $sexp);
+$phar->stopBuffering();
+var_dump($phar->getStub());
+var_dump($phar->getStub() == $stub);
+var_dump($phar->getStub() == $sexp);
+
+$phar = new Phar($fname);
+var_dump($phar->getStub() == $stub);
+var_dump($phar->getStub() == $sexp);
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php');
+__HALT_COMPILER();
+?>
+--EXPECT--
+string(48) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>"
+string(48) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>"
+bool(true)
+string(51) "<?php echo "second stub\n"; __HALT_COMPILER(); ?>
+"
+bool(false)
+bool(true)
+string(51) "<?php echo "second stub\n"; __HALT_COMPILER(); ?>
+"
+bool(false)
+bool(true)
+bool(false)
+bool(true)
+===DONE===
diff --git a/ext/phar/tests/phar_stub_write_file.phpt b/ext/phar/tests/phar_stub_write_file.phpt
new file mode 100755
index 0000000000..c5a0a1eba9
--- /dev/null
+++ b/ext/phar/tests/phar_stub_write_file.phpt
@@ -0,0 +1,65 @@
+--TEST--
+Phar::setStub()/getStub() from file
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+allow_url_fopen=1
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$stub = '<?php echo "first stub\n"; __HALT_COMPILER(); ?>';
+$file = $stub;
+
+$files = array();
+$files['a'] = 'a';
+$files['b'] = 'b';
+$files['c'] = 'c';
+
+include 'files/phar_test.inc';
+
+$phar = new Phar($fname);
+var_dump($stub);
+var_dump($phar->getStub());
+var_dump($phar->getStub() == $stub);
+
+$stub = '<?php echo "second stub\n"; __HALT_COMPILER(); ?>';
+$sexp = $stub . "\r\n";
+$stub = fopen('data://,'.$stub, 'r');
+$phar->setStub($stub);
+var_dump($phar->getStub());
+var_dump($phar->getStub() == $stub);
+var_dump($phar->getStub() == $sexp);
+$phar->stopBuffering();
+var_dump($phar->getStub());
+var_dump($phar->getStub() == $stub);
+var_dump($phar->getStub() == $sexp);
+
+$phar = new Phar($fname);
+var_dump($phar->getStub() == $stub);
+var_dump($phar->getStub() == $sexp);
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php');
+__HALT_COMPILER();
+?>
+--EXPECT--
+string(48) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>"
+string(48) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>"
+bool(true)
+string(51) "<?php echo "second stub\n"; __HALT_COMPILER(); ?>
+"
+bool(false)
+bool(true)
+string(51) "<?php echo "second stub\n"; __HALT_COMPILER(); ?>
+"
+bool(false)
+bool(true)
+bool(false)
+bool(true)
+===DONE===
diff --git a/ext/phar/tests/phar_unlinkarchive.phpt b/ext/phar/tests/phar_unlinkarchive.phpt
new file mode 100644
index 0000000000..910ef873d2
--- /dev/null
+++ b/ext/phar/tests/phar_unlinkarchive.phpt
@@ -0,0 +1,108 @@
+--TEST--
+Phar::unlinkArchive()
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+
+try {
+Phar::unlinkArchive("");
+} catch (Exception $e) {
+echo $e->getMessage(),"\n";
+}
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar';
+$pdname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar';
+
+try {
+Phar::unlinkArchive($fname);
+} catch (Exception $e) {
+echo $e->getMessage(),"\n";
+}
+file_put_contents($pdname, 'blahblah');
+try {
+Phar::unlinkArchive($pdname);
+} catch (Exception $e) {
+echo $e->getMessage(),"\n";
+}
+Phar::unlinkArchive(array());
+
+$pname = 'phar://' . $fname;
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip';
+$fname3 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.phar.zip';
+$stub = '<?php echo "first stub\n"; __HALT_COMPILER(); ?>';
+$file = $stub;
+
+$files = array();
+$files['a'] = 'a';
+$files['b'] = 'b';
+$files['c'] = 'c';
+
+include 'files/phar_test.inc';
+
+$phar = new Phar($fname);
+var_dump($phar->isFileFormat(Phar::ZIP));
+var_dump($phar->getStub());
+try {
+Phar::unlinkArchive($fname);
+} catch (Exception $e) {
+echo $e->getMessage(),"\n";
+}
+$phar = $phar->convertToExecutable(Phar::ZIP);
+var_dump($phar->isFileFormat(Phar::ZIP));
+var_dump($phar->getStub());
+
+copy($fname2, $fname3);
+
+$phar = new Phar($fname3);
+var_dump($phar->isFileFormat(Phar::ZIP));
+var_dump($phar->getStub());
+
+Phar::unlinkArchive($fname);
+var_dump(file_exists($fname));
+$phar = new Phar($fname);
+var_dump(count($phar));
+$phar['evil.php'] = '<?php
+try {
+Phar::unlinkArchive(Phar::running(false));
+} catch (Exception $e) {echo $e->getMessage(),"\n";}
+var_dump(Phar::running(false));
+include Phar::running(true) . "/another.php";
+?>';
+$phar['another.php'] = "hi\n";
+unset($phar);
+include $pname . '/evil.php';
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar.zip');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip');
+__HALT_COMPILER();
+?>
+--EXPECTF--
+Unknown phar archive ""
+Unknown phar archive "%sphar_unlinkarchive.phar"
+Unknown phar archive "%sphar_unlinkarchive.phar.tar": internal corruption of phar "%sphar_unlinkarchive.phar.tar" (truncated entry)
+
+Warning: Phar::unlinkArchive() expects parameter 1 to be string, array given in %sphar_unlinkarchive.php on line %d
+bool(false)
+string(48) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>"
+phar archive "%sphar_unlinkarchive.phar" has open file handles or objects. fclose() all file handles, and unset() all objects prior to calling unlinkArchive()
+bool(true)
+string(60) "<?php // zip-based phar archive stub file
+__HALT_COMPILER();"
+bool(true)
+string(60) "<?php // zip-based phar archive stub file
+__HALT_COMPILER();"
+bool(false)
+int(0)
+phar archive "%sphar_unlinkarchive.phar" cannot be unlinked from within itself
+string(%d) "%sphar_unlinkarchive.phar"
+hi
+===DONE===
diff --git a/ext/phar/tests/pharfileinfo_chmod.phpt b/ext/phar/tests/pharfileinfo_chmod.phpt
new file mode 100644
index 0000000000..e99be5d6b9
--- /dev/null
+++ b/ext/phar/tests/pharfileinfo_chmod.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Phar: PharFileInfo::chmod extra code coverage
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar';
+$pname = 'phar://' . $fname;
+
+$phar = new Phar($fname);
+
+$phar['a/b'] = 'hi there';
+
+$b = $phar['a/b'];
+try {
+$phar['a']->chmod(066);
+} catch (Exception $e) {
+echo $e->getMessage(), "\n";
+}
+$b->chmod(array());
+lstat($pname . '/a/b'); // sets BG(CurrentLStatFile)
+$b->chmod(0666);
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar'); ?>
+--EXPECTF--
+Phar entry "a" is a temporary directory (not an actual entry in the archive), cannot chmod
+
+Warning: PharFileInfo::chmod() expects parameter 1 to be long, array given in %spharfileinfo_chmod.php on line %d
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/pharfileinfo_compression.phpt b/ext/phar/tests/pharfileinfo_compression.phpt
new file mode 100644
index 0000000000..fbac499127
--- /dev/null
+++ b/ext/phar/tests/pharfileinfo_compression.phpt
@@ -0,0 +1,94 @@
+--TEST--
+Phar: PharFileInfo compression-related methods
+--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.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar';
+$pname = 'phar://' . $fname;
+
+$phar = new Phar($fname);
+
+$phar['a/b'] = 'hi there';
+
+$b = $phar['a/b'];
+
+$b->isCompressed(array());
+try {
+$b->isCompressed(25);
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+try {
+$b->compress(25);
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+$tar = $phar->convertToData(Phar::TAR);
+
+$c = $tar['a/b'];
+try {
+$c->compress(Phar::GZ);
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+try {
+$phar['a']->compress(Phar::GZ);
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+ini_set('phar.readonly', 1);
+try {
+$b->compress(Phar::GZ);
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+ini_set('phar.readonly', 0);
+var_dump($b->compress(Phar::GZ));
+var_dump($b->compress(Phar::GZ));
+var_dump($b->compress(Phar::BZ2));
+var_dump($b->compress(Phar::BZ2));
+
+echo "decompress\n";
+
+ini_set('phar.readonly', 1);
+try {
+$phar['a/b']->decompress();
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+ini_set('phar.readonly', 0);
+try {
+$phar['a']->decompress();
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+var_dump($b->decompress());
+var_dump($b->decompress());
+
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar'); ?>
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.tar'); ?>
+--EXPECTF--
+Warning: PharFileInfo::isCompressed() expects parameter 1 to be long, array given in %spharfileinfo_compression.php on line 11
+Unknown compression type specified
+Unknown compression type specified
+Cannot compress with Gzip compression, not possible with tar-based phar archives
+Phar entry is a directory, cannot set compression
+Phar is readonly, cannot change compression
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+decompress
+Phar is readonly, cannot decompress
+Phar entry is a directory, cannot set compression
+bool(true)
+bool(true)
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/pharfileinfo_construct.phpt b/ext/phar/tests/pharfileinfo_construct.phpt
new file mode 100644
index 0000000000..480c1222c4
--- /dev/null
+++ b/ext/phar/tests/pharfileinfo_construct.phpt
@@ -0,0 +1,54 @@
+--TEST--
+Phar: PharFileInfo::__construct
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar';
+$pname = 'phar://' . $fname;
+
+try {
+file_put_contents($fname, 'blah');
+$a = new PharFileInfo($pname . '/oops');
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+unlink($fname);
+}
+
+$a = new PharFileInfo(array());
+
+$a = new Phar($fname);
+$a['a'] = 'hi';
+$b = $a['a'];
+
+try {
+$a = new PharFileInfo($pname . '/oops/I/do/not/exist');
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+
+try {
+$b->__construct('oops');
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+
+try {
+$a = new PharFileInfo(__FILE__);
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar'); ?>
+--EXPECTF--
+Cannot open phar file 'phar://%spharfileinfo_construct.phar/oops': internal corruption of phar "%spharfileinfo_construct.phar" (truncated entry)
+
+Warning: PharFileInfo::__construct() expects parameter 1 to be string, array given in %spharfileinfo_construct.php on line %d
+Cannot access phar file entry '/oops/I/do/not/exist' in archive '%spharfileinfo_construct.phar'
+Cannot call constructor twice
+'%spharfileinfo_construct.php' is not a valid phar archive URL (must have at least phar://filename.phar)
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/pharfileinfo_destruct.phpt b/ext/phar/tests/pharfileinfo_destruct.phpt
new file mode 100644
index 0000000000..48a58c0d09
--- /dev/null
+++ b/ext/phar/tests/pharfileinfo_destruct.phpt
@@ -0,0 +1,25 @@
+--TEST--
+Phar: PharFileInfo::__destruct
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar';
+$pname = 'phar://' . $fname;
+
+$a = new Phar($fname);
+$a['a/subdir/here'] = 'hi';
+
+$b = new PharFileInfo($pname . '/a/subdir');
+unset($b);
+
+$b = new PharFileInfo($pname . '/a/subdir/here');
+unset($b);
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar'); ?>
+--EXPECTF--
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/pharfileinfo_getcrc32.phpt b/ext/phar/tests/pharfileinfo_getcrc32.phpt
new file mode 100644
index 0000000000..dfa12f4ca4
--- /dev/null
+++ b/ext/phar/tests/pharfileinfo_getcrc32.phpt
@@ -0,0 +1,49 @@
+--TEST--
+Phar: PharFileInfo::getCRC32
+--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';
+$pname = 'phar://' . $fname;
+$file = "<?php
+Phar::mapPhar('hio');
+__HALT_COMPILER(); ?>";
+
+// compressed file length does not match incompressed lentgh for an uncompressed file
+
+$files = array();
+$files['a/subdir/here'] = array('cont'=>'a','ulen'=>1,'clen'=>1);;
+include 'files/phar_test.inc';
+
+$b = new PharFileInfo($pname . '/a/subdir');
+try {
+var_dump($b->getCRC32());
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+
+$b = new PharFileInfo($pname . '/a/subdir/here');
+try {
+var_dump($b->getCRC32());
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+$a = file_get_contents($pname . '/a/subdir/here');
+try {
+var_dump($b->getCRC32());
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar'); ?>
+--EXPECTF--
+Phar entry is a directory, does not have a CRC
+Phar entry was not CRC checked
+int(%s)
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/pharfileinfo_setmetadata.phpt b/ext/phar/tests/pharfileinfo_setmetadata.phpt
new file mode 100644
index 0000000000..8589fcb1d8
--- /dev/null
+++ b/ext/phar/tests/pharfileinfo_setmetadata.phpt
@@ -0,0 +1,65 @@
+--TEST--
+Phar: PharFileInfo::setMetadata/delMetadata extra code coverage
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar';
+$pname = 'phar://' . $fname;
+
+$phar = new Phar($fname);
+
+$phar['a/b'] = 'hi there';
+$tar = $phar->convertToData(Phar::TAR);
+
+$b = $phar['a/b'];
+try {
+$tar['a/b']->setMetadata('hi');
+} catch (Exception $e) {
+echo $e->getMessage(), "\n";
+}
+try {
+$tar['a/b']->delMetadata();
+} catch (Exception $e) {
+echo $e->getMessage(), "\n";
+}
+try {
+$phar['a']->setMetadata('hi');
+} catch (Exception $e) {
+echo $e->getMessage(), "\n";
+}
+try {
+$phar['a']->delMetadata();
+} catch (Exception $e) {
+echo $e->getMessage(), "\n";
+}
+ini_set('phar.readonly', 1);
+try {
+$b->setMetadata('hi');
+} catch (Exception $e) {
+echo $e->getMessage(), "\n";
+}
+try {
+$b->delMetadata();
+} catch (Exception $e) {
+echo $e->getMessage(), "\n";
+}
+ini_set('phar.readonly', 0);
+$b->setMetadata(1,2,3);
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar'); ?>
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.tar'); ?>
+--EXPECTF--
+Cannot set metadata, not possible with tar-based phar archives
+Cannot delete metadata, not possible with tar-based phar archives
+Phar entry is a temporary directory (not an actual entry in the archive), cannot set metadata
+Phar entry is a temporary directory (not an actual entry in the archive), cannot delete metadata
+Write operations disabled by phar.readonly INI setting
+Write operations disabled by phar.readonly INI setting
+
+Warning: PharFileInfo::setMetadata() expects exactly 1 parameter, 3 given in %spharfileinfo_setmetadata.php on line %d
+===DONE===
diff --git a/ext/phar/tests/phpinfo_001.phpt b/ext/phar/tests/phpinfo_001.phpt
new file mode 100644
index 0000000000..7b31185827
--- /dev/null
+++ b/ext/phar/tests/phpinfo_001.phpt
@@ -0,0 +1,59 @@
+--TEST--
+Phar: phpinfo display 1
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zlib")) die("skip zlib not loaded"); ?>
+<?php if (!extension_loaded("bz2")) die("skip bz2 not loaded"); ?>
+--INI--
+phar.readonly=0
+phar.require_hash=0
+--FILE--
+<?php
+phpinfo(INFO_MODULES);
+ini_set('phar.readonly',1);
+ini_set('phar.require_hash',1);
+phpinfo(INFO_MODULES);
+?>
+===DONE===
+--EXPECTF--
+%aPhar
+
+Phar: PHP Archive support => enabled
+Phar EXT version => %s
+Phar API version => 1.1.1
+CVS revision => %sRevision: %s $
+Phar-based phar archives => enabled
+Tar-based phar archives => enabled
+ZIP-based phar archives => enabled
+gzip compression => enabled
+bzip2 compression => enabled
+
+
+Phar based on pear/PHP_Archive, original concept by Davey Shafik.
+Phar fully realized by Gregory Beaver and Marcus Boerger.
+Portions of tar implementation Copyright (c) 2003-2007 Tim Kientzle.
+Directive => Local Value => Master Value
+phar.readonly => Off => Off
+phar.require_hash => Off => Off
+%a
+Phar
+
+Phar: PHP Archive support => enabled
+Phar EXT version => %s
+Phar API version => 1.1.1
+CVS revision => %sRevision: %s $
+Phar-based phar archives => enabled
+Tar-based phar archives => enabled
+ZIP-based phar archives => enabled
+gzip compression => enabled
+bzip2 compression => enabled
+
+
+Phar based on pear/PHP_Archive, original concept by Davey Shafik.
+Phar fully realized by Gregory Beaver and Marcus Boerger.
+Portions of tar implementation Copyright (c) 2003-2007 Tim Kientzle.
+Directive => Local Value => Master Value
+phar.readonly => On => Off
+phar.require_hash => On => Off
+%a
+===DONE===
diff --git a/ext/phar/tests/phpinfo_002.phpt b/ext/phar/tests/phpinfo_002.phpt
new file mode 100644
index 0000000000..1e0e567aff
--- /dev/null
+++ b/ext/phar/tests/phpinfo_002.phpt
@@ -0,0 +1,37 @@
+--TEST--
+Phar: phpinfo display 2
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zlib")) die("skip zlib not loaded"); ?>
+<?php if (!extension_loaded("bz2")) die("skip bz2 not loaded"); ?>
+--INI--
+phar.readonly=1
+phar.require_hash=1
+--FILE--
+<?php
+phpinfo(INFO_MODULES);
+?>
+===DONE===
+--EXPECTF--
+%a
+Phar
+
+Phar: PHP Archive support => enabled
+Phar EXT version => %s
+Phar API version => 1.1.1
+CVS revision => %sRevision: %s $
+Phar-based phar archives => enabled
+Tar-based phar archives => enabled
+ZIP-based phar archives => enabled
+gzip compression => enabled
+bzip2 compression => enabled
+
+
+Phar based on pear/PHP_Archive, original concept by Davey Shafik.
+Phar fully realized by Gregory Beaver and Marcus Boerger.
+Portions of tar implementation Copyright (c) 2003-2007 Tim Kientzle.
+Directive => Local Value => Master Value
+phar.readonly => On => On
+phar.require_hash => On => On
+%a
+===DONE===
diff --git a/ext/phar/tests/phpinfo_003.phpt b/ext/phar/tests/phpinfo_003.phpt
new file mode 100644
index 0000000000..5894c83ea8
--- /dev/null
+++ b/ext/phar/tests/phpinfo_003.phpt
@@ -0,0 +1,37 @@
+--TEST--
+Phar: phpinfo display 3
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (extension_loaded("zlib")) die("skip zlib loaded"); ?>
+<?php if (extension_loaded("bz2")) die("skip bz2 loaded"); ?>
+--INI--
+phar.readonly=1
+phar.require_hash=1
+--FILE--
+<?php
+phpinfo(INFO_MODULES);
+?>
+===DONE===
+--EXPECTF--
+%a
+Phar
+
+Phar: PHP Archive support => enabled
+Phar EXT version => %s
+Phar API version => 1.1.1
+CVS revision => $Revision$
+Phar-based phar archives => enabled
+Tar-based phar archives => enabled
+ZIP-based phar archives => enabled
+gzip compression => disabled (install ext/zlib)
+bzip2 compression => disabled (install pecl/bz2)
+
+
+Phar based on pear/PHP_Archive, original concept by Davey Shafik.
+Phar fully realized by Gregory Beaver and Marcus Boerger.
+Portions of tar implementation Copyright (c) 2003-2007 Tim Kientzle.
+Directive => Local Value => Master Value
+phar.readonly => On => On
+phar.require_hash => On => On
+%a
+===DONE===
diff --git a/ext/phar/tests/phpinfo_004.phpt b/ext/phar/tests/phpinfo_004.phpt
new file mode 100644
index 0000000000..1dbccda889
--- /dev/null
+++ b/ext/phar/tests/phpinfo_004.phpt
@@ -0,0 +1,66 @@
+--TEST--
+Phar: phpinfo display 4
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zlib")) die("skip zlib not loaded"); ?>
+<?php if (!extension_loaded("bz2")) die("skip bz2 not loaded"); ?>
+--INI--
+phar.readonly=0
+phar.require_hash=0
+--POST--
+a=b
+--FILE--
+<?php
+phpinfo(INFO_MODULES);
+ini_set('phar.readonly',1);
+ini_set('phar.require_hash',1);
+phpinfo(INFO_MODULES);
+?>
+===DONE===
+--EXPECTF--
+%a<br />
+<h2><a name="module_Phar">Phar</a></h2>
+<table border="0" cellpadding="3" width="600">
+<tr class="h"><th>Phar: PHP Archive support</th><th>enabled</th></tr>
+<tr><td class="e">Phar EXT version </td><td class="v">%s </td></tr>
+<tr><td class="e">Phar API version </td><td class="v">1.1.1 </td></tr>
+<tr><td class="e">CVS revision </td><td class="v">%sRevision: %s $ </td></tr>
+<tr><td class="e">Phar-based phar archives </td><td class="v">enabled </td></tr>
+<tr><td class="e">Tar-based phar archives </td><td class="v">enabled </td></tr>
+<tr><td class="e">ZIP-based phar archives </td><td class="v">enabled </td></tr>
+<tr><td class="e">gzip compression </td><td class="v">enabled </td></tr>
+<tr><td class="e">bzip2 compression </td><td class="v">enabled </td></tr>
+</table><br />
+<table border="0" cellpadding="3" width="600">
+<tr class="v"><td>
+Phar based on pear/PHP_Archive, original concept by Davey Shafik.<br />Phar fully realized by Gregory Beaver and Marcus Boerger.<br />Portions of tar implementation Copyright (c) 2003-2007 Tim Kientzle.</td></tr>
+</table><br />
+<table border="0" cellpadding="3" width="600">
+<tr class="h"><th>Directive</th><th>Local Value</th><th>Master Value</th></tr>
+<tr><td class="e">phar.readonly</td><td class="v">Off</td><td class="v">Off</td></tr>
+<tr><td class="e">phar.require_hash</td><td class="v">Off</td><td class="v">Off</td></tr>
+</table><br />
+%a<br />
+<h2><a name="module_Phar">Phar</a></h2>
+<table border="0" cellpadding="3" width="600">
+<tr class="h"><th>Phar: PHP Archive support</th><th>enabled</th></tr>
+<tr><td class="e">Phar EXT version </td><td class="v">%s </td></tr>
+<tr><td class="e">Phar API version </td><td class="v">1.1.1 </td></tr>
+<tr><td class="e">CVS revision </td><td class="v">%sRevision: %s $ </td></tr>
+<tr><td class="e">Phar-based phar archives </td><td class="v">enabled </td></tr>
+<tr><td class="e">Tar-based phar archives </td><td class="v">enabled </td></tr>
+<tr><td class="e">ZIP-based phar archives </td><td class="v">enabled </td></tr>
+<tr><td class="e">gzip compression </td><td class="v">enabled </td></tr>
+<tr><td class="e">bzip2 compression </td><td class="v">enabled </td></tr>
+</table><br />
+<table border="0" cellpadding="3" width="600">
+<tr class="v"><td>
+Phar based on pear/PHP_Archive, original concept by Davey Shafik.<br />Phar fully realized by Gregory Beaver and Marcus Boerger.<br />Portions of tar implementation Copyright (c) 2003-2007 Tim Kientzle.</td></tr>
+</table><br />
+<table border="0" cellpadding="3" width="600">
+<tr class="h"><th>Directive</th><th>Local Value</th><th>Master Value</th></tr>
+<tr><td class="e">phar.readonly</td><td class="v">On</td><td class="v">Off</td></tr>
+<tr><td class="e">phar.require_hash</td><td class="v">On</td><td class="v">Off</td></tr>
+</table><br />
+%a<br />
+</div></body></html>===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/readfile.phpt b/ext/phar/tests/readfile.phpt
new file mode 100644
index 0000000000..60fdad1792
--- /dev/null
+++ b/ext/phar/tests/readfile.phpt
@@ -0,0 +1,30 @@
+--TEST--
+Phar: test readfile() interception
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");?>
+--INI--
+phar.require_hash=1
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$a = new Phar($fname);
+$a['index.php'] = '<?php
+readfile("dir/file1.txt");
+readfile("file1.txt", true);
+?>';
+$a['dir/file1.txt'] = 'hi';
+$a['dir/file2.txt'] = 'hi2';
+$a['dir/file3.txt'] = 'hi3';
+$a->setStub('<?php
+Phar::interceptFileFuncs();
+set_include_path("phar://" . __FILE__ . "/dir" . PATH_SEPARATOR . "phar://" . __FILE__);
+include "index.php";
+__HALT_COMPILER();');
+include $fname;
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECT--
+hihi===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/readfile_edgecases.phpt b/ext/phar/tests/readfile_edgecases.phpt
new file mode 100644
index 0000000000..1a78d7b5b0
--- /dev/null
+++ b/ext/phar/tests/readfile_edgecases.phpt
@@ -0,0 +1,62 @@
+--TEST--
+Phar: test edge cases of readfile() function interception
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+Phar::interceptFileFuncs();
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+
+readfile(array());
+chdir(dirname(__FILE__));
+file_put_contents($fname, "blah\n");
+file_put_contents("foob", "test\n");
+readfile($fname);
+unlink($fname);
+mkdir($pname . '/oops');
+file_put_contents($pname . '/foo/hi', '<?php
+readfile("foo/" . basename(__FILE__));
+$context = stream_context_create();
+readfile("foob");
+set_include_path("' . addslashes(dirname(__FILE__)) . '");
+readfile("foob", true);
+readfile("./hi", 0, $context);
+readfile("../oops");
+?>
+');
+include $pname . '/foo/hi';
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+<?php rmdir(dirname(__FILE__) . '/poo'); ?>
+<?php unlink(dirname(__FILE__) . '/foob'); ?>
+--EXPECTF--
+Warning: readfile() expects parameter 1 to be string, array given in %sreadfile_edgecases.php on line %d
+blah
+<?php
+readfile("foo/" . basename(__FILE__));
+$context = stream_context_create();
+readfile("foob");
+set_include_path("%stests");
+readfile("foob", true);
+readfile("./hi", 0, $context);
+readfile("../oops");
+?>
+test
+test
+<?php
+readfile("foo/" . basename(__FILE__));
+$context = stream_context_create();
+readfile("foob");
+set_include_path("%stests");
+readfile("foob", true);
+readfile("./hi", 0, $context);
+readfile("../oops");
+?>
+
+Warning: readfile(phar://%sreadfile_edgecases.phar.php/oops): failed to open stream: phar error: path "oops" is a directory in phar://%sreadfile_edgecases.phar.php/foo/hi on line %d
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/refcount1.phpt b/ext/phar/tests/refcount1.phpt
new file mode 100644
index 0000000000..234d49111c
--- /dev/null
+++ b/ext/phar/tests/refcount1.phpt
@@ -0,0 +1,62 @@
+--TEST--
+Phar: test that refcounting avoids problems with deleting a file
+--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.php';
+$pname = 'phar://' . $fname;
+$file = "<?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"; ?>';
+include 'files/phar_test.inc';
+
+$fp = fopen($pname . '/b/c.php', 'wb');
+fwrite($fp, "extra");
+fclose($fp);
+echo "===CLOSE===\n";
+$p = new Phar($fname);
+$b = fopen($pname . '/b/c.php', 'rb');
+$a = $p['b/c.php'];
+var_dump($a);
+var_dump(fread($b, 20));
+rewind($b);
+echo "===UNLINK===\n";
+unlink($pname . '/b/c.php');
+var_dump($a);
+var_dump(fread($b, 20));
+include $pname . '/b/c.php';
+?>
+
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECTF--
+===CLOSE===
+object(PharFileInfo)#%d (2) {
+ ["pathName":"SplFileInfo":private]=>
+ string(%d) "phar://%srefcount1.phar.php/b"
+ ["fileName":"SplFileInfo":private]=>
+ string(%d) "phar://%srefcount1.phar.php/b/c.php"
+}
+string(5) "extra"
+===UNLINK===
+
+Warning: unlink(): phar error: "b/c.php" in phar "%srefcount1.phar.php", has open file pointers, cannot unlink in %srefcount1.php on line %d
+object(PharFileInfo)#%d (2) {
+ ["pathName":"SplFileInfo":private]=>
+ string(%d) "phar://%srefcount1.phar.php/b"
+ ["fileName":"SplFileInfo":private]=>
+ string(%s) "phar://%srefcount1.phar.php/b/c.php"
+}
+string(5) "extra"
+extra
+===DONE===
diff --git a/ext/phar/tests/refcount1_5_2.phpt b/ext/phar/tests/refcount1_5_2.phpt
new file mode 100755
index 0000000000..bf2c2b76b3
--- /dev/null
+++ b/ext/phar/tests/refcount1_5_2.phpt
@@ -0,0 +1,64 @@
+--TEST--
+Phar: test that refcounting avoids problems with deleting a file
+--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';
+$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'); ?>
+--EXPECTF--
+===CLOSE===
+object(PharFileInfo)#%d (0) {
+}
+string(5) "extra"
+===UNLINK===
+
+Warning: unlink(): phar error: "b/c.php" in phar "%sefcount1_5_2.phar", 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/rename.phpt b/ext/phar/tests/rename.phpt
new file mode 100644
index 0000000000..c73c98ec81
--- /dev/null
+++ b/ext/phar/tests/rename.phpt
@@ -0,0 +1,32 @@
+--TEST--
+Phar: rename test
+--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.php';
+$pname = 'phar://' . $fname;
+$file = "<?php
+Phar::mapPhar('hio');
+__HALT_COMPILER(); ?>";
+
+$files = array();
+$files['a'] = 'a';
+include 'files/phar_test.inc';
+include $fname;
+
+echo file_get_contents($pname . '/a') . "\n";
+rename($pname . '/a', $pname . '/b');
+echo file_get_contents($pname . '/b') . "\n";
+echo file_get_contents($pname . '/a') . "\n";
+?>
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECTF--
+a
+a
+
+Warning: file_get_contents(phar://%srename.phar.php/a): failed to open stream: phar error: "a" is not a file in phar "%srename.phar.php" in %srename.php on line %d \ No newline at end of file
diff --git a/ext/phar/tests/security.phpt b/ext/phar/tests/security.phpt
new file mode 100644
index 0000000000..2d54db7908
--- /dev/null
+++ b/ext/phar/tests/security.phpt
@@ -0,0 +1,36 @@
+--TEST--
+Phar: test to ensure phar.readonly cannot be circumvented
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.1.php';
+$a = new Phar($fname);
+$a->setStub('<?php
+Phar::mapPhar();
+$phar = new Phar(__FILE__);
+var_dump($phar->isWritable());
+try {
+$phar["b"] = "should not work!";
+} catch (Exception $e) {
+echo $e->getMessage(),"\n";
+}
+__HALT_COMPILER();
+?>');
+$a['hi'] = 'hi';
+unset($a);
+copy($fname, $fname2);
+Phar::unlinkArchive($fname);
+ini_set('phar.readonly', 1);
+include $fname2;
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.1.php'); ?>
+--EXPECT--
+bool(false)
+Write operations disabled by INI setting
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/stat.phpt b/ext/phar/tests/stat.phpt
new file mode 100644
index 0000000000..020fc24f86
--- /dev/null
+++ b/ext/phar/tests/stat.phpt
@@ -0,0 +1,215 @@
+--TEST--
+Phar: test stat function interceptions
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");?>
+--INI--
+phar.require_hash=1
+phar.readonly=0
+--FILE--
+<?php
+Phar::interceptFileFuncs();
+var_dump(stat(""));
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.tar';
+$fname3 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar';
+$a = new Phar($fname);
+$a['index.php'] = '<?php
+echo "stat\n";
+var_dump(stat("dir/file1.txt"));
+echo "lstat\n";
+var_dump(lstat("dir/file1.txt"));
+echo "fileperms\n";
+var_dump(fileperms("dir/file1.txt"));
+echo "fileinode\n";
+var_dump(fileinode("dir/file1.txt"));
+echo "filesize\n";
+var_dump(filesize("dir/file1.txt"));
+echo "fileowner\n";
+var_dump(fileowner("dir/file1.txt"));
+echo "filegroup\n";
+var_dump(filegroup("dir/file1.txt"));
+echo "filemtime\n";
+var_dump(filemtime("dir/file1.txt"));
+echo "fileatime\n";
+var_dump(fileatime("dir/file1.txt"));
+echo "filectime\n";
+var_dump(filectime("dir/file1.txt"));
+echo "filetype\n";
+var_dump(filetype("dir/file1.txt"));
+echo "is_writable\n";
+var_dump(is_writable("dir/file1.txt"));
+echo "is_writeable\n";
+var_dump(is_writeable("dir/file1.txt"));
+echo "is_readable\n";
+var_dump(is_readable("dir/file1.txt"));
+echo "is_executable\n";
+var_dump(is_executable("dir/file1.txt"));
+echo "file_exists\n";
+var_dump(file_exists("dir/file1.txt"));
+echo "is_dir\n";
+var_dump(is_dir("dir/file1.txt"));
+echo "is_file\n";
+var_dump(is_file("dir/file1.txt"));
+echo "is_link\n";
+var_dump(is_link("dir/file1.txt"));
+?>';
+$a['dir/file1.txt'] = 'hi';
+$a['dir/file2.txt'] = 'hi2';
+$a['dir/file3.txt'] = 'hi3';
+$a->setStub('<?php
+set_include_path("phar://" . __FILE__ . "/dir" . PATH_SEPARATOR . "phar://" . __FILE__);
+include "index.php";
+__HALT_COMPILER();');
+include $fname;
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECTF--
+bool(false)
+stat
+array(26) {
+ [0]=>
+ int(12)
+ [1]=>
+ int(%d)
+ [2]=>
+ int(33206)
+ [3]=>
+ int(1)
+ [4]=>
+ int(0)
+ [5]=>
+ int(0)
+ [6]=>
+ int(%s)
+ [7]=>
+ int(2)
+ [8]=>
+ int(%d)
+ [9]=>
+ int(%d)
+ [10]=>
+ int(%d)
+ [11]=>
+ int(%s)
+ [12]=>
+ int(%s)
+ ["dev"]=>
+ int(12)
+ ["ino"]=>
+ int(%d)
+ ["mode"]=>
+ int(33206)
+ ["nlink"]=>
+ int(1)
+ ["uid"]=>
+ int(0)
+ ["gid"]=>
+ int(0)
+ ["rdev"]=>
+ int(%s)
+ ["size"]=>
+ int(2)
+ ["atime"]=>
+ int(%d)
+ ["mtime"]=>
+ int(%d)
+ ["ctime"]=>
+ int(%d)
+ ["blksize"]=>
+ int(%s)
+ ["blocks"]=>
+ int(%s)
+}
+lstat
+array(26) {
+ [0]=>
+ int(12)
+ [1]=>
+ int(%d)
+ [2]=>
+ int(33206)
+ [3]=>
+ int(1)
+ [4]=>
+ int(0)
+ [5]=>
+ int(0)
+ [6]=>
+ int(%s)
+ [7]=>
+ int(2)
+ [8]=>
+ int(%d)
+ [9]=>
+ int(%d)
+ [10]=>
+ int(%d)
+ [11]=>
+ int(%s)
+ [12]=>
+ int(%s)
+ ["dev"]=>
+ int(12)
+ ["ino"]=>
+ int(%d)
+ ["mode"]=>
+ int(33206)
+ ["nlink"]=>
+ int(1)
+ ["uid"]=>
+ int(0)
+ ["gid"]=>
+ int(0)
+ ["rdev"]=>
+ int(%s)
+ ["size"]=>
+ int(2)
+ ["atime"]=>
+ int(%d)
+ ["mtime"]=>
+ int(%d)
+ ["ctime"]=>
+ int(%d)
+ ["blksize"]=>
+ int(%s)
+ ["blocks"]=>
+ int(%s)
+}
+fileperms
+int(33206)
+fileinode
+int(%d)
+filesize
+int(2)
+fileowner
+int(0)
+filegroup
+int(0)
+filemtime
+int(%d)
+fileatime
+int(%d)
+filectime
+int(%d)
+filetype
+string(4) "file"
+is_writable
+bool(true)
+is_writeable
+bool(false)
+is_readable
+bool(true)
+is_executable
+bool(false)
+file_exists
+bool(true)
+is_dir
+bool(false)
+is_file
+bool(true)
+is_link
+bool(false)
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/stat2.phpt b/ext/phar/tests/stat2.phpt
new file mode 100644
index 0000000000..6e911028ca
--- /dev/null
+++ b/ext/phar/tests/stat2.phpt
@@ -0,0 +1,60 @@
+--TEST--
+Phar: test stat function interceptions and is_file/is_link edge cases (PHP 5.2)
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");?>
+<?php if (substr(phpversion(), 0, 3) != '5.2') die("skip PHP 5.2 required for this test");?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+Phar::interceptFileFuncs();
+is_file();
+is_link();
+var_dump(is_file(__FILE__));
+
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.tar';
+$fname3 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar';
+copy(dirname(__FILE__) . '/tar/files/links.tar', $fname2);
+$a = new PharData($fname2);
+$b = $a->convertToExecutable();
+unset($a);
+Phar::unlinkArchive($fname2);
+$b['foo/stat.php'] = '<?php
+echo "is_link\n";
+var_dump(is_link("./stat.php"),is_file("./stat.php"), is_link("./oops"), is_file("./oops"));
+var_dump(is_link("testit/link"), filetype("testit/link"), filetype("testit"), is_file("testit/link"));
+echo "not found\n";
+var_dump(is_link("notfound"));
+echo "dir\n";
+var_dump(is_dir("./bar"), is_file("foo/bar/blah"));
+?>';
+$b->addEmptyDir('foo/bar/blah');
+$b->setStub('<?php
+include "phar://" . __FILE__ . "/foo/stat.php";
+__HALT_COMPILER();');
+include $fname3;
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); ?>
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.tar'); ?>
+--EXPECTF--
+Warning: Wrong parameter count for is_file() in %sstat2.php on line %d
+
+Warning: Wrong parameter count for is_link() in %sstat2.php on line %d
+bool(true)
+is_link
+bool(false)
+bool(true)
+bool(false)
+bool(false)
+bool(true)
+string(4) "link"
+string(3) "dir"
+bool(true)
+not found
+bool(false)
+dir
+bool(true)
+bool(false)
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/stat2_5.3.phpt b/ext/phar/tests/stat2_5.3.phpt
new file mode 100644
index 0000000000..58ca54a16a
--- /dev/null
+++ b/ext/phar/tests/stat2_5.3.phpt
@@ -0,0 +1,60 @@
+--TEST--
+Phar: test stat function interceptions and is_file/is_link edge cases (PHP 5.3+)
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");?>
+<?php if (substr(phpversion(), 0, 3) == '5.2') die("skip PHP 5.3+ required for this test");?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+Phar::interceptFileFuncs();
+is_file();
+is_link();
+var_dump(is_file(__FILE__));
+
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.tar';
+$fname3 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar';
+copy(dirname(__FILE__) . '/tar/files/links.tar', $fname2);
+$a = new PharData($fname2);
+$b = $a->convertToExecutable(Phar::TAR, Phar::NONE, '.3.phar.tar');
+unset($a);
+Phar::unlinkArchive($fname2);
+$b['foo/stat.php'] = '<?php
+echo "is_link\n";
+var_dump(is_link("./stat.php"),is_file("./stat.php"), is_link("./oops"), is_file("./oops"));
+var_dump(is_link("testit/link"), filetype("testit/link"), filetype("testit"), is_file("testit/link"));
+echo "not found\n";
+var_dump(is_link("notfound"));
+echo "dir\n";
+var_dump(is_dir("./bar"), is_file("foo/bar/blah"));
+?>';
+$b->addEmptyDir('foo/bar/blah');
+$b->setStub('<?php
+include "phar://" . __FILE__ . "/foo/stat.php";
+__HALT_COMPILER();');
+include $fname3;
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); ?>
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.tar'); ?>
+--EXPECTF--
+Warning: is_file() expects exactly 1 parameter, 0 given in %sstat2_5.3.php on line %d
+
+Warning: is_link() expects exactly 1 parameter, 0 given in %sstat2_5.3.php on line %d
+bool(true)
+is_link
+bool(false)
+bool(true)
+bool(false)
+bool(false)
+bool(true)
+string(4) "link"
+string(3) "dir"
+bool(true)
+not found
+bool(false)
+dir
+bool(true)
+bool(false)
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/tar/033.phpt b/ext/phar/tests/tar/033.phpt
new file mode 100644
index 0000000000..29223e49e3
--- /dev/null
+++ b/ext/phar/tests/tar/033.phpt
@@ -0,0 +1,50 @@
+--TEST--
+Phar::chmod tar-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.tar';
+$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);
+ 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']->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.tar');
+?>
+--EXPECTF--
+bool(false)
+bool(true)
+bool(false)
+test dir
+bool(true)
+bool(false)
+bool(true)
+===DONE===
diff --git a/ext/phar/tests/tar/033a.phpt b/ext/phar/tests/tar/033a.phpt
new file mode 100644
index 0000000000..09b5446aec
--- /dev/null
+++ b/ext/phar/tests/tar/033a.phpt
@@ -0,0 +1,45 @@
+--TEST--
+Phar::chmod tar-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.tar';
+$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']->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.tar');
+?>
+--EXPECTF--
+bool(false)
+Cannot modify permissions for file "a.php" in phar "%s033a.phar.tar", write operations are prohibited
+===DONE===
diff --git a/ext/phar/tests/tar/alias_acrobatics.phpt b/ext/phar/tests/tar/alias_acrobatics.phpt
new file mode 100644
index 0000000000..d08dc0467c
--- /dev/null
+++ b/ext/phar/tests/tar/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.tar';
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.phar.tar';
+
+$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.tar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar.tar');
+?>
+--EXPECTF--
+alias "foo" is already used for archive "%salias_acrobatics.phar.tar" cannot be overloaded with "%salias_acrobatics.2.phar.tar"
+2
+phar error: Unable to add tar-based phar "%salias_acrobatics.2.phar.tar", alias is already in use
+alias "another" is already used for archive "%salias_acrobatics.phar.tar" cannot be overloaded with "%salias_acrobatics.phar.tar"
+===DONE===
diff --git a/ext/phar/tests/tar/badalias.phpt b/ext/phar/tests/tar/badalias.phpt
new file mode 100644
index 0000000000..441fc03ae7
--- /dev/null
+++ b/ext/phar/tests/tar/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.tar");
+} catch (Exception $ee) {
+echo $ee->getMessage(), "\n";
+}
+}
+?>
+===DONE===
+--EXPECTF--
+phar error: invalid alias "hi/thereaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa..." in tar-based phar "%sbadalias1.phar.tar"
+phar error: invalid alias "hi\there" in tar-based phar "%sbadalias2.phar.tar"
+phar error: invalid alias "hi;there" in tar-based phar "%sbadalias3.phar.tar"
+phar error: invalid alias "hi:there" in tar-based phar "%sbadalias4.phar.tar"
+phar error: tar-based phar "%sbadalias5.phar.tar" has alias that is larger than 511 bytes, cannot process
+===DONE===
diff --git a/ext/phar/tests/tar/badchecksum.phpt b/ext/phar/tests/tar/badchecksum.phpt
new file mode 100644
index 0000000000..fae19b153d
--- /dev/null
+++ b/ext/phar/tests/tar/badchecksum.phpt
@@ -0,0 +1,30 @@
+--TEST--
+Phar: tar with bad checksum
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.tar';
+$pname = 'phar://' . $fname;
+
+include dirname(__FILE__) . '/files/corrupt_tarmaker.php.inc';
+$a = new corrupt_tarmaker($fname, 'none');
+$a->init();
+$a->addFile('hithere', 'contents', null, 'checksum');
+$a->close();
+
+try {
+ $p = new PharData($fname);
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.tar');
+?>
+--EXPECTF--
+phar error: "%sbadchecksum.tar" is a corrupted tar file (checksum mismatch of file "hithere")
+===DONE===
diff --git a/ext/phar/tests/tar/bignames.phpt b/ext/phar/tests/tar/bignames.phpt
new file mode 100644
index 0000000000..19d5f638e1
--- /dev/null
+++ b/ext/phar/tests/tar/bignames.phpt
@@ -0,0 +1,35 @@
+--TEST--
+Phar: tar with huge filenames
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.tar';
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.tar';
+$pname = 'phar://' . $fname;
+
+$p1 = new PharData($fname);
+$p1[str_repeat('a', 101)] = 'hi';
+$p1[str_repeat('a', 255)] = 'hi2';
+copy($fname, $fname2);
+$p2 = new PharData($fname2);
+echo $p2[str_repeat('a', 101)]->getContent() . "\n";
+echo $p2[str_repeat('a', 255)]->getContent() . "\n";
+
+try {
+ $p2[str_repeat('a', 400)] = 'yuck';
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.tar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.tar');
+?>
+--EXPECTF--
+hi
+hi2
+tar-based phar "%sbignames.2.tar" cannot be created, filename "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" is too long for tar file format
+===DONE===
diff --git a/ext/phar/tests/tar/create_new_and_modify.phpt b/ext/phar/tests/tar/create_new_and_modify.phpt
new file mode 100644
index 0000000000..8062fda769
--- /dev/null
+++ b/ext/phar/tests/tar/create_new_and_modify.phpt
@@ -0,0 +1,45 @@
+--TEST--
+Phar: create and modify tar-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.tar.php';
+$pname = 'phar://' . $fname;
+
+@unlink($fname);
+
+file_put_contents($pname . '/a.php', "brand new!\n");
+
+$phar = new Phar($fname);
+var_dump($phar->isFileFormat(Phar::TAR));
+$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.tar.php'); ?>
+--EXPECTF--
+bool(true)
+brand new!
+bool(true)
+modified!
+another!
+===DONE===
diff --git a/ext/phar/tests/tar/create_new_phar_b.phpt b/ext/phar/tests/tar/create_new_phar_b.phpt
new file mode 100644
index 0000000000..a608be4705
--- /dev/null
+++ b/ext/phar/tests/tar/create_new_phar_b.phpt
@@ -0,0 +1,27 @@
+--TEST--
+Phar: create a completely new tar-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.tar/a.php',
+ 'brand new!');
+include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar/a.php';
+?>
+
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); ?>
+--EXPECTF--
+
+Warning: file_put_contents(phar://%screate_new_phar_b.phar.tar/a.php): failed to open stream: phar error: write operations disabled by INI setting in %screate_new_phar_b.php on line %d
+
+Warning: include(phar://%screate_new_phar_b.phar.tar/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.tar/a.php' for inclusion (include_path='%s') in %screate_new_phar_b.php on line %d
+
+===DONE===
diff --git a/ext/phar/tests/tar/delete.phpt b/ext/phar/tests/tar/delete.phpt
new file mode 100644
index 0000000000..32b2b1e28b
--- /dev/null
+++ b/ext/phar/tests/tar/delete.phpt
@@ -0,0 +1,32 @@
+--TEST--
+Phar: delete test, tar-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.tar';
+$alias = 'phar://' . $fname;
+$stub = "<?php
+Phar::mapPhar('hio');
+__HALT_COMPILER(); ?>";
+
+$phar = new Phar($fname);
+$phar['a'] = 'a';
+$phar->setStub($stub);
+$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.tar'); ?>
+--EXPECTF--
+a
+
+Warning: file_get_contents(phar://%sdelete.phar.tar/a): failed to open stream: phar error: "a" is not a file in phar "%sdelete.phar.tar" in %sdelete.php on line %d \ No newline at end of file
diff --git a/ext/phar/tests/tar/delete_in_phar.phpt b/ext/phar/tests/tar/delete_in_phar.phpt
new file mode 100644
index 0000000000..91ef4a2046
--- /dev/null
+++ b/ext/phar/tests/tar/delete_in_phar.phpt
@@ -0,0 +1,49 @@
+--TEST--
+Phar: delete a file within a tar-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.tar';
+$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.tar'); ?>
+--EXPECTF--
+This is a
+This is b
+This is b/c
+===AFTER===
+This is a
+This is b
+
+Warning: include(%sdelete_in_phar.phar.tar/b/c.php): failed to open stream: phar error: "b/c.php" is not a file in phar "%sdelete_in_phar.phar.tar" in %sdelete_in_phar.php on line %d
+
+Warning: include(): Failed opening 'phar://%sdelete_in_phar.phar.tar/b/c.php' for inclusion (include_path='%s') in %sdelete_in_phar.php on line %d
+
+===DONE===
diff --git a/ext/phar/tests/tar/delete_in_phar_b.phpt b/ext/phar/tests/tar/delete_in_phar_b.phpt
new file mode 100644
index 0000000000..2af1c66deb
--- /dev/null
+++ b/ext/phar/tests/tar/delete_in_phar_b.phpt
@@ -0,0 +1,49 @@
+--TEST--
+Phar: delete a file within a tar-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.tar';
+$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.tar'); ?>
+--EXPECTF--
+This is a
+This is b
+This is b/c
+
+Warning: unlink(): phar error: write operations disabled by INI setting 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/tar/delete_in_phar_confirm.phpt b/ext/phar/tests/tar/delete_in_phar_confirm.phpt
new file mode 100644
index 0000000000..707bcbd0ed
--- /dev/null
+++ b/ext/phar/tests/tar/delete_in_phar_confirm.phpt
@@ -0,0 +1,52 @@
+--TEST--
+Phar: delete a file within a tar-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.tar';
+$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.tar/a.php';
+include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar/b.php';
+include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar/b/c.php';
+?>
+
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); ?>
+--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.tar/b/c.php): failed to open stream: phar error: "b/c.php" is not a file in phar "%sdelete_in_phar_confirm.phar.tar" in %sdelete_in_phar_confirm.php on line %d
+
+Warning: include(): Failed opening 'phar://%sdelete_in_phar_confirm.phar.tar/b/c.php' for inclusion (include_path='%s') in %sdelete_in_phar_confirm.php on line %d
+
+===DONE===
diff --git a/ext/phar/tests/tar/dir.phpt b/ext/phar/tests/tar/dir.phpt
new file mode 100644
index 0000000000..53bf65f9a7
--- /dev/null
+++ b/ext/phar/tests/tar/dir.phpt
@@ -0,0 +1,43 @@
+--TEST--
+Phar: mkdir/rmdir test tar-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.tar.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::TAR));
+
+$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.tar.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/tar/exists_as_phar.phpt b/ext/phar/tests/tar/exists_as_phar.phpt
new file mode 100644
index 0000000000..9a8cfc81f0
--- /dev/null
+++ b/ext/phar/tests/tar/exists_as_phar.phpt
@@ -0,0 +1,38 @@
+--TEST--
+Phar: phar-based phar named with ".tar" 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.tar';
+$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.tar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar');
+?>
+--EXPECTF--
+phar tar error: "%sexists_as_phar.phar.tar" already exists as a regular phar and must be deleted from disk prior to creating as a tar-based phar
+===DONE===
diff --git a/ext/phar/tests/tar/files/badalias1.phar.tar b/ext/phar/tests/tar/files/badalias1.phar.tar
new file mode 100644
index 0000000000..6cd4716d8f
--- /dev/null
+++ b/ext/phar/tests/tar/files/badalias1.phar.tar
Binary files differ
diff --git a/ext/phar/tests/tar/files/badalias2.phar.tar b/ext/phar/tests/tar/files/badalias2.phar.tar
new file mode 100644
index 0000000000..5face85827
--- /dev/null
+++ b/ext/phar/tests/tar/files/badalias2.phar.tar
Binary files differ
diff --git a/ext/phar/tests/tar/files/badalias3.phar.tar b/ext/phar/tests/tar/files/badalias3.phar.tar
new file mode 100644
index 0000000000..ab36e1f343
--- /dev/null
+++ b/ext/phar/tests/tar/files/badalias3.phar.tar
Binary files differ
diff --git a/ext/phar/tests/tar/files/badalias4.phar.tar b/ext/phar/tests/tar/files/badalias4.phar.tar
new file mode 100644
index 0000000000..c54e31d4fc
--- /dev/null
+++ b/ext/phar/tests/tar/files/badalias4.phar.tar
Binary files differ
diff --git a/ext/phar/tests/tar/files/badalias5.phar.tar b/ext/phar/tests/tar/files/badalias5.phar.tar
new file mode 100644
index 0000000000..dd52b6ac7d
--- /dev/null
+++ b/ext/phar/tests/tar/files/badalias5.phar.tar
Binary files differ
diff --git a/ext/phar/tests/tar/files/biglink.tar b/ext/phar/tests/tar/files/biglink.tar
new file mode 100644
index 0000000000..43bbf58423
--- /dev/null
+++ b/ext/phar/tests/tar/files/biglink.tar
Binary files differ
diff --git a/ext/phar/tests/tar/files/corrupt_tarmaker.php.inc b/ext/phar/tests/tar/files/corrupt_tarmaker.php.inc
new file mode 100644
index 0000000000..b0eba6cc69
--- /dev/null
+++ b/ext/phar/tests/tar/files/corrupt_tarmaker.php.inc
@@ -0,0 +1,177 @@
+<?php
+// stolen from PEAR2_Pyrus_Developer_Creator_Tar by Greg Beaver, the original author, for use in unit tests
+class corrupt_tarmaker
+{
+ /**
+ * Path to archive file
+ *
+ * @var string
+ */
+ protected $archive;
+ /**
+ * Temporary stream used for creating the archive
+ *
+ * @var stream
+ */
+ protected $tmp;
+ protected $path;
+ protected $compress;
+ function __construct($path, $compress = 'zlib')
+ {
+ $this->compress = $compress;
+ if ($compress === 'bz2' && !function_exists('bzopen')) {
+ throw new PEAR2_Pyrus_Developer_Creator_Exception(
+ 'bzip2 extension not available');
+ }
+ if ($compress === 'zlib' && !function_exists('gzopen')) {
+ throw new PEAR2_Pyrus_Developer_Creator_Exception(
+ 'zlib extension not available');
+ }
+ $this->path = $path;
+ }
+
+ /**
+ * save a file inside this package
+ *
+ * This code is modified from Vincent Lascaux's File_Archive
+ * package, which is licensed under the LGPL license.
+ * @param string relative path within the package
+ * @param string|resource file contents or open file handle
+ */
+ function addFile($path, $fileOrStream, $stat = null, $corrupt = null)
+ {
+ clearstatcache();
+ if ($stat === null) {
+ if (is_resource($fileOrStream)) {
+ $stat = fstat($fileOrStream);
+ } else {
+ $stat = array(
+ 'mode' => 0x8000 + 0644,
+ 'uid' => 0,
+ 'gid' => 0,
+ 'size' => strlen($fileOrStream),
+ 'mtime' => time(),
+ );
+ }
+ }
+
+ $link = null;
+ if ($stat['mode'] & 0xA000 && $corrupt === 'symlink') {
+ $type = 2; // Symbolic Link
+ $link = $fileOrStream;
+ $stat['size'] = 0;
+ $fileOrStream = '';
+ } else if ($stat['mode'] & 0xA000) {
+ $type = 1; // Link
+ $link = $fileOrStream;
+ $stat['size'] = 0;
+ $fileOrStream = '';
+ } else if ($stat['mode'] & 0x4000) {
+ $type = 5; // Directory
+ } else if ($stat['mode'] & 0x8000) {
+ $type = 0; // Regular
+ } else {
+ $type = 9; // Unknown
+ }
+
+ $filePrefix = '';
+ if (strlen($path) > 255) {
+ throw new Exception(
+ "$path is too long, must be 255 characters or less"
+ );
+ } else if (strlen($path) > 100) {
+ $filePrefix = substr($path, 0, strlen($path)-100);
+ $path = substr($path, -100);
+ }
+
+ $block = pack('a100a8a8a8a12A12',
+ $path,
+ decoct($stat['mode']),
+ sprintf('%6s ',decoct($stat['uid'])),
+ sprintf('%6s ',decoct($stat['gid'])),
+ sprintf('%11s ',decoct($stat['size'])),
+ sprintf('%11s ',decoct($stat['mtime']))
+ );
+
+ $blockend = pack('a1a100a6a2a32a32a8a8a155a12',
+ $type,
+ $link,
+ 'ustar',
+ '00',
+ 'Pyrus',
+ 'Pyrus',
+ '',
+ '',
+ $filePrefix,
+ '');
+
+ $checkheader = array_merge(str_split($block), str_split($blockend));
+ if (!function_exists('_pear2tarchecksum')) {
+ function _pear2tarchecksum($a, $b) {return $a + ord($b);}
+ }
+ $checksum = 256; // 8 * ord(' ');
+ $checksum += array_reduce($checkheader, '_pear2tarchecksum');
+
+ if ($corrupt === 'checksum') $checksum++;
+ $checksum = pack('a8', sprintf('%6s ', decoct($checksum)));
+
+ fwrite($this->tmp, $block . $checksum . $blockend, 512);
+ if (is_resource($fileOrStream)) {
+ stream_copy_to_stream($fileOrStream, $this->tmp);
+ if ($stat['size'] % 512) {
+ fwrite($this->tmp, str_repeat("\0", 512 - $stat['size'] % 512));
+ }
+ } else {
+ fwrite($this->tmp, $fileOrStream);
+ if (strlen($fileOrStream) && !isset($link) && strlen($fileOrStream) % 512) {
+ fwrite($this->tmp, str_repeat("\0", 512 - strlen($fileOrStream) % 512));
+ }
+ }
+ }
+
+ /**
+ * Initialize the package creator
+ */
+ function init()
+ {
+ switch ($this->compress) {
+ case 'zlib' :
+ $this->tmp = gzopen($this->path, 'wb');
+ break;
+ case 'bz2' :
+ $this->tmp = bzopen($this->path, 'w');
+ break;
+ case 'none' :
+ $this->tmp = fopen($this->path, 'wb');
+ break;
+ default :
+ throw new Exception(
+ 'unknown compression type ' . $this->compress);
+ }
+ }
+
+ /**
+ * Create an internal directory, creating parent directories as needed
+ *
+ * @param string $dir
+ */
+ function mkdir($dir)
+ {
+ $this->addFile($dir, "", array(
+ 'mode' => 0x4000 + 0644,
+ 'uid' => 0,
+ 'gid' => 0,
+ 'size' => 0,
+ 'mtime' => time(),
+ ));
+ }
+
+ /**
+ * Finish saving the package
+ */
+ function close()
+ {
+ fwrite($this->tmp, pack('a1024', ''));
+ fclose($this->tmp);
+ }
+} \ No newline at end of file
diff --git a/ext/phar/tests/tar/files/frontcontroller.phar.inc b/ext/phar/tests/tar/files/frontcontroller.phar.inc
new file mode 100644
index 0000000000..6f426e8864
--- /dev/null
+++ b/ext/phar/tests/tar/files/frontcontroller.phar.inc
@@ -0,0 +1,13 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller.phar.tar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller.phar.tar');
+$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/tar/files/frontcontroller.phar.tar b/ext/phar/tests/tar/files/frontcontroller.phar.tar
new file mode 100644
index 0000000000..522d097845
--- /dev/null
+++ b/ext/phar/tests/tar/files/frontcontroller.phar.tar
Binary files differ
diff --git a/ext/phar/tests/tar/files/frontcontroller10.phar.inc b/ext/phar/tests/tar/files/frontcontroller10.phar.inc
new file mode 100644
index 0000000000..5b132fa117
--- /dev/null
+++ b/ext/phar/tests/tar/files/frontcontroller10.phar.inc
@@ -0,0 +1,20 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller10.phar.tar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller10.phar.tar');
+$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/tar/files/frontcontroller10.phar.tar b/ext/phar/tests/tar/files/frontcontroller10.phar.tar
new file mode 100644
index 0000000000..d43ed916a1
--- /dev/null
+++ b/ext/phar/tests/tar/files/frontcontroller10.phar.tar
Binary files differ
diff --git a/ext/phar/tests/tar/files/frontcontroller11.phar.inc b/ext/phar/tests/tar/files/frontcontroller11.phar.inc
new file mode 100644
index 0000000000..2fa15f097e
--- /dev/null
+++ b/ext/phar/tests/tar/files/frontcontroller11.phar.inc
@@ -0,0 +1,20 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller11.phar.tar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller11.phar.tar');
+$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/tar/files/frontcontroller11.phar.tar b/ext/phar/tests/tar/files/frontcontroller11.phar.tar
new file mode 100644
index 0000000000..c8f98a1e78
--- /dev/null
+++ b/ext/phar/tests/tar/files/frontcontroller11.phar.tar
Binary files differ
diff --git a/ext/phar/tests/tar/files/frontcontroller12.phar.inc b/ext/phar/tests/tar/files/frontcontroller12.phar.inc
new file mode 100644
index 0000000000..693ef0aa01
--- /dev/null
+++ b/ext/phar/tests/tar/files/frontcontroller12.phar.inc
@@ -0,0 +1,20 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller12.phar.tar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller12.phar.tar');
+$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"));
+Phar::webPhar();
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
diff --git a/ext/phar/tests/tar/files/frontcontroller12.phar.tar b/ext/phar/tests/tar/files/frontcontroller12.phar.tar
new file mode 100644
index 0000000000..06e7e59b03
--- /dev/null
+++ b/ext/phar/tests/tar/files/frontcontroller12.phar.tar
Binary files differ
diff --git a/ext/phar/tests/tar/files/frontcontroller2.phar.inc b/ext/phar/tests/tar/files/frontcontroller2.phar.inc
new file mode 100644
index 0000000000..8ae1171a38
--- /dev/null
+++ b/ext/phar/tests/tar/files/frontcontroller2.phar.inc
@@ -0,0 +1,12 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller2.phar.tar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller2.phar.tar');
+$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/tar/files/frontcontroller2.phar.tar b/ext/phar/tests/tar/files/frontcontroller2.phar.tar
new file mode 100644
index 0000000000..857b116890
--- /dev/null
+++ b/ext/phar/tests/tar/files/frontcontroller2.phar.tar
Binary files differ
diff --git a/ext/phar/tests/tar/files/frontcontroller3.phar.inc b/ext/phar/tests/tar/files/frontcontroller3.phar.inc
new file mode 100644
index 0000000000..9729d0065b
--- /dev/null
+++ b/ext/phar/tests/tar/files/frontcontroller3.phar.inc
@@ -0,0 +1,18 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller3.phar.tar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller3.phar.tar');
+$a['a.php'] = 'hio';
+$a['a.jpg'] = 'hio';
+$a['a.phps'] = '<?php function hio(){}';
+$a->setStub('<?php
+function s($a)
+{
+ static $b = array("/hi" => "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/tar/files/frontcontroller3.phar.tar b/ext/phar/tests/tar/files/frontcontroller3.phar.tar
new file mode 100644
index 0000000000..f733884d12
--- /dev/null
+++ b/ext/phar/tests/tar/files/frontcontroller3.phar.tar
Binary files differ
diff --git a/ext/phar/tests/tar/files/frontcontroller4.phar.inc b/ext/phar/tests/tar/files/frontcontroller4.phar.inc
new file mode 100644
index 0000000000..eb1d56f0d4
--- /dev/null
+++ b/ext/phar/tests/tar/files/frontcontroller4.phar.inc
@@ -0,0 +1,18 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller4.phar.tar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller4.phar.tar');
+$a['a.php'] = 'hio';
+$a['a.jpg'] = 'hio';
+$a['a.phps'] = '<?php function hio(){}';
+$a->setStub('<?php
+function s($a)
+{
+ static $b = array("/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/tar/files/frontcontroller4.phar.tar b/ext/phar/tests/tar/files/frontcontroller4.phar.tar
new file mode 100644
index 0000000000..5d11af499c
--- /dev/null
+++ b/ext/phar/tests/tar/files/frontcontroller4.phar.tar
Binary files differ
diff --git a/ext/phar/tests/tar/files/frontcontroller5.phar.inc b/ext/phar/tests/tar/files/frontcontroller5.phar.inc
new file mode 100644
index 0000000000..d6204c7d97
--- /dev/null
+++ b/ext/phar/tests/tar/files/frontcontroller5.phar.inc
@@ -0,0 +1,12 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller5.phar.tar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller5.phar.tar');
+$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/tar/files/frontcontroller5.phar.tar b/ext/phar/tests/tar/files/frontcontroller5.phar.tar
new file mode 100644
index 0000000000..e6e9015bf8
--- /dev/null
+++ b/ext/phar/tests/tar/files/frontcontroller5.phar.tar
Binary files differ
diff --git a/ext/phar/tests/tar/files/frontcontroller6.phar.inc b/ext/phar/tests/tar/files/frontcontroller6.phar.inc
new file mode 100644
index 0000000000..66212d82e8
--- /dev/null
+++ b/ext/phar/tests/tar/files/frontcontroller6.phar.inc
@@ -0,0 +1,12 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller6.phar.tar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller6.phar.tar');
+$a['a.php'] = 'hio';
+$a['a.jpg'] = 'hio';
+$a['a.phps'] = '<?php function hio(){}';
+$a->setStub('<?php
+Phar::webPhar("whatever", "index.php", null, array("blah" => 100));
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
diff --git a/ext/phar/tests/tar/files/frontcontroller6.phar.tar b/ext/phar/tests/tar/files/frontcontroller6.phar.tar
new file mode 100644
index 0000000000..d30b7ab9eb
--- /dev/null
+++ b/ext/phar/tests/tar/files/frontcontroller6.phar.tar
Binary files differ
diff --git a/ext/phar/tests/tar/files/frontcontroller7.phar.inc b/ext/phar/tests/tar/files/frontcontroller7.phar.inc
new file mode 100644
index 0000000000..74adf2c008
--- /dev/null
+++ b/ext/phar/tests/tar/files/frontcontroller7.phar.inc
@@ -0,0 +1,12 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller7.phar.tar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller7.phar.tar');
+$a['a.php'] = 'hio';
+$a['a.jpg'] = 'hio';
+$a['a.phps'] = '<?php function hio(){}';
+$a->setStub('<?php
+Phar::webPhar("whatever", "index.php", null, array("blah" => null));
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
diff --git a/ext/phar/tests/tar/files/frontcontroller7.phar.tar b/ext/phar/tests/tar/files/frontcontroller7.phar.tar
new file mode 100644
index 0000000000..c7ccc940c1
--- /dev/null
+++ b/ext/phar/tests/tar/files/frontcontroller7.phar.tar
Binary files differ
diff --git a/ext/phar/tests/tar/files/frontcontroller8.phar.inc b/ext/phar/tests/tar/files/frontcontroller8.phar.inc
new file mode 100644
index 0000000000..f51a762806
--- /dev/null
+++ b/ext/phar/tests/tar/files/frontcontroller8.phar.inc
@@ -0,0 +1,13 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller8.phar.tar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller8.phar.tar');
+$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/tar/files/frontcontroller8.phar.tar b/ext/phar/tests/tar/files/frontcontroller8.phar.tar
new file mode 100644
index 0000000000..98495717ce
--- /dev/null
+++ b/ext/phar/tests/tar/files/frontcontroller8.phar.tar
Binary files differ
diff --git a/ext/phar/tests/tar/files/frontcontroller9.phar.inc b/ext/phar/tests/tar/files/frontcontroller9.phar.inc
new file mode 100644
index 0000000000..758ce4ff4e
--- /dev/null
+++ b/ext/phar/tests/tar/files/frontcontroller9.phar.inc
@@ -0,0 +1,14 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller9.phar.tar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller9.phar.tar');
+$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/tar/files/frontcontroller9.phar.tar b/ext/phar/tests/tar/files/frontcontroller9.phar.tar
new file mode 100644
index 0000000000..481864c1cf
--- /dev/null
+++ b/ext/phar/tests/tar/files/frontcontroller9.phar.tar
Binary files differ
diff --git a/ext/phar/tests/tar/files/links.tar b/ext/phar/tests/tar/files/links.tar
new file mode 100644
index 0000000000..6cd22df2bc
--- /dev/null
+++ b/ext/phar/tests/tar/files/links.tar
Binary files differ
diff --git a/ext/phar/tests/tar/files/make_invalid_tar.php.inc b/ext/phar/tests/tar/files/make_invalid_tar.php.inc
new file mode 100644
index 0000000000..c18bd199b3
--- /dev/null
+++ b/ext/phar/tests/tar/files/make_invalid_tar.php.inc
@@ -0,0 +1,9 @@
+<?php
+include dirname(__FILE__) . '/tarmaker.php.inc';
+class corrupter extends tarmaker {
+function close()
+{
+ fwrite($this->tmp, 'oopsie');
+ fclose($this->tmp);
+}
+} \ No newline at end of file
diff --git a/ext/phar/tests/tar/files/subdirlink.tar b/ext/phar/tests/tar/files/subdirlink.tar
new file mode 100644
index 0000000000..5463a4942d
--- /dev/null
+++ b/ext/phar/tests/tar/files/subdirlink.tar
Binary files differ
diff --git a/ext/phar/tests/tar/files/tarmaker.php.inc b/ext/phar/tests/tar/files/tarmaker.php.inc
new file mode 100644
index 0000000000..902507881a
--- /dev/null
+++ b/ext/phar/tests/tar/files/tarmaker.php.inc
@@ -0,0 +1,169 @@
+<?php
+// stolen from PEAR2_Pyrus_Developer_Creator_Tar by Greg Beaver, the original author, for use in unit tests
+class tarmaker
+{
+ /**
+ * Path to archive file
+ *
+ * @var string
+ */
+ protected $archive;
+ /**
+ * Temporary stream used for creating the archive
+ *
+ * @var stream
+ */
+ protected $tmp;
+ protected $path;
+ protected $compress;
+ function __construct($path, $compress = 'zlib')
+ {
+ $this->compress = $compress;
+ if ($compress === 'bz2' && !function_exists('bzopen')) {
+ throw new PEAR2_Pyrus_Developer_Creator_Exception(
+ 'bzip2 extension not available');
+ }
+ if ($compress === 'zlib' && !function_exists('gzopen')) {
+ throw new PEAR2_Pyrus_Developer_Creator_Exception(
+ 'zlib extension not available');
+ }
+ $this->path = $path;
+ }
+
+ /**
+ * save a file inside this package
+ *
+ * This code is modified from Vincent Lascaux's File_Archive
+ * package, which is licensed under the LGPL license.
+ * @param string relative path within the package
+ * @param string|resource file contents or open file handle
+ */
+ function addFile($path, $fileOrStream, $stat = null)
+ {
+ clearstatcache();
+ if ($stat === null) {
+ if (is_resource($fileOrStream)) {
+ $stat = fstat($fileOrStream);
+ } else {
+ $stat = array(
+ 'mode' => 0x8000 + 0644,
+ 'uid' => 0,
+ 'gid' => 0,
+ 'size' => strlen($fileOrStream),
+ 'mtime' => time(),
+ );
+ }
+ }
+
+ $link = null;
+ if ($stat['mode'] & 0x4000) {
+ $type = 5; // Directory
+ } else if ($stat['mode'] & 0x8000) {
+ $type = 0; // Regular
+ } else if ($stat['mode'] & 0xA000) {
+ $type = 1; // Link
+ $link = @readlink($current);
+ } else {
+ $type = 9; // Unknown
+ }
+
+ $filePrefix = '';
+ if (strlen($path) > 255) {
+ throw new Exception(
+ "$path is too long, must be 255 characters or less"
+ );
+ } else if (strlen($path) > 100) {
+ $filePrefix = substr($path, 0, strlen($path)-100);
+ $path = substr($path, -100);
+ }
+
+ $block = pack('a100a8a8a8a12A12',
+ $path,
+ decoct($stat['mode']),
+ sprintf('%6s ',decoct($stat['uid'])),
+ sprintf('%6s ',decoct($stat['gid'])),
+ sprintf('%11s ',decoct($stat['size'])),
+ sprintf('%11s ',decoct($stat['mtime']))
+ );
+
+ $blockend = pack('a1a100a6a2a32a32a8a8a155a12',
+ $type,
+ $link,
+ 'ustar',
+ '00',
+ 'Pyrus',
+ 'Pyrus',
+ '',
+ '',
+ $filePrefix,
+ '');
+
+ $checkheader = array_merge(str_split($block), str_split($blockend));
+ if (!function_exists('_pear2tarchecksum')) {
+ function _pear2tarchecksum($a, $b) {return $a + ord($b);}
+ }
+ $checksum = 256; // 8 * ord(' ');
+ $checksum += array_reduce($checkheader, '_pear2tarchecksum');
+
+ $checksum = pack('a8', sprintf('%6s ', decoct($checksum)));
+
+ fwrite($this->tmp, $block . $checksum . $blockend, 512);
+ if (is_resource($fileOrStream)) {
+ stream_copy_to_stream($fileOrStream, $this->tmp);
+ if ($stat['size'] % 512) {
+ fwrite($this->tmp, str_repeat("\0", 512 - $stat['size'] % 512));
+ }
+ } else {
+ fwrite($this->tmp, $fileOrStream);
+ if (strlen($fileOrStream) % 512) {
+ fwrite($this->tmp, str_repeat("\0", 512 - strlen($fileOrStream) % 512));
+ }
+ }
+ }
+
+ /**
+ * Initialize the package creator
+ */
+ function init()
+ {
+ switch ($this->compress) {
+ case 'zlib' :
+ $this->tmp = gzopen($this->path, 'wb');
+ break;
+ case 'bz2' :
+ $this->tmp = bzopen($this->path, 'w');
+ break;
+ case 'none' :
+ $this->tmp = fopen($this->path, 'wb');
+ break;
+ default :
+ throw new Exception(
+ 'unknown compression type ' . $this->compress);
+ }
+ }
+
+ /**
+ * Create an internal directory, creating parent directories as needed
+ *
+ * @param string $dir
+ */
+ function mkdir($dir)
+ {
+ $this->addFile($dir, "", array(
+ 'mode' => 0x4000 + 0644,
+ 'uid' => 0,
+ 'gid' => 0,
+ 'size' => 0,
+ 'mtime' => time(),
+ ));
+ }
+
+ /**
+ * Finish saving the package
+ */
+ function close()
+ {
+ fwrite($this->tmp, pack('a1024', ''));
+ fclose($this->tmp);
+ }
+} \ No newline at end of file
diff --git a/ext/phar/tests/tar/files/tinylink.tar b/ext/phar/tests/tar/files/tinylink.tar
new file mode 100644
index 0000000000..741b56c2f5
--- /dev/null
+++ b/ext/phar/tests/tar/files/tinylink.tar
Binary files differ
diff --git a/ext/phar/tests/tar/files/trunc.tar b/ext/phar/tests/tar/files/trunc.tar
new file mode 100644
index 0000000000..2156b5c623
--- /dev/null
+++ b/ext/phar/tests/tar/files/trunc.tar
Binary files differ
diff --git a/ext/phar/tests/tar/frontcontroller1.phar.phpt b/ext/phar/tests/tar/frontcontroller1.phar.phpt
new file mode 100644
index 0000000000..77158169bb
--- /dev/null
+++ b/ext/phar/tests/tar/frontcontroller1.phar.phpt
@@ -0,0 +1,15 @@
+--TEST--
+Phar front controller other tar-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller1.phar.php
+REQUEST_URI=/frontcontroller1.phar.php/a.jpg
+PATH_INFO=/a.jpg
+--FILE_EXTERNAL--
+files/frontcontroller.phar.tar
+--EXPECTHEADERS--
+Content-type: image/jpeg
+Content-length: 3
+--EXPECT--
+hio
diff --git a/ext/phar/tests/tar/frontcontroller10.phar.phpt b/ext/phar/tests/tar/frontcontroller10.phar.phpt
new file mode 100644
index 0000000000..0ca67b3d3e
--- /dev/null
+++ b/ext/phar/tests/tar/frontcontroller10.phar.phpt
@@ -0,0 +1,22 @@
+--TEST--
+Phar front controller rewrite array invalid tar-based
+--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.tar
+--EXPECTHEADERS--
+Content-type: text/html
+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/tar/frontcontroller11.phar.phpt b/ext/phar/tests/tar/frontcontroller11.phar.phpt
new file mode 100644
index 0000000000..3a420f6c85
--- /dev/null
+++ b/ext/phar/tests/tar/frontcontroller11.phar.phpt
@@ -0,0 +1,18 @@
+--TEST--
+Phar front controller mime type extension is not a string tar-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller11.phar.php
+REQUEST_URI=/frontcontroller11.phar.php/a.php
+PATH_INFO=/a.php
+--FILE_EXTERNAL--
+files/frontcontroller5.phar.tar
+--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/tar/frontcontroller12.phar.phpt b/ext/phar/tests/tar/frontcontroller12.phar.phpt
new file mode 100644
index 0000000000..e659434e07
--- /dev/null
+++ b/ext/phar/tests/tar/frontcontroller12.phar.phpt
@@ -0,0 +1,18 @@
+--TEST--
+Phar front controller mime type unknown int tar-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller12.phar.php
+REQUEST_URI=/frontcontroller12.phar.php/a.php
+PATH_INFO=/a.php
+--FILE_EXTERNAL--
+files/frontcontroller6.phar.tar
+--EXPECTHEADERS--
+Content-type: text/html
+--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/tar/frontcontroller13.phar.phpt b/ext/phar/tests/tar/frontcontroller13.phar.phpt
new file mode 100644
index 0000000000..0b9d3e3895
--- /dev/null
+++ b/ext/phar/tests/tar/frontcontroller13.phar.phpt
@@ -0,0 +1,18 @@
+--TEST--
+Phar front controller mime type not string/int tar-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller13.phar.php
+REQUEST_URI=/frontcontroller13.phar.php/a.php
+PATH_INFO=/a.php
+--FILE_EXTERNAL--
+files/frontcontroller7.phar.tar
+--EXPECTHEADERS--
+Content-type: text/html
+--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/tar/frontcontroller14.phar.phpt b/ext/phar/tests/tar/frontcontroller14.phar.phpt
new file mode 100644
index 0000000000..c40f9b6c34
--- /dev/null
+++ b/ext/phar/tests/tar/frontcontroller14.phar.phpt
@@ -0,0 +1,15 @@
+--TEST--
+Phar front controller mime type override, other tar-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller14.phar.php
+REQUEST_URI=/frontcontroller14.phar.php/a.jpg
+PATH_INFO=/a.jpg
+--FILE_EXTERNAL--
+files/frontcontroller8.phar.tar
+--EXPECTHEADERS--
+Content-type: foo/bar
+Content-length: 4
+--EXPECT--
+hio2
diff --git a/ext/phar/tests/tar/frontcontroller15.phar.phpt b/ext/phar/tests/tar/frontcontroller15.phar.phpt
new file mode 100644
index 0000000000..154117fda4
--- /dev/null
+++ b/ext/phar/tests/tar/frontcontroller15.phar.phpt
@@ -0,0 +1,18 @@
+--TEST--
+Phar front controller mime type override, Phar::PHPS tar-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller15.phar.php
+REQUEST_URI=/frontcontroller15.phar.php/a.php
+PATH_INFO=/a.php
+--FILE_EXTERNAL--
+files/frontcontroller8.phar.tar
+--EXPECTHEADERS--
+Content-type: text/html
+--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/tar/frontcontroller16.phar.phpt b/ext/phar/tests/tar/frontcontroller16.phar.phpt
new file mode 100644
index 0000000000..042a695eb3
--- /dev/null
+++ b/ext/phar/tests/tar/frontcontroller16.phar.phpt
@@ -0,0 +1,15 @@
+--TEST--
+Phar front controller mime type override, Phar::PHP tar-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller16.phar.php
+REQUEST_URI=/frontcontroller16.phar.php/a.phps
+PATH_INFO=/a.phps
+--FILE_EXTERNAL--
+files/frontcontroller8.phar.tar
+--EXPECTHEADERS--
+Content-type: text/html
+--EXPECT--
+hio1
+
diff --git a/ext/phar/tests/tar/frontcontroller17.phar.phpt b/ext/phar/tests/tar/frontcontroller17.phar.phpt
new file mode 100644
index 0000000000..17d04baf30
--- /dev/null
+++ b/ext/phar/tests/tar/frontcontroller17.phar.phpt
@@ -0,0 +1,16 @@
+--TEST--
+Phar front controller mime type unknown tar-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller17.phar.php
+REQUEST_URI=/frontcontroller17.phar.php/fronk.gronk
+PATH_INFO=/fronk.gronk
+--FILE_EXTERNAL--
+files/frontcontroller8.phar.tar
+--EXPECTHEADERS--
+Content-type: application/octet-stream
+Content-length: 4
+--EXPECT--
+hio3
+
diff --git a/ext/phar/tests/tar/frontcontroller18.phar.phpt b/ext/phar/tests/tar/frontcontroller18.phar.phpt
new file mode 100644
index 0000000000..c52ce291c7
--- /dev/null
+++ b/ext/phar/tests/tar/frontcontroller18.phar.phpt
@@ -0,0 +1,16 @@
+--TEST--
+Phar front controller $_SERVER munging failure tar-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller18.phar.php
+REQUEST_URI=/frontcontroller18.phar.php/fronk.gronk
+PATH_INFO=/fronk.gronk
+--FILE_EXTERNAL--
+files/frontcontroller9.phar.tar
+--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/tar/frontcontroller19.phar.phpt b/ext/phar/tests/tar/frontcontroller19.phar.phpt
new file mode 100644
index 0000000000..6b07438787
--- /dev/null
+++ b/ext/phar/tests/tar/frontcontroller19.phar.phpt
@@ -0,0 +1,16 @@
+--TEST--
+Phar front controller $_SERVER munging failure 2 tar-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller19.phar.php
+REQUEST_URI=/frontcontroller19.phar.php/
+PATH_INFO=/
+--FILE_EXTERNAL--
+files/frontcontroller10.phar.tar
+--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/tar/frontcontroller2.phar.phpt b/ext/phar/tests/tar/frontcontroller2.phar.phpt
new file mode 100644
index 0000000000..a6b1c780fd
--- /dev/null
+++ b/ext/phar/tests/tar/frontcontroller2.phar.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Phar front controller PHP test tar-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller2.phar.php
+REQUEST_URI=/frontcontroller2.phar.php/a.php
+PATH_INFO=/a.php
+--FILE_EXTERNAL--
+files/frontcontroller.phar.tar
+--EXPECTHEADERS--
+Content-type: text/html
+--EXPECT--
+hio
diff --git a/ext/phar/tests/tar/frontcontroller20.phar.phpt b/ext/phar/tests/tar/frontcontroller20.phar.phpt
new file mode 100644
index 0000000000..3cc470d41b
--- /dev/null
+++ b/ext/phar/tests/tar/frontcontroller20.phar.phpt
@@ -0,0 +1,16 @@
+--TEST--
+Phar front controller $_SERVER munging failure 3 tar-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller20.phar.php
+REQUEST_URI=/frontcontroller20.phar.php/
+PATH_INFO=/
+--FILE_EXTERNAL--
+files/frontcontroller11.phar.tar
+--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/tar/frontcontroller21.phar.phpt b/ext/phar/tests/tar/frontcontroller21.phar.phpt
new file mode 100644
index 0000000000..eb21897226
--- /dev/null
+++ b/ext/phar/tests/tar/frontcontroller21.phar.phpt
@@ -0,0 +1,22 @@
+--TEST--
+Phar front controller $_SERVER munging success tar-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--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.tar
+--EXPECTHEADERS--
+Content-type: text/html
+--EXPECTF--
+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/tar/frontcontroller3.phar.phpt b/ext/phar/tests/tar/frontcontroller3.phar.phpt
new file mode 100644
index 0000000000..dee16ee2b2
--- /dev/null
+++ b/ext/phar/tests/tar/frontcontroller3.phar.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Phar front controller phps tar-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller3.phar.php
+REQUEST_URI=/frontcontroller3.phar.php/a.phps
+PATH_INFO=/a.phps
+--FILE_EXTERNAL--
+files/frontcontroller.phar.tar
+--EXPECTHEADERS--
+Content-type: text/html
+--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/tar/frontcontroller4.phar.phpt b/ext/phar/tests/tar/frontcontroller4.phar.phpt
new file mode 100644
index 0000000000..db4846c69b
--- /dev/null
+++ b/ext/phar/tests/tar/frontcontroller4.phar.phpt
@@ -0,0 +1,13 @@
+--TEST--
+Phar front controller index.php relocate (no /) tar-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller4.phar.php
+REQUEST_URI=/frontcontroller4.phar.php
+--FILE_EXTERNAL--
+files/frontcontroller.phar.tar
+--EXPECTHEADERS--
+Status: 301 Moved Permanently
+Location: /frontcontroller4.phar.php/index.php
+--EXPECT--
diff --git a/ext/phar/tests/tar/frontcontroller5.phar.phpt b/ext/phar/tests/tar/frontcontroller5.phar.phpt
new file mode 100644
index 0000000000..534e66a1e3
--- /dev/null
+++ b/ext/phar/tests/tar/frontcontroller5.phar.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Phar front controller index.php relocate tar-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller5.phar.php
+REQUEST_URI=/frontcontroller5.phar.php/
+PATH_INFO=/
+--FILE_EXTERNAL--
+files/frontcontroller.phar.tar
+--EXPECTHEADERS--
+Status: 301 Moved Permanently
+Location: /frontcontroller5.phar.php/index.php
+--EXPECT--
diff --git a/ext/phar/tests/tar/frontcontroller6.phar.phpt b/ext/phar/tests/tar/frontcontroller6.phar.phpt
new file mode 100644
index 0000000000..5375beef8c
--- /dev/null
+++ b/ext/phar/tests/tar/frontcontroller6.phar.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Phar front controller 404 tar-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller6.phar.php
+REQUEST_URI=/frontcontroller6.phar.php/notfound.php
+PATH_INFO=/notfound.php
+--FILE_EXTERNAL--
+files/frontcontroller.phar.tar
+--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/tar/frontcontroller7.phar.phpt b/ext/phar/tests/tar/frontcontroller7.phar.phpt
new file mode 100644
index 0000000000..3b73f2075c
--- /dev/null
+++ b/ext/phar/tests/tar/frontcontroller7.phar.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Phar front controller alternate index file tar-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller7.phar.php
+REQUEST_URI=/frontcontroller7.phar.php/
+PATH_INFO=/
+--FILE_EXTERNAL--
+files/frontcontroller2.phar.tar
+--EXPECTHEADERS--
+Status: 301 Moved Permanently
+Location: /frontcontroller7.phar.php/a.php
+--EXPECT--
diff --git a/ext/phar/tests/tar/frontcontroller8.phar.phpt b/ext/phar/tests/tar/frontcontroller8.phar.phpt
new file mode 100644
index 0000000000..19844cb199
--- /dev/null
+++ b/ext/phar/tests/tar/frontcontroller8.phar.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Phar front controller no index file 404 tar-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.tar
+--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/tar/frontcontroller9.phar.phpt b/ext/phar/tests/tar/frontcontroller9.phar.phpt
new file mode 100644
index 0000000000..080db58f8f
--- /dev/null
+++ b/ext/phar/tests/tar/frontcontroller9.phar.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Phar front controller rewrite array tar-based
+--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.tar
+--EXPECTHEADERS--
+Content-type: text/html
+--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/tar/links.phpt b/ext/phar/tests/tar/links.phpt
new file mode 100644
index 0000000000..73e257b8be
--- /dev/null
+++ b/ext/phar/tests/tar/links.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Phar: tar with hard link and symbolic link
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.tar';
+copy(dirname(__FILE__) . '/files/links.tar', $fname);
+try {
+ $p = new PharData($fname);
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+var_dump($p['testit/link']->getContent());
+var_dump($p['testit/hard']->getContent());
+var_dump($p['testit/file']->getContent());
+$p['testit/link'] = 'overwriting';
+var_dump($p['testit/link']->getContent());
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.tar');
+?>
+--EXPECT--
+string(3) "hi
+"
+string(3) "hi
+"
+string(3) "hi
+"
+string(11) "overwriting"
+===DONE===
diff --git a/ext/phar/tests/tar/links2.phpt b/ext/phar/tests/tar/links2.phpt
new file mode 100644
index 0000000000..1939e002bd
--- /dev/null
+++ b/ext/phar/tests/tar/links2.phpt
@@ -0,0 +1,35 @@
+--TEST--
+Phar: tar with hard link to nowhere
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.tar';
+$pname = 'phar://' . $fname;
+
+include dirname(__FILE__) . '/files/corrupt_tarmaker.php.inc';
+$a = new corrupt_tarmaker($fname, 'none');
+$a->init();
+$a->addFile('hardlink', 'internal/file.txt', array(
+ 'mode' => 0xA000 + 0644,
+ 'uid' => 0,
+ 'gid' => 0,
+ 'size' => 0,
+ 'mtime' => time(),
+ ));
+$a->close();
+
+try {
+ $p = new PharData($fname);
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.tar');
+?>
+--EXPECTF--
+phar error: "%slinks2.tar" is a corrupted tar file - hard link to non-existent file "internal/file.txt"
+===DONE===
diff --git a/ext/phar/tests/tar/links3.phpt b/ext/phar/tests/tar/links3.phpt
new file mode 100644
index 0000000000..2241081660
--- /dev/null
+++ b/ext/phar/tests/tar/links3.phpt
@@ -0,0 +1,19 @@
+--TEST--
+Phar: tar with link to absolute path
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--FILE--
+<?php
+try {
+ $p = new PharData(dirname(__FILE__) . '/files/biglink.tar');
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+echo $p['file.txt']->getContent();
+echo $p['my/file']->getContent();
+?>
+===DONE===
+--EXPECT--
+my file
+my file
+===DONE===
diff --git a/ext/phar/tests/tar/links4.phpt b/ext/phar/tests/tar/links4.phpt
new file mode 100644
index 0000000000..d0783e84ac
--- /dev/null
+++ b/ext/phar/tests/tar/links4.phpt
@@ -0,0 +1,19 @@
+--TEST--
+Phar: tar with link to root directory file from root directory file
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--FILE--
+<?php
+try {
+ $p = new PharData(dirname(__FILE__) . '/files/tinylink.tar');
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+echo $p['file.txt']->getContent();
+echo $p['link.txt']->getContent();
+?>
+===DONE===
+--EXPECT--
+hi
+hi
+===DONE===
diff --git a/ext/phar/tests/tar/links5.phpt b/ext/phar/tests/tar/links5.phpt
new file mode 100644
index 0000000000..262d41d841
--- /dev/null
+++ b/ext/phar/tests/tar/links5.phpt
@@ -0,0 +1,19 @@
+--TEST--
+Phar: tar with relative link to subdirectory file from subdirectory file
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--FILE--
+<?php
+try {
+ $p = new PharData(dirname(__FILE__) . '/files/subdirlink.tar');
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+echo $p['hi/test.txt']->getContent();
+echo $p['hi/link.txt']->getContent();
+?>
+===DONE===
+--EXPECT--
+hi
+hi
+===DONE===
diff --git a/ext/phar/tests/tar/open_for_write_existing.phpt b/ext/phar/tests/tar/open_for_write_existing.phpt
new file mode 100644
index 0000000000..641e5ce21d
--- /dev/null
+++ b/ext/phar/tests/tar/open_for_write_existing.phpt
@@ -0,0 +1,42 @@
+--TEST--
+Phar: fopen a .phar for writing (existing file) tar-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.tar';
+$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, 'extra');
+fclose($fp);
+
+include $alias . '/b/c.php';
+
+?>
+
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); ?>
+--EXPECT--
+extra
+===DONE===
diff --git a/ext/phar/tests/tar/open_for_write_existing_b.phpt b/ext/phar/tests/tar/open_for_write_existing_b.phpt
new file mode 100755
index 0000000000..54ec5855fb
--- /dev/null
+++ b/ext/phar/tests/tar/open_for_write_existing_b.phpt
@@ -0,0 +1,56 @@
+--TEST--
+Phar: fopen a .phar for writing (existing file) tar-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.tar';
+$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.tar'); ?>
+--EXPECTF--
+
+Warning: fopen(phar://%sopen_for_write_existing_b.phar.tar/b/c.php): failed to open stream: phar error: write operations disabled by INI setting in %sopen_for_write_existing_b.php on line %d
+
+Warning: fwrite(): supplied argument is not a valid stream resource in %sopen_for_write_existing_b.php on line %d
+
+Warning: fclose(): supplied argument is not a valid stream resource in %spen_for_write_existing_b.php on line %d
+This is b/c
+
+===DONE===
diff --git a/ext/phar/tests/tar/open_for_write_existing_c.phpt b/ext/phar/tests/tar/open_for_write_existing_c.phpt
new file mode 100755
index 0000000000..0e5a181e65
--- /dev/null
+++ b/ext/phar/tests/tar/open_for_write_existing_c.phpt
@@ -0,0 +1,50 @@
+--TEST--
+Phar: fopen a .phar for writing (existing file) tar-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.tar';
+$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.tar'); ?>
+--EXPECTF--
+
+Warning: fopen(phar://%sopen_for_write_existing_c.phar.tar/b/c.php): failed to open stream: phar error: write operations disabled by INI setting in %sopen_for_write_existing_c.php on line %d
+
+Warning: fwrite(): supplied argument is not a valid stream resource in %sopen_for_write_existing_c.php on line %d
+
+Warning: fclose(): supplied argument is not a valid stream resource in %sopen_for_write_existing_c.php on line %d
+This is b/c
+
+===DONE===
diff --git a/ext/phar/tests/tar/open_for_write_newfile.phpt b/ext/phar/tests/tar/open_for_write_newfile.phpt
new file mode 100644
index 0000000000..31e9d4a7e9
--- /dev/null
+++ b/ext/phar/tests/tar/open_for_write_newfile.phpt
@@ -0,0 +1,44 @@
+--TEST--
+Phar: fopen a .phar for writing (new file) tar-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.tar';
+$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, 'extra');
+fclose($fp);
+
+include $alias . '/b/c.php';
+include $alias . '/b/new.php';
+
+?>
+
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); ?>
+--EXPECT--
+This is b/c
+extra
+===DONE===
diff --git a/ext/phar/tests/tar/open_for_write_newfile_b.phpt b/ext/phar/tests/tar/open_for_write_newfile_b.phpt
new file mode 100755
index 0000000000..d3a21b4caf
--- /dev/null
+++ b/ext/phar/tests/tar/open_for_write_newfile_b.phpt
@@ -0,0 +1,61 @@
+--TEST--
+Phar: fopen a .phar for writing (new file) tar-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.tar';
+$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.tar'); ?>
+--EXPECTF--
+
+Warning: fopen(phar://%sopen_for_write_newfile_b.phar.tar/b/new.php): failed to open stream: phar error: write operations disabled by INI setting in %sopen_for_write_newfile_b.php on line %d
+
+Warning: fwrite(): supplied argument is not a valid stream resource in %sopen_for_write_newfile_b.php on line %d
+
+Warning: fclose(): supplied argument is not a valid stream resource in %sopen_for_write_newfile_b.php on line %d
+This is b/c
+
+Warning: include(phar://%sopen_for_write_newfile_b.phar.tar/b/new.php): failed to open stream: phar error: "b/new.php" is not a file in phar "%sopen_for_write_newfile_b.phar.tar" in %sopen_for_write_newfile_b.php on line %d
+
+Warning: include(): Failed opening 'phar://%sopen_for_write_newfile_b.phar.tar/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/tar/open_for_write_newfile_c.phpt b/ext/phar/tests/tar/open_for_write_newfile_c.phpt
new file mode 100755
index 0000000000..231241c8ad
--- /dev/null
+++ b/ext/phar/tests/tar/open_for_write_newfile_c.phpt
@@ -0,0 +1,54 @@
+--TEST--
+Phar: fopen a .phar for writing (new file) tar-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.tar';
+$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.tar'); ?>
+--EXPECTF--
+
+Warning: fopen(phar://%sopen_for_write_newfile_c.phar.tar/b/new.php): failed to open stream: phar error: write operations disabled by INI setting in %sopen_for_write_newfile_c.php on line %d
+
+Warning: fwrite(): supplied argument is not a valid stream resource in %sopen_for_write_newfile_c.php on line %d
+
+Warning: fclose(): supplied argument is not a valid stream resource in %sopen_for_write_newfile_c.php on line %d
+This is b/c
+
+Warning: include(phar://%sopen_for_write_newfile_c.phar.tar/b/new.php): failed to open stream: phar error: "b/new.php" is not a file in phar "%sopen_for_write_newfile_c.phar.tar" in %sopen_for_write_newfile_c.php on line %d
+
+Warning: include(): Failed opening 'phar://%sopen_for_write_newfile_c.phar.tar/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/tar/phar_begin_setstub_commit.phpt b/ext/phar/tests/tar/phar_begin_setstub_commit.phpt
new file mode 100755
index 0000000000..c990ff9b98
--- /dev/null
+++ b/ext/phar/tests/tar/phar_begin_setstub_commit.phpt
@@ -0,0 +1,51 @@
+--TEST--
+Phar::startBuffering()/setStub()/stopBuffering() tar-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+$p = new Phar(dirname(__FILE__) . '/brandnewphar.phar.tar', 0, 'brandnewphar.phar');
+var_dump($p->isFileFormat(Phar::TAR));
+//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());
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/brandnewphar.phar.tar');
+?>
+--EXPECT--
+bool(true)
+bool(true)
+bool(false)
+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(true)
+string(5) "Hello"
+string(5) "World"
+string(85) "<?php var_dump("Second"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>
+"
+===DONE===
diff --git a/ext/phar/tests/tar/phar_buildfromiterator4.phpt b/ext/phar/tests/tar/phar_buildfromiterator4.phpt
new file mode 100644
index 0000000000..b7d6d56f64
--- /dev/null
+++ b/ext/phar/tests/tar/phar_buildfromiterator4.phpt
@@ -0,0 +1,66 @@
+--TEST--
+Phar::buildFromIterator() iterator, 1 file passed in tar-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.tar');
+ var_dump($phar->buildFromIterator(new myIterator(array('a' => basename(__FILE__, 'php') . 'phpt'))));
+ var_dump($phar->isFileFormat(Phar::TAR));
+} catch (Exception $e) {
+ var_dump(get_class($e));
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/buildfromiterator.phar.tar');
+__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/tar/phar_buildfromiterator5.phpt b/ext/phar/tests/tar/phar_buildfromiterator5.phpt
new file mode 100644
index 0000000000..600bd2ee5c
--- /dev/null
+++ b/ext/phar/tests/tar/phar_buildfromiterator5.phpt
@@ -0,0 +1,59 @@
+--TEST--
+Phar::buildFromIterator() iterator, iterator returns non-string tar-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.tar');
+ 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.tar');
+__HALT_COMPILER();
+?>
+--EXPECTF--
+rewind
+valid
+current
+string(24) "UnexpectedValueException"
+Iterator myIterator returned an invalid value (must return a string)
+===DONE===
diff --git a/ext/phar/tests/tar/phar_buildfromiterator6.phpt b/ext/phar/tests/tar/phar_buildfromiterator6.phpt
new file mode 100644
index 0000000000..e891a5d065
--- /dev/null
+++ b/ext/phar/tests/tar/phar_buildfromiterator6.phpt
@@ -0,0 +1,60 @@
+--TEST--
+Phar::buildFromIterator() iterator, key is int tar-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.tar');
+ 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.tar');
+__HALT_COMPILER();
+?>
+--EXPECTF--
+rewind
+valid
+current
+key
+string(24) "UnexpectedValueException"
+Iterator myIterator returned an invalid key (must return a string)
+===DONE===
diff --git a/ext/phar/tests/tar/phar_buildfromiterator7.phpt b/ext/phar/tests/tar/phar_buildfromiterator7.phpt
new file mode 100644
index 0000000000..d64c032d71
--- /dev/null
+++ b/ext/phar/tests/tar/phar_buildfromiterator7.phpt
@@ -0,0 +1,60 @@
+--TEST--
+Phar::buildFromIterator() iterator, file can't be opened tar-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.tar');
+ 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.tar');
+__HALT_COMPILER();
+?>
+--EXPECT--
+rewind
+valid
+current
+key
+string(24) "UnexpectedValueException"
+Iterator myIterator returned a file that could not be opened "phar_buildfromiterator7./oopsie/there.phpt"
+===DONE===
diff --git a/ext/phar/tests/tar/phar_buildfromiterator8.phpt b/ext/phar/tests/tar/phar_buildfromiterator8.phpt
new file mode 100644
index 0000000000..f42640f692
--- /dev/null
+++ b/ext/phar/tests/tar/phar_buildfromiterator8.phpt
@@ -0,0 +1,73 @@
+--TEST--
+Phar::buildFromIterator() iterator, SplFileInfo as current tar-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.tar');
+ $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::TAR));
+} catch (Exception $e) {
+ var_dump(get_class($e));
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/buildfromiterator.phar.tar');
+__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/tar/phar_buildfromiterator9.phpt b/ext/phar/tests/tar/phar_buildfromiterator9.phpt
new file mode 100644
index 0000000000..f9deef4d9f
--- /dev/null
+++ b/ext/phar/tests/tar/phar_buildfromiterator9.phpt
@@ -0,0 +1,65 @@
+--TEST--
+Phar::buildFromIterator() iterator, 1 file resource passed in tar-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.tar');
+ 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.tar');
+__HALT_COMPILER();
+?>
+--EXPECTF--
+rewind
+valid
+current
+key
+next
+valid
+array(1) {
+ ["a"]=>
+ string(%d) "[stream]"
+}
+===DONE===
diff --git a/ext/phar/tests/tar/phar_commitwrite.phpt b/ext/phar/tests/tar/phar_commitwrite.phpt
new file mode 100644
index 0000000000..b926b9a081
--- /dev/null
+++ b/ext/phar/tests/tar/phar_commitwrite.phpt
@@ -0,0 +1,44 @@
+--TEST--
+Phar::setStub()/stopBuffering() tar-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+$p = new Phar(dirname(__FILE__) . '/brandnewphar.phar.tar', 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::TAR));
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/brandnewphar.phar.tar');
+?>
+--EXPECT--
+string(60) "<?php // tar-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=== \ No newline at end of file
diff --git a/ext/phar/tests/tar/phar_convert_phar.phpt b/ext/phar/tests/tar/phar_convert_phar.phpt
new file mode 100644
index 0000000000..6a7d78ea8b
--- /dev/null
+++ b/ext/phar/tests/tar/phar_convert_phar.phpt
@@ -0,0 +1,58 @@
+--TEST--
+Phar::convertToPhar() from tar
+--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::TAR));
+var_dump(strlen($phar->getStub()));
+
+$phar = $phar->convertToExecutable(Phar::TAR);
+var_dump($phar->isFileFormat(Phar::TAR));
+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.tar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.tar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.3.phar');
+__HALT_COMPILER();
+?>
+--EXPECT--
+bool(false)
+int(6651)
+bool(true)
+string(60) "<?php // tar-based phar archive stub file
+__HALT_COMPILER();"
+bool(true)
+int(6651)
+bool(true)
+int(6651)
+===DONE===
diff --git a/ext/phar/tests/tar/phar_convert_phar2.phpt b/ext/phar/tests/tar/phar_convert_phar2.phpt
new file mode 100644
index 0000000000..496948b14c
--- /dev/null
+++ b/ext/phar/tests/tar/phar_convert_phar2.phpt
@@ -0,0 +1,62 @@
+--TEST--
+Phar::convertToPhar() gzipped
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("zlib")) 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';
+
+$phar = new Phar($fname);
+$phar['a.txt'] = 'some text';
+$phar->stopBuffering();
+var_dump($phar->isFileFormat(Phar::TAR));
+var_dump(strlen($phar->getStub()));
+
+$phar = $phar->convertToExecutable(Phar::TAR);
+var_dump($phar->isFileFormat(Phar::TAR));
+var_dump($phar->getStub());
+
+$phar['a'] = 'hi there';
+
+$phar = $phar->convertToExecutable(Phar::PHAR, Phar::GZ);
+var_dump($phar->isFileFormat(Phar::PHAR));
+var_dump($phar->isCompressed());
+var_dump(strlen($phar->getStub()));
+
+copy($fname . '.gz', $fname2);
+
+$phar = new Phar($fname2);
+var_dump($phar->isFileFormat(Phar::PHAR));
+var_dump($phar->isCompressed() == Phar::GZ);
+var_dump(strlen($phar->getStub()));
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.gz');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar.gz');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '2.phar');
+__HALT_COMPILER();
+?>
+--EXPECT--
+bool(false)
+int(6651)
+bool(true)
+string(60) "<?php // tar-based phar archive stub file
+__HALT_COMPILER();"
+bool(true)
+int(4096)
+int(6651)
+bool(true)
+bool(true)
+int(6651)
+===DONE===
diff --git a/ext/phar/tests/tar/phar_convert_phar3.phpt b/ext/phar/tests/tar/phar_convert_phar3.phpt
new file mode 100644
index 0000000000..f4768194d1
--- /dev/null
+++ b/ext/phar/tests/tar/phar_convert_phar3.phpt
@@ -0,0 +1,62 @@
+--TEST--
+Phar::convertToPhar() bzipped
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("bz2")) 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';
+
+$phar = new Phar($fname);
+$phar['a.txt'] = 'some text';
+$phar->stopBuffering();
+var_dump($phar->isFileFormat(Phar::TAR));
+var_dump(strlen($phar->getStub()));
+
+$phar = $phar->convertToExecutable(Phar::TAR);
+var_dump($phar->isFileFormat(Phar::TAR));
+var_dump($phar->getStub());
+
+$phar['a'] = 'hi there';
+
+$phar = $phar->convertToExecutable(Phar::PHAR, Phar::BZ2);
+var_dump($phar->isFileFormat(Phar::PHAR));
+var_dump($phar->isCompressed());
+var_dump(strlen($phar->getStub()));
+
+copy($fname . '.bz2', $fname2);
+
+$phar = new Phar($fname2);
+var_dump($phar->isFileFormat(Phar::PHAR));
+var_dump($phar->isCompressed() == Phar::BZ2);
+var_dump(strlen($phar->getStub()));
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.bz2');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '2.phar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar.bz2');
+__HALT_COMPILER();
+?>
+--EXPECT--
+bool(false)
+int(6651)
+bool(true)
+string(60) "<?php // tar-based phar archive stub file
+__HALT_COMPILER();"
+bool(true)
+int(8192)
+int(6651)
+bool(true)
+bool(true)
+int(6651)
+===DONE===
diff --git a/ext/phar/tests/tar/phar_copy.phpt b/ext/phar/tests/tar/phar_copy.phpt
new file mode 100644
index 0000000000..ed5cdac8bc
--- /dev/null
+++ b/ext/phar/tests/tar/phar_copy.phpt
@@ -0,0 +1,56 @@
+--TEST--
+Phar: copy() tar-based
+--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"); ?>
+--INI--
+phar.readonly=0
+phar.require_hash=1
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar.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::TAR));
+ $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::TAR));
+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.tar.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/tar/phar_magic.phpt b/ext/phar/tests/tar/phar_magic.phpt
new file mode 100644
index 0000000000..1bb336f96c
--- /dev/null
+++ b/ext/phar/tests/tar/phar_magic.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Phar: include/fopen magic tar-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.tar.php';
+$p = new Phar($fname);
+var_dump($p->isFileFormat(Phar::TAR));
+$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
+set_include_path("phar://" . __FILE__);
+include "phar://" . __FILE__ . "/a";
+__HALT_COMPILER();');
+include $fname;
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar.php');
+__HALT_COMPILER();
+?>
+--EXPECTF--
+bool(true)
+in b
+<?php include "b/c.php";
+in d
+===DONE===
diff --git a/ext/phar/tests/tar/phar_setalias.phpt b/ext/phar/tests/tar/phar_setalias.phpt
new file mode 100644
index 0000000000..a1bc51154c
--- /dev/null
+++ b/ext/phar/tests/tar/phar_setalias.phpt
@@ -0,0 +1,51 @@
+--TEST--
+Phar::setAlias() tar-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.tar';
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '2.phar.tar';
+
+$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";
+
+copy($fname, $fname2);
+$phar->setAlias('unused');
+$a = new Phar($fname2);
+echo $a->getAlias() . "\n";
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phartmp.tar');
+__HALT_COMPILER();
+?>
+--EXPECT--
+hio
+test
+test
+===DONE===
diff --git a/ext/phar/tests/tar/phar_setalias2.phpt b/ext/phar/tests/tar/phar_setalias2.phpt
new file mode 100644
index 0000000000..a44cc397c2
--- /dev/null
+++ b/ext/phar/tests/tar/phar_setalias2.phpt
@@ -0,0 +1,53 @@
+--TEST--
+Phar::setAlias() error tar-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.tar';
+
+$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.tar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phartmp.tar');
+__HALT_COMPILER();
+?>
+--EXPECTF--
+hio
+test
+alias "test" is already used for archive "%sphar_setalias2.phar.tar" and cannot be used for other archives
+===DONE===
diff --git a/ext/phar/tests/tar/phar_setdefaultstub.phpt b/ext/phar/tests/tar/phar_setdefaultstub.phpt
new file mode 100644
index 0000000000..c1e6642a17
--- /dev/null
+++ b/ext/phar/tests/tar/phar_setdefaultstub.phpt
@@ -0,0 +1,80 @@
+--TEST--
+Phar: Phar::setDefaultStub() with and without arg, tar-based phar
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar';
+
+$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.tar');
+?>
+--EXPECTF--
+string(51) "<?php echo "Hello World\n"; __HALT_COMPILER(); ?>
+"
+============================================================================
+============================================================================
+string(60) "<?php // tar-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 // tar-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 // tar-based phar archive stub file
+__HALT_COMPILER();"
+===DONE===
diff --git a/ext/phar/tests/tar/phar_stub.phpt b/ext/phar/tests/tar/phar_stub.phpt
new file mode 100644
index 0000000000..e0d728f6f8
--- /dev/null
+++ b/ext/phar/tests/tar/phar_stub.phpt
@@ -0,0 +1,75 @@
+--TEST--
+Phar::setStub() (tar-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.tar.php';
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar.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 = '<?php echo "second stub\n"; __HALT_COMPILER(); ?>';
+
+//// 2
+$phar->setStub($file);
+echo $phar->getStub();
+
+$fname3 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phartmp.php';
+$file = '<?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, '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.tar.php');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar.tar.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/tar/phar_stub_error.phpt b/ext/phar/tests/tar/phar_stub_error.phpt
new file mode 100755
index 0000000000..5d35b932fe
--- /dev/null
+++ b/ext/phar/tests/tar/phar_stub_error.phpt
@@ -0,0 +1,57 @@
+--TEST--
+Phar::setStub()/getStub() tar-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.tar';
+
+$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($stub);
+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.tar');
+__HALT_COMPILER();
+?>
+--EXPECTF--
+string(50) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>
+"
+string(50) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>
+"
+bool(true)
+Exception: illegal stub for tar-based phar "%sphar_stub_error.phar.tar"
+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/tar/refcount1.phpt b/ext/phar/tests/tar/refcount1.phpt
new file mode 100644
index 0000000000..c6808afb63
--- /dev/null
+++ b/ext/phar/tests/tar/refcount1.phpt
@@ -0,0 +1,74 @@
+--TEST--
+Phar: test that refcounting avoids problems with deleting a file tar-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
+include dirname(__FILE__) . '/files/tarmaker.php.inc';
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar';
+$alias = 'phar://' . $fname;
+
+$tar = new tarmaker($fname, 'none');
+$tar->init();
+$tar->addFile('.phar/stub.php', "<?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"; ?>';
+$files['.phar/alias.txt'] = 'hio';
+
+foreach ($files as $n => $file) {
+ $tar->addFile($n, $file);
+}
+
+$tar->close();
+
+$fp = fopen($alias . '/b/c.php', 'wb');
+fwrite($fp, "extra");
+fclose($fp);
+echo "===CLOSE===\n";
+$phar = new Phar($fname);
+$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.tar'); ?>
+--EXPECTF--
+===CLOSE===
+object(PharFileInfo)#%d (2) {
+ ["pathName":"SplFileInfo":private]=>
+ string(%d) "phar://%srefcount1.phar.tar/b"
+ ["fileName":"SplFileInfo":private]=>
+ string(%d) "phar://%srefcount1.phar.tar/b/c.php"
+}
+string(5) "extra"
+===UNLINK===
+
+Warning: unlink(): phar error: "b/c.php" in phar "%srefcount1.phar.tar", has open file pointers, cannot unlink in %srefcount1.php on line %d
+object(PharFileInfo)#%d (2) {
+ ["pathName":"SplFileInfo":private]=>
+ string(%d) "phar://%srefcount1.phar.tar/b"
+ ["fileName":"SplFileInfo":private]=>
+ string(%s) "phar://%srefcount1.phar.tar/b/c.php"
+}
+string(5) "extra"
+extra
+===DONE===
diff --git a/ext/phar/tests/tar/refcount1_5_2.phpt b/ext/phar/tests/tar/refcount1_5_2.phpt
new file mode 100755
index 0000000000..18587d91ad
--- /dev/null
+++ b/ext/phar/tests/tar/refcount1_5_2.phpt
@@ -0,0 +1,64 @@
+--TEST--
+Phar: test that refcounting avoids problems with deleting a file tar-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.tar';
+$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.tar'); ?>
+--EXPECTF--
+===CLOSE===
+object(PharFileInfo)#%d (0) {
+}
+string(5) "extra"
+===UNLINK===
+
+Warning: unlink(): phar error: "b/c.php" in phar "%sefcount1_5_2.phar.tar", 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/tar/rename.phpt b/ext/phar/tests/tar/rename.phpt
new file mode 100644
index 0000000000..96588a6596
--- /dev/null
+++ b/ext/phar/tests/tar/rename.phpt
@@ -0,0 +1,42 @@
+--TEST--
+Phar: rename test tar-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+phar.require_hash=0
+--FILE--
+<?php
+include dirname(__FILE__) . '/files/tarmaker.php.inc';
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar';
+$alias = 'phar://' . $fname;
+
+$tar = new tarmaker($fname, 'none');
+$tar->init();
+$tar->addFile('.phar/stub.php', "<?php
+Phar::mapPhar('hio');
+__HALT_COMPILER(); ?>");
+
+$files = array();
+$files['a'] = 'a';
+
+foreach ($files as $n => $file) {
+ $tar->addFile($n, $file);
+}
+
+$tar->close();
+
+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.tar'); ?>
+--EXPECTF--
+a
+a
+
+Warning: file_get_contents(phar://%srename.phar.tar/a): failed to open stream: phar error: "a" is not a file in phar "%srename.phar.tar" in %srename.php on line %d
diff --git a/ext/phar/tests/tar/tar_001.phpt b/ext/phar/tests/tar/tar_001.phpt
new file mode 100644
index 0000000000..500058b70d
--- /dev/null
+++ b/ext/phar/tests/tar/tar_001.phpt
@@ -0,0 +1,31 @@
+--TEST--
+Phar: tar-based phar corrupted
+--SKIPIF--
+<?php if (!extension_loaded('phar')) die('skip'); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+--FILE--
+<?php
+include dirname(__FILE__) . '/files/make_invalid_tar.php.inc';
+
+$tar = new corrupter(dirname(__FILE__) . '/tar_001.phar.tar', 'none');
+$tar->init();
+$tar->addFile('tar_001.phpt', __FILE__);
+$tar->close();
+
+$tar = fopen('phar://' . dirname(__FILE__) . '/tar_001.phar.tar/tar_001.phpt', 'rb');
+try {
+ $phar = new Phar(dirname(__FILE__) . '/tar_001.phar.tar');
+ echo "should not execute\n";
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+@unlink(dirname(__FILE__) . '/tar_001.phar.tar');
+?>
+--EXPECTF--
+Warning: fopen(phar://%star_001.phar.tar/tar_001.phpt): failed to open stream: phar error: "%star_001.phar.tar" is a corrupted tar file (truncated) in %star_001.php on line 9
+phar error: "%star_001.phar.tar" is a corrupted tar file (truncated)
+===DONE===
diff --git a/ext/phar/tests/tar/tar_002.phpt b/ext/phar/tests/tar/tar_002.phpt
new file mode 100644
index 0000000000..75fc220b40
--- /dev/null
+++ b/ext/phar/tests/tar/tar_002.phpt
@@ -0,0 +1,34 @@
+--TEST--
+Phar: tar-based phar corrupted 2
+--SKIPIF--
+<?php if (!extension_loaded('phar')) die('skip'); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+include dirname(__FILE__) . '/files/make_invalid_tar.php.inc';
+
+$tar = new corrupter(dirname(__FILE__) . '/tar_002.phar.tar', 'none');
+$tar->init();
+$tar->addFile('tar_002.phpt', __FILE__);
+$tar->close();
+
+$tar = fopen('phar://' . dirname(__FILE__) . '/tar_002.phar.tar/tar_002.phpt', 'rb');
+
+try {
+ $phar = new Phar(dirname(__FILE__) . '/tar_002.phar.tar');
+ echo "should not execute\n";
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+@unlink(dirname(__FILE__) . '/tar_002.phar.tar');
+?>
+--EXPECTF--
+Warning: fopen(phar://%star_002.phar.tar/tar_002.phpt): failed to open stream: phar error: "%star_002.phar.tar" is a corrupted tar file (truncated) in %star_002.php on line 9
+phar error: "%star_002.phar.tar" is a corrupted tar file (truncated)
+===DONE===
diff --git a/ext/phar/tests/tar/tar_003.phpt b/ext/phar/tests/tar/tar_003.phpt
new file mode 100644
index 0000000000..47f1d6ca9b
--- /dev/null
+++ b/ext/phar/tests/tar/tar_003.phpt
@@ -0,0 +1,74 @@
+--TEST--
+Phar: tar-based phar, valid 1
+--SKIPIF--
+<?php if (!extension_loaded('phar')) die('skip'); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+include dirname(__FILE__) . '/files/tarmaker.php.inc';
+
+$fname = dirname(__FILE__) . '/tar_003.phar.tar';
+$alias = 'phar://' . $fname;
+
+$tar = new tarmaker($fname, 'none');
+$tar->init();
+$tar->addFile('.phar/stub.php', "<?php // tar-based phar archive stub file\n__HALT_COMPILER();");
+$tar->addFile('tar_003.phpt', $g = fopen(__FILE__, 'r'));
+$tar->addFile('internal/file/here', "hi there!\n");
+$tar->mkDir('internal/dir');
+$tar->mkDir('dir');
+$tar->close();
+
+fclose($g);
+
+echo file_get_contents($alias . '/internal/file/here');
+
+try {
+$tar = opendir($alias . '/');
+} catch (Exception $e) {
+echo $e->getMessage()."\n";
+}
+
+while (false !== ($v = readdir($tar))) {
+ echo (is_file($alias . '/' . $v) ? "file\n" : "dir\n");
+ echo $v . "\n";
+}
+closedir($tar);
+
+/* ensure none of the dir tar files were freed */
+echo "second round\n";
+$tar = opendir($alias . '/');
+while (false !== ($v = readdir($tar))) {
+ echo (is_file($alias . '/' . $v) ? "file\n" : "dir\n");
+ echo $v . "\n";
+}
+closedir($tar);
+
+?>
+===DONE===
+--CLEAN--
+<?php
+@unlink(dirname(__FILE__) . '/tar_003.phar.tar');
+?>
+--EXPECT--
+hi there!
+dir
+.phar
+dir
+dir
+dir
+internal
+file
+tar_003.phpt
+second round
+dir
+.phar
+dir
+dir
+dir
+internal
+file
+tar_003.phpt
+===DONE===
diff --git a/ext/phar/tests/tar/tar_004.phpt b/ext/phar/tests/tar/tar_004.phpt
new file mode 100644
index 0000000000..2dd7ba169f
--- /dev/null
+++ b/ext/phar/tests/tar/tar_004.phpt
@@ -0,0 +1,38 @@
+--TEST--
+Phar: tar-based phar, tar phar with stub, mapPhar()
+--SKIPIF--
+<?php if (!extension_loaded('phar')) die('skip'); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+include dirname(__FILE__) . '/files/tarmaker.php.inc';
+
+$fname = dirname(__FILE__) . '/tar_004.phar.tar';
+$alias = 'phar://' . $fname;
+
+$tar = new tarmaker($fname, 'none');
+$tar->init();
+$tar->addFile('tar_004.php', '<?php var_dump(__FILE__);');
+$tar->addFile('internal/file/here', "hi there!\n");
+$tar->mkDir('internal/dir');
+$tar->mkDir('dir');
+$tar->addFile('.phar/stub.php', '<?php
+Phar::mapPhar();
+var_dump("it worked");
+include "phar://" . __FILE__ . "/tar_004.php";
+');
+$tar->close();
+
+include $fname;
+?>
+===DONE===
+--CLEAN--
+<?php
+@unlink(dirname(__FILE__) . '/tar_004.phar.tar');
+?>
+--EXPECTF--
+string(9) "it worked"
+string(%d) "phar://%star_004.phar.tar/tar_004.php"
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/tar/tar_bz2.phpt b/ext/phar/tests/tar/tar_bz2.phpt
new file mode 100644
index 0000000000..ad14541431
--- /dev/null
+++ b/ext/phar/tests/tar/tar_bz2.phpt
@@ -0,0 +1,54 @@
+--TEST--
+Phar: tar-based phar, bzipped tar
+--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"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+include dirname(__FILE__) . '/files/tarmaker.php.inc';
+
+$fname = dirname(__FILE__) . '/tar_bz2.phar';
+$alias = 'phar://' . $fname;
+$fname2 = dirname(__FILE__) . '/tar_bz2.phar.tar';
+$alias2 = 'phar://' . $fname2;
+
+$tar = new tarmaker($fname, 'bz2');
+$tar->init();
+$tar->addFile('tar_004.php', '<?php var_dump(__FILE__);');
+$tar->addFile('internal/file/here', "hi there!\n");
+$tar->mkDir('internal/dir');
+$tar->mkDir('dir');
+$tar->addFile('.phar/stub.php', '<?php
+Phar::mapPhar();
+var_dump("it worked");
+include "phar://" . __FILE__ . "/tar_004.php";
+');
+$tar->close();
+
+include $fname;
+
+$phar = new Phar($fname);
+$phar['test'] = 'hi';
+
+copy($fname, $fname2);
+
+$phar2 = new Phar($fname2);
+var_dump($phar2->isFileFormat(Phar::TAR));
+var_dump($phar2->isCompressed() == Phar::BZ2);
+
+?>
+===DONE===
+--CLEAN--
+<?php
+@unlink(dirname(__FILE__) . '/tar_bz2.phar');
+@unlink(dirname(__FILE__) . '/tar_bz2.phar.tar');
+?>
+--EXPECTF--
+string(9) "it worked"
+string(%d) "phar://%star_bz2.phar/tar_004.php"
+bool(true)
+bool(true)
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/tar/tar_gzip.phpt b/ext/phar/tests/tar/tar_gzip.phpt
new file mode 100644
index 0000000000..8287ee7f06
--- /dev/null
+++ b/ext/phar/tests/tar/tar_gzip.phpt
@@ -0,0 +1,51 @@
+--TEST--
+Phar: tar-based phar, gzipped tar
+--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"); ?>
+<?php if (version_compare(phpversion(), '5.2.6', '<')) die("skip zlib is buggy in PHP < 5.2.6"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+include dirname(__FILE__) . '/files/tarmaker.php.inc';
+$fname = dirname(__FILE__) . '/tar_gzip.phar';
+$pname = 'phar://' . $fname;
+$fname2 = dirname(__FILE__) . '/tar_gzip.phar.tar';
+$pname2 = 'phar://' . $fname2;
+
+$a = new tarmaker($fname, 'zlib');
+$a->init();
+$a->addFile('tar_004.php', '<?php var_dump(__FILE__);');
+$a->addFile('internal/file/here', "hi there!\n");
+$a->mkDir('internal/dir');
+$a->mkDir('dir');
+$a->addFile('.phar/stub.php', '<?php
+Phar::mapPhar();
+var_dump("it worked");
+include "phar://" . __FILE__ . "/tar_004.php";
+');
+$a->close();
+
+include $fname;
+
+$a = new Phar($fname);
+$a['test'] = 'hi';
+copy($fname, $fname2);
+$b = new Phar($fname2);
+var_dump($b->isFileFormat(Phar::TAR));
+var_dump($b->isCompressed() == Phar::GZ);
+?>
+===DONE===
+--CLEAN--
+<?php
+@unlink(dirname(__FILE__) . '/tar_gzip.phar');
+@unlink(dirname(__FILE__) . '/tar_gzip.phar.tar');
+?>
+--EXPECTF--
+string(9) "it worked"
+string(%d) "phar://%star_gzip.phar/tar_004.php"
+bool(true)
+bool(true)
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/tar/tar_makebz2.phpt b/ext/phar/tests/tar/tar_makebz2.phpt
new file mode 100644
index 0000000000..f703b46924
--- /dev/null
+++ b/ext/phar/tests/tar/tar_makebz2.phpt
@@ -0,0 +1,40 @@
+--TEST--
+Phar: tar-based phar, make new bzipped tar
+--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"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/tar_makebz2.phar.tar';
+$fname2 = dirname(__FILE__) . '/tar_makebz2.phar.tar.bz2';
+$fname3 = dirname(__FILE__) . '/tar_makebz2_b.phar.tar.bz2';
+
+$phar = new Phar($fname);
+$phar['test'] = 'hi';
+var_dump($phar->isFileFormat(Phar::TAR));
+$phar = $phar->compress(Phar::BZ2);
+
+copy($fname2, $fname3);
+
+$phar2 = new Phar($fname3);
+var_dump($phar2->isFileFormat(Phar::TAR));
+var_dump($phar2->isCompressed() == Phar::BZ2);
+
+?>
+===DONE===
+--CLEAN--
+<?php
+@unlink(dirname(__FILE__) . '/tar_makebz2.phar.bz2');
+@unlink(dirname(__FILE__) . '/tar_makebz2.phar.tar');
+@unlink(dirname(__FILE__) . '/tar_makebz2.phar.tar.bz2');
+@unlink(dirname(__FILE__) . '/tar_makebz2_b.phar.tar.bz2');
+?>
+--EXPECTF--
+bool(true)
+bool(true)
+bool(true)
+===DONE===
diff --git a/ext/phar/tests/tar/tar_makegz.phpt b/ext/phar/tests/tar/tar_makegz.phpt
new file mode 100644
index 0000000000..46fe177611
--- /dev/null
+++ b/ext/phar/tests/tar/tar_makegz.phpt
@@ -0,0 +1,41 @@
+--TEST--
+Phar: tar-based phar, make new gzipped tar
+--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"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/tar_makegz.phar.tar';
+$fname2 = dirname(__FILE__) . '/tar_makegz.phar.tar.gz';
+$fname3 = dirname(__FILE__) . '/tar_makegz_b.phar.tar.gz';
+
+$phar = new Phar($fname);
+$phar['test'] = 'hi';
+var_dump($phar->isFileFormat(Phar::TAR));
+$phar = $phar->compress(Phar::GZ);
+
+
+copy($fname2, $fname3);
+
+$phar2 = new Phar($fname3);
+var_dump($phar2->isFileFormat(Phar::TAR));
+var_dump($phar2->isCompressed() == Phar::GZ);
+
+?>
+===DONE===
+--CLEAN--
+<?php
+@unlink(dirname(__FILE__) . '/tar_makegz.phar.gz');
+@unlink(dirname(__FILE__) . '/tar_makegz.phar.tar');
+@unlink(dirname(__FILE__) . '/tar_makegz.phar.tar.gz');
+@unlink(dirname(__FILE__) . '/tar_makegz_b.phar.tar.gz');
+?>
+--EXPECTF--
+bool(true)
+bool(true)
+bool(true)
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/tar/tar_nostub.phpt b/ext/phar/tests/tar/tar_nostub.phpt
new file mode 100644
index 0000000000..a107a37deb
--- /dev/null
+++ b/ext/phar/tests/tar/tar_nostub.phpt
@@ -0,0 +1,48 @@
+--TEST--
+Phar: tar-based phar, third-party tar with no stub, Phar->getStub()
+--SKIPIF--
+<?php if (!extension_loaded('phar')) die('skip'); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+--INI--
+phar.readonly=1
+--FILE--
+<?php
+include dirname(__FILE__) . '/files/tarmaker.php.inc';
+$fname = dirname(__FILE__) . '/tar_004.phar.tar';
+$alias = 'phar://' . $fname;
+$fname2 = dirname(__FILE__) . '/tar_004.tar';
+
+$tar = new tarmaker($fname, 'none');
+$tar->init();
+$tar->addFile('tar_004.php', '<?php var_dump(__FILE__);');
+$tar->addFile('internal/file/here', "hi there!\n");
+$tar->close();
+
+try {
+ $phar = new Phar($fname);
+ var_dump($phar->getStub());
+} catch (Exception $e) {
+ echo $e->getMessage()."\n";
+}
+
+copy($fname, $fname2);
+
+try {
+ $phar = new PharData($fname2);
+ var_dump($phar->getStub());
+} catch (Exception $e) {
+ echo $e->getMessage()."\n";
+}
+
+?>
+===DONE===
+--CLEAN--
+<?php
+@unlink(dirname(__FILE__) . '/tar_004.phar.tar');
+@unlink(dirname(__FILE__) . '/tar_004.tar');
+?>
+--EXPECTF--
+RecursiveDirectoryIterator::__construct(phar://%star_004.phar.tar/): failed to open dir: '%star_004.phar.tar' is not a phar archive. Use PharData::__construct() for a standard zip or tar archive
+phar url "phar://%star_004.phar.tar/" is unknown
+string(0) ""
+===DONE===
diff --git a/ext/phar/tests/tar/truncated.phpt b/ext/phar/tests/tar/truncated.phpt
new file mode 100644
index 0000000000..fbcabb7986
--- /dev/null
+++ b/ext/phar/tests/tar/truncated.phpt
@@ -0,0 +1,22 @@
+--TEST--
+Phar: truncated tar
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--FILE--
+<?php
+try {
+ $p = new PharData(dirname(__FILE__) . '/files/trunc.tar');
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar');
+?>
+--EXPECTF--
+phar error: "%strunc.tar" is a corrupted tar file (truncated)
+===DONE===
diff --git a/ext/phar/tests/test_alias_unset.phpt b/ext/phar/tests/test_alias_unset.phpt
new file mode 100644
index 0000000000..0127d8bba2
--- /dev/null
+++ b/ext/phar/tests/test_alias_unset.phpt
@@ -0,0 +1,45 @@
+--TEST--
+Phar: test for the odd case where we intend to remove an archive from memory
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.phar.php';
+$pname2 = 'phar://' . $fname2;
+
+$phar = new Phar($fname);
+$phar->setAlias('first');
+$phar['file1.txt'] = 'hi';
+unset($phar);
+
+$phar2 = new Phar($fname2);
+$phar2->setAlias('first'); // this works because there are no references to $fname open
+$phar2['file1.txt'] = 'hi';
+unset($phar2);
+
+$a = fopen($pname . '/file1.txt', 'r'); // this works because there are no references to $fname2 open
+try {
+$phar2 = new Phar($fname2); // fails because references open to $fname
+} catch (Exception $e) {
+echo $e->getMessage(),"\n";
+}
+fclose($a);
+$phar2 = new Phar($fname2); // succeeds because all refs are closed
+var_dump($phar2->getAlias());
+
+$a = file_get_contents($pname . '/file1.txt'); // this fails because $fname2 ref exists
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar.php'); ?>
+--EXPECTF--
+Cannot open archive "%stest_alias_unset.2.phar.php", alias is already in use by existing archive
+string(5) "first"
+
+Warning: file_get_contents(phar://%sfile1.txt): failed to open stream: Cannot open archive "%stest_alias_unset.phar.php", alias is already in use by existing archive in %stest_alias_unset.php on line %d
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/test_signaturealgos.phpt b/ext/phar/tests/test_signaturealgos.phpt
new file mode 100644
index 0000000000..74f9e639ae
--- /dev/null
+++ b/ext/phar/tests/test_signaturealgos.phpt
@@ -0,0 +1,30 @@
+--TEST--
+Phar: verify signature parsing works
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("hash")) die("skip extension hash conflicts"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+$a = new Phar(dirname(__FILE__) . '/files/sha1.phar');
+$r = $a->getSignature();
+var_dump($r['hash_type']);
+$a = new Phar(dirname(__FILE__) . '/files/sha512.phar');
+$r = $a->getSignature();
+var_dump($r['hash_type']);
+$a = new Phar(dirname(__FILE__) . '/files/sha256.phar');
+$r = $a->getSignature();
+var_dump($r['hash_type']);
+$a = new Phar(dirname(__FILE__) . '/files/md5.phar');
+$r = $a->getSignature();
+var_dump($r['hash_type']);
+?>
+===DONE===
+--EXPECT--
+string(5) "SHA-1"
+string(7) "SHA-512"
+string(7) "SHA-256"
+string(3) "MD5"
+===DONE===
diff --git a/ext/phar/tests/test_unset.phpt b/ext/phar/tests/test_unset.phpt
new file mode 100644
index 0000000000..3da537c13c
--- /dev/null
+++ b/ext/phar/tests/test_unset.phpt
@@ -0,0 +1,42 @@
+--TEST--
+Phar: ensure unset() works properly on a non-flushed phar archive
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.phar.php';
+
+if (file_exists($fname)) unlink($fname);
+if (file_exists($fname2)) unlink($fname2);
+
+$phar = new Phar($fname); // no entries, never flushed
+$phar->setAlias('first');
+$phar->setMetadata('hi');
+unset($phar);
+
+$phar = new Phar($fname2);
+$phar['b'] = 'whatever'; // flushed
+try {
+ $phar->setAlias('first');
+} catch(Exception $e) {
+ echo $e->getMessage()."\n";
+}
+
+$phar = new Phar($fname);
+var_dump($phar->getMetadata());
+var_dump($phar->getAlias());
+var_dump(file_exists($fname));
+
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar.php'); ?>
+--EXPECTF--
+NULL
+string(%d) "%stest_unset.phar.php"
+bool(false)
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/webphar_compilefail.phpt b/ext/phar/tests/webphar_compilefail.phpt
new file mode 100644
index 0000000000..ab5532d6be
--- /dev/null
+++ b/ext/phar/tests/webphar_compilefail.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Phar: Phar::webPhar, open compiled file fails
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");?>
+--INI--
+phar.readonly=1
+--FILE--
+<?php
+try {
+Phar::webPhar('oopsiedaisy.phar', '/index.php');
+} catch (Exception $e) {
+echo $e->getMessage() . "\n";
+}
+__HALT_COMPILER();
+?>
+--EXPECTF--
+internal corruption of phar "%swebphar_compilefail.php" (truncated manifest at manifest length) \ No newline at end of file
diff --git a/ext/phar/tests/withphar.phpt b/ext/phar/tests/withphar.phpt
new file mode 100644
index 0000000000..c422fa9843
--- /dev/null
+++ b/ext/phar/tests/withphar.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Phar: phar run with pecl/phar with default stub
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--FILE--
+<?php
+include dirname(__FILE__) . '/files/nophar.phar';
+?>
+===DONE===
+--EXPECT--
+in b
+<?php include "b/c.php";
+in d
+===DONE===
diff --git a/ext/phar/tests/withphar_web.phpt b/ext/phar/tests/withphar_web.phpt
new file mode 100644
index 0000000000..45acf13d7f
--- /dev/null
+++ b/ext/phar/tests/withphar_web.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Phar: default web stub, with phar extension
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");?>
+--ENV--
+SCRIPT_NAME=/withphar_web.php
+REQUEST_URI=/withphar_web.php/web.php
+PATH_INFO=/web.php
+--FILE_EXTERNAL--
+files/nophar.phar
+--EXPECTHEADERS--
+Content-type: text/html
+--EXPECT--
+web
diff --git a/ext/phar/tests/zf_test.phpt b/ext/phar/tests/zf_test.phpt
new file mode 100644
index 0000000000..99e5c4f6e7
--- /dev/null
+++ b/ext/phar/tests/zf_test.phpt
@@ -0,0 +1,49 @@
+--TEST--
+Phar: test broken app
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+
+$file = "zfapp";
+$orig_file = dirname(__FILE__) . "/files/$file.tgz";
+$tgz_file = dirname(__FILE__) . "/$file.tgz";
+$phar_file = dirname(__FILE__) . "/$file.phar.tar.gz";
+copy($orig_file, $tgz_file);
+
+$phar = new PharData($tgz_file);
+$phar = $phar->convertToExecutable();
+
+$phar = new Phar($phar_file);
+$phar->startBuffering();
+$phar->setStub("<?php
+Phar::interceptFileFuncs();
+Phar::webPhar('$file.phar', 'html/index.php');
+echo 'BlogApp is intended to be executed from a web browser\n';
+exit -1;
+__HALT_COMPILER();
+");
+$phar->stopBuffering();
+
+foreach(new RecursiveIteratorIterator($phar) as $path) {
+ echo str_replace('\\', '/', $path->getPathName()) . "\n";
+}
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/zfapp.tgz');
+unlink(dirname(__FILE__) . '/zfapp.phar.tar.gz');
+?>
+--EXPECTF--
+phar://%szfapp.phar.tar.gz/.phar/stub.php
+phar://%szfapp.phar.tar.gz/application/default/controllers/ErrorController.php
+phar://%szfapp.phar.tar.gz/application/default/controllers/IndexController.php
+phar://%szfapp.phar.tar.gz/application/default/views/scripts/error/error.phtml
+phar://%szfapp.phar.tar.gz/application/default/views/scripts/index/index.phtml
+phar://%szfapp.phar.tar.gz/html/.htaccess
+phar://%szfapp.phar.tar.gz/html/index.php
+===DONE===
diff --git a/ext/phar/tests/zip/033.phpt b/ext/phar/tests/zip/033.phpt
new file mode 100644
index 0000000000..c980758a83
--- /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 0000000000..429d3bdd98
--- /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 0000000000..2a58e39efc
--- /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 0000000000..84bbfc36be
--- /dev/null
+++ b/ext/phar/tests/zip/all.phpt
@@ -0,0 +1,62 @@
+--TEST--
+Phar: test that creation of zip-based phar generates valid zip with all bells/whistles
+--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"); ?>
+<?php 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)
+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/badalias.phpt b/ext/phar/tests/zip/badalias.phpt
new file mode 100644
index 0000000000..0291c4b089
--- /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/corrupt_001.phpt b/ext/phar/tests/zip/corrupt_001.phpt
new file mode 100644
index 0000000000..0b019c6d83
--- /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 0000000000..86a271231d
--- /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 0000000000..c41e0153d8
--- /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 0000000000..3760e8f9ae
--- /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 0000000000..6b5d31d967
--- /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 0000000000..9c83617a9a
--- /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 0000000000..80c9139025
--- /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 0000000000..5a20f4d2ec
--- /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/create_new_and_modify.phpt b/ext/phar/tests/zip/create_new_and_modify.phpt
new file mode 100644
index 0000000000..5a3ec3317b
--- /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 0000000000..e6a5398f64
--- /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 INI setting 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 0000000000..06078b3a39
--- /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 0000000000..b7bda7ca4b
--- /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 0000000000..7bc3a2bf1a
--- /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 INI setting 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 0000000000..fdd0b42b5c
--- /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 0000000000..3cbeacd1c1
--- /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 0000000000..ccb37e8187
--- /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 0000000000..0e3adfc7cf
--- /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 0000000000..7b5baaa089
--- /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 0000000000..7b5baaa089
--- /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 0000000000..49b7be0dae
--- /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 0000000000..9f2b0e8282
--- /dev/null
+++ b/ext/phar/tests/zip/files/badalias5.phar.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 0000000000..9172554f2d
--- /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 0000000000..bd1f72baf8
--- /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 0000000000..2a7f22128c
--- /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 0000000000..d4941437d9
--- /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 0000000000..7ef221763c
--- /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 0000000000..8086d4546f
--- /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 0000000000..d827d2d3a2
--- /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 0000000000..d4acc60c1f
--- /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 0000000000..76a4dc1aef
--- /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 0000000000..d42155de53
--- /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 0000000000..50846409cd
--- /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 0000000000..65c2e23664
--- /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 0000000000..df0c767a58
--- /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 0000000000..907f365bf7
--- /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 0000000000..54f19fb3a0
--- /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 0000000000..170695462a
--- /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 0000000000..3edf620310
--- /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/corrupt_count1.php.inc b/ext/phar/tests/zip/files/corrupt_count1.php.inc
new file mode 100644
index 0000000000..314fdef6db
--- /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 0000000000..2c1719920d
--- /dev/null
+++ b/ext/phar/tests/zip/files/corrupt_zipmaker.php.inc
@@ -0,0 +1,317 @@
+<?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;
+ }
+ 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 '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 0000000000..73b556103a
--- /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 0000000000..6aa2619539
--- /dev/null
+++ b/ext/phar/tests/zip/files/count2.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 0000000000..dee73cad37
--- /dev/null
+++ b/ext/phar/tests/zip/files/encrypted.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 0000000000..414b121fdc
--- /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 0000000000..241dceb57b
--- /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 0000000000..4ee905dd3a
--- /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 0000000000..c973cc15d9
--- /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 0000000000..c37cb381fb
--- /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 0000000000..c24a6f14e4
--- /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 0000000000..48e5fc678a
--- /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 0000000000..77c4a1dd0e
--- /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["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"));
+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 0000000000..c086c4d4a4
--- /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 0000000000..6cfa052a83
--- /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 0000000000..7ef43dc000
--- /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 0000000000..ab28f7b3d0
--- /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("/hi" => "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 0000000000..40c1d4994b
--- /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 0000000000..d78399142e
--- /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("/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 0000000000..4dc83408b0
--- /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 0000000000..931fa975e1
--- /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 0000000000..0ab0472101
--- /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 0000000000..3b551f268d
--- /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("blah" => 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 0000000000..bf98255fe9
--- /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 0000000000..42c10bc739
--- /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("blah" => 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 0000000000..02fc3e27b6
--- /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 0000000000..e04ac414e9
--- /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 0000000000..41952ce745
--- /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 0000000000..50440451f7
--- /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 0000000000..d3f4ff8404
--- /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 0000000000..cec8ef7793
--- /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 0000000000..932fc961e3
--- /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 0000000000..3c5cf0065f
--- /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 0000000000..f97607221c
--- /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 0000000000..527e09fefc
--- /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 0000000000..4376eb67fa
--- /dev/null
+++ b/ext/phar/tests/zip/files/stdin.zip
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 0000000000..d8a526a4bb
--- /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 0000000000..5ee9cae6ac
--- /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 0000000000..aceab0d26b
--- /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/frontcontroller1.phar.phpt b/ext/phar/tests/zip/frontcontroller1.phar.phpt
new file mode 100644
index 0000000000..0a6847885d
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller1.phar.phpt
@@ -0,0 +1,15 @@
+--TEST--
+Phar front controller other zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--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 0000000000..ffe23bc08e
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller10.phar.phpt
@@ -0,0 +1,22 @@
+--TEST--
+Phar front controller rewrite array invalid zip-based
+--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
+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 0000000000..f1fd26bb75
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller11.phar.phpt
@@ -0,0 +1,18 @@
+--TEST--
+Phar front controller mime type extension is not a string zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) 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 0000000000..dc5bcdce78
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller12.phar.phpt
@@ -0,0 +1,18 @@
+--TEST--
+Phar front controller mime type unknown int zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--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
+--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 0000000000..592d662536
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller13.phar.phpt
@@ -0,0 +1,18 @@
+--TEST--
+Phar front controller mime type not string/int zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--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
+--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 0000000000..1caa85bc07
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller14.phar.phpt
@@ -0,0 +1,15 @@
+--TEST--
+Phar front controller mime type override, other zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--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 0000000000..89adc0a106
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller15.phar.phpt
@@ -0,0 +1,18 @@
+--TEST--
+Phar front controller mime type override, Phar::PHPS zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--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
+--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 0000000000..e27faf3931
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller16.phar.phpt
@@ -0,0 +1,15 @@
+--TEST--
+Phar front controller mime type override, Phar::PHP zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--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
+--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 0000000000..f85bec2911
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller17.phar.phpt
@@ -0,0 +1,16 @@
+--TEST--
+Phar front controller mime type unknown zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--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 0000000000..c687dd0664
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller18.phar.phpt
@@ -0,0 +1,16 @@
+--TEST--
+Phar front controller $_SERVER munging failure zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--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 0000000000..5b828e9e60
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller19.phar.phpt
@@ -0,0 +1,16 @@
+--TEST--
+Phar front controller $_SERVER munging failure 2 zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--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 0000000000..0e101f6d41
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller2.phar.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Phar front controller PHP test zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--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
+--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 0000000000..1cf54860ac
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller20.phar.phpt
@@ -0,0 +1,16 @@
+--TEST--
+Phar front controller $_SERVER munging failure 3 zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--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 0000000000..d31b730ab8
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller21.phar.phpt
@@ -0,0 +1,22 @@
+--TEST--
+Phar front controller $_SERVER munging success zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--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
+--EXPECTF--
+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 0000000000..abe33bb502
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller3.phar.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Phar front controller phps zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--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
+--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 0000000000..6c03620c1c
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller4.phar.phpt
@@ -0,0 +1,13 @@
+--TEST--
+Phar front controller index.php relocate (no /) zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--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 0000000000..9597a1c14c
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller5.phar.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Phar front controller index.php relocate zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--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 0000000000..1da20e96d7
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller6.phar.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Phar front controller 404 zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--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 0000000000..d13cf33c16
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller7.phar.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Phar front controller alternate index file zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--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 0000000000..1b0d133bc7
--- /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 0000000000..8c550539fc
--- /dev/null
+++ b/ext/phar/tests/zip/frontcontroller9.phar.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Phar front controller rewrite array zip-based
+--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
+--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 0000000000..9c917633c9
--- /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 0000000000..a8438eb7b7
--- /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 0000000000..cf0945d153
--- /dev/null
+++ b/ext/phar/tests/zip/metadata_write_commit.phpt
@@ -0,0 +1,85 @@
+--TEST--
+Phar with meta-data (write) 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.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/notphar.phpt b/ext/phar/tests/zip/notphar.phpt
new file mode 100644
index 0000000000..26dcd71ed9
--- /dev/null
+++ b/ext/phar/tests/zip/notphar.phpt
@@ -0,0 +1,23 @@
+--TEST--
+Phar: a non-executable zip with no stub named .phar.zip
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=1
+--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 \ No newline at end of file
diff --git a/ext/phar/tests/zip/odt.phpt b/ext/phar/tests/zip/odt.phpt
new file mode 100644
index 0000000000..28187f68b7
--- /dev/null
+++ b/ext/phar/tests/zip/odt.phpt
@@ -0,0 +1,34 @@
+--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"); ?>
+--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%cConfigurations2%caccelerator%ccurrent.xml
+phar://%sodt.odt%cMETA-INF%cmanifest.xml
+phar://%sodt.odt%cThumbnails%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
+===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 0000000000..94f85b4e3f
--- /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, '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 100755
index 0000000000..347a1ce719
--- /dev/null
+++ b/ext/phar/tests/zip/open_for_write_existing_b.phpt
@@ -0,0 +1,52 @@
+--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();
+
+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.phar.zip/b/c.php): failed to open stream: phar error: write operations disabled by INI setting in %sopen_for_write_existing_b.php on line %d
+
+Warning: fwrite(): supplied argument is not a valid stream resource in %spen_for_write_existing_b.php on line %d
+
+Warning: fclose(): supplied argument is not a valid stream resource in %spen_for_write_existing_b.php on line %d
+This is b/c
+===DONE=== \ No newline at end of file
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 100755
index 0000000000..b66a77b212
--- /dev/null
+++ b/ext/phar/tests/zip/open_for_write_existing_c.phpt
@@ -0,0 +1,46 @@
+--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();
+
+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.phar.zip/b/c.php): failed to open stream: phar error: write operations disabled by INI setting in %sopen_for_write_existing_c.php on line %d
+
+Warning: fwrite(): supplied argument is not a valid stream resource in %sopen_for_write_existing_c.php on line %d
+
+Warning: fclose(): supplied argument is not a valid stream resource in %sopen_for_write_existing_c.php on line %d
+This is b/c
+===DONE=== \ No newline at end of file
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 0000000000..c3782d4fd3
--- /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, '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 100755
index 0000000000..44ad7487fa
--- /dev/null
+++ b/ext/phar/tests/zip/open_for_write_newfile_b.phpt
@@ -0,0 +1,60 @@
+--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();
+
+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.phar.zip/b/new.php): failed to open stream: phar error: write operations disabled by INI setting in %sopen_for_write_newfile_b.php on line %d
+
+Warning: fwrite(): supplied argument is not a valid stream resource in %sopen_for_write_newfile_b.php on line %d
+
+Warning: fclose(): supplied argument is not a valid stream resource 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_c.phpt b/ext/phar/tests/zip/open_for_write_newfile_c.phpt
new file mode 100755
index 0000000000..b664397a99
--- /dev/null
+++ b/ext/phar/tests/zip/open_for_write_newfile_c.phpt
@@ -0,0 +1,54 @@
+--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();
+
+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.phar.zip/b/new.php): failed to open stream: phar error: write operations disabled by INI setting in %sopen_for_write_newfile_c.php on line %d
+
+Warning: fwrite(): supplied argument is not a valid stream resource in %sopen_for_write_newfile_c.php on line %d
+
+Warning: fclose(): supplied argument is not a valid stream resource 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/phar_begin_setstub_commit.phpt b/ext/phar/tests/zip/phar_begin_setstub_commit.phpt
new file mode 100755
index 0000000000..81cf4001c3
--- /dev/null
+++ b/ext/phar/tests/zip/phar_begin_setstub_commit.phpt
@@ -0,0 +1,68 @@
+--TEST--
+Phar::startBuffering()/setStub()/stopBuffering() zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--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(true)
+bool(false)
+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(true)
+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_buildfromiterator4.phpt b/ext/phar/tests/zip/phar_buildfromiterator4.phpt
new file mode 100644
index 0000000000..cc11fe5537
--- /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 0000000000..450ada100d
--- /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
+string(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 0000000000..2dfb04dbf0
--- /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
+string(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 0000000000..16ba6d61b9
--- /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();
+?>
+--EXPECT--
+rewind
+valid
+current
+key
+string(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 0000000000..d2b1be2087
--- /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 0000000000..0b56307545
--- /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 0000000000..84bccb9fae
--- /dev/null
+++ b/ext/phar/tests/zip/phar_commitwrite.phpt
@@ -0,0 +1,44 @@
+--TEST--
+Phar::setStub()/stopBuffering() zip-based
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--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=== \ No newline at end of file
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 0000000000..815656dbf6
--- /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(6651)
+bool(true)
+string(60) "<?php // zip-based phar archive stub file
+__HALT_COMPILER();"
+bool(true)
+int(6651)
+bool(true)
+int(6651)
+===DONE===
diff --git a/ext/phar/tests/zip/phar_copy.phpt b/ext/phar/tests/zip/phar_copy.phpt
new file mode 100644
index 0000000000..14034c92c0
--- /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 0000000000..4a17207376
--- /dev/null
+++ b/ext/phar/tests/zip/phar_magic.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Phar: include/fopen magic 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.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
+set_include_path("phar://" . __FILE__);
+include "phar://" . __FILE__ . "/a";
+__HALT_COMPILER();');
+include $fname;
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip.php');
+__HALT_COMPILER();
+?>
+--EXPECTF--
+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 0000000000..d6b0a8f4cf
--- /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 0000000000..47dddac487
--- /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 0000000000..1a39633863
--- /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 0000000000..c89f4c777a
--- /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 0000000000..e21d764487
--- /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_stub.phpt b/ext/phar/tests/zip/phar_stub.phpt
new file mode 100644
index 0000000000..a2a6aa6f2a
--- /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 = '<?php echo "second stub\n"; __HALT_COMPILER(); ?>';
+
+//// 2
+$phar->setStub($file);
+echo $phar->getStub();
+
+$fname3 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phartmp.php';
+$file = '<?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, '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 100755
index 0000000000..268130df40
--- /dev/null
+++ b/ext/phar/tests/zip/phar_stub_error.phpt
@@ -0,0 +1,58 @@
+--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($stub);
+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(); ?>
+"
+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 0000000000..6d7b7420c6
--- /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, "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) {
+ ["pathName":"SplFileInfo":private]=>
+ string(%d) "phar://%srefcount1.phar.zip/b"
+ ["fileName":"SplFileInfo":private]=>
+ string(%d) "phar://%srefcount1.phar.zip/b/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) {
+ ["pathName":"SplFileInfo":private]=>
+ string(%d) "phar://%srefcount1.phar.zip/b"
+ ["fileName":"SplFileInfo":private]=>
+ string(%s) "phar://%srefcount1.phar.zip/b/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 100755
index 0000000000..f3b2771f44
--- /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 0000000000..9b1f5c98cd
--- /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/unixzip.phpt b/ext/phar/tests/zip/unixzip.phpt
new file mode 100644
index 0000000000..374489d013
--- /dev/null
+++ b/ext/phar/tests/zip/unixzip.phpt
@@ -0,0 +1,26 @@
+--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";
+ }
+}
+if (isset($a['notempty/hi.txt'])) {
+ echo $a['notempty/hi.txt']->getPathName() . "\n";
+}
+?>
+===DONE===
+--EXPECTF--
+dir phar://%szip.zip%cempty
+phar://%szip.zip%chi.txt
+dir phar://%szip.zip%cnotempty
+phar://%szip.zip/notempty/hi.txt
+===DONE===