Annotation of embedaddon/php/ext/standard/tests/file/pathinfo_variation1.phpt, revision 1.1.1.1
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: $options = PATHINFO_DIRNAME;
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 path
100:
101: foreach($inputs as $key =>$value) {
102: echo "\n--$key--\n";
103: var_dump( pathinfo($value, $options) );
104: };
105:
106: ?>
107: ===DONE===
108: --EXPECTF--
109: *** Testing pathinfo() : usage variation ***
110:
111: --int 0--
112: string(1) "."
113:
114: --int 1--
115: string(1) "."
116:
117: --int 12345--
118: string(1) "."
119:
120: --int -12345--
121: string(1) "."
122:
123: --float 10.5--
124: string(1) "."
125:
126: --float -10.5--
127: string(1) "."
128:
129: --float 12.3456789000e10--
130: string(1) "."
131:
132: --float -12.3456789000e10--
133: string(1) "."
134:
135: --float .5--
136: string(1) "."
137:
138: --empty array--
139: Error: 2 - pathinfo() expects parameter 1 to be string, array given, %s(%d)
140: NULL
141:
142: --int indexed array--
143: Error: 2 - pathinfo() expects parameter 1 to be string, array given, %s(%d)
144: NULL
145:
146: --associative array--
147: Error: 2 - pathinfo() expects parameter 1 to be string, array given, %s(%d)
148: NULL
149:
150: --nested arrays--
151: Error: 2 - pathinfo() expects parameter 1 to be string, array given, %s(%d)
152: NULL
153:
154: --uppercase NULL--
155: string(0) ""
156:
157: --lowercase null--
158: string(0) ""
159:
160: --lowercase true--
161: string(1) "."
162:
163: --lowercase false--
164: string(0) ""
165:
166: --uppercase TRUE--
167: string(1) "."
168:
169: --uppercase FALSE--
170: string(0) ""
171:
172: --empty string DQ--
173: string(0) ""
174:
175: --empty string SQ--
176: string(0) ""
177:
178: --instance of classWithToString--
179: string(1) "."
180:
181: --instance of classWithoutToString--
182: Error: 2 - pathinfo() expects parameter 1 to be string, object given, %s(%d)
183: NULL
184:
185: --undefined var--
186: string(0) ""
187:
188: --unset var--
189: string(0) ""
190: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>