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 = __DIR__; 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_variation"; 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--CLEAN-- 59<?php 60$file_path = __DIR__; 61rmdir($file_path."/disk_free_space_variation"); 62?> 63--EXPECTF-- 64*** Testing with a directory *** 65float(%d) 66float(%d) 67 68Testing for the return type *** 69bool(true) 70 71*** Testing with different directory combinations *** 72-- Iteration 1 -- 73float(%d) 74float(%d) 75 76-- Iteration 2 -- 77float(%d) 78float(%d) 79 80-- Iteration 3 -- 81float(%d) 82float(%d) 83 84-- Iteration 4 -- 85float(%d) 86float(%d) 87 88-- Iteration 5 -- 89float(%d) 90float(%d) 91 92-- Iteration 6 -- 93float(%d) 94float(%d) 95 96-- Iteration 7 -- 97float(%d) 98float(%d) 99 100-- Iteration 8 -- 101float(%d) 102float(%d) 103 104-- Iteration 9 -- 105 106Warning: disk_free_space() expects parameter 1 to be a valid path, string given in %s on line %d 107NULL 108 109Warning: diskfreespace() expects parameter 1 to be a valid path, string given in %s on line %d 110NULL 111 112-- Iteration 10 -- 113 114Warning: disk_free_space() expects parameter 1 to be a valid path, string given in %s on line %d 115NULL 116 117Warning: diskfreespace() expects parameter 1 to be a valid path, string given in %s on line %d 118NULL 119 120-- Iteration 11 -- 121 122Warning: disk_free_space() expects parameter 1 to be a valid path, string given in %s on line %d 123NULL 124 125Warning: diskfreespace() expects parameter 1 to be a valid path, string given in %s on line %d 126NULL 127 128-- Iteration 12 -- 129 130Warning: disk_free_space() expects parameter 1 to be a valid path, string given in %s on line %d 131NULL 132 133Warning: diskfreespace() expects parameter 1 to be a valid path, string given in %s on line %d 134NULL 135 136--- Done --- 137