metadata_write_commit.phpt 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. --TEST--
  2. Phar with meta-data (write)
  3. --SKIPIF--
  4. <?php
  5. if (!extension_loaded("phar")) die("skip");
  6. if (version_compare(PHP_VERSION, "6.0", ">")) die("skip pre-unicode version of PHP required");
  7. ?>
  8. --INI--
  9. phar.require_hash=0
  10. phar.readonly=0
  11. --FILE--
  12. <?php
  13. $fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
  14. $pname = 'phar://' . $fname;
  15. $file = "<?php __HALT_COMPILER(); ?>";
  16. $files = array();
  17. $files['a'] = array('cont' => 'a');
  18. $files['b'] = array('cont' => 'b', 'meta' => 'hi there');
  19. $files['c'] = array('cont' => 'c', 'meta' => array('hi', 'there'));
  20. $files['d'] = array('cont' => 'd', 'meta' => array('hi'=>'there','foo'=>'bar'));
  21. include 'files/phar_test.inc';
  22. foreach($files as $name => $cont) {
  23. var_dump(file_get_contents($pname.'/'.$name));
  24. }
  25. $phar = new Phar($fname);
  26. $phar->startBuffering();
  27. $phar['a']->setMetadata(42);
  28. $phar['b']->setMetadata(NULL);
  29. $phar['c']->setMetadata(array(25, 'foo'=>'bar'));
  30. $phar['d']->setMetadata(true);
  31. foreach($files as $name => $cont) {
  32. var_dump($phar[$name]->getMetadata());
  33. }
  34. $phar->stopBuffering();
  35. unset($phar);
  36. $phar = new Phar($fname);
  37. foreach($files as $name => $cont) {
  38. var_dump(file_get_contents($pname.'/'.$name));
  39. }
  40. foreach($files as $name => $cont) {
  41. var_dump($phar[$name]->getMetadata());
  42. }
  43. ?>
  44. ===DONE===
  45. --CLEAN--
  46. <?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
  47. --EXPECT--
  48. string(1) "a"
  49. string(1) "b"
  50. string(1) "c"
  51. string(1) "d"
  52. int(42)
  53. NULL
  54. array(2) {
  55. [0]=>
  56. int(25)
  57. ["foo"]=>
  58. string(3) "bar"
  59. }
  60. bool(true)
  61. string(1) "a"
  62. string(1) "b"
  63. string(1) "c"
  64. string(1) "d"
  65. int(42)
  66. NULL
  67. array(2) {
  68. [0]=>
  69. int(25)
  70. ["foo"]=>
  71. string(3) "bar"
  72. }
  73. bool(true)
  74. ===DONE===