Annotation of embedaddon/php/ext/standard/tests/file/parse_ini_file_variation4.phpt, revision 1.1.1.2
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: $process_sections = false;
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: // int data
56: 'int 0' => 0,
57: 'int 1' => 1,
58: 'int 12345' => 12345,
59: 'int -12345' => -2345,
60:
61: // float data
62: 'float 10.5' => 10.5,
63: 'float -10.5' => -10.5,
64: 'float 12.3456789000e10' => 12.3456789000e10,
65: 'float -12.3456789000e10' => -12.3456789000e10,
66: 'float .5' => .5,
67:
68: // array data
69: 'empty array' => array(),
70: 'int indexed array' => $index_array,
71: 'associative array' => $assoc_array,
72: 'nested arrays' => array('foo', $index_array, $assoc_array),
73:
74: // null data
75: 'uppercase NULL' => NULL,
76: 'lowercase null' => null,
77:
78: // boolean data
79: 'lowercase true' => true,
80: 'lowercase false' =>false,
81: 'uppercase TRUE' =>TRUE,
82: 'uppercase FALSE' =>FALSE,
83:
84: // empty data
85: 'empty string DQ' => "",
86: 'empty string SQ' => '',
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 filename
100:
101: foreach($inputs as $key =>$value) {
102: echo "\n--$key--\n";
103: var_dump( parse_ini_file($value, $process_sections) );
104: };
105:
106: ?>
107: ===DONE===
108: --EXPECTF--
109: *** Testing parse_ini_file() : usage variation ***
110:
111: --int 0--
112: Error: 2 - parse_ini_file(0): failed to open stream: No such file or directory, %s(%d)
113: bool(false)
114:
115: --int 1--
116: Error: 2 - parse_ini_file(1): failed to open stream: No such file or directory, %s(%d)
117: bool(false)
118:
119: --int 12345--
120: Error: 2 - parse_ini_file(12345): failed to open stream: No such file or directory, %s(%d)
121: bool(false)
122:
123: --int -12345--
124: Error: 2 - parse_ini_file(-2345): failed to open stream: No such file or directory, %s(%d)
125: bool(false)
126:
127: --float 10.5--
128: Error: 2 - parse_ini_file(10.5): failed to open stream: No such file or directory, %s(%d)
129: bool(false)
130:
131: --float -10.5--
132: Error: 2 - parse_ini_file(-10.5): failed to open stream: No such file or directory, %s(%d)
133: bool(false)
134:
135: --float 12.3456789000e10--
136: Error: 2 - parse_ini_file(123456789000): failed to open stream: No such file or directory, %s(%d)
137: bool(false)
138:
139: --float -12.3456789000e10--
140: Error: 2 - parse_ini_file(-123456789000): failed to open stream: No such file or directory, %s(%d)
141: bool(false)
142:
143: --float .5--
144: Error: 2 - parse_ini_file(0.5): failed to open stream: No such file or directory, %s(%d)
145: bool(false)
146:
147: --empty array--
1.1.1.2 ! misho 148: Error: 2 - parse_ini_file() expects parameter 1 to be a valid path, array given, %s(%d)
1.1 misho 149: bool(false)
150:
151: --int indexed array--
1.1.1.2 ! misho 152: Error: 2 - parse_ini_file() expects parameter 1 to be a valid path, array given, %s(%d)
1.1 misho 153: bool(false)
154:
155: --associative array--
1.1.1.2 ! misho 156: Error: 2 - parse_ini_file() expects parameter 1 to be a valid path, array given, %s(%d)
1.1 misho 157: bool(false)
158:
159: --nested arrays--
1.1.1.2 ! misho 160: Error: 2 - parse_ini_file() expects parameter 1 to be a valid path, array given, %s(%d)
1.1 misho 161: bool(false)
162:
163: --uppercase NULL--
164: Error: 2 - parse_ini_file(): Filename cannot be empty!, %s(%d)
165: bool(false)
166:
167: --lowercase null--
168: Error: 2 - parse_ini_file(): Filename cannot be empty!, %s(%d)
169: bool(false)
170:
171: --lowercase true--
172: Error: 2 - parse_ini_file(1): failed to open stream: No such file or directory, %s(%d)
173: bool(false)
174:
175: --lowercase false--
176: Error: 2 - parse_ini_file(): Filename cannot be empty!, %s(%d)
177: bool(false)
178:
179: --uppercase TRUE--
180: Error: 2 - parse_ini_file(1): failed to open stream: No such file or directory, %s(%d)
181: bool(false)
182:
183: --uppercase FALSE--
184: Error: 2 - parse_ini_file(): Filename cannot be empty!, %s(%d)
185: bool(false)
186:
187: --empty string DQ--
188: Error: 2 - parse_ini_file(): Filename cannot be empty!, %s(%d)
189: bool(false)
190:
191: --empty string SQ--
192: Error: 2 - parse_ini_file(): Filename cannot be empty!, %s(%d)
193: bool(false)
194:
195: --instance of classWithToString--
196: Error: 2 - parse_ini_file(Class A object): failed to open stream: No such file or directory, %s(%d)
197: bool(false)
198:
199: --instance of classWithoutToString--
1.1.1.2 ! misho 200: Error: 2 - parse_ini_file() expects parameter 1 to be a valid path, object given, %s(%d)
1.1 misho 201: bool(false)
202:
203: --undefined var--
204: Error: 2 - parse_ini_file(): Filename cannot be empty!, %s(%d)
205: bool(false)
206:
207: --unset var--
208: Error: 2 - parse_ini_file(): Filename cannot be empty!, %s(%d)
209: bool(false)
210: ===DONE===
211:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>