diff options
| author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2013-03-14 05:42:27 +0000 |
|---|---|---|
| committer | <> | 2013-04-03 16:25:08 +0000 |
| commit | c4dd7a1a684490673e25aaf4fabec5df138854c4 (patch) | |
| tree | 4d57c44caae4480efff02b90b9be86f44bf25409 /ext/spl/tests/iterator_047.phpt | |
| download | php2-master.tar.gz | |
Imported from /home/lorry/working-area/delta_php2/php-5.4.13.tar.bz2.HEADphp-5.4.13master
Diffstat (limited to 'ext/spl/tests/iterator_047.phpt')
| -rw-r--r-- | ext/spl/tests/iterator_047.phpt | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/ext/spl/tests/iterator_047.phpt b/ext/spl/tests/iterator_047.phpt new file mode 100644 index 0000000..548f486 --- /dev/null +++ b/ext/spl/tests/iterator_047.phpt @@ -0,0 +1,125 @@ +--TEST-- +SPL: RecursiveCachingIterator and exception in has/getChildren +--FILE-- +<?php + +class MyRecursiveArrayIterator extends RecursiveArrayIterator +{ + static public $fail = 0; + + static function fail($state, $method) + { + if (self::$fail == $state) + { + throw new Exception("State $state: $method()"); + } + } + + function hasChildren() + { + echo __METHOD__ . "()\n"; + self::fail(1, __METHOD__); + return parent::hasChildren(); + } + + function getChildren() + { + echo __METHOD__ . "()\n"; + self::fail(2, __METHOD__); + return parent::getChildren(); + } +} + +class MyRecursiveCachingIterator extends RecursiveCachingIterator +{ + function show() + { + MyRecursiveArrayIterator::$fail = 0; + while(MyRecursiveArrayIterator::$fail < 4) + { + echo "===" . MyRecursiveArrayIterator::$fail . "===\n"; + try + { + foreach(new RecursiveIteratorIterator($this) as $k => $v) + { + var_dump($k); + var_dump($v); + } + } + catch (Exception $e) + { + echo "Exception: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . "\n"; + } + MyRecursiveArrayIterator::$fail++; + } + } +} + +$it = new MyRecursiveArrayIterator(array(0, array(10), 2, array(30), 4)); +$it = new MyRecursiveCachingIterator($it); + +$it->show(); + +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +===0=== +MyRecursiveArrayIterator::hasChildren() +int(0) +int(0) +MyRecursiveArrayIterator::hasChildren() +MyRecursiveArrayIterator::getChildren() + +Notice: Array to string conversion in %siterator_047.php on line %d +MyRecursiveArrayIterator::hasChildren() +int(0) +int(10) +MyRecursiveArrayIterator::hasChildren() +int(2) +int(2) +MyRecursiveArrayIterator::hasChildren() +MyRecursiveArrayIterator::getChildren() + +Notice: Array to string conversion in %siterator_047.php on line %d +MyRecursiveArrayIterator::hasChildren() +int(0) +int(30) +MyRecursiveArrayIterator::hasChildren() +int(4) +int(4) +===1=== +MyRecursiveArrayIterator::hasChildren() +Exception: State 1: MyRecursiveArrayIterator::hasChildren() in %s on line %d +===2=== +MyRecursiveArrayIterator::hasChildren() +int(0) +int(0) +MyRecursiveArrayIterator::hasChildren() +MyRecursiveArrayIterator::getChildren() +Exception: State 2: MyRecursiveArrayIterator::getChildren() in %s on line %d +===3=== +MyRecursiveArrayIterator::hasChildren() +int(0) +int(0) +MyRecursiveArrayIterator::hasChildren() +MyRecursiveArrayIterator::getChildren() + +Notice: Array to string conversion in %siterator_047.php on line %d +MyRecursiveArrayIterator::hasChildren() +int(0) +int(10) +MyRecursiveArrayIterator::hasChildren() +int(2) +int(2) +MyRecursiveArrayIterator::hasChildren() +MyRecursiveArrayIterator::getChildren() + +Notice: Array to string conversion in %siterator_047.php on line %d +MyRecursiveArrayIterator::hasChildren() +int(0) +int(30) +MyRecursiveArrayIterator::hasChildren() +int(4) +int(4) +===DONE=== |
