Annotation of embedaddon/php/ext/spl/tests/iterator_047.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: SPL: RecursiveCachingIterator and exception in has/getChildren
! 3: --FILE--
! 4: <?php
! 5:
! 6: class MyRecursiveArrayIterator extends RecursiveArrayIterator
! 7: {
! 8: static public $fail = 0;
! 9:
! 10: static function fail($state, $method)
! 11: {
! 12: if (self::$fail == $state)
! 13: {
! 14: throw new Exception("State $state: $method()");
! 15: }
! 16: }
! 17:
! 18: function hasChildren()
! 19: {
! 20: echo __METHOD__ . "()\n";
! 21: self::fail(1, __METHOD__);
! 22: return parent::hasChildren();
! 23: }
! 24:
! 25: function getChildren()
! 26: {
! 27: echo __METHOD__ . "()\n";
! 28: self::fail(2, __METHOD__);
! 29: return parent::getChildren();
! 30: }
! 31: }
! 32:
! 33: class MyRecursiveCachingIterator extends RecursiveCachingIterator
! 34: {
! 35: function show()
! 36: {
! 37: MyRecursiveArrayIterator::$fail = 0;
! 38: while(MyRecursiveArrayIterator::$fail < 4)
! 39: {
! 40: echo "===" . MyRecursiveArrayIterator::$fail . "===\n";
! 41: try
! 42: {
! 43: foreach(new RecursiveIteratorIterator($this) as $k => $v)
! 44: {
! 45: var_dump($k);
! 46: var_dump($v);
! 47: }
! 48: }
! 49: catch (Exception $e)
! 50: {
! 51: echo "Exception: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . "\n";
! 52: }
! 53: MyRecursiveArrayIterator::$fail++;
! 54: }
! 55: }
! 56: }
! 57:
! 58: $it = new MyRecursiveArrayIterator(array(0, array(10), 2, array(30), 4));
! 59: $it = new MyRecursiveCachingIterator($it);
! 60:
! 61: $it->show();
! 62:
! 63: ?>
! 64: ===DONE===
! 65: <?php exit(0); ?>
! 66: --EXPECTF--
! 67: ===0===
! 68: MyRecursiveArrayIterator::hasChildren()
! 69: int(0)
! 70: int(0)
! 71: MyRecursiveArrayIterator::hasChildren()
! 72: MyRecursiveArrayIterator::getChildren()
! 73: MyRecursiveArrayIterator::hasChildren()
! 74: int(0)
! 75: int(10)
! 76: MyRecursiveArrayIterator::hasChildren()
! 77: int(2)
! 78: int(2)
! 79: MyRecursiveArrayIterator::hasChildren()
! 80: MyRecursiveArrayIterator::getChildren()
! 81: MyRecursiveArrayIterator::hasChildren()
! 82: int(0)
! 83: int(30)
! 84: MyRecursiveArrayIterator::hasChildren()
! 85: int(4)
! 86: int(4)
! 87: ===1===
! 88: MyRecursiveArrayIterator::hasChildren()
! 89: Exception: State 1: MyRecursiveArrayIterator::hasChildren() in %s on line %d
! 90: ===2===
! 91: MyRecursiveArrayIterator::hasChildren()
! 92: int(0)
! 93: int(0)
! 94: MyRecursiveArrayIterator::hasChildren()
! 95: MyRecursiveArrayIterator::getChildren()
! 96: Exception: State 2: MyRecursiveArrayIterator::getChildren() in %s on line %d
! 97: ===3===
! 98: MyRecursiveArrayIterator::hasChildren()
! 99: int(0)
! 100: int(0)
! 101: MyRecursiveArrayIterator::hasChildren()
! 102: MyRecursiveArrayIterator::getChildren()
! 103: MyRecursiveArrayIterator::hasChildren()
! 104: int(0)
! 105: int(10)
! 106: MyRecursiveArrayIterator::hasChildren()
! 107: int(2)
! 108: int(2)
! 109: MyRecursiveArrayIterator::hasChildren()
! 110: MyRecursiveArrayIterator::getChildren()
! 111: MyRecursiveArrayIterator::hasChildren()
! 112: int(0)
! 113: int(30)
! 114: MyRecursiveArrayIterator::hasChildren()
! 115: int(4)
! 116: int(4)
! 117: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>