xref: /PHP-8.3/ext/spl/tests/heap_004.phpt (revision 6d805ed2)
1--TEST--
2SPL: SplHeap: exceptions
3--FILE--
4<?php
5class myHeap extends SplHeap {
6    public function compare($a, $b): int {
7        throw new exception("foo");
8    }
9}
10
11$h = new myHeap;
12
13try {
14    $h->insert(1);
15    echo "inserted 1\n";
16    $h->insert(2);
17    echo "inserted 2\n";
18    $h->insert(3);
19    echo "inserted 3\n";
20} catch(Exception $e) {
21    echo "Exception: ".$e->getMessage()."\n";
22}
23
24try {
25    $h->insert(4);
26    echo "inserted 4\n";
27} catch(Exception $e) {
28    echo "Exception: ".$e->getMessage()."\n";
29}
30
31try {
32    var_dump($h->extract());
33} catch(Exception $e) {
34    echo "Exception: ".$e->getMessage()."\n";
35}
36try {
37    var_dump($h->extract());
38} catch(Exception $e) {
39    echo "Exception: ".$e->getMessage()."\n";
40}
41
42echo "Recovering..\n";
43$h->recoverFromCorruption();
44
45try {
46    var_dump($h->extract());
47} catch(Exception $e) {
48    echo "Exception: ".$e->getMessage()."\n";
49}
50try {
51    var_dump($h->extract());
52} catch(Exception $e) {
53    echo "Exception: ".$e->getMessage()."\n";
54}
55?>
56--EXPECT--
57inserted 1
58Exception: foo
59Exception: Heap is corrupted, heap properties are no longer ensured.
60Exception: Heap is corrupted, heap properties are no longer ensured.
61Exception: Heap is corrupted, heap properties are no longer ensured.
62Recovering..
63int(1)
64int(2)
65