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