]> granicus.if.org Git - php/commitdiff
Backported 5.3 tests to 5.2 and added more RecursiveIteratorIterator tests
authorWilliam Martin <wimartin@php.net>
Tue, 8 Dec 2009 19:51:56 +0000 (19:51 +0000)
committerWilliam Martin <wimartin@php.net>
Tue, 8 Dec 2009 19:51:56 +0000 (19:51 +0000)
ext/spl/tests/iterator_069.phpt [new file with mode: 0644]
ext/spl/tests/iterator_070.phpt [new file with mode: 0644]
ext/spl/tests/iterator_071.phpt [new file with mode: 0644]
ext/spl/tests/recursiveIteratorIterator_beginchildren_error.phpt [new file with mode: 0644]
ext/spl/tests/recursiveIteratorIterator_callHasChildren_error.phpt [new file with mode: 0644]
ext/spl/tests/recursiveIteratorIterator_endchildren_error.phpt [new file with mode: 0644]
ext/spl/tests/recursiveIteratorIterator_nextelement_error.phpt [new file with mode: 0644]

diff --git a/ext/spl/tests/iterator_069.phpt b/ext/spl/tests/iterator_069.phpt
new file mode 100644 (file)
index 0000000..e9b3177
--- /dev/null
@@ -0,0 +1,17 @@
+--TEST--\r
+SPL: RecursiveIteratorIterator cannot be used with foreach by reference\r
+--FILE--\r
+<?php \r
+\r
+$arr = array(array(1,2));\r
+$arrOb = new ArrayObject($arr);\r
+\r
+$recArrIt = new RecursiveArrayIterator($arrOb->getIterator());\r
+\r
+$recItIt = new RecursiveIteratorIterator($recArrIt);\r
+\r
+foreach ($recItIt as &$val) echo "$val\n";\r
+\r
+?>\r
+--EXPECTF--\r
+Fatal error: An iterator cannot be used with foreach by reference in %s on line %d\r
diff --git a/ext/spl/tests/iterator_070.phpt b/ext/spl/tests/iterator_070.phpt
new file mode 100644 (file)
index 0000000..c45f08e
--- /dev/null
@@ -0,0 +1,20 @@
+--TEST--\r
+SPL: RecursiveIteratorIterator - Ensure that non-overriden methods execute problem free.\r
+--FILE--\r
+<?php\r
+\r
+$array = array();\r
+$recArrIt = new RecursiveArrayIterator($array);\r
+\r
+$recItIt = new RecursiveIteratorIterator($recArrIt);\r
+\r
+var_dump($recItIt->beginIteration());\r
+var_dump($recItIt->endIteration());\r
+var_dump($recItIt->nextElement());\r
+\r
+?>\r
+\r
+--EXPECTF--\r
+NULL\r
+NULL\r
+NULL
\ No newline at end of file
diff --git a/ext/spl/tests/iterator_071.phpt b/ext/spl/tests/iterator_071.phpt
new file mode 100644 (file)
index 0000000..21ec798
--- /dev/null
@@ -0,0 +1,32 @@
+--TEST--\r
+SPL: RecursiveIteratorIterator - Test where the case is RS_SELF and mode is CHILD_FIRST\r
+--FILE--\r
+<?php \r
+\r
+$arr = array(array(1,2),2);\r
+$arrOb = new ArrayObject($arr);\r
+\r
+$recArrIt = new RecursiveArrayIterator($arrOb->getIterator());\r
+\r
+class MyRecursiveIteratorIterator extends RecursiveIteratorIterator {\r
+    \r
+    function nextelement() {\r
+       echo __METHOD__."\n";\r
+    }\r
+}\r
+\r
+\r
+$recItIt = new MyRecursiveIteratorIterator($recArrIt, RecursiveIteratorIterator::CHILD_FIRST);\r
+\r
+foreach ($recItIt as $key => $val) echo "$key\n";\r
+\r
+?>\r
+--EXPECTF--\r
+MyRecursiveIteratorIterator::nextelement\r
+0\r
+MyRecursiveIteratorIterator::nextelement\r
+1\r
+MyRecursiveIteratorIterator::nextelement\r
+0\r
+MyRecursiveIteratorIterator::nextelement\r
+1
\ No newline at end of file
diff --git a/ext/spl/tests/recursiveIteratorIterator_beginchildren_error.phpt b/ext/spl/tests/recursiveIteratorIterator_beginchildren_error.phpt
new file mode 100644 (file)
index 0000000..f543072
--- /dev/null
@@ -0,0 +1,36 @@
+--TEST--\r
+SPL: RecursiveIteratorIterator - Exception thrown in beginchildren which should be handled in next()\r
+--FILE--\r
+<?php \r
+\r
+$arr = array(array(1,2),2);\r
+$arrOb = new ArrayObject($arr);\r
+\r
+$recArrIt = new RecursiveArrayIterator($arrOb->getIterator());\r
+\r
+class MyRecursiveIteratorIterator extends RecursiveIteratorIterator {\r
+    \r
+    function beginchildren() {\r
+       throw new Exception;\r
+    }\r
+}\r
+\r
+\r
+$recItIt = new MyRecursiveIteratorIterator($recArrIt, RecursiveIteratorIterator::LEAVES_ONLY, RecursiveIteratorIterator::CATCH_GET_CHILD);\r
+\r
+var_dump($recItIt->next());\r
+\r
+$recItIt2 = new MyRecursiveIteratorIterator($recArrIt, RecursiveIteratorIterator::LEAVES_ONLY);\r
+\r
+var_dump($recItIt2->next());\r
+\r
+?>\r
+--EXPECTF--\r
+NULL\r
+\r
+Fatal error: Uncaught exception 'Exception' in %s\r
+Stack trace:\r
+#0 [internal function]: MyRecursiveIteratorIterator->beginchildren()\r
+#1 %s: RecursiveIteratorIterator->next()\r
+#2 {main}\r
+  thrown in %s on line %d\r
diff --git a/ext/spl/tests/recursiveIteratorIterator_callHasChildren_error.phpt b/ext/spl/tests/recursiveIteratorIterator_callHasChildren_error.phpt
new file mode 100644 (file)
index 0000000..88f03fb
--- /dev/null
@@ -0,0 +1,36 @@
+--TEST--\r
+SPL: RecursiveIteratorIterator - Exception thrown in callHasChildren which should be handled in next()\r
+--FILE--\r
+<?php \r
+\r
+$arr = array(1,2);\r
+$arrOb = new ArrayObject($arr);\r
+\r
+$recArrIt = new RecursiveArrayIterator($arrOb->getIterator());\r
+\r
+class MyRecursiveIteratorIterator extends RecursiveIteratorIterator {\r
+    \r
+    function callHasChildren() {\r
+       throw new Exception;\r
+    }\r
+}\r
+\r
+\r
+$recItIt = new MyRecursiveIteratorIterator($recArrIt, RecursiveIteratorIterator::LEAVES_ONLY, RecursiveIteratorIterator::CATCH_GET_CHILD);\r
+\r
+var_dump($recItIt->next());\r
+\r
+$recItIt2 = new MyRecursiveIteratorIterator($recArrIt, RecursiveIteratorIterator::LEAVES_ONLY);\r
+\r
+var_dump($recItIt2->next());\r
+\r
+?>\r
+--EXPECTF--\r
+NULL\r
+\r
+Fatal error: Uncaught exception 'Exception' in %s\r
+Stack trace:\r
+#0 [internal function]: MyRecursiveIteratorIterator->callHasChildren()\r
+#1 %s: RecursiveIteratorIterator->next()\r
+#2 {main}\r
+  thrown in %s on line %d\r
diff --git a/ext/spl/tests/recursiveIteratorIterator_endchildren_error.phpt b/ext/spl/tests/recursiveIteratorIterator_endchildren_error.phpt
new file mode 100644 (file)
index 0000000..e25d3ed
--- /dev/null
@@ -0,0 +1,42 @@
+--TEST--\r
+SPL: RecursiveIteratorIterator - Exception thrown in endchildren which should be handled in next()\r
+--FILE--\r
+<?php \r
+\r
+$arr = array(array(1,2));\r
+$arrOb = new ArrayObject($arr);\r
+\r
+$recArrIt = new RecursiveArrayIterator($arrOb->getIterator());\r
+\r
+class MyRecursiveIteratorIterator extends RecursiveIteratorIterator {\r
+    \r
+    function endchildren() {\r
+       throw new Exception;\r
+    }\r
+}\r
+\r
+\r
+$recItIt = new MyRecursiveIteratorIterator($recArrIt, RecursiveIteratorIterator::LEAVES_ONLY, RecursiveIteratorIterator::CATCH_GET_CHILD);\r
+\r
+foreach ($recItIt as $val) echo "$val\n";\r
+\r
+$recItIt2 = new MyRecursiveIteratorIterator($recArrIt, RecursiveIteratorIterator::LEAVES_ONLY);\r
+\r
+echo "===NEXT LOOP===\n";\r
+\r
+foreach ($recItIt2 as $val) echo "$val\n";\r
+\r
+?>\r
+--EXPECTF--\r
+1\r
+2\r
+===NEXT LOOP===\r
+1\r
+2\r
+\r
+Fatal error: Uncaught exception 'Exception' in %s\r
+Stack trace:\r
+#0 [internal function]: MyRecursiveIteratorIterator->endchildren()\r
+#1 %s: RecursiveIteratorIterator->next()\r
+#2 {main}\r
+  thrown in %s on line %d\r
diff --git a/ext/spl/tests/recursiveIteratorIterator_nextelement_error.phpt b/ext/spl/tests/recursiveIteratorIterator_nextelement_error.phpt
new file mode 100644 (file)
index 0000000..3a91ed5
--- /dev/null
@@ -0,0 +1,36 @@
+--TEST--\r
+SPL: RecursiveIteratorIterator - Exception thrown in nextelement which should be handled in next()\r
+--FILE--\r
+<?php \r
+\r
+$arr = array(1,2);\r
+$arrOb = new ArrayObject($arr);\r
+\r
+$recArrIt = new RecursiveArrayIterator($arrOb->getIterator());\r
+\r
+class MyRecursiveIteratorIterator extends RecursiveIteratorIterator {\r
+    \r
+    function nextelement() {\r
+       throw new Exception;\r
+    }\r
+}\r
+\r
+\r
+$recItIt = new MyRecursiveIteratorIterator($recArrIt, RecursiveIteratorIterator::LEAVES_ONLY, RecursiveIteratorIterator::CATCH_GET_CHILD);\r
+\r
+var_dump($recItIt->next());\r
+\r
+$recItIt = new MyRecursiveIteratorIterator($recArrIt, RecursiveIteratorIterator::LEAVES_ONLY);\r
+\r
+var_dump($recItIt->next());\r
+\r
+?>\r
+--EXPECTF--\r
+NULL\r
+\r
+Fatal error: Uncaught exception 'Exception' in %s\r
+Stack trace:\r
+#0 [internal function]: MyRecursiveIteratorIterator->nextelement()\r
+#1 %s: RecursiveIteratorIterator->next()\r
+#2 {main}\r
+  thrown in %s on line %d\r