From 696dafa3700ab054ac5e523d54621060341dc9eb Mon Sep 17 00:00:00 2001 From: Greg Beaver Date: Thu, 24 Apr 2008 04:05:20 +0000 Subject: [PATCH] new test for Phar::decompress() --- ext/phar/phar_object.c | 6 +-- ext/phar/tests/phar_decompress.phpt | 69 +++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 ext/phar/tests/phar_decompress.phpt diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index 7eb6a347667..7cc2f2423f5 100755 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -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; } diff --git a/ext/phar/tests/phar_decompress.phpt b/ext/phar/tests/phar_decompress.phpt new file mode 100644 index 00000000000..ae199eb03b8 --- /dev/null +++ b/ext/phar/tests/phar_decompress.phpt @@ -0,0 +1,69 @@ +--TEST-- +Phar::decompress() +--SKIPIF-- + + +--INI-- +phar.require_hash=0 +phar.readonly=0 +--FILE-- +'; + +$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-- + +--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===