Return to dir_variation1-win32.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / dir |
1.1 misho 1: --TEST-- 2: Test dir() function : usage variations - unexpected value for 'dir' argument 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: /* 12: * Prototype : object dir(string $directory[, resource $context]) 13: * Description: Directory class with properties, handle and class and methods read, rewind and close 14: * Source code: ext/standard/dir.c 15: */ 16: 17: /* 18: * Passing non string values to 'directory' argument of dir() and see 19: * that the function outputs proper warning messages wherever expected. 20: */ 21: 22: echo "*** Testing dir() : unexpected values for \$directory argument ***\n"; 23: 24: // get an unset variable 25: $unset_var = 10; 26: unset($unset_var); 27: 28: class A 29: { 30: public $var; 31: public function init() { 32: $this->var = 10; 33: } 34: } 35: 36: // get a resource variable 37: $fp = fopen(__FILE__, "r"); // get a file handle 38: $dfp = opendir( dirname(__FILE__) ); // get a dir handle 39: 40: // unexpected values to be passed to $directory argument 41: $unexpected_values = array ( 42: 43: // array data 44: /*1*/ array(), 45: array(0), 46: array(1), 47: array(1, 2), 48: array('color' => 'red', 'item' => 'pen'), 49: 50: // null data 51: /*6*/ NULL, 52: null, 53: 54: // boolean data 55: /*8*/ true, 56: false, 57: TRUE, 58: FALSE, 59: 60: // empty data 61: /*12*/ "", 62: '', 63: 64: // undefined data 65: /*14*/ @$undefined_var, 66: 67: // unset data 68: /*15*/ @$unset_var, 69: 70: // resource variable(dir and file handle) 71: /*16*/ $fp, 72: $dfp, 73: 74: // object data 75: /*18*/ new A() 76: ); 77: 78: // loop through various elements of $unexpected_values to check the behavior of dir() 79: $iterator = 1; 80: foreach( $unexpected_values as $unexpected_value ) { 81: echo "\n-- Iteration $iterator --\n"; 82: var_dump( dir($unexpected_value) ); 83: $iterator++; 84: } 85: 86: fclose($fp); 87: closedir($dfp); 88: echo "Done"; 89: ?> 90: --EXPECTF-- 91: *** Testing dir() : unexpected values for $directory argument *** 92: 93: -- Iteration 1 -- 94: 95: Warning: dir() expects parameter 1 to be string, array given in %s on line %d 96: NULL 97: 98: -- Iteration 2 -- 99: 100: Warning: dir() expects parameter 1 to be string, array given in %s on line %d 101: NULL 102: 103: -- Iteration 3 -- 104: 105: Warning: dir() expects parameter 1 to be string, array given in %s on line %d 106: NULL 107: 108: -- Iteration 4 -- 109: 110: Warning: dir() expects parameter 1 to be string, array given in %s on line %d 111: NULL 112: 113: -- Iteration 5 -- 114: 115: Warning: dir() expects parameter 1 to be string, array given in %s on line %d 116: NULL 117: 118: -- Iteration 6 -- 119: bool(false) 120: 121: -- Iteration 7 -- 122: bool(false) 123: 124: -- Iteration 8 -- 125: 126: Warning: dir(1,1): The system cannot find the file specified. (code: 2) in %s on line %d 127: 128: Warning: dir(1): failed to open dir: %s in %s on line %d 129: bool(false) 130: 131: -- Iteration 9 -- 132: bool(false) 133: 134: -- Iteration 10 -- 135: 136: Warning: dir(1,1): The system cannot find the file specified. (code: 2) in %s on line %d 137: 138: Warning: dir(1): failed to open dir: %s in %s on line %d 139: bool(false) 140: 141: -- Iteration 11 -- 142: bool(false) 143: 144: -- Iteration 12 -- 145: bool(false) 146: 147: -- Iteration 13 -- 148: bool(false) 149: 150: -- Iteration 14 -- 151: bool(false) 152: 153: -- Iteration 15 -- 154: bool(false) 155: 156: -- Iteration 16 -- 157: 158: Warning: dir() expects parameter 1 to be string, resource given in %s on line %d 159: NULL 160: 161: -- Iteration 17 -- 162: 163: Warning: dir() expects parameter 1 to be string, resource given in %s on line %d 164: NULL 165: 166: -- Iteration 18 -- 167: 168: Warning: dir() expects parameter 1 to be string, object given in %s on line %d 169: NULL 170: Done