Annotation of embedaddon/php/ext/spl/tests/multiple_iterator_001.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: SPL: MultipleIterator
3: --FILE--
4: <?php
5:
6: $iter1 = new ArrayIterator(array(1,2,3));
7: $iter2 = new ArrayIterator(array(1,2));
8: $iter3 = new ArrayIterator(array(new stdClass(),"string",3));
9:
10: $m = new MultipleIterator();
11:
12: echo "-- Default flags, no iterators --\n";
13: foreach($m as $value) {
14: var_dump($value);
15: }
16: var_dump($m->current());
17:
18: $m->attachIterator($iter1);
19: $m->attachIterator($iter2);
20: $m->attachIterator($iter3);
21:
22: echo "-- Default flags, MultipleIterator::MIT_NEED_ALL | MultipleIterator::MIT_KEYS_NUMERIC --\n";
23:
24: var_dump($m->getFlags() === (MultipleIterator::MIT_NEED_ALL | MultipleIterator::MIT_KEYS_NUMERIC));
25:
26: foreach($m as $value) {
27: var_dump($m->key(), $value);
28: }
29: try {
30: $m->current();
31: } catch(RuntimeException $e) {
32: echo "RuntimeException thrown: " . $e->getMessage() . "\n";
33: }
34: try {
35: $m->key();
36: } catch(RuntimeException $e) {
37: echo "RuntimeException thrown: " . $e->getMessage() . "\n";
38: }
39:
40: echo "-- Flags = MultipleIterator::MIT_NEED_ANY | MultipleIterator::MIT_KEYS_NUMERIC --\n";
41:
42: $m->setFlags(MultipleIterator::MIT_NEED_ANY | MultipleIterator::MIT_KEYS_NUMERIC);
43: var_dump($m->getFlags() === (MultipleIterator::MIT_NEED_ANY | MultipleIterator::MIT_KEYS_NUMERIC));
44:
45: foreach($m as $value) {
46: var_dump($m->key(), $value);
47: }
48:
49: echo "-- Default flags, added element --\n";
50:
51: $m->setFlags(MultipleIterator::MIT_NEED_ALL | MultipleIterator::MIT_KEYS_NUMERIC);
52:
53: $iter2[] = 3;
54: foreach($m as $value) {
55: var_dump($m->key(), $value);
56: }
57:
58: echo "-- Flags |= MultipleIterator::MIT_KEYS_ASSOC, with iterator associated with NULL --\n";
59:
60: $m->setFlags(MultipleIterator::MIT_NEED_ALL | MultipleIterator::MIT_KEYS_ASSOC);
61: $m->rewind();
62: try {
63: $m->current();
64: } catch(InvalidArgumentException $e) {
65: echo "InvalidArgumentException thrown: " . $e->getMessage() . "\n";
66: }
67:
68: echo "-- Flags |= MultipleIterator::MIT_KEYS_ASSOC --\n";
69:
70: $m->attachIterator($iter1, "iter1");
71: $m->attachIterator($iter2, b"iter2");
72: $m->attachIterator($iter3, 3);
73:
74: foreach($m as $value) {
75: var_dump($m->key(), $value);
76: }
77:
78: echo "-- Associate with invalid value --\n";
79:
80: try {
81: $m->attachIterator($iter3, new stdClass());
82: } catch(InvalidArgumentException $e) {
83: echo "InvalidArgumentException thrown: " . $e->getMessage() . "\n";
84: }
85:
86: echo "-- Associate with duplicate value --\n";
87:
88: try {
89: $m->attachIterator($iter3, "iter1");
90: } catch(InvalidArgumentException $e) {
91: echo "InvalidArgumentException thrown: " . $e->getMessage() . "\n";
92: }
93:
94: echo "-- Count, contains, detach, count, contains, iterate --\n";
95:
96: var_dump($m->countIterators());
97: var_dump($m->containsIterator($iter2));
98: var_dump($m->detachIterator($iter2));
99: var_dump($m->countIterators());
100: var_dump($m->containsIterator($iter2));
101: foreach($m as $value) {
102: var_dump($m->key(), $value);
103: }
104:
105: ?>
106: --EXPECTF--
107: -- Default flags, no iterators --
108: bool(false)
109: -- Default flags, MultipleIterator::MIT_NEED_ALL | MultipleIterator::MIT_KEYS_NUMERIC --
110: bool(true)
111: array(3) {
112: [0]=>
113: int(0)
114: [1]=>
115: int(0)
116: [2]=>
117: int(0)
118: }
119: array(3) {
120: [0]=>
121: int(1)
122: [1]=>
123: int(1)
124: [2]=>
125: object(stdClass)#%d (0) {
126: }
127: }
128: array(3) {
129: [0]=>
130: int(1)
131: [1]=>
132: int(1)
133: [2]=>
134: int(1)
135: }
136: array(3) {
137: [0]=>
138: int(2)
139: [1]=>
140: int(2)
141: [2]=>
142: string(6) "string"
143: }
144: RuntimeException thrown: Called current() with non valid sub iterator
145: RuntimeException thrown: Called key() with non valid sub iterator
146: -- Flags = MultipleIterator::MIT_NEED_ANY | MultipleIterator::MIT_KEYS_NUMERIC --
147: bool(true)
148: array(3) {
149: [0]=>
150: int(0)
151: [1]=>
152: int(0)
153: [2]=>
154: int(0)
155: }
156: array(3) {
157: [0]=>
158: int(1)
159: [1]=>
160: int(1)
161: [2]=>
162: object(stdClass)#%d (0) {
163: }
164: }
165: array(3) {
166: [0]=>
167: int(1)
168: [1]=>
169: int(1)
170: [2]=>
171: int(1)
172: }
173: array(3) {
174: [0]=>
175: int(2)
176: [1]=>
177: int(2)
178: [2]=>
179: string(6) "string"
180: }
181: array(3) {
182: [0]=>
183: int(2)
184: [1]=>
185: NULL
186: [2]=>
187: int(2)
188: }
189: array(3) {
190: [0]=>
191: int(3)
192: [1]=>
193: NULL
194: [2]=>
195: int(3)
196: }
197: -- Default flags, added element --
198: array(3) {
199: [0]=>
200: int(0)
201: [1]=>
202: int(0)
203: [2]=>
204: int(0)
205: }
206: array(3) {
207: [0]=>
208: int(1)
209: [1]=>
210: int(1)
211: [2]=>
212: object(stdClass)#%d (0) {
213: }
214: }
215: array(3) {
216: [0]=>
217: int(1)
218: [1]=>
219: int(1)
220: [2]=>
221: int(1)
222: }
223: array(3) {
224: [0]=>
225: int(2)
226: [1]=>
227: int(2)
228: [2]=>
229: string(6) "string"
230: }
231: array(3) {
232: [0]=>
233: int(2)
234: [1]=>
235: int(2)
236: [2]=>
237: int(2)
238: }
239: array(3) {
240: [0]=>
241: int(3)
242: [1]=>
243: int(3)
244: [2]=>
245: int(3)
246: }
247: -- Flags |= MultipleIterator::MIT_KEYS_ASSOC, with iterator associated with NULL --
248: InvalidArgumentException thrown: Sub-Iterator is associated with NULL
249: -- Flags |= MultipleIterator::MIT_KEYS_ASSOC --
250: array(3) {
251: ["iter1"]=>
252: int(0)
253: ["iter2"]=>
254: int(0)
255: [3]=>
256: int(0)
257: }
258: array(3) {
259: ["iter1"]=>
260: int(1)
261: ["iter2"]=>
262: int(1)
263: [3]=>
264: object(stdClass)#%d (0) {
265: }
266: }
267: array(3) {
268: ["iter1"]=>
269: int(1)
270: ["iter2"]=>
271: int(1)
272: [3]=>
273: int(1)
274: }
275: array(3) {
276: ["iter1"]=>
277: int(2)
278: ["iter2"]=>
279: int(2)
280: [3]=>
281: string(6) "string"
282: }
283: array(3) {
284: ["iter1"]=>
285: int(2)
286: ["iter2"]=>
287: int(2)
288: [3]=>
289: int(2)
290: }
291: array(3) {
292: ["iter1"]=>
293: int(3)
294: ["iter2"]=>
295: int(3)
296: [3]=>
297: int(3)
298: }
299: -- Associate with invalid value --
300: InvalidArgumentException thrown: Info must be NULL, integer or string
301: -- Associate with duplicate value --
302: InvalidArgumentException thrown: Key duplication error
303: -- Count, contains, detach, count, contains, iterate --
304: int(3)
305: bool(true)
306: NULL
307: int(2)
308: bool(false)
309: array(2) {
310: ["iter1"]=>
311: int(0)
312: [3]=>
313: int(0)
314: }
315: array(2) {
316: ["iter1"]=>
317: int(1)
318: [3]=>
319: object(stdClass)#%d (0) {
320: }
321: }
322: array(2) {
323: ["iter1"]=>
324: int(1)
325: [3]=>
326: int(1)
327: }
328: array(2) {
329: ["iter1"]=>
330: int(2)
331: [3]=>
332: string(6) "string"
333: }
334: array(2) {
335: ["iter1"]=>
336: int(2)
337: [3]=>
338: int(2)
339: }
340: array(2) {
341: ["iter1"]=>
342: int(3)
343: [3]=>
344: int(3)
345: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>