Annotation of embedaddon/php/ext/standard/tests/file/dirname_variation1.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test dirname() function : usage variation
3: --CREDITS--
4: Dave Kelsey <d_kelsey@uk.ibm.com>
5: --FILE--
6: <?php
7: /* Prototype : string dirname(string path)
8: * Description: Returns the directory name component of the path
9: * Source code: ext/standard/string.c
10: * Alias to functions:
11: */
12:
13: echo "*** Testing dirname() : 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:
26: //get an unset variable
27: $unset_var = 10;
28: unset ($unset_var);
29:
30: // define some classes
31: class classWithToString
32: {
33: public function __toString() {
34: return "Class A object";
35: }
36: }
37:
38: class classWithoutToString
39: {
40: }
41:
42: // heredoc string
43: $heredoc = <<<EOT
44: hello world
45: EOT;
46:
47: // add arrays
48: $index_array = array (1, 2, 3);
49: $assoc_array = array ('one' => 1, 'two' => 2);
50:
51: //array of values to iterate over
52: $inputs = array(
53:
54: // int data
55: 'int 0' => 0,
56: 'int 1' => 1,
57: 'int 12345' => 12345,
58: 'int -12345' => -2345,
59:
60: // float data
61: 'float 10.5' => 10.5,
62: 'float -10.5' => -10.5,
63: 'float 12.3456789000e10' => 12.3456789000e10,
64: 'float -12.3456789000e10' => -12.3456789000e10,
65: 'float .5' => .5,
66:
67: // array data
68: 'empty array' => array(),
69: 'int indexed array' => $index_array,
70: 'associative array' => $assoc_array,
71: 'nested arrays' => array('foo', $index_array, $assoc_array),
72:
73: // null data
74: 'uppercase NULL' => NULL,
75: 'lowercase null' => null,
76:
77: // boolean data
78: 'lowercase true' => true,
79: 'lowercase false' =>false,
80: 'uppercase TRUE' =>TRUE,
81: 'uppercase FALSE' =>FALSE,
82:
83: // empty data
84: 'empty string DQ' => "",
85: 'empty string SQ' => '',
86:
87: // object data
88: 'instance of classWithToString' => new classWithToString(),
89: 'instance of classWithoutToString' => new classWithoutToString(),
90:
91: // undefined data
92: 'undefined var' => @$undefined_var,
93:
94: // unset data
95: 'unset var' => @$unset_var,
96: );
97:
98: // loop through each element of the array for path
99:
100: foreach($inputs as $key =>$value) {
101: echo "\n--$key--\n";
102: var_dump( dirname($value) );
103: };
104:
105: ?>
106: ===DONE===
107: --EXPECTF--
108: *** Testing dirname() : usage variation ***
109:
110: --int 0--
111: string(1) "."
112:
113: --int 1--
114: string(1) "."
115:
116: --int 12345--
117: string(1) "."
118:
119: --int -12345--
120: string(1) "."
121:
122: --float 10.5--
123: string(1) "."
124:
125: --float -10.5--
126: string(1) "."
127:
128: --float 12.3456789000e10--
129: string(1) "."
130:
131: --float -12.3456789000e10--
132: string(1) "."
133:
134: --float .5--
135: string(1) "."
136:
137: --empty array--
138: Error: 2 - dirname() expects parameter 1 to be string, array given, %s(%d)
139: NULL
140:
141: --int indexed array--
142: Error: 2 - dirname() expects parameter 1 to be string, array given, %s(%d)
143: NULL
144:
145: --associative array--
146: Error: 2 - dirname() expects parameter 1 to be string, array given, %s(%d)
147: NULL
148:
149: --nested arrays--
150: Error: 2 - dirname() expects parameter 1 to be string, array given, %s(%d)
151: NULL
152:
153: --uppercase NULL--
154: string(0) ""
155:
156: --lowercase null--
157: string(0) ""
158:
159: --lowercase true--
160: string(1) "."
161:
162: --lowercase false--
163: string(0) ""
164:
165: --uppercase TRUE--
166: string(1) "."
167:
168: --uppercase FALSE--
169: string(0) ""
170:
171: --empty string DQ--
172: string(0) ""
173:
174: --empty string SQ--
175: string(0) ""
176:
177: --instance of classWithToString--
178: string(1) "."
179:
180: --instance of classWithoutToString--
181: Error: 2 - dirname() expects parameter 1 to be string, object given, %s(%d)
182: NULL
183:
184: --undefined var--
185: string(0) ""
186:
187: --unset var--
188: string(0) ""
189: ===DONE===
190:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>