mirror of
https://github.com/php/php-src.git
synced 2026-04-02 13:43:02 +02:00
add test to make sure the phar is modified on disk
This commit is contained in:
62
ext/phar/tests/delete_in_phar_confirm.phpt
Normal file
62
ext/phar/tests/delete_in_phar_confirm.phpt
Normal file
@@ -0,0 +1,62 @@
|
||||
--TEST--
|
||||
Phar: delete a file within a .phar
|
||||
--SKIPIF--
|
||||
<?php if (!extension_loaded("phar")) print "skip"; ?>
|
||||
--INI--
|
||||
phar.readonly=0
|
||||
--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);
|
||||
|
||||
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';
|
||||
$md5 = md5_file(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php');
|
||||
unlink('phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php/b/c.php');
|
||||
clearstatcache();
|
||||
$md52 = md5_file(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php');
|
||||
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.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='.') in %sdelete_in_phar.php on line %d
|
||||
|
||||
===DONE===
|
||||
|
||||
Reference in New Issue
Block a user