]> granicus.if.org Git - php/commitdiff
new test with code coverage for PharFileInfo::setMetadata/delMetadata, improve error...
authorGreg Beaver <cellog@php.net>
Fri, 25 Apr 2008 16:05:05 +0000 (16:05 +0000)
committerGreg Beaver <cellog@php.net>
Fri, 25 Apr 2008 16:05:05 +0000 (16:05 +0000)
ext/phar/phar_object.c
ext/phar/tests/pharfileinfo_setmetadata.phpt [new file with mode: 0644]

index c48bd9697cc3274f546244aa671e2b0fc64f7783..2a41384ff6569e2b2fae4e163971863022c130ec 100755 (executable)
@@ -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 (file)
index 0000000..8589fcb
--- /dev/null
@@ -0,0 +1,65 @@
+--TEST--
+Phar: PharFileInfo::setMetadata/delMetadata extra code coverage
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar';
+$pname = 'phar://' . $fname;
+
+$phar = new Phar($fname);
+
+$phar['a/b'] = 'hi there';
+$tar = $phar->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--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar'); ?>
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.tar'); ?>
+--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===