heap_top_variation_002.phpt 650 B

12345678910111213141516171819202122232425262728293031
  1. --TEST--
  2. SPL: SplHeap top, corrupted heap
  3. --CREDITS--
  4. Mark Schaschke (mark@fractalturtle.com)
  5. TestFest London May 2009
  6. --FILE--
  7. <?php
  8. // override heap to force corruption by throwing exception in compare
  9. class SplMinHeap2 extends SplMinHeap {
  10. public function compare($a, $b) {
  11. throw new Exception('Corrupt heap');
  12. }
  13. }
  14. $h = new SplMinHeap2();
  15. // insert 2 elements to hit our overridden compare
  16. $h->insert(4);
  17. try {
  18. $h->insert(5);
  19. } catch (Exception $e) {}
  20. // call top, should fail with corrupted heap
  21. try {
  22. $h->top();
  23. } catch (Exception $e) {
  24. echo $e->getMessage();
  25. }
  26. ?>
  27. --EXPECTF--
  28. Heap is corrupted, heap properties are no longer ensured.