1--TEST-- 2Test disk_free_space and its alias diskfreespace() functions : Usage Variations 3--FILE-- 4<?php 5/* 6 * Prototype: float disk_free_space( string directory ) 7 * Description: Given a string containing a directory, this function 8 * will return the number of bytes available on the corresponding 9 * filesystem or disk partition 10 */ 11 12$file_path = dirname(__FILE__); 13 14echo "*** Testing with a directory ***\n"; 15var_dump( disk_free_space($file_path."/..") ); 16var_dump( diskfreespace($file_path."/..") ); 17 18echo "\nTesting for the return type ***\n"; 19$return_value = disk_free_space($file_path); 20var_dump( is_float($return_value) ); 21 22echo "\n*** Testing with different directory combinations ***"; 23$dir = "/disk_free_space"; 24mkdir($file_path.$dir); 25 26$dirs_arr = array( 27 ".", 28 $file_path.$dir, 29 $file_path."/.".$dir, 30 31 /* Testing a file trailing slash */ 32 $file_path."".$dir."/", 33 $file_path."/.".$dir."/", 34 35 /* Testing file with double trailing slashes */ 36 $file_path.$dir."//", 37 $file_path."/.".$dir."//", 38 $file_path."/./".$dir."//", 39 40 /* Testing Binary safe */ 41 $file_path.$dir.chr(0), 42 $file_path."/.".$dir.chr(0), 43 ".".chr(0).$file_path.$dir, 44 ".".chr(0).$file_path.$dir.chr(0) 45); 46 47$count = 1; 48/* loop through to test each element the above array */ 49foreach($dirs_arr as $dir1) { 50 echo "\n-- Iteration $count --\n"; 51 var_dump( disk_free_space( $dir1 ) ); 52 var_dump( diskfreespace( $dir1 ) ); 53 $count++; 54} 55 56echo"\n--- Done ---"; 57?> 58 59--CLEAN-- 60<?php 61$file_path = dirname(__FILE__); 62rmdir($file_path."/disk_free_space"); 63?> 64 65 66--EXPECTF-- 67*** Testing with a directory *** 68float(%d) 69float(%d) 70 71Testing for the return type *** 72bool(true) 73 74*** Testing with different directory combinations *** 75-- Iteration 1 -- 76float(%d) 77float(%d) 78 79-- Iteration 2 -- 80float(%d) 81float(%d) 82 83-- Iteration 3 -- 84float(%d) 85float(%d) 86 87-- Iteration 4 -- 88float(%d) 89float(%d) 90 91-- Iteration 5 -- 92float(%d) 93float(%d) 94 95-- Iteration 6 -- 96float(%d) 97float(%d) 98 99-- Iteration 7 -- 100float(%d) 101float(%d) 102 103-- Iteration 8 -- 104float(%d) 105float(%d) 106 107-- Iteration 9 -- 108 109Warning: disk_free_space() expects parameter 1 to be a valid path, string given in %s on line %d 110NULL 111 112Warning: diskfreespace() expects parameter 1 to be a valid path, string given in %s on line %d 113NULL 114 115-- Iteration 10 -- 116 117Warning: disk_free_space() expects parameter 1 to be a valid path, string given in %s on line %d 118NULL 119 120Warning: diskfreespace() expects parameter 1 to be a valid path, string given in %s on line %d 121NULL 122 123-- Iteration 11 -- 124 125Warning: disk_free_space() expects parameter 1 to be a valid path, string given in %s on line %d 126NULL 127 128Warning: diskfreespace() expects parameter 1 to be a valid path, string given in %s on line %d 129NULL 130 131-- Iteration 12 -- 132 133Warning: disk_free_space() expects parameter 1 to be a valid path, string given in %s on line %d 134NULL 135 136Warning: diskfreespace() expects parameter 1 to be a valid path, string given in %s on line %d 137NULL 138 139--- Done --- 140