Return to pathinfo_variation2.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / file |
1.1 misho 1: --TEST-- 2: Test pathinfo() function : usage variation 3: --CREDITS-- 4: Dave Kelsey <d_kelsey@uk.ibm.com> 5: --FILE-- 6: <?php 7: /* Prototype : array pathinfo(string path[, int options]) 8: * Description: Returns information about a certain string 9: * Source code: ext/standard/string.c 10: * Alias to functions: 11: */ 12: 13: echo "*** Testing pathinfo() : usage variation ***\n"; 14: 15: // Define error handler 16: function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { 17: if (error_reporting() != 0) { 18: // report non-silenced errors 19: echo "Error: $err_no - $err_msg, $filename($linenum)\n"; 20: } 21: } 22: set_error_handler('test_error_handler'); 23: 24: // Initialise function arguments not being substituted (if any) 25: $path = '/usr/include/arpa/inet.h'; 26: 27: //get an unset variable 28: $unset_var = 10; 29: unset ($unset_var); 30: 31: // define some classes 32: class classWithToString 33: { 34: public function __toString() { 35: return "Class A object"; 36: } 37: } 38: 39: class classWithoutToString 40: { 41: } 42: 43: // heredoc string 44: $heredoc = <<<EOT 45: hello world 46: EOT; 47: 48: // add arrays 49: $index_array = array (1, 2, 3); 50: $assoc_array = array ('one' => 1, 'two' => 2); 51: 52: //array of values to iterate over 53: $inputs = array( 54: 55: // float data 56: 'float 10.5' => 10.5, 57: 'float -10.5' => -10.5, 58: 'float 12.3456789000e10' => 12.3456789000e10, 59: 'float -12.3456789000e10' => -12.3456789000e10, 60: 'float .5' => .5, 61: 62: // array data 63: 'empty array' => array(), 64: 'int indexed array' => $index_array, 65: 'associative array' => $assoc_array, 66: 'nested arrays' => array('foo', $index_array, $assoc_array), 67: 68: // null data 69: 'uppercase NULL' => NULL, 70: 'lowercase null' => null, 71: 72: // boolean data 73: 'lowercase true' => true, 74: 'lowercase false' =>false, 75: 'uppercase TRUE' =>TRUE, 76: 'uppercase FALSE' =>FALSE, 77: 78: // empty data 79: 'empty string DQ' => "", 80: 'empty string SQ' => '', 81: 82: // string data 83: 'string DQ' => "string", 84: 'string SQ' => 'string', 85: 'mixed case string' => "sTrInG", 86: 'heredoc' => $heredoc, 87: 88: // object data 89: 'instance of classWithToString' => new classWithToString(), 90: 'instance of classWithoutToString' => new classWithoutToString(), 91: 92: // undefined data 93: 'undefined var' => @$undefined_var, 94: 95: // unset data 96: 'unset var' => @$unset_var, 97: ); 98: 99: // loop through each element of the array for options 100: 101: foreach($inputs as $key =>$value) { 102: echo "\n--$key--\n"; 103: var_dump( pathinfo($path, $value) ); 104: }; 105: 106: ?> 107: ===DONE=== 108: --EXPECTF-- 109: *** Testing pathinfo() : usage variation *** 110: 111: --float 10.5-- 112: string(6) "inet.h" 113: 114: --float -10.5-- 115: string(6) "inet.h" 116: 117: --float 12.3456789000e10-- 118: string(%d) %s 119: 120: --float -12.3456789000e10-- 121: string(%d) %s 122: 123: --float .5-- 124: string(%d) %s 125: 126: --empty array-- 127: Error: 2 - pathinfo() expects parameter 2 to be long, array given, %s(%d) 128: NULL 129: 130: --int indexed array-- 131: Error: 2 - pathinfo() expects parameter 2 to be long, array given, %s(%d) 132: NULL 133: 134: --associative array-- 135: Error: 2 - pathinfo() expects parameter 2 to be long, array given, %s(%d) 136: NULL 137: 138: --nested arrays-- 139: Error: 2 - pathinfo() expects parameter 2 to be long, array given, %s(%d) 140: NULL 141: 142: --uppercase NULL-- 143: string(0) "" 144: 145: --lowercase null-- 146: string(0) "" 147: 148: --lowercase true-- 149: string(17) "/usr/include/arpa" 150: 151: --lowercase false-- 152: string(0) "" 153: 154: --uppercase TRUE-- 155: string(17) "/usr/include/arpa" 156: 157: --uppercase FALSE-- 158: string(0) "" 159: 160: --empty string DQ-- 161: Error: 2 - pathinfo() expects parameter 2 to be long, string given, %s(%d) 162: NULL 163: 164: --empty string SQ-- 165: Error: 2 - pathinfo() expects parameter 2 to be long, string given, %s(%d) 166: NULL 167: 168: --string DQ-- 169: Error: 2 - pathinfo() expects parameter 2 to be long, string given, %s(%d) 170: NULL 171: 172: --string SQ-- 173: Error: 2 - pathinfo() expects parameter 2 to be long, string given, %s(%d) 174: NULL 175: 176: --mixed case string-- 177: Error: 2 - pathinfo() expects parameter 2 to be long, string given, %s(%d) 178: NULL 179: 180: --heredoc-- 181: Error: 2 - pathinfo() expects parameter 2 to be long, string given, %s(%d) 182: NULL 183: 184: --instance of classWithToString-- 185: Error: 2 - pathinfo() expects parameter 2 to be long, object given, %s(%d) 186: NULL 187: 188: --instance of classWithoutToString-- 189: Error: 2 - pathinfo() expects parameter 2 to be long, object given, %s(%d) 190: NULL 191: 192: --undefined var-- 193: string(0) "" 194: 195: --unset var-- 196: string(0) "" 197: ===DONE===