1--TEST-- 2Test readdir() function : usage variations - sub-directories 3--FILE-- 4<?php 5/* 6 * Pass a directory handle pointing to a directory that has a sub-directory 7 * to test behaviour of readdir() 8 */ 9 10echo "*** Testing readdir() : usage variations ***\n"; 11 12// include the file.inc for Function: function create_files() 13chdir(__DIR__); 14include(__DIR__."/../file/file.inc"); 15 16$path_top = __DIR__ . '/readdir_variation3'; 17$path_sub = $path_top . '/sub_folder'; 18mkdir($path_top); 19mkdir($path_sub); 20 21create_files($path_top, 2); 22create_files($path_sub, 2); 23 24$dir_handle = opendir($path_top); 25while(FALSE !== ($file = readdir($dir_handle))) { 26 27 // different OS order files differently so will 28 // store file names into an array so can use sorted in expected output 29 $contents[] = $file; 30} 31 32// more important to check that all contents are present than order they are returned in 33sort($contents); 34var_dump($contents); 35 36delete_files($path_top, 2); 37delete_files($path_sub, 2); 38 39closedir($dir_handle); 40?> 41--CLEAN-- 42<?php 43$path_top = __DIR__ . '/readdir_variation3'; 44$path_sub = $path_top . '/sub_folder'; 45rmdir($path_sub); 46rmdir($path_top); 47?> 48--EXPECT-- 49*** Testing readdir() : usage variations *** 50array(5) { 51 [0]=> 52 string(1) "." 53 [1]=> 54 string(2) ".." 55 [2]=> 56 string(9) "file1.tmp" 57 [3]=> 58 string(9) "file2.tmp" 59 [4]=> 60 string(10) "sub_folder" 61} 62