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