]> 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)
19 files changed:
ext/spl/tests/iterator_056.phpt [new file with mode: 0644]
ext/spl/tests/iterator_057.phpt [new file with mode: 0644]
ext/spl/tests/iterator_058.phpt [new file with mode: 0644]
ext/spl/tests/iterator_059.phpt [new file with mode: 0644]
ext/spl/tests/iterator_060.phpt [new file with mode: 0644]
ext/spl/tests/iterator_061.phpt [new file with mode: 0644]
ext/spl/tests/iterator_062.phpt [new file with mode: 0644]
ext/spl/tests/iterator_063.phpt [new file with mode: 0644]
ext/spl/tests/iterator_064.phpt [new file with mode: 0644]
ext/spl/tests/iterator_065.phpt [new file with mode: 0644]
ext/spl/tests/iterator_066.phpt [new file with mode: 0644]
ext/spl/tests/iterator_067.phpt [new file with mode: 0644]
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_056.phpt b/ext/spl/tests/iterator_056.phpt
new file mode 100644 (file)
index 0000000..c629087
--- /dev/null
@@ -0,0 +1,21 @@
+--TEST--\r
+SPL: FilterIterator::__construct(void)\r
+--SKIPIF--\r
+<?php if (!extension_loaded("spl")) print "skip"; ?>\r
+--CREDITS--\r
+Sebastian Schürmann\r
+--FILE--\r
+<?php\r
+class myFilterIterator extends FilterIterator {\r
+       function accept() {\r
+               \r
+       }\r
+}\r
+try {\r
+       $it = new myFilterIterator();   \r
+} catch (InvalidArgumentException $e) {\r
+       echo 'InvalidArgumentException thrown';\r
+}\r
+?>\r
+--EXPECT--\r
+InvalidArgumentException thrown\r
diff --git a/ext/spl/tests/iterator_057.phpt b/ext/spl/tests/iterator_057.phpt
new file mode 100644 (file)
index 0000000..b15cbb7
--- /dev/null
@@ -0,0 +1,23 @@
+--TEST--\r
+SPL: ArrayIterator::__construct(void)\r
+--SKIPIF--\r
+<?php if (!extension_loaded("spl")) print "skip"; ?>\r
+--CREDITS--\r
+Sebastian Schürmann\r
+--FILE--\r
+<?php\r
+/**\r
+ * From Docs: Construct a new array iterator from anything that has a hash table. \r
+ * NULL, NOTHING is not a hash table ;) \r
+ */\r
+class myArrayIterator extends ArrayIterator {\r
+}\r
+try {\r
+       $it = new myArrayIterator();\r
+} catch (InvalidArgumentException $e) {\r
+       echo 'InvalidArgumentException thrown';\r
+}\r
+echo 'no Exception thrown'\r
+?>\r
+--EXPECT--\r
+no Exception thrown\r
diff --git a/ext/spl/tests/iterator_058.phpt b/ext/spl/tests/iterator_058.phpt
new file mode 100644 (file)
index 0000000..6b58fcd
--- /dev/null
@@ -0,0 +1,26 @@
+--TEST--\r
+SPL: Iterator::__construct(void)\r
+--SKIPIF--\r
+<?php if (!extension_loaded("spl")) print "skip"; ?>\r
+--CREDITS--\r
+Sebastian Schürmann\r
+--FILE--\r
+<?php\r
+class myIterator implements Iterator {\r
+       \r
+       function current() {}\r
+       function next() {}\r
+       function key() {}       \r
+       function valid() {}\r
+       function rewind() {}\r
+       \r
+}\r
+try {\r
+       $it = new myIterator(); \r
+} catch (InvalidArgumentException $e) {\r
+       echo 'InvalidArgumentException thrown';\r
+}\r
+echo 'no Exception thrown';\r
+?>\r
+--EXPECT--\r
+no Exception thrown\r
diff --git a/ext/spl/tests/iterator_059.phpt b/ext/spl/tests/iterator_059.phpt
new file mode 100644 (file)
index 0000000..8a0fce5
--- /dev/null
@@ -0,0 +1,19 @@
+--TEST--\r
+SPL: CachingIterator::__construct(void)\r
+--SKIPIF--\r
+<?php if (!extension_loaded("spl")) print "skip"; ?>\r
+--CREDITS--\r
+Sebastian Schürmann\r
+--FILE--\r
+<?php\r
+class myCachingIterator extends CachingIterator {\r
+       \r
+}\r
+try {\r
+       $it = new myCachingIterator();  \r
+} catch (InvalidArgumentException $e) {\r
+       echo 'InvalidArgumentException thrown';\r
+}\r
+?>\r
+--EXPECT--\r
+InvalidArgumentException thrown\r
diff --git a/ext/spl/tests/iterator_060.phpt b/ext/spl/tests/iterator_060.phpt
new file mode 100644 (file)
index 0000000..ef835a3
--- /dev/null
@@ -0,0 +1,19 @@
+--TEST--\r
+SPL: RecursiveCachingIterator::__construct(void)\r
+--SKIPIF--\r
+<?php if (!extension_loaded("spl")) print "skip"; ?>\r
+--CREDITS--\r
+Sebastian Schürmann\r
+--FILE--\r
+<?php\r
+class myRecursiveCachingIterator extends RecursiveCachingIterator {\r
+       \r
+}\r
+try {\r
+       $it = new myRecursiveCachingIterator(); \r
+} catch (InvalidArgumentException $e) {\r
+       echo 'InvalidArgumentException thrown';\r
+}\r
+?>\r
+--EXPECT--\r
+InvalidArgumentException thrown\r
diff --git a/ext/spl/tests/iterator_061.phpt b/ext/spl/tests/iterator_061.phpt
new file mode 100644 (file)
index 0000000..7a30c6b
--- /dev/null
@@ -0,0 +1,19 @@
+--TEST--\r
+SPL: ParentIterator::__construct(void)\r
+--SKIPIF--\r
+<?php if (!extension_loaded("spl")) print "skip"; ?>\r
+--CREDITS--\r
+Sebastian Schürmann\r
+--FILE--\r
+<?php\r
+class myParentIterator extends ParentIterator {\r
+       \r
+}\r
+try {\r
+       $it = new myParentIterator();   \r
+} catch (InvalidArgumentException $e) {\r
+       echo 'InvalidArgumentException thrown';\r
+}\r
+?>\r
+--EXPECT--\r
+InvalidArgumentException thrown\r
diff --git a/ext/spl/tests/iterator_062.phpt b/ext/spl/tests/iterator_062.phpt
new file mode 100644 (file)
index 0000000..55be4e9
--- /dev/null
@@ -0,0 +1,20 @@
+--TEST--\r
+SPL: RecursiveIteratorIterator::__construct(void)\r
+--SKIPIF--\r
+<?php if (!extension_loaded("spl")) print "skip"; ?>\r
+--CREDITS--\r
+Sebastian Schürmann\r
+--FILE--\r
+<?php\r
+class myRecursiveIteratorIterator extends RecursiveIteratorIterator {\r
+       \r
+}\r
+\r
+try {\r
+       $it = new myRecursiveIteratorIterator();\r
+} catch (InvalidArgumentException $e) {\r
+       echo 'InvalidArgumentException thrown';\r
+}\r
+?>\r
+--EXPECT--\r
+InvalidArgumentException thrown
\ No newline at end of file
diff --git a/ext/spl/tests/iterator_063.phpt b/ext/spl/tests/iterator_063.phpt
new file mode 100644 (file)
index 0000000..f6ab61b
--- /dev/null
@@ -0,0 +1,19 @@
+--TEST--\r
+SPL: LimitIterator::__construct(void)\r
+--SKIPIF--\r
+<?php if (!extension_loaded("spl")) print "skip"; ?>\r
+--CREDITS--\r
+Sebastian Schürmann\r
+--FILE--\r
+<?php\r
+class myLimitIterator extends LimitIterator {\r
+       \r
+}\r
+try {\r
+       $it = new myLimitIterator();\r
+} catch (InvalidArgumentException $e) {\r
+       echo 'InvalidArgumentException thrown';\r
+}\r
+?>\r
+--EXPECT--\r
+InvalidArgumentException thrown
\ No newline at end of file
diff --git a/ext/spl/tests/iterator_064.phpt b/ext/spl/tests/iterator_064.phpt
new file mode 100644 (file)
index 0000000..1ed06a0
--- /dev/null
@@ -0,0 +1,17 @@
+--TEST--\r
+SPL: CachingIterator::__construct(void)\r
+--SKIPIF--\r
+<?php if (!extension_loaded("spl")) print "skip"; ?>\r
+--CREDITS--\r
+Sebastian Schürmann\r
+--FILE--\r
+<?php\r
+class myCachingIterator  extends CachingIterator  {}\r
+try {\r
+       $it = new myCachingIterator();\r
+} catch (InvalidArgumentException $e) {\r
+       echo 'InvalidArgumentException thrown';\r
+}\r
+?>\r
+--EXPECT--\r
+InvalidArgumentException thrown\r
diff --git a/ext/spl/tests/iterator_065.phpt b/ext/spl/tests/iterator_065.phpt
new file mode 100644 (file)
index 0000000..78c2689
--- /dev/null
@@ -0,0 +1,17 @@
+--TEST--\r
+SPL: RecursiveCachingIterator::__construct(void)\r
+--SKIPIF--\r
+<?php if (!extension_loaded("spl")) print "skip"; ?>\r
+--CREDITS--\r
+Sebastian Schürmann\r
+--FILE--\r
+<?php\r
+class myRecursiveCachingIterator  extends RecursiveCachingIterator  {}\r
+try {\r
+       $it = new myRecursiveCachingIterator();\r
+} catch (InvalidArgumentException $e) {\r
+       echo 'InvalidArgumentException thrown';\r
+}\r
+?>\r
+--EXPECT--\r
+InvalidArgumentException thrown\r
diff --git a/ext/spl/tests/iterator_066.phpt b/ext/spl/tests/iterator_066.phpt
new file mode 100644 (file)
index 0000000..8f08ff4
--- /dev/null
@@ -0,0 +1,17 @@
+--TEST--\r
+SPL: NoRewindIterator::__construct(void)\r
+--SKIPIF--\r
+<?php if (!extension_loaded("spl")) print "skip"; ?>\r
+--CREDITS--\r
+Sebastian Schürmann\r
+--FILE--\r
+<?php\r
+class myNoRewindIterator extends NoRewindIterator  {}\r
+try {\r
+       $it = new myNoRewindIterator();\r
+} catch (InvalidArgumentException $e) {\r
+       echo 'InvalidArgumentException thrown';\r
+}\r
+?>\r
+--EXPECT--\r
+InvalidArgumentException thrown\r
diff --git a/ext/spl/tests/iterator_067.phpt b/ext/spl/tests/iterator_067.phpt
new file mode 100644 (file)
index 0000000..65db114
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--\r
+SPL: AppendIterator::__construct(void)\r
+--SKIPIF--\r
+<?php if (!extension_loaded("spl")) print "skip"; ?>\r
+--CREDITS--\r
+Sebastian Schürmann\r
+--FILE--\r
+<?php\r
+class myAppendIterator extends AppendIterator {}\r
+try {\r
+       $it = new myAppendIterator();\r
+       echo "no exception";\r
+} catch (InvalidArgumentException $e) {\r
+       echo 'InvalidArgumentException thrown';\r
+}\r
+?>\r
+--EXPECT--\r
+no exception\r
diff --git a/ext/spl/tests/iterator_069.phpt b/ext/spl/tests/iterator_069.phpt
new file mode 100644 (file)
index 0000000..e842da9
--- /dev/null
@@ -0,0 +1,19 @@
+--TEST--\r
+SPL: RecursiveIteratorIterator cannot be used with foreach by reference\r
+--SKIPIF--\r
+<?php if (!extension_loaded("spl")) print "skip"; ?>\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..3175385
--- /dev/null
@@ -0,0 +1,22 @@
+--TEST--\r
+SPL: RecursiveIteratorIterator - Ensure that non-overriden methods execute problem free.\r
+--SKIPIF--\r
+<?php if (!extension_loaded("spl")) print "skip"; ?>\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..62bc5fe
--- /dev/null
@@ -0,0 +1,34 @@
+--TEST--\r
+SPL: RecursiveIteratorIterator - Test where the case is RS_SELF and mode is CHILD_FIRST\r
+--SKIPIF--\r
+<?php if (!extension_loaded("spl")) print "skip"; ?>\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..2ef68a5
--- /dev/null
@@ -0,0 +1,38 @@
+--TEST--\r
+SPL: RecursiveIteratorIterator - Exception thrown in beginchildren which should be handled in next()\r
+--SKIPIF--\r
+<?php if (!extension_loaded("spl")) print "skip"; ?>\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..acae9db
--- /dev/null
@@ -0,0 +1,38 @@
+--TEST--\r
+SPL: RecursiveIteratorIterator - Exception thrown in callHasChildren which should be handled in next()\r
+--SKIPIF--\r
+<?php if (!extension_loaded("spl")) print "skip"; ?>\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..ef51dfa
--- /dev/null
@@ -0,0 +1,44 @@
+--TEST--\r
+SPL: RecursiveIteratorIterator - Exception thrown in endchildren which should be handled in next()\r
+--SKIPIF--\r
+<?php if (!extension_loaded("spl")) print "skip"; ?>\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..25cf709
--- /dev/null
@@ -0,0 +1,38 @@
+--TEST--\r
+SPL: RecursiveIteratorIterator - Exception thrown in nextelement which should be handled in next()\r
+--SKIPIF--\r
+<?php if (!extension_loaded("spl")) print "skip"; ?>\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