]> granicus.if.org Git - php/commitdiff
- Update tests
authorMarcus Boerger <helly@php.net>
Sun, 21 Jan 2007 16:58:23 +0000 (16:58 +0000)
committerMarcus Boerger <helly@php.net>
Sun, 21 Jan 2007 16:58:23 +0000 (16:58 +0000)
ext/phar/tests/011.phpt
ext/phar/tests/013.phpt
ext/phar/tests/014.phpt
ext/phar/tests/015.phpt
ext/phar/tests/015b.phpt
ext/phar/tests/016.phpt
ext/phar/tests/016b.phpt
ext/phar/tests/017.phpt
ext/phar/tests/018.phpt
ext/phar/tests/metadata_read.phpt
ext/phar/tests/phar_test.inc

index 009d51d4e7388b51aa887a3eb428c5b030b69212..3b0cde1d192d469647a15fe234492b135235f84b 100644 (file)
@@ -6,6 +6,8 @@ Phar::mapPhar filesize too small in manifest
 phar.require_hash=0
 --FILE--
 <?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
 $file = "<?php
 Phar::mapPhar('hio');
 __HALT_COMPILER(); ?>";
@@ -13,22 +15,10 @@ __HALT_COMPILER(); ?>";
 // compressed file length does not match incompressed lentgh for an uncompressed file
 
 $files = array();
-$files['a'] = 'a';
-$manifest = '';
-foreach($files as $name => $cont) {
-       $len = strlen($cont);
-       $manifest .= pack('V', strlen($name)) . $name . pack('VVVVVV', $len, time(), $len+1, crc32($cont), 0x00000000, 0);
-}
-$alias = 'hio';
-$manifest = pack('VnVV', count($files), 0x0900, 0x00000000, strlen($alias)) . $alias . $manifest;
-$file .= pack('V', strlen($manifest)) . $manifest;
-foreach($files as $cont)
-{
-       $file .= $cont;
-}
+$files['a'] = array('cont'=>'a','ulen'=>1,'clen'=>2);;
+include 'phar_test.inc';
 
-file_put_contents(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php', $file);
-include dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+include $fname;
 echo file_get_contents('phar://hio/a');
 ?>
 --CLEAN--
index 808d37462ae79d2fa2a3b59dff496b188104407f..2d00a93f30a887517f7b9e7d1e87b1394e750e46 100644 (file)
@@ -8,31 +8,16 @@ phar.require_hash=0
 <?php
 $fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
 $pname = 'phar://' . $fname;
-$file = "<?php
-Phar::mapPhar('hio');
-__HALT_COMPILER(); ?>";
+$file = "<?php __HALT_COMPILER(); ?>";
 // filesize should be 1, and is 2
 
 $files = array();
-$files['a'] = 'a';
-$manifest = '';
-foreach($files as $name => $cont) {
-       $len = strlen($cont)+1;
-       $manifest .= pack('V', strlen($name)) . $name . pack('VVVVVV', $len, time(), $len, crc32($cont), 0x00000000, 0);
-}
-$alias = 'hio';
-$manifest = pack('VnVV', count($files), 0x0900, 0x00000000, strlen($alias)) . $alias . $manifest;
-$file .= pack('V', strlen($manifest)) . $manifest;
-foreach($files as $cont)
-{
-       $file .= $cont;
-}
+$files['a'] = array('cont'=>'a', 'ulen'=>2, 'clen'=>2);
+include 'phar_test.inc';
 
-file_put_contents(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php', $file);
-include dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
-echo file_get_contents('phar://hio/a');
+echo file_get_contents($pname.'/a');
 ?>
 --CLEAN--
 <?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
 --EXPECTF--
-Warning: file_get_contents(phar://hio/a): failed to open stream: phar error: internal corruption of phar "%s" (actual filesize mismatch on file "a") in %s on line %d
+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
index 2117eaaff9a94a0e7ab5e8559255412ec2bd56a1..70a5b53c356151ce7cc3f97179aa1ca046875a92 100644 (file)
@@ -6,31 +6,18 @@ Phar::mapPhar filesize mismatch
 phar.require_hash=0
 --FILE--
 <?php
-$file = "<?php
-Phar::mapPhar('hio');
-__HALT_COMPILER(); ?>";
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$file = "<?php __HALT_COMPILER(); ?>";
 // wrong crc32
 
 $files = array();
-$files['a'] = 'a';
-$manifest = '';
-foreach($files as $name => $cont) {
-       $len = strlen($cont);
-       $manifest .= pack('V', strlen($name)) . $name . pack('VVVVVV', $len, time(), $len, crc32($cont.'X'), 0x00000000, 0);
-}
-$alias = 'hio';
-$manifest = pack('VnVV', count($files), 0x0900, 0x00000000, strlen($alias)) . $alias . $manifest;
-$file .= pack('V', strlen($manifest)) . $manifest;
-foreach($files as $cont)
-{
-       $file .= $cont;
-}
+$files['a'] = array('cont'=>'a', 'crc32'=>crc32('aX'));
+include 'phar_test.inc';
 
-file_put_contents(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php', $file);
-include dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
-echo file_get_contents('phar://hio/a');
+echo file_get_contents($pname.'/a');
 ?>
 --CLEAN--
 <?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
 --EXPECTF--
-Warning: file_get_contents(phar://hio/a): failed to open stream: phar error: internal corruption of phar "%s" (crc32 mismatch on file "a") in %s on line %d
\ No newline at end of file
+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
index 4d5477c557f57ae978223f6a4ccb7523921f2d1c..b7c42414332922c1de86808cd38b772982e1f56f 100644 (file)
@@ -1,36 +1,23 @@
 --TEST--
 Phar::mapPhar valid file (gzipped)
 --SKIPIF--
-<?php if (!extension_loaded("phar")) print "skip";
-if (!extension_loaded("zlib")) print "skip zlib not present"; ?>
+<?php if (!extension_loaded("phar")) print "skip"; ?>
+<?php if (!extension_loaded("zlib")) print "skip zlib not present"; ?>
 --INI--
 phar.require_hash=0
 --FILE--
 <?php
-$file = "<?php
-Phar::mapPhar('hio');
-__HALT_COMPILER(); ?>";
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$file = "<?php __HALT_COMPILER(); ?>";
 
 $files = array();
-$files['a'] = 'a';
-$manifest = '';
-foreach($files as $name => $cont) {
-       $len = strlen($cont);
-       $manifest .= pack('V', strlen($name)) . $name . pack('VVVVVV', $len, time(), 3, crc32($cont), 0x00001000, 0);
-}
-$alias = 'hio';
-$manifest = pack('VnVV', count($files), 0x0900, 0x00001000, strlen($alias)) . $alias . $manifest;
-$file .= pack('V', strlen($manifest)) . $manifest;
-foreach($files as $cont)
-{
-       $file .= chr(75) . chr(4) . chr(0); // 'a' gzdeflated
-}
+$files['a'] = array('cont'=>'a','comp'=>chr(75) . chr(4) . chr(0) /* 'a' gzdeflated */, 'flags'=>0x00001000);
+include 'phar_test.inc';
 
-file_put_contents(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php', $file);
-include dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
-echo file_get_contents('phar://hio/a');
+echo file_get_contents($pname .'/a');
 ?>
 --CLEAN--
 <?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
 --EXPECT--
-a
\ No newline at end of file
+a
index 1909da6a825aa9f9ece7438b64b690dd9d397785..973c5d28c8aa7d7dc327e6a276d5c5bc4b416a06 100755 (executable)
@@ -1,33 +1,21 @@
 --TEST--
 Phar::mapPhar valid file (bzip2)
 --SKIPIF--
-<?php if (!extension_loaded("phar")) print "skip";
-if (!extension_loaded("bz2")) print "skip bz2 not present"; ?>
+<?php if (!extension_loaded("phar")) print "skip";?>
+<?php if (!extension_loaded("bz2")) print "skip bz2 not present"; ?>
 --INI--
 phar.require_hash=0
 --FILE--
 <?php
-$file = "<?php
-Phar::mapPhar('hio');
-__HALT_COMPILER(); ?>";
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$file = "<?php __HALT_COMPILER(); ?>";
 
 $files = array();
-$files['a'] = array('Hello World', pack('H*', '425a6839314159265359d872012f00000157800010400000400080060490002000220686d420c988c769e8281f8bb9229c28486c39009780'));
-$manifest = '';
-foreach($files as $name => $cont) {
-       $manifest .= pack('V', strlen($name)) . $name . pack('VVVVVV', strlen($cont[0]), time(), strlen($cont[1]), crc32($cont[0]), 0x00002000, 0);
-}
-$alias = 'hio';
-$manifest = pack('VnVV', count($files), 0x0900, 0x00002000, strlen($alias)) . $alias . $manifest;
-$file .= pack('V', strlen($manifest)) . $manifest;
-foreach($files as $cont)
-{
-       $file .= $cont[1];
-}
+$files['a'] = array('cont'=>'Hello World', 'comp'=>pack('H*', '425a6839314159265359d872012f00000157800010400000400080060490002000220686d420c988c769e8281f8bb9229c28486c39009780'),'flags'=>0x00002000);
+include 'phar_test.inc';
 
-file_put_contents(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php', $file);
-include dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
-var_dump(file_get_contents('phar://hio/a'));
+var_dump(file_get_contents($pname . '/a'));
 ?>
 --CLEAN--
 <?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
index 929e21a1f31fa17569f4651a16b4a056e68e805e..1bb9e1e8c02b0354df1067869f71e004a836860b 100644 (file)
@@ -1,53 +1,38 @@
 --TEST--
 Phar::mapPhar invalid file (gzipped file length is too short)
 --SKIPIF--
-<?php if (!extension_loaded("phar")) print "skip";
-if (!extension_loaded("zlib")) print "skip zlib not present"; ?>
+<?php if (!extension_loaded("phar")) print "skip";?>
+<?php if (!extension_loaded("zlib")) print "skip zlib not present"; ?>
 --INI--
 phar.require_hash=0
 --FILE--
 <?php
-$file = "<?php
-Phar::mapPhar('hio');
-__HALT_COMPILER(); ?>";
+$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('a', chr(75)/*. chr(4) . chr(0): 'a' gzdeflated */, 0x00001000);
-$files['b'] = array('a', chr(75)/*. chr(4) . chr(0): 'a' gzdeflated */, 0x00001000);
-$files['c'] = array('*', '*',                                           0x00000000);
-$files['d'] = array('a', chr(75)/*. chr(4) . chr(0): 'a' gzdeflated */, 0x00001000);
-$manifest = '';
-foreach($files as $name => $cont) {
-       $ulen = strlen($cont[0]);
-       $clen = strlen($cont[1]);
-       $manifest .= pack('V', strlen($name)) . $name 
-                 . pack('VVVVVV', $ulen, time(), $clen, crc32($cont[0]), $cont[2], 0);
-}
-$alias = 'hio';
-$manifest = pack('VnVV', count($files), 0x0900, 0x00001000, strlen($alias)) . $alias . $manifest;
-$file .= pack('V', strlen($manifest)) . $manifest;
-foreach($files as $cont)
-{
-       $file .= $cont[1];
-}
+$files['a'] = array('cont'=>'a','comp'=>chr(75)/*. chr(4) . chr(0): 'a' gzdeflated */,'flags'=>0x00001000);
+$files['b'] = $files['a'];
+$files['c'] = array('cont'=>'*');
+$files['d'] = $files['a'];
+include 'phar_test.inc';
 
-file_put_contents(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php', $file);
-include dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
-var_dump(file_get_contents('phar://hio/a'));
-var_dump(file_get_contents('phar://hio/b'));
-var_dump(file_get_contents('phar://hio/c'));
-var_dump(file_get_contents('phar://hio/d'));
+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://hio/a): failed to open stream: phar error: internal corruption of phar "%s" (actual filesize mismatch on file "a") in %s on line %d
+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://hio/b): failed to open stream: phar error: internal corruption of phar "%s" (actual filesize mismatch on file "b") in %s on line %d
+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://hio/d): failed to open stream: phar error: internal corruption of phar "%s" (actual filesize mismatch on file "d") in %s on line %d
+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)
index ae5ec5fded0d282e5cbe83d0ef6a7de3516e8cac..027657f281868700fb94189e6ea23016a57145cd 100755 (executable)
@@ -1,37 +1,24 @@
 --TEST--
 Phar::mapPhar invalid file (gzipped file length is too short)
 --SKIPIF--
-<?php if (!extension_loaded("phar")) print "skip";
-if (!extension_loaded("zlib")) print "skip zlib not present"; ?>
+<?php if (!extension_loaded("phar")) print "skip";?>
+<?php if (!extension_loaded("zlib")) print "skip zlib not present"; ?>
 --INI--
 phar.require_hash=0
 --FILE--
 <?php
-$file = "<?php
-Phar::mapPhar('hio');
-__HALT_COMPILER(); ?>";
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$file = "<?php __HALT_COMPILER(); ?>";
 // file length is too short
 
 $files = array();
-$files['a'] = 'a';
-$manifest = '';
-foreach($files as $name => $cont) {
-       $len = strlen($cont);
-       $manifest .= pack('V', strlen($name)) . $name . pack('VVVVVV', $len, time(), 1, crc32($cont), 0x00001000, 0);
-}
-$alias = 'hio';
-$manifest = pack('VnVV', count($files), 0x0900, 0x00001000, strlen($alias)) . $alias . $manifest;
-$file .= pack('V', strlen($manifest)) . $manifest;
-foreach($files as $cont)
-{
-       $file .= chr(0) . chr(4) . chr(0); // 'a' gzdeflated
-}
+$files['a'] = array('cont'=>'a','flags'=>0x00001000);
+include 'phar_test.inc';
 
-file_put_contents(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php', $file);
-include dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
-echo file_get_contents('phar://hio/a');
+echo file_get_contents($pname . '/a');
 ?>
 --CLEAN--
 <?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
 --EXPECTF--
-Warning: file_get_contents(phar://hio/a): failed to open stream: phar error: internal corruption of phar "%s" (actual filesize mismatch on file "a") in %s on line %d
\ No newline at end of file
+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
index b3332bb6dc8e34062b01791a026a67c5b97b3e3b..9be69708c4812d80955d5a07fb1bb90c2086923d 100644 (file)
@@ -6,31 +6,20 @@ Phar: opendir test - no dir specified at all
 phar.require_hash=0
 --FILE--
 <?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
 $file = "<?php
 Phar::mapPhar('hio');
 __HALT_COMPILER(); ?>";
-// file length is too short
 
 $files = array();
 $files['a'] = 'abc';
-$manifest = '';
-foreach($files as $name => $cont) {
-       $len = strlen($cont);
-       $manifest .= pack('V', strlen($name)) . $name . pack('VVVVVV', $len, time(), $len, crc32($cont), 0x00000001, 0);
-}
-$alias = 'hio';
-$manifest = pack('VnVV', count($files), 0x0900, 0x00000001, strlen($alias)) . $alias . $manifest;
-$file .= pack('V', strlen($manifest)) . $manifest;
-foreach($files as $cont)
-{
-       $file .= $cont;
-}
+include 'phar_test.inc';
 
-file_put_contents(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php', $file);
-include dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+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 in %s on line %d
\ No newline at end of file
+Warning: opendir(phar://hio): failed to open dir: phar error: no directory in "phar://hio", must have at least phar://hio/ for root directory in %s on line %d
index e30b42917109f9d344801f4a400e9f0ff481b431..84b8e088b7bb970f7b8f87ee3541aed0d14417bf 100644 (file)
@@ -16,7 +16,8 @@ $files = array();
 $files['a'] = 'a';
 $files['b/a'] = 'b';
 include 'phar_test.inc';
-include dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+
+include $fname;
 $dir = opendir('phar://hio/');
 while (false !== ($a = readdir($dir))) {
        var_dump($a);
index c9dbc7eb21e053bdf211beadbf09ba9cbad12266..195ec28c95e0249c57e2980f2ea58d73bb1f2256 100644 (file)
@@ -13,7 +13,6 @@ $file = "<?php __HALT_COMPILER(); ?>";
 
 $files = array();
 $files['c'] = array('cont' => '*', 'meta' => array(1, 'hi there'));
-
 include 'phar_test.inc';
 
 var_dump(file_get_contents($pname.'/c'));
index 13b9c8b5a59ac09eca6eb2aa8c9f70763e5adc4d..82987cb19dd2b315601f40e785622940ae764ec6 100755 (executable)
@@ -1,15 +1,25 @@
 <?php
 
 $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 = array();
+
+       // overwrite if array
        if (is_array($cont))
        {
-               foreach(array('time','perm','meta','cont') as $what)
+               foreach(array('comp','crc32','clen','ulen','time','flags','perm','meta','cont') as $what)
                {
                        if (isset($cont[$what]))
                        {
@@ -17,22 +27,34 @@ foreach($files as $name => $cont)
                        }
                }
        }
-       $ulen = strlen($cont);
-       $clen = $ulen;
+
+       // 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);
+
+       // write manifest entry
        $manifest .= pack('V', strlen($name)) . $name;
-       $manifest .= pack('VVVVV', $ulen, $time, $clen, crc32($cont), $perm);
+       $manifest .= pack('VVVVV', $ulen, $time, $clen, $crc32, $flags|$perm);
        foreach($meta as $type => $data)
        {
                $manifest .= pack('Vv', $type, strlen($data)) . $data;
        }
        $manifest .= pack('V', 0);
+
+       // globals
+       $gflags |= $flags;
+       $files[$name] = $comp;
 }
+
 $alias = 'hio';
-$manifest = pack('VnVV', count($files), 0x0900, 0x00000000, strlen($alias)) . $alias . $manifest;
+$manifest = pack('VnVV', count($files), 0x0900, $glags, strlen($alias)) . $alias . $manifest;
 $file .= pack('V', strlen($manifest)) . $manifest;
+
 foreach($files as $cont)
 {
-       $file .= is_array($cont) ? $cont['cont'] : $cont;
+       $file .= $cont;
 }
 
 file_put_contents($fname, $file);