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