|
| 1 | +--TEST-- |
| 2 | +Test opendir() function : usage variations - different data types as $path arg |
| 3 | +--SKIPIF-- |
| 4 | +<?php |
| 5 | +if (substr(PHP_OS, 0, 3) != 'WIN') { |
| 6 | + die("skip Valid only on Windows"); |
| 7 | +} |
| 8 | +?> |
| 9 | +--FILE-- |
| 10 | +<?php |
| 11 | +/* Prototype : mixed opendir(string $path[, resource $context]) |
| 12 | + * Description: Open a directory and return a dir_handle |
| 13 | + * Source code: ext/standard/dir.c |
| 14 | + */ |
| 15 | + |
| 16 | +/* |
| 17 | + * Pass different data types as $path argument to opendir() to test behaviour |
| 18 | + * Where possible, an existing directory has been entered as a string value |
| 19 | + */ |
| 20 | + |
| 21 | +echo "*** Testing opendir() : usage variations ***\n"; |
| 22 | + |
| 23 | +// create directory to be passed as string value where possible |
| 24 | +$path = dirname(__FILE__) . "/opendir_variation1"; |
| 25 | +mkdir($path); |
| 26 | + |
| 27 | +//get an unset variable |
| 28 | +$unset_var = 10; |
| 29 | +unset ($unset_var); |
| 30 | + |
| 31 | +// get a class |
| 32 | +class classA { |
| 33 | + |
| 34 | + var $path; |
| 35 | + function __construct($path) { |
| 36 | + $this->path = $path; |
| 37 | + } |
| 38 | + public function __toString() { |
| 39 | + return $this->path; |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +// heredoc string |
| 44 | +$heredoc = <<<EOT |
| 45 | +$path |
| 46 | +EOT; |
| 47 | + |
| 48 | +// get a resource variable |
| 49 | +$fp = fopen(__FILE__, "r"); |
| 50 | + |
| 51 | +// unexpected values to be passed to $path argument |
| 52 | +$inputs = array( |
| 53 | + |
| 54 | + // int data |
| 55 | +/*1*/ 0, |
| 56 | + 1, |
| 57 | + 12345, |
| 58 | + -2345, |
| 59 | + |
| 60 | + // float data |
| 61 | +/*5*/ 10.5, |
| 62 | + -10.5, |
| 63 | + 12.3456789000e10, |
| 64 | + 12.3456789000E-10, |
| 65 | + .5, |
| 66 | + |
| 67 | + // null data |
| 68 | +/*10*/ NULL, |
| 69 | + null, |
| 70 | + |
| 71 | + // boolean data |
| 72 | +/*12*/ true, |
| 73 | + false, |
| 74 | + TRUE, |
| 75 | + FALSE, |
| 76 | + |
| 77 | + // empty data |
| 78 | +/*16*/ "", |
| 79 | + '', |
| 80 | + array(), |
| 81 | + |
| 82 | + // string data |
| 83 | +/*19*/ "$path", |
| 84 | + 'string', |
| 85 | + $heredoc, |
| 86 | + |
| 87 | + // object data |
| 88 | +/*22*/ new classA($path), |
| 89 | + |
| 90 | + // undefined data |
| 91 | +/*23*/ @$undefined_var, |
| 92 | + |
| 93 | + // unset data |
| 94 | +/*24*/ @$unset_var, |
| 95 | + |
| 96 | + // resource variable |
| 97 | +/*25*/ $fp |
| 98 | +); |
| 99 | + |
| 100 | +// loop through each element of $inputs to check the behavior of opendir() |
| 101 | +$iterator = 1; |
| 102 | +foreach($inputs as $input) { |
| 103 | + echo "\n-- Iteration $iterator --\n"; |
| 104 | + var_dump( $dh = opendir($input) ); |
| 105 | + if ($dh) { |
| 106 | + closedir($dh); |
| 107 | + } |
| 108 | + $iterator++; |
| 109 | +}; |
| 110 | + |
| 111 | +fclose($fp); |
| 112 | +?> |
| 113 | +===DONE=== |
| 114 | +--CLEAN-- |
| 115 | +<?php |
| 116 | +$path = dirname(__FILE__) . "/opendir_variation1"; |
| 117 | +rmdir($path); |
| 118 | +?> |
| 119 | +--EXPECTF-- |
| 120 | +*** Testing opendir() : usage variations *** |
| 121 | + |
| 122 | +-- Iteration 1 -- |
| 123 | + |
| 124 | +Warning: opendir(0,0): The system cannot find the file specified. (code: 2) in %s on line %d |
| 125 | + |
| 126 | +Warning: opendir(0): failed to open dir: %s in %s on line %d |
| 127 | +bool(false) |
| 128 | + |
| 129 | +-- Iteration 2 -- |
| 130 | + |
| 131 | +Warning: opendir(1,1): The system cannot find the file specified. (code: 2) in %s on line %d |
| 132 | + |
| 133 | +Warning: opendir(1): failed to open dir: %s in %s on line %d |
| 134 | +bool(false) |
| 135 | + |
| 136 | +-- Iteration 3 -- |
| 137 | + |
| 138 | +Warning: opendir(12345,12345): The system cannot find the file specified. (code: 2) in %s on line %d |
| 139 | + |
| 140 | +Warning: opendir(12345): failed to open dir: %s in %s on line %d |
| 141 | +bool(false) |
| 142 | + |
| 143 | +-- Iteration 4 -- |
| 144 | + |
| 145 | +Warning: opendir(-2345,-2345): The system cannot find the file specified. (code: 2) in %s on line %d |
| 146 | + |
| 147 | +Warning: opendir(-2345): failed to open dir: %s in %s on line %d |
| 148 | +bool(false) |
| 149 | + |
| 150 | +-- Iteration 5 -- |
| 151 | + |
| 152 | +Warning: opendir(10.5,10.5): The system cannot find the file specified. (code: 2) in %s on line %d |
| 153 | + |
| 154 | +Warning: opendir(10.5): failed to open dir: %s in %s on line %d |
| 155 | +bool(false) |
| 156 | + |
| 157 | +-- Iteration 6 -- |
| 158 | + |
| 159 | +Warning: opendir(-10.5,-10.5): The system cannot find the file specified. (code: 2) in %s on line %d |
| 160 | + |
| 161 | +Warning: opendir(-10.5): failed to open dir: %s in %s on line %d |
| 162 | +bool(false) |
| 163 | + |
| 164 | +-- Iteration 7 -- |
| 165 | + |
| 166 | +Warning: opendir(123456789000,123456789000): The system cannot find the file specified. (code: 2) in %s on line %d |
| 167 | + |
| 168 | +Warning: opendir(123456789000): failed to open dir: %s in %s on line %d |
| 169 | +bool(false) |
| 170 | + |
| 171 | +-- Iteration 8 -- |
| 172 | + |
| 173 | +Warning: opendir(1.23456789E-9,1.23456789E-9): The system cannot find the file specified. (code: 2) in %s on line %d |
| 174 | + |
| 175 | +Warning: opendir(1.23456789E-9): failed to open dir: %s in %s on line %d |
| 176 | +bool(false) |
| 177 | + |
| 178 | +-- Iteration 9 -- |
| 179 | + |
| 180 | +Warning: opendir(0.5,0.5): The system cannot find the file specified. (code: 2) in %s on line %d |
| 181 | + |
| 182 | +Warning: opendir(0.5): failed to open dir: %s in %s on line %d |
| 183 | +bool(false) |
| 184 | + |
| 185 | +-- Iteration 10 -- |
| 186 | +bool(false) |
| 187 | + |
| 188 | +-- Iteration 11 -- |
| 189 | +bool(false) |
| 190 | + |
| 191 | +-- Iteration 12 -- |
| 192 | + |
| 193 | +Warning: opendir(1,1): The system cannot find the file specified. (code: 2) in %s on line %d |
| 194 | + |
| 195 | +Warning: opendir(1): failed to open dir: %s in %s on line %d |
| 196 | +bool(false) |
| 197 | + |
| 198 | +-- Iteration 13 -- |
| 199 | +bool(false) |
| 200 | + |
| 201 | +-- Iteration 14 -- |
| 202 | + |
| 203 | +Warning: opendir(1,1): The system cannot find the file specified. (code: 2) in %s on line %d |
| 204 | + |
| 205 | +Warning: opendir(1): failed to open dir: %s in %s on line %d |
| 206 | +bool(false) |
| 207 | + |
| 208 | +-- Iteration 15 -- |
| 209 | +bool(false) |
| 210 | + |
| 211 | +-- Iteration 16 -- |
| 212 | +bool(false) |
| 213 | + |
| 214 | +-- Iteration 17 -- |
| 215 | +bool(false) |
| 216 | + |
| 217 | +-- Iteration 18 -- |
| 218 | + |
| 219 | +Warning: opendir() expects parameter 1 to be a valid path, array given in %s on line %d |
| 220 | +NULL |
| 221 | + |
| 222 | +-- Iteration 19 -- |
| 223 | +resource(%d) of type (stream) |
| 224 | + |
| 225 | +-- Iteration 20 -- |
| 226 | + |
| 227 | +Warning: opendir(string,string): The system cannot find the file specified. (code: 2) in %s on line %d |
| 228 | + |
| 229 | +Warning: opendir(string): failed to open dir: %s in %s on line %d |
| 230 | +bool(false) |
| 231 | + |
| 232 | +-- Iteration 21 -- |
| 233 | +resource(%d) of type (stream) |
| 234 | + |
| 235 | +-- Iteration 22 -- |
| 236 | +resource(%d) of type (stream) |
| 237 | + |
| 238 | +-- Iteration 23 -- |
| 239 | +bool(false) |
| 240 | + |
| 241 | +-- Iteration 24 -- |
| 242 | +bool(false) |
| 243 | + |
| 244 | +-- Iteration 25 -- |
| 245 | + |
| 246 | +Warning: opendir() expects parameter 1 to be a valid path, resource given in %s on line %d |
| 247 | +NULL |
| 248 | +===DONE=== |
0 commit comments