summaryrefslogtreecommitdiff
path: root/ext/phar/tests/open_for_write_newfile.phpt
diff options
context:
space:
mode:
authorGreg Beaver <cellog@php.net>2007-01-05 01:50:26 +0000
committerGreg Beaver <cellog@php.net>2007-01-05 01:50:26 +0000
commit00f516cc99e107bc315172251c66ba562210f507 (patch)
tree30113585832ca54b0f2ba7c539d01cccaa681414 /ext/phar/tests/open_for_write_newfile.phpt
parentfe0f4b6a00b586e2ddc0463dcefa3918c198908d (diff)
downloadphp-git-00f516cc99e107bc315172251c66ba562210f507.tar.gz
fix creation of new files within an existing phar, add test
Diffstat (limited to 'ext/phar/tests/open_for_write_newfile.phpt')
-rw-r--r--ext/phar/tests/open_for_write_newfile.phpt41
1 files changed, 41 insertions, 0 deletions
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..ed017d733c
--- /dev/null
+++ b/ext/phar/tests/open_for_write_newfile.phpt
@@ -0,0 +1,41 @@
+--TEST--
+Phar: fopen a .phar for writing (new file)
+--SKIPIF--
+<?php if (!extension_loaded("phar")) print "skip"; ?>
+--FILE--
+<?php
+$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"; ?>';
+$manifest = '';
+foreach($files as $name => $cont) {
+ $len = strlen($cont);
+ $manifest .= pack('V', strlen($name)) . $name . pack('VVVVC', $len, time(), $len, crc32($cont), 0x00);
+}
+$alias = '';
+$manifest = pack('VnV', count($files), 0x0800, strlen($alias)) . $alias . $manifest;
+$file .= pack('V', strlen($manifest)) . $manifest;
+foreach($files as $cont)
+{
+ $file .= $cont;
+}
+
+file_put_contents(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php', $file);
+
+$fp = fopen('phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php/b/new.php', 'wb');
+fwrite($fp, 'extra');
+fclose($fp);
+include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php/b/c.php';
+include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php/b/new.php';
+?>
+
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECT--
+This is b/c
+extra
+===DONE===