Return to readdir_variation4.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / dir |
1.1 misho 1: --TEST-- 2: Test readdir() function : usage variations - different file names 3: --FILE-- 4: <?php 5: /* Prototype : string readdir([resource $dir_handle]) 6: * Description: Read directory entry from dir_handle 7: * Source code: ext/standard/dir.c 8: */ 9: 10: /* 11: * Pass a directory handle pointing to a directory that contains 12: * files with different file names to test how readdir() reads them 13: */ 14: 15: echo "*** Testing readdir() : usage variations ***\n"; 16: 17: $dir_path = dirname(__FILE__) . "/readdir_variation4/"; 18: mkdir($dir_path); 19: 20: // heredoc string 21: $heredoc = <<<EOT 22: hd_file 23: EOT; 24: 25: $inputs = array( 26: 27: // int data 28: /*1*/ 0, 29: 1, 30: 12345, 31: -2345, 32: 33: // float data 34: /*5*/ 10.5, 35: -10.5, 36: 12.3456789000e10, 37: 12.3456789000E-10, 38: .5, 39: 40: // empty data 41: /*10*/ "", 42: array(), 43: 44: // string data 45: /*12*/ "double_file", 46: 'single_file', 47: $heredoc, 48: ); 49: 50: $iterator = 1; 51: foreach($inputs as $key => $input) { 52: echo "\n-- Iteration $iterator --\n"; 53: $handle = "fp{$iterator}"; 54: var_dump( $$handle = fopen($dir_path . $input . '.tmp', 'w') ); 55: var_dump( fwrite($$handle, $key)); 56: fclose($$handle); 57: $iterator++; 58: }; 59: 60: echo "\n-- Call to readdir() --\n"; 61: $dir_handle = opendir($dir_path); 62: while(FALSE !== ($file = readdir($dir_handle))){ 63: 64: // different OS order files differently so will 65: // store file names into an array so can use sorted in expected output 66: $contents[] = $file; 67: 68: // remove files while going through directory 69: @unlink($dir_path . $file); 70: } 71: 72: // more important to check that all contents are present than order they are returned in 73: sort($contents); 74: var_dump($contents); 75: 76: closedir($dir_handle); 77: ?> 78: ===DONE=== 79: --CLEAN-- 80: <?php 81: $dir_path = dirname(__FILE__) . "/readdir_variation4/"; 82: rmdir($dir_path); 83: ?> 84: --EXPECTF-- 85: *** Testing readdir() : usage variations *** 86: 87: -- Iteration 1 -- 88: resource(%d) of type (stream) 89: int(1) 90: 91: -- Iteration 2 -- 92: resource(%d) of type (stream) 93: int(1) 94: 95: -- Iteration 3 -- 96: resource(%d) of type (stream) 97: int(1) 98: 99: -- Iteration 4 -- 100: resource(%d) of type (stream) 101: int(1) 102: 103: -- Iteration 5 -- 104: resource(%d) of type (stream) 105: int(1) 106: 107: -- Iteration 6 -- 108: resource(%d) of type (stream) 109: int(1) 110: 111: -- Iteration 7 -- 112: resource(%d) of type (stream) 113: int(1) 114: 115: -- Iteration 8 -- 116: resource(%d) of type (stream) 117: int(1) 118: 119: -- Iteration 9 -- 120: resource(%d) of type (stream) 121: int(1) 122: 123: -- Iteration 10 -- 124: resource(%d) of type (stream) 125: int(1) 126: 127: -- Iteration 11 -- 128: resource(%d) of type (stream) 129: int(2) 130: 131: -- Iteration 12 -- 132: resource(%d) of type (stream) 133: int(2) 134: 135: -- Iteration 13 -- 136: resource(%d) of type (stream) 137: int(2) 138: 139: -- Iteration 14 -- 140: resource(%d) of type (stream) 141: int(2) 142: 143: -- Call to readdir() -- 144: array(16) { 145: [0]=> 146: string(9) "-10.5.tmp" 147: [1]=> 148: string(9) "-2345.tmp" 149: [2]=> 150: string(1) "." 151: [3]=> 152: string(2) ".." 153: [4]=> 154: string(4) ".tmp" 155: [5]=> 156: string(7) "0.5.tmp" 157: [6]=> 158: string(5) "0.tmp" 159: [7]=> 160: string(17) "1.23456789E-9.tmp" 161: [8]=> 162: string(5) "1.tmp" 163: [9]=> 164: string(8) "10.5.tmp" 165: [10]=> 166: string(9) "12345.tmp" 167: [11]=> 168: string(16) "123456789000.tmp" 169: [12]=> 170: string(9) "Array.tmp" 171: [13]=> 172: string(15) "double_file.tmp" 173: [14]=> 174: string(11) "hd_file.tmp" 175: [15]=> 176: string(15) "single_file.tmp" 177: } 178: ===DONE===