Annotation of embedaddon/php/ext/standard/tests/file/parse_ini_file_variation5.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test parse_ini_file() function : usage variation
! 3: --CREDITS--
! 4: Dave Kelsey <d_kelsey@uk.ibm.com>
! 5: --FILE--
! 6: <?php
! 7: /* Prototype : array parse_ini_file(string filename [, bool process_sections])
! 8: * Description: Parse configuration file
! 9: * Source code: ext/standard/basic_functions.c
! 10: * Alias to functions:
! 11: */
! 12:
! 13: echo "*** Testing parse_ini_file() : 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: $filename = __FILE__."ParseIniFileVar5.ini";
! 26: $contents = "a=test";
! 27: @unlink($filename);
! 28: file_put_contents($filename, $contents);
! 29:
! 30:
! 31: //get an unset variable
! 32: $unset_var = 10;
! 33: unset ($unset_var);
! 34:
! 35: // define some classes
! 36: class classWithToString
! 37: {
! 38: public function __toString() {
! 39: return "Class A object";
! 40: }
! 41: }
! 42:
! 43: class classWithoutToString
! 44: {
! 45: }
! 46:
! 47: // heredoc string
! 48: $heredoc = <<<EOT
! 49: hello world
! 50: EOT;
! 51:
! 52: // add arrays
! 53: $index_array = array (1, 2, 3);
! 54: $assoc_array = array ('one' => 1, 'two' => 2);
! 55:
! 56: //array of values to iterate over
! 57: $inputs = array(
! 58:
! 59: // int data
! 60: 'int 0' => 0,
! 61: 'int 1' => 1,
! 62: 'int 12345' => 12345,
! 63: 'int -12345' => -2345,
! 64:
! 65: // float data
! 66: 'float 10.5' => 10.5,
! 67: 'float -10.5' => -10.5,
! 68: 'float 12.3456789000e10' => 12.3456789000e10,
! 69: 'float -12.3456789000e10' => -12.3456789000e10,
! 70: 'float .5' => .5,
! 71:
! 72: // array data
! 73: 'empty array' => array(),
! 74: 'int indexed array' => $index_array,
! 75: 'associative array' => $assoc_array,
! 76: 'nested arrays' => array('foo', $index_array, $assoc_array),
! 77:
! 78: // null data
! 79: 'uppercase NULL' => NULL,
! 80: 'lowercase null' => null,
! 81:
! 82: // empty data
! 83: 'empty string DQ' => "",
! 84: 'empty string SQ' => '',
! 85:
! 86: // string data
! 87: 'string DQ' => "string",
! 88: 'string SQ' => 'string',
! 89: 'mixed case string' => "sTrInG",
! 90: 'heredoc' => $heredoc,
! 91:
! 92: // object data
! 93: 'instance of classWithToString' => new classWithToString(),
! 94: 'instance of classWithoutToString' => new classWithoutToString(),
! 95:
! 96: // undefined data
! 97: 'undefined var' => @$undefined_var,
! 98:
! 99: // unset data
! 100: 'unset var' => @$unset_var,
! 101: );
! 102:
! 103: // loop through each element of the array for process_sections
! 104:
! 105: foreach($inputs as $key =>$value) {
! 106: echo "\n--$key--\n";
! 107: var_dump( parse_ini_file($filename, $value) );
! 108: };
! 109:
! 110: unlink($filename);
! 111: ?>
! 112: ===DONE===
! 113: --EXPECTF--
! 114: *** Testing parse_ini_file() : usage variation ***
! 115:
! 116: --int 0--
! 117: array(1) {
! 118: ["a"]=>
! 119: string(4) "test"
! 120: }
! 121:
! 122: --int 1--
! 123: array(1) {
! 124: ["a"]=>
! 125: string(4) "test"
! 126: }
! 127:
! 128: --int 12345--
! 129: array(1) {
! 130: ["a"]=>
! 131: string(4) "test"
! 132: }
! 133:
! 134: --int -12345--
! 135: array(1) {
! 136: ["a"]=>
! 137: string(4) "test"
! 138: }
! 139:
! 140: --float 10.5--
! 141: array(1) {
! 142: ["a"]=>
! 143: string(4) "test"
! 144: }
! 145:
! 146: --float -10.5--
! 147: array(1) {
! 148: ["a"]=>
! 149: string(4) "test"
! 150: }
! 151:
! 152: --float 12.3456789000e10--
! 153: array(1) {
! 154: ["a"]=>
! 155: string(4) "test"
! 156: }
! 157:
! 158: --float -12.3456789000e10--
! 159: array(1) {
! 160: ["a"]=>
! 161: string(4) "test"
! 162: }
! 163:
! 164: --float .5--
! 165: array(1) {
! 166: ["a"]=>
! 167: string(4) "test"
! 168: }
! 169:
! 170: --empty array--
! 171: Error: 2 - parse_ini_file() expects parameter 2 to be boolean, array given, %s(%d)
! 172: bool(false)
! 173:
! 174: --int indexed array--
! 175: Error: 2 - parse_ini_file() expects parameter 2 to be boolean, array given, %s(%d)
! 176: bool(false)
! 177:
! 178: --associative array--
! 179: Error: 2 - parse_ini_file() expects parameter 2 to be boolean, array given, %s(%d)
! 180: bool(false)
! 181:
! 182: --nested arrays--
! 183: Error: 2 - parse_ini_file() expects parameter 2 to be boolean, array given, %s(%d)
! 184: bool(false)
! 185:
! 186: --uppercase NULL--
! 187: array(1) {
! 188: ["a"]=>
! 189: string(4) "test"
! 190: }
! 191:
! 192: --lowercase null--
! 193: array(1) {
! 194: ["a"]=>
! 195: string(4) "test"
! 196: }
! 197:
! 198: --empty string DQ--
! 199: array(1) {
! 200: ["a"]=>
! 201: string(4) "test"
! 202: }
! 203:
! 204: --empty string SQ--
! 205: array(1) {
! 206: ["a"]=>
! 207: string(4) "test"
! 208: }
! 209:
! 210: --string DQ--
! 211: array(1) {
! 212: ["a"]=>
! 213: string(4) "test"
! 214: }
! 215:
! 216: --string SQ--
! 217: array(1) {
! 218: ["a"]=>
! 219: string(4) "test"
! 220: }
! 221:
! 222: --mixed case string--
! 223: array(1) {
! 224: ["a"]=>
! 225: string(4) "test"
! 226: }
! 227:
! 228: --heredoc--
! 229: array(1) {
! 230: ["a"]=>
! 231: string(4) "test"
! 232: }
! 233:
! 234: --instance of classWithToString--
! 235: Error: 2 - parse_ini_file() expects parameter 2 to be boolean, object given, %s(%d)
! 236: bool(false)
! 237:
! 238: --instance of classWithoutToString--
! 239: Error: 2 - parse_ini_file() expects parameter 2 to be boolean, object given, %s(%d)
! 240: bool(false)
! 241:
! 242: --undefined var--
! 243: array(1) {
! 244: ["a"]=>
! 245: string(4) "test"
! 246: }
! 247:
! 248: --unset var--
! 249: array(1) {
! 250: ["a"]=>
! 251: string(4) "test"
! 252: }
! 253: ===DONE===
! 254:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>