Annotation of embedaddon/php/ext/phar/tests/phar_stub.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Phar::setStub()
! 3: --SKIPIF--
! 4: <?php if (!extension_loaded("phar")) die("skip"); ?>
! 5: --INI--
! 6: phar.require_hash=0
! 7: phar.readonly=0
! 8: --FILE--
! 9: <?php
! 10: $fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
! 11: $pname = 'phar://' . $fname;
! 12: $file = '<?php echo "first stub\n"; __HALT_COMPILER(); ?>';
! 13:
! 14: $files = array();
! 15: $files['a'] = 'a';
! 16: $files['b'] = 'b';
! 17: $files['c'] = 'c';
! 18:
! 19: include 'files/phar_test.inc';
! 20:
! 21: $file = '<?php echo "first stub\n"; __HALT_COMPILER(); ?>';
! 22: $fp = fopen($fname, 'rb');
! 23: //// 1
! 24: echo fread($fp, strlen($file)) . "\n";
! 25: fclose($fp);
! 26: $phar = new Phar($fname);
! 27: $file = '<?php echo "second stub\n"; __HALT_COMPILER(); ?>';
! 28:
! 29: //// 2
! 30: $phar->setStub($file);
! 31: $fp = fopen($fname, 'rb');
! 32: echo fread($fp, strlen($file)) . "\n";
! 33: fclose($fp);
! 34:
! 35: $fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phartmp.php';
! 36: $file = b'<?php echo "third stub\n"; __HALT_COMPILER(); ?>';
! 37: $fp = fopen($fname2, 'wb');
! 38: fwrite($fp, $file);
! 39: fclose($fp);
! 40: $fp = fopen($fname2, 'rb');
! 41:
! 42: //// 3
! 43: $phar->setStub($fp);
! 44: fclose($fp);
! 45:
! 46: $fp = fopen($fname, 'rb');
! 47: echo fread($fp, strlen($file)) . "\n";
! 48: fclose($fp);
! 49:
! 50: $fp = fopen($fname2, 'ab');
! 51: fwrite($fp, b'booya');
! 52: fclose($fp);
! 53: echo file_get_contents($fname2) . "\n";
! 54:
! 55: $fp = fopen($fname2, 'rb');
! 56:
! 57: //// 4
! 58: $phar->setStub($fp, strlen($file));
! 59: fclose($fp);
! 60:
! 61: $fp = fopen($fname, 'rb');
! 62: echo fread($fp, strlen($file)) . "\n";
! 63: if (fread($fp, strlen('booya')) == 'booya') {
! 64: echo 'failed - copied booya';
! 65: }
! 66: fclose($fp);
! 67: $phar['testing'] = 'hi';
! 68:
! 69: // ensure stub is not overwritten
! 70: $fp = fopen($fname, 'rb');
! 71: echo fread($fp, strlen($file)) . "\n";
! 72: if (fread($fp, strlen('booya')) == 'booya') {
! 73: echo 'failed - copied booya';
! 74: }
! 75: fclose($fp);
! 76:
! 77: ?>
! 78: ===DONE===
! 79: --CLEAN--
! 80: <?php
! 81: unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php');
! 82: unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phartmp.php');
! 83: __HALT_COMPILER();
! 84: ?>
! 85: --EXPECT--
! 86: <?php echo "first stub\n"; __HALT_COMPILER(); ?>
! 87: <?php echo "second stub\n"; __HALT_COMPILER(); ?>
! 88: <?php echo "third stub\n"; __HALT_COMPILER(); ?>
! 89: <?php echo "third stub\n"; __HALT_COMPILER(); ?>booya
! 90: <?php echo "third stub\n"; __HALT_COMPILER(); ?>
! 91: <?php echo "third stub\n"; __HALT_COMPILER(); ?>
! 92: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>