phar_copy.phpt 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. --TEST--
  2. Phar: copy()
  3. --SKIPIF--
  4. <?php if (!extension_loaded("phar")) die("skip"); ?>
  5. <?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
  6. <?php if (!extension_loaded("zlib")) die("skip zlib not available"); ?>
  7. --INI--
  8. phar.readonly=0
  9. phar.require_hash=1
  10. --FILE--
  11. <?php
  12. $fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
  13. $fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '2.phar.php';
  14. $pname = 'phar://'.$fname;
  15. $iname = '/file.txt';
  16. $ename = '/error/..';
  17. $p = new Phar($fname);
  18. try
  19. {
  20. $p['a'] = 'hi';
  21. $p->startBuffering();
  22. $p->copy('a', 'b');
  23. echo file_get_contents($p['b']->getPathName());
  24. $p['a']->compress(Phar::GZ);
  25. $p['b']->setMetadata('a');
  26. $p->copy('b', 'c');
  27. $p->stopBuffering();
  28. echo file_get_contents($p['c']->getPathName());
  29. copy($fname, $fname2);
  30. $p->copy('a', $ename);
  31. }
  32. catch(Exception $e)
  33. {
  34. echo $e->getMessage() . "\n";
  35. }
  36. ini_set('phar.readonly',1);
  37. $p2 = new Phar($fname2);
  38. echo "\n";
  39. echo 'a: ' , file_get_contents($p2['a']->getPathName());
  40. echo 'b: ' ,file_get_contents($p2['b']->getPathName());
  41. echo 'c: ' ,file_get_contents($p2['c']->getPathName()), $p2['c']->getMetaData(), "\n";
  42. ini_set('phar.readonly', 0);
  43. try {
  44. $p2->copy('notexisting', 'another');
  45. } catch (Exception $e) {
  46. echo $e->getMessage() . "\n";
  47. }
  48. try {
  49. $p2->copy('a', 'b');
  50. } catch (Exception $e) {
  51. echo $e->getMessage() . "\n";
  52. }
  53. $p2['a']->compress(Phar::GZ);
  54. $p2->copy('a', 'd');
  55. echo $p2['d']->getContent() . "\n";
  56. try {
  57. $p2->copy('d', '.phar/stub.php');
  58. } catch (Exception $e) {
  59. echo $e->getMessage(),"\n";
  60. }
  61. try {
  62. $p2->copy('.phar/stub.php', 'd');
  63. } catch (Exception $e) {
  64. echo $e->getMessage(),"\n";
  65. }
  66. ?>
  67. ===DONE===
  68. --CLEAN--
  69. <?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
  70. <?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '2.phar.php'); ?>
  71. --EXPECTF--
  72. hihifile "/error/.." contains invalid characters upper directory reference, cannot be copied from "a" in phar %s
  73. a: hib: hic: hia
  74. file "notexisting" cannot be copied to file "another", file does not exist in %sphar_copy2.phar.php
  75. file "a" cannot be copied to file "b", file must not already exist in phar %sphar_copy2.phar.php
  76. hi
  77. file "d" cannot be copied to file ".phar/stub.php", cannot copy to Phar meta-file in %sphar_copy2.phar.php
  78. file ".phar/stub.php" cannot be copied to file "d", cannot copy Phar meta-file in %sphar_copy2.phar.php
  79. ===DONE===