mirror of
https://github.com/php/php-src.git
synced 2024-12-14 12:26:19 +08:00
new test for Phar::decompress()
This commit is contained in:
parent
09aa78c440
commit
696dafa370
@ -2595,7 +2595,7 @@ PHP_METHOD(Phar, compress)
|
||||
|
||||
if (phar_obj->arc.archive->is_zip) {
|
||||
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC,
|
||||
"Cannot compress zipbased archives with whole-archive compression");
|
||||
"Cannot compress zip-based archives with whole-archive compression");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -2655,13 +2655,13 @@ PHP_METHOD(Phar, decompress)
|
||||
|
||||
if (PHAR_G(readonly) && !phar_obj->arc.archive->is_data) {
|
||||
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC,
|
||||
"Cannot compress phar archive, phar is read-only");
|
||||
"Cannot decompress phar archive, phar is read-only");
|
||||
return;
|
||||
}
|
||||
|
||||
if (phar_obj->arc.archive->is_zip) {
|
||||
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC,
|
||||
"Cannot compress zipbased archives with whole-archive compression");
|
||||
"Cannot decompress zip-based archives with whole-archive compression");
|
||||
return;
|
||||
}
|
||||
|
||||
|
69
ext/phar/tests/phar_decompress.phpt
Normal file
69
ext/phar/tests/phar_decompress.phpt
Normal file
@ -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===
|
Loading…
Reference in New Issue
Block a user