From: Greg Beaver Date: Fri, 25 Apr 2008 16:05:05 +0000 (+0000) Subject: new test with code coverage for PharFileInfo::setMetadata/delMetadata, improve error... X-Git-Tag: RELEASE_2_0_0b1~208 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=84004bf248d3b9e8e8fbdb8867bc3c3edd3527e6;p=php new test with code coverage for PharFileInfo::setMetadata/delMetadata, improve error messages --- diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index c48bd9697c..2a41384ff6 100755 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -3583,7 +3583,7 @@ PHP_METHOD(PharFileInfo, setMetadata) PHAR_ENTRY_OBJECT(); if (PHAR_G(readonly) && !entry_obj->ent.entry->phar->is_data) { - zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Write operations disabled by INI setting"); + zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Write operations disabled by phar.readonly INI setting"); return; } if (entry_obj->ent.entry->is_tar) { @@ -3591,9 +3591,9 @@ PHP_METHOD(PharFileInfo, setMetadata) "Cannot set metadata, not possible with tar-based phar archives"); return; } - if (entry_obj->ent.entry->is_dir) { + if (entry_obj->ent.entry->is_temp_dir) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, \ - "Phar entry is a directory, cannot set metadata"); \ + "Phar entry is a temporary directory (not an actual entry in the archive), cannot set metadata"); \ return; } if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &metadata) == FAILURE) { @@ -3625,7 +3625,7 @@ PHP_METHOD(PharFileInfo, delMetadata) PHAR_ENTRY_OBJECT(); if (PHAR_G(readonly) && !entry_obj->ent.entry->phar->is_data) { - zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Write operations disabled by INI setting"); + zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Write operations disabled by phar.readonly INI setting"); return; } if (entry_obj->ent.entry->is_tar) { @@ -3634,7 +3634,9 @@ PHP_METHOD(PharFileInfo, delMetadata) return; } if (entry_obj->ent.entry->is_temp_dir) { - RETURN_FALSE; + zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, \ + "Phar entry is a temporary directory (not an actual entry in the archive), cannot delete metadata"); \ + return; } if (entry_obj->ent.entry->metadata) { zval_ptr_dtor(&entry_obj->ent.entry->metadata); diff --git a/ext/phar/tests/pharfileinfo_setmetadata.phpt b/ext/phar/tests/pharfileinfo_setmetadata.phpt new file mode 100644 index 0000000000..8589fcb1d8 --- /dev/null +++ b/ext/phar/tests/pharfileinfo_setmetadata.phpt @@ -0,0 +1,65 @@ +--TEST-- +Phar: PharFileInfo::setMetadata/delMetadata extra code coverage +--SKIPIF-- + +--INI-- +phar.readonly=0 +--FILE-- +convertToData(Phar::TAR); + +$b = $phar['a/b']; +try { +$tar['a/b']->setMetadata('hi'); +} catch (Exception $e) { +echo $e->getMessage(), "\n"; +} +try { +$tar['a/b']->delMetadata(); +} catch (Exception $e) { +echo $e->getMessage(), "\n"; +} +try { +$phar['a']->setMetadata('hi'); +} catch (Exception $e) { +echo $e->getMessage(), "\n"; +} +try { +$phar['a']->delMetadata(); +} catch (Exception $e) { +echo $e->getMessage(), "\n"; +} +ini_set('phar.readonly', 1); +try { +$b->setMetadata('hi'); +} catch (Exception $e) { +echo $e->getMessage(), "\n"; +} +try { +$b->delMetadata(); +} catch (Exception $e) { +echo $e->getMessage(), "\n"; +} +ini_set('phar.readonly', 0); +$b->setMetadata(1,2,3); +?> +===DONE=== +--CLEAN-- + + +--EXPECTF-- +Cannot set metadata, not possible with tar-based phar archives +Cannot delete metadata, not possible with tar-based phar archives +Phar entry is a temporary directory (not an actual entry in the archive), cannot set metadata +Phar entry is a temporary directory (not an actual entry in the archive), cannot delete metadata +Write operations disabled by phar.readonly INI setting +Write operations disabled by phar.readonly INI setting + +Warning: PharFileInfo::setMetadata() expects exactly 1 parameter, 3 given in %spharfileinfo_setmetadata.php on line %d +===DONE===