chdir_variation1.phpt 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. --TEST--
  2. Test chdir() function : usage variations - different data type as $directory arg
  3. --FILE--
  4. <?php
  5. /* Prototype : bool chdir(string $directory)
  6. * Description: Change the current directory
  7. * Source code: ext/standard/dir.c
  8. */
  9. /*
  10. * Pass different data types as $directory argument to test behaviour
  11. */
  12. echo "*** Testing chdir() : usage variations ***\n";
  13. // create the temporary directory
  14. $file_path = dirname(__FILE__);
  15. $dir_path = $file_path."/chdir_basic";
  16. @mkdir($dir_path);
  17. //get an unset variable
  18. $unset_var = 10;
  19. unset ($unset_var);
  20. // get a class
  21. class classA {
  22. var $dir_path;
  23. function __construct($dir) {
  24. $this->dir_path = $dir;
  25. }
  26. public function __toString() {
  27. return "$this->dir_path";
  28. }
  29. }
  30. // heredoc string
  31. $heredoc = <<<EOT
  32. $dir_path
  33. EOT;
  34. // get a resource variable
  35. $fp = fopen(__FILE__, "r");
  36. // unexpected values to be passed to $directory argument
  37. $inputs = array(
  38. // int data
  39. /*1*/ 0,
  40. 1,
  41. 12345,
  42. -2345,
  43. // float data
  44. /*5*/ 10.5,
  45. -10.5,
  46. 12.3456789000e10,
  47. 12.3456789000E-10,
  48. .5,
  49. // null data
  50. /*10*/ NULL,
  51. null,
  52. // boolean data
  53. /*12*/ true,
  54. false,
  55. TRUE,
  56. FALSE,
  57. // empty data
  58. /*16*/ "",
  59. '',
  60. array(),
  61. // string data
  62. /*19*/ "$dir_path",
  63. 'string',
  64. $heredoc,
  65. // object data
  66. /*22*/ new classA($dir_path),
  67. // undefined data
  68. /*23*/ @$undefined_var,
  69. // unset data
  70. /*24*/ @$unset_var,
  71. // resource variable
  72. /*25*/ $fp
  73. );
  74. // loop through each element of $inputs to check the behavior of chdir()
  75. $iterator = 1;
  76. foreach($inputs as $input) {
  77. echo "\n-- Iteration $iterator --\n";
  78. var_dump( chdir($input) );
  79. $iterator++;
  80. };
  81. fclose($fp);
  82. ?>
  83. ===DONE===
  84. --CLEAN--
  85. <?php
  86. $file_path = dirname(__FILE__);
  87. $dir_path = $file_path."/chdir_basic";
  88. rmdir($dir_path);
  89. ?>
  90. --EXPECTF--
  91. *** Testing chdir() : usage variations ***
  92. -- Iteration 1 --
  93. Warning: chdir(): %s (errno %d) in %s on line %d
  94. bool(false)
  95. -- Iteration 2 --
  96. Warning: chdir(): %s (errno %d) in %s on line %d
  97. bool(false)
  98. -- Iteration 3 --
  99. Warning: chdir(): %s (errno %d) in %s on line %d
  100. bool(false)
  101. -- Iteration 4 --
  102. Warning: chdir(): %s (errno %d) in %s on line %d
  103. bool(false)
  104. -- Iteration 5 --
  105. Warning: chdir(): %s (errno %d) in %s on line %d
  106. bool(false)
  107. -- Iteration 6 --
  108. Warning: chdir(): %s (errno %d) in %s on line %d
  109. bool(false)
  110. -- Iteration 7 --
  111. Warning: chdir(): %s (errno %d) in %s on line %d
  112. bool(false)
  113. -- Iteration 8 --
  114. Warning: chdir(): %s (errno %d) in %s on line %d
  115. bool(false)
  116. -- Iteration 9 --
  117. Warning: chdir(): %s (errno %d) in %s on line %d
  118. bool(false)
  119. -- Iteration 10 --
  120. Warning: chdir(): %s (errno %d) in %s on line %d
  121. bool(false)
  122. -- Iteration 11 --
  123. Warning: chdir(): %s (errno %d) in %s on line %d
  124. bool(false)
  125. -- Iteration 12 --
  126. Warning: chdir(): %s (errno %d) in %s on line %d
  127. bool(false)
  128. -- Iteration 13 --
  129. Warning: chdir(): %s (errno %d) in %s on line %d
  130. bool(false)
  131. -- Iteration 14 --
  132. Warning: chdir(): %s (errno %d) in %s on line %d
  133. bool(false)
  134. -- Iteration 15 --
  135. Warning: chdir(): %s (errno %d) in %s on line %d
  136. bool(false)
  137. -- Iteration 16 --
  138. Warning: chdir(): %s (errno %d) in %s on line %d
  139. bool(false)
  140. -- Iteration 17 --
  141. Warning: chdir(): %s (errno %d) in %s on line %d
  142. bool(false)
  143. -- Iteration 18 --
  144. Warning: chdir() expects parameter 1 to be a valid path, array given in %s on line %d
  145. bool(false)
  146. -- Iteration 19 --
  147. bool(true)
  148. -- Iteration 20 --
  149. Warning: chdir(): %s (errno %d) in %s on line %d
  150. bool(false)
  151. -- Iteration 21 --
  152. bool(true)
  153. -- Iteration 22 --
  154. bool(true)
  155. -- Iteration 23 --
  156. Warning: chdir(): %s (errno %d) in %s on line %d
  157. bool(false)
  158. -- Iteration 24 --
  159. Warning: chdir(): %s (errno %d) in %s on line %d
  160. bool(false)
  161. -- Iteration 25 --
  162. Warning: chdir() expects parameter 1 to be a valid path, resource given in %s on line %d
  163. bool(false)
  164. ===DONE===