phar_copy.phpt 2.2 KB

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