pharfileinfo_setmetadata.phpt 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. --TEST--
  2. Phar: PharFileInfo::setMetadata/delMetadata extra code coverage
  3. --EXTENSIONS--
  4. phar
  5. --INI--
  6. phar.readonly=0
  7. --FILE--
  8. <?php
  9. $fname = __DIR__ . '/' . basename(__FILE__, '.php') . '.phar';
  10. $pname = 'phar://' . $fname;
  11. $phar = new Phar($fname);
  12. $phar['a/b'] = 'hi there';
  13. $tar = $phar->convertToData(Phar::TAR);
  14. $b = $phar['a/b'];
  15. try {
  16. $phar['a']->setMetadata('hi');
  17. } catch (Exception $e) {
  18. echo $e->getMessage(), "\n";
  19. }
  20. try {
  21. $phar['a']->delMetadata();
  22. } catch (Exception $e) {
  23. echo $e->getMessage(), "\n";
  24. }
  25. ini_set('phar.readonly', 1);
  26. try {
  27. $b->setMetadata('hi');
  28. } catch (Exception $e) {
  29. echo $e->getMessage(), "\n";
  30. }
  31. try {
  32. $b->delMetadata();
  33. } catch (Exception $e) {
  34. echo $e->getMessage(), "\n";
  35. }
  36. ?>
  37. --CLEAN--
  38. <?php unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar'); ?>
  39. <?php unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.tar'); ?>
  40. --EXPECT--
  41. Phar entry is a temporary directory (not an actual entry in the archive), cannot set metadata
  42. Phar entry is a temporary directory (not an actual entry in the archive), cannot delete metadata
  43. Write operations disabled by the php.ini setting phar.readonly
  44. Write operations disabled by the php.ini setting phar.readonly