xref: /PHP-5.5/ext/spl/tests/heap_009.phpt (revision 2882dde0)
1--TEST--
2SPL: SplHeap and friends, throw: An iterator cannot be used with foreach by reference
3--CREDITS--
4Thomas Koch <thomas@koch.ro>
5#Hackday Webtuesday 2008-05-24
6--FILE--
7<?php
8function testForException( $heap )
9{
10    try
11    {
12        foreach( $heap as &$item );
13    }
14    catch( RuntimeException $e )
15    {
16        echo $e->getMessage(),"\n";
17    }
18}
19
20// 1. SplMinHeap emtpy
21$heap = new SplMinHeap;
22testForException( $heap );
23
24// 2. SplMinHeap non-emtpy
25$heap = new SplMinHeap;
26$heap->insert( 1 );
27testForException( $heap );
28
29// 3. SplMaxHeap emtpy
30$heap = new SplMaxHeap;
31testForException( $heap );
32
33// 4. SplMaxHeap non-emtpy
34$heap = new SplMaxHeap;
35$heap->insert( 1 );
36testForException( $heap );
37
38// 5. SplPriorityQueue empty
39$heap = new SplPriorityQueue;
40testForException( $heap );
41
42// 6. SplPriorityQueue non-empty
43$heap = new SplPriorityQueue;
44$heap->insert( 1, 2 );
45testForException( $heap );
46
47?>
48==DONE==
49--EXPECT--
50An iterator cannot be used with foreach by reference
51An iterator cannot be used with foreach by reference
52An iterator cannot be used with foreach by reference
53An iterator cannot be used with foreach by reference
54An iterator cannot be used with foreach by reference
55An iterator cannot be used with foreach by reference
56==DONE==
57