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