mounteddir.phpt 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. --TEST--
  2. Phar: mounted manifest directory test
  3. --EXTENSIONS--
  4. phar
  5. --CONFLICTS--
  6. tempmanifest1.phar.php
  7. --INI--
  8. phar.readonly=0
  9. --FILE--
  10. <?php
  11. $fname = __DIR__ . '/tempmanifest1.phar.php';
  12. $pname = 'phar://' . $fname;
  13. $a = new Phar($fname);
  14. $a['index.php'] = '<?php
  15. Phar::mount("testit", dirname(Phar::running(0)) . "/testit");
  16. echo file_get_contents(Phar::running(1) . "/testit/extfile.php"), "\n";
  17. echo file_get_contents(Phar::running(1) . "/testit/directory"), "\n";
  18. echo file_get_contents(Phar::running(1) . "/testit/existing.txt"), "\n";
  19. include "testit/extfile.php";
  20. include "testit/extfile2.php";
  21. try {
  22. Phar::mount(".phar/stub.php", dirname(Phar::running(0)) . "/testit/extfile.php");
  23. } catch (Exception $e) {
  24. echo $e->getMessage(),"\n";
  25. }
  26. ?>';
  27. $a['testit/existing.txt'] = 'oops';
  28. $a->setStub('<?php
  29. set_include_path("phar://" . __FILE__);
  30. include "index.php";
  31. __HALT_COMPILER();');
  32. unset($a);
  33. mkdir(__DIR__ . '/testit');
  34. mkdir(__DIR__ . '/testit/directory');
  35. file_put_contents(__DIR__ . '/testit/extfile.php', '<?php
  36. var_dump(__FILE__);
  37. ?>');
  38. file_put_contents(__DIR__ . '/testit/extfile2.php', '<?php
  39. var_dump(__FILE__);
  40. ?>');
  41. include __DIR__ . '/testit/extfile.php';
  42. include $fname;
  43. $a = opendir($pname . '/testit');
  44. $out = array();
  45. while (false !== ($b = readdir($a))) {
  46. $out[] = $b;
  47. }
  48. sort($out);
  49. foreach ($out as $b) {
  50. echo "$b\n";
  51. }
  52. $out = array();
  53. foreach (new Phar($pname . '/testit') as $b) {
  54. $out[] = $b->getPathName();
  55. }
  56. sort($out);
  57. foreach ($out as $b) {
  58. echo "$b\n";
  59. }
  60. try {
  61. Phar::mount($pname . '/testit', 'another\\..\\mistake');
  62. } catch (Exception $e) {
  63. echo $e->getMessage(), "\n";
  64. }
  65. try {
  66. Phar::mount($pname . '/notfound', __DIR__ . '/this/does/not/exist');
  67. } catch (Exception $e) {
  68. echo $e->getMessage(), "\n";
  69. }
  70. try {
  71. Phar::mount($pname . '/testit', __DIR__);
  72. } catch (Exception $e) {
  73. echo $e->getMessage(), "\n";
  74. }
  75. try {
  76. Phar::mount($pname . '/testit/extfile.php', __DIR__);
  77. } catch (Exception $e) {
  78. echo $e->getMessage(), "\n";
  79. }
  80. ?>
  81. --CLEAN--
  82. <?php
  83. @unlink(__DIR__ . '/tempmanifest1.phar.php');
  84. @unlink(__DIR__ . '/testit/extfile.php');
  85. @unlink(__DIR__ . '/testit/extfile2.php');
  86. @rmdir(__DIR__ . '/testit/directory');
  87. @rmdir(__DIR__ . '/testit');
  88. ?>
  89. --EXPECTF--
  90. string(%d) "%sextfile.php"
  91. <?php
  92. var_dump(__FILE__);
  93. ?>
  94. Warning: file_get_contents(phar://%stempmanifest1.phar.php/testit/directory): Failed to open stream: phar error: path "testit/directory" is a directory in phar://%stempmanifest1.phar.php/index.php on line %d
  95. oops
  96. string(%d) "phar://%sextfile.php"
  97. string(%d) "phar://%sextfile2.php"
  98. Mounting of .phar/stub.php to %sextfile.php within phar %stests/tempmanifest1.phar.php failed
  99. .
  100. ..
  101. directory
  102. extfile.php
  103. extfile2.php
  104. phar://%stempmanifest1.phar.php/testit%cdirectory
  105. phar://%stempmanifest1.phar.php/testit%cextfile.php
  106. phar://%stempmanifest1.phar.php/testit%cextfile2.php
  107. Mounting of /testit to another\..\mistake within phar %stempmanifest1.phar.php failed
  108. Mounting of /notfound to %stests/this/does/not/exist within phar %stempmanifest1.phar.php failed
  109. Mounting of /testit to %stests within phar %stests/tempmanifest1.phar.php failed
  110. Mounting of /testit/extfile.php to %stests within phar %stests/tempmanifest1.phar.php failed