metadata_write_commit.phpt 1.5 KB

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