Return to opendir_variation1.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / dir |
1.1 misho 1: --TEST-- 2: Test opendir() function : usage variations - different data types as $path arg 1.1.1.2 ! misho 3: --SKIPIF-- ! 4: <?php ! 5: if (substr(PHP_OS, 0, 3) == 'WIN') { ! 6: die('skip.. Not valid for Windows'); ! 7: } ! 8: ?> 1.1 misho 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): failed to open dir: %s in %s on line %d 125: bool(false) 126: 127: -- Iteration 2 -- 128: 129: Warning: opendir(1): failed to open dir: %s in %s on line %d 130: bool(false) 131: 132: -- Iteration 3 -- 133: 134: Warning: opendir(12345): failed to open dir: %s in %s on line %d 135: bool(false) 136: 137: -- Iteration 4 -- 138: 139: Warning: opendir(-2345): failed to open dir: %s in %s on line %d 140: bool(false) 141: 142: -- Iteration 5 -- 143: 144: Warning: opendir(10.5): failed to open dir: %s in %s on line %d 145: bool(false) 146: 147: -- Iteration 6 -- 148: 149: Warning: opendir(-10.5): failed to open dir: %s in %s on line %d 150: bool(false) 151: 152: -- Iteration 7 -- 153: 154: Warning: opendir(123456789000): failed to open dir: %s in %s on line %d 155: bool(false) 156: 157: -- Iteration 8 -- 158: 159: Warning: opendir(1.23456789E-9): failed to open dir: %s in %s on line %d 160: bool(false) 161: 162: -- Iteration 9 -- 163: 164: Warning: opendir(0.5): failed to open dir: %s in %s on line %d 165: bool(false) 166: 167: -- Iteration 10 -- 168: bool(false) 169: 170: -- Iteration 11 -- 171: bool(false) 172: 173: -- Iteration 12 -- 174: 175: Warning: opendir(1): failed to open dir: %s in %s on line %d 176: bool(false) 177: 178: -- Iteration 13 -- 179: bool(false) 180: 181: -- Iteration 14 -- 182: 183: Warning: opendir(1): failed to open dir: %s in %s on line %d 184: bool(false) 185: 186: -- Iteration 15 -- 187: bool(false) 188: 189: -- Iteration 16 -- 190: bool(false) 191: 192: -- Iteration 17 -- 193: bool(false) 194: 195: -- Iteration 18 -- 196: 197: Warning: opendir() expects parameter 1 to be string, array given in %s on line %d 198: NULL 199: 200: -- Iteration 19 -- 201: resource(%d) of type (stream) 202: 203: -- Iteration 20 -- 204: 205: Warning: opendir(string): failed to open dir: %s in %s on line %d 206: bool(false) 207: 208: -- Iteration 21 -- 209: resource(%d) of type (stream) 210: 211: -- Iteration 22 -- 212: resource(%d) of type (stream) 213: 214: -- Iteration 23 -- 215: bool(false) 216: 217: -- Iteration 24 -- 218: bool(false) 219: 220: -- Iteration 25 -- 221: 222: Warning: opendir() expects parameter 1 to be string, resource given in %s on line %d 223: NULL 224: ===DONE===