From faee4c72b8a644889ec122e8a9ae10a40f3c4356 Mon Sep 17 00:00:00 2001 From: William Martin Date: Tue, 8 Dec 2009 19:51:56 +0000 Subject: [PATCH] Backported 5.3 tests to 5.2 and added more RecursiveIteratorIterator tests --- ext/spl/tests/iterator_056.phpt | 21 +++++++++ ext/spl/tests/iterator_057.phpt | 23 ++++++++++ ext/spl/tests/iterator_058.phpt | 26 +++++++++++ ext/spl/tests/iterator_059.phpt | 19 ++++++++ ext/spl/tests/iterator_060.phpt | 19 ++++++++ ext/spl/tests/iterator_061.phpt | 19 ++++++++ ext/spl/tests/iterator_062.phpt | 20 +++++++++ ext/spl/tests/iterator_063.phpt | 19 ++++++++ ext/spl/tests/iterator_064.phpt | 17 +++++++ ext/spl/tests/iterator_065.phpt | 17 +++++++ ext/spl/tests/iterator_066.phpt | 17 +++++++ ext/spl/tests/iterator_067.phpt | 18 ++++++++ ext/spl/tests/iterator_069.phpt | 19 ++++++++ ext/spl/tests/iterator_070.phpt | 22 ++++++++++ ext/spl/tests/iterator_071.phpt | 34 ++++++++++++++ ...eIteratorIterator_beginchildren_error.phpt | 38 ++++++++++++++++ ...teratorIterator_callHasChildren_error.phpt | 38 ++++++++++++++++ ...iveIteratorIterator_endchildren_error.phpt | 44 +++++++++++++++++++ ...iveIteratorIterator_nextelement_error.phpt | 38 ++++++++++++++++ 19 files changed, 468 insertions(+) create mode 100644 ext/spl/tests/iterator_056.phpt create mode 100644 ext/spl/tests/iterator_057.phpt create mode 100644 ext/spl/tests/iterator_058.phpt create mode 100644 ext/spl/tests/iterator_059.phpt create mode 100644 ext/spl/tests/iterator_060.phpt create mode 100644 ext/spl/tests/iterator_061.phpt create mode 100644 ext/spl/tests/iterator_062.phpt create mode 100644 ext/spl/tests/iterator_063.phpt create mode 100644 ext/spl/tests/iterator_064.phpt create mode 100644 ext/spl/tests/iterator_065.phpt create mode 100644 ext/spl/tests/iterator_066.phpt create mode 100644 ext/spl/tests/iterator_067.phpt create mode 100644 ext/spl/tests/iterator_069.phpt create mode 100644 ext/spl/tests/iterator_070.phpt create mode 100644 ext/spl/tests/iterator_071.phpt create mode 100644 ext/spl/tests/recursiveIteratorIterator_beginchildren_error.phpt create mode 100644 ext/spl/tests/recursiveIteratorIterator_callHasChildren_error.phpt create mode 100644 ext/spl/tests/recursiveIteratorIterator_endchildren_error.phpt create mode 100644 ext/spl/tests/recursiveIteratorIterator_nextelement_error.phpt diff --git a/ext/spl/tests/iterator_056.phpt b/ext/spl/tests/iterator_056.phpt new file mode 100644 index 0000000000..c629087aee --- /dev/null +++ b/ext/spl/tests/iterator_056.phpt @@ -0,0 +1,21 @@ +--TEST-- +SPL: FilterIterator::__construct(void) +--SKIPIF-- + +--CREDITS-- +Sebastian Schürmann +--FILE-- + +--EXPECT-- +InvalidArgumentException thrown diff --git a/ext/spl/tests/iterator_057.phpt b/ext/spl/tests/iterator_057.phpt new file mode 100644 index 0000000000..b15cbb75ce --- /dev/null +++ b/ext/spl/tests/iterator_057.phpt @@ -0,0 +1,23 @@ +--TEST-- +SPL: ArrayIterator::__construct(void) +--SKIPIF-- + +--CREDITS-- +Sebastian Schürmann +--FILE-- + +--EXPECT-- +no Exception thrown diff --git a/ext/spl/tests/iterator_058.phpt b/ext/spl/tests/iterator_058.phpt new file mode 100644 index 0000000000..6b58fcd984 --- /dev/null +++ b/ext/spl/tests/iterator_058.phpt @@ -0,0 +1,26 @@ +--TEST-- +SPL: Iterator::__construct(void) +--SKIPIF-- + +--CREDITS-- +Sebastian Schürmann +--FILE-- + +--EXPECT-- +no Exception thrown diff --git a/ext/spl/tests/iterator_059.phpt b/ext/spl/tests/iterator_059.phpt new file mode 100644 index 0000000000..8a0fce5544 --- /dev/null +++ b/ext/spl/tests/iterator_059.phpt @@ -0,0 +1,19 @@ +--TEST-- +SPL: CachingIterator::__construct(void) +--SKIPIF-- + +--CREDITS-- +Sebastian Schürmann +--FILE-- + +--EXPECT-- +InvalidArgumentException thrown diff --git a/ext/spl/tests/iterator_060.phpt b/ext/spl/tests/iterator_060.phpt new file mode 100644 index 0000000000..ef835a3f26 --- /dev/null +++ b/ext/spl/tests/iterator_060.phpt @@ -0,0 +1,19 @@ +--TEST-- +SPL: RecursiveCachingIterator::__construct(void) +--SKIPIF-- + +--CREDITS-- +Sebastian Schürmann +--FILE-- + +--EXPECT-- +InvalidArgumentException thrown diff --git a/ext/spl/tests/iterator_061.phpt b/ext/spl/tests/iterator_061.phpt new file mode 100644 index 0000000000..7a30c6bd7b --- /dev/null +++ b/ext/spl/tests/iterator_061.phpt @@ -0,0 +1,19 @@ +--TEST-- +SPL: ParentIterator::__construct(void) +--SKIPIF-- + +--CREDITS-- +Sebastian Schürmann +--FILE-- + +--EXPECT-- +InvalidArgumentException thrown diff --git a/ext/spl/tests/iterator_062.phpt b/ext/spl/tests/iterator_062.phpt new file mode 100644 index 0000000000..55be4e94be --- /dev/null +++ b/ext/spl/tests/iterator_062.phpt @@ -0,0 +1,20 @@ +--TEST-- +SPL: RecursiveIteratorIterator::__construct(void) +--SKIPIF-- + +--CREDITS-- +Sebastian Schürmann +--FILE-- + +--EXPECT-- +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 index 0000000000..f6ab61b30f --- /dev/null +++ b/ext/spl/tests/iterator_063.phpt @@ -0,0 +1,19 @@ +--TEST-- +SPL: LimitIterator::__construct(void) +--SKIPIF-- + +--CREDITS-- +Sebastian Schürmann +--FILE-- + +--EXPECT-- +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 index 0000000000..1ed06a0f35 --- /dev/null +++ b/ext/spl/tests/iterator_064.phpt @@ -0,0 +1,17 @@ +--TEST-- +SPL: CachingIterator::__construct(void) +--SKIPIF-- + +--CREDITS-- +Sebastian Schürmann +--FILE-- + +--EXPECT-- +InvalidArgumentException thrown diff --git a/ext/spl/tests/iterator_065.phpt b/ext/spl/tests/iterator_065.phpt new file mode 100644 index 0000000000..78c2689e50 --- /dev/null +++ b/ext/spl/tests/iterator_065.phpt @@ -0,0 +1,17 @@ +--TEST-- +SPL: RecursiveCachingIterator::__construct(void) +--SKIPIF-- + +--CREDITS-- +Sebastian Schürmann +--FILE-- + +--EXPECT-- +InvalidArgumentException thrown diff --git a/ext/spl/tests/iterator_066.phpt b/ext/spl/tests/iterator_066.phpt new file mode 100644 index 0000000000..8f08ff475a --- /dev/null +++ b/ext/spl/tests/iterator_066.phpt @@ -0,0 +1,17 @@ +--TEST-- +SPL: NoRewindIterator::__construct(void) +--SKIPIF-- + +--CREDITS-- +Sebastian Schürmann +--FILE-- + +--EXPECT-- +InvalidArgumentException thrown diff --git a/ext/spl/tests/iterator_067.phpt b/ext/spl/tests/iterator_067.phpt new file mode 100644 index 0000000000..65db114c6e --- /dev/null +++ b/ext/spl/tests/iterator_067.phpt @@ -0,0 +1,18 @@ +--TEST-- +SPL: AppendIterator::__construct(void) +--SKIPIF-- + +--CREDITS-- +Sebastian Schürmann +--FILE-- + +--EXPECT-- +no exception diff --git a/ext/spl/tests/iterator_069.phpt b/ext/spl/tests/iterator_069.phpt new file mode 100644 index 0000000000..e842da94e7 --- /dev/null +++ b/ext/spl/tests/iterator_069.phpt @@ -0,0 +1,19 @@ +--TEST-- +SPL: RecursiveIteratorIterator cannot be used with foreach by reference +--SKIPIF-- + +--FILE-- +getIterator()); + +$recItIt = new RecursiveIteratorIterator($recArrIt); + +foreach ($recItIt as &$val) echo "$val\n"; + +?> +--EXPECTF-- +Fatal error: An iterator cannot be used with foreach by reference in %s on line %d diff --git a/ext/spl/tests/iterator_070.phpt b/ext/spl/tests/iterator_070.phpt new file mode 100644 index 0000000000..317538536f --- /dev/null +++ b/ext/spl/tests/iterator_070.phpt @@ -0,0 +1,22 @@ +--TEST-- +SPL: RecursiveIteratorIterator - Ensure that non-overriden methods execute problem free. +--SKIPIF-- + +--FILE-- +beginIteration()); +var_dump($recItIt->endIteration()); +var_dump($recItIt->nextElement()); + +?> + +--EXPECTF-- +NULL +NULL +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 index 0000000000..62bc5feedf --- /dev/null +++ b/ext/spl/tests/iterator_071.phpt @@ -0,0 +1,34 @@ +--TEST-- +SPL: RecursiveIteratorIterator - Test where the case is RS_SELF and mode is CHILD_FIRST +--SKIPIF-- + +--FILE-- +getIterator()); + +class MyRecursiveIteratorIterator extends RecursiveIteratorIterator { + + function nextelement() { + echo __METHOD__."\n"; + } +} + + +$recItIt = new MyRecursiveIteratorIterator($recArrIt, RecursiveIteratorIterator::CHILD_FIRST); + +foreach ($recItIt as $key => $val) echo "$key\n"; + +?> +--EXPECTF-- +MyRecursiveIteratorIterator::nextelement +0 +MyRecursiveIteratorIterator::nextelement +1 +MyRecursiveIteratorIterator::nextelement +0 +MyRecursiveIteratorIterator::nextelement +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 index 0000000000..2ef68a5c17 --- /dev/null +++ b/ext/spl/tests/recursiveIteratorIterator_beginchildren_error.phpt @@ -0,0 +1,38 @@ +--TEST-- +SPL: RecursiveIteratorIterator - Exception thrown in beginchildren which should be handled in next() +--SKIPIF-- + +--FILE-- +getIterator()); + +class MyRecursiveIteratorIterator extends RecursiveIteratorIterator { + + function beginchildren() { + throw new Exception; + } +} + + +$recItIt = new MyRecursiveIteratorIterator($recArrIt, RecursiveIteratorIterator::LEAVES_ONLY, RecursiveIteratorIterator::CATCH_GET_CHILD); + +var_dump($recItIt->next()); + +$recItIt2 = new MyRecursiveIteratorIterator($recArrIt, RecursiveIteratorIterator::LEAVES_ONLY); + +var_dump($recItIt2->next()); + +?> +--EXPECTF-- +NULL + +Fatal error: Uncaught exception 'Exception' in %s +Stack trace: +#0 [internal function]: MyRecursiveIteratorIterator->beginchildren() +#1 %s: RecursiveIteratorIterator->next() +#2 {main} + thrown in %s on line %d diff --git a/ext/spl/tests/recursiveIteratorIterator_callHasChildren_error.phpt b/ext/spl/tests/recursiveIteratorIterator_callHasChildren_error.phpt new file mode 100644 index 0000000000..acae9dbe64 --- /dev/null +++ b/ext/spl/tests/recursiveIteratorIterator_callHasChildren_error.phpt @@ -0,0 +1,38 @@ +--TEST-- +SPL: RecursiveIteratorIterator - Exception thrown in callHasChildren which should be handled in next() +--SKIPIF-- + +--FILE-- +getIterator()); + +class MyRecursiveIteratorIterator extends RecursiveIteratorIterator { + + function callHasChildren() { + throw new Exception; + } +} + + +$recItIt = new MyRecursiveIteratorIterator($recArrIt, RecursiveIteratorIterator::LEAVES_ONLY, RecursiveIteratorIterator::CATCH_GET_CHILD); + +var_dump($recItIt->next()); + +$recItIt2 = new MyRecursiveIteratorIterator($recArrIt, RecursiveIteratorIterator::LEAVES_ONLY); + +var_dump($recItIt2->next()); + +?> +--EXPECTF-- +NULL + +Fatal error: Uncaught exception 'Exception' in %s +Stack trace: +#0 [internal function]: MyRecursiveIteratorIterator->callHasChildren() +#1 %s: RecursiveIteratorIterator->next() +#2 {main} + thrown in %s on line %d diff --git a/ext/spl/tests/recursiveIteratorIterator_endchildren_error.phpt b/ext/spl/tests/recursiveIteratorIterator_endchildren_error.phpt new file mode 100644 index 0000000000..ef51dfa4fd --- /dev/null +++ b/ext/spl/tests/recursiveIteratorIterator_endchildren_error.phpt @@ -0,0 +1,44 @@ +--TEST-- +SPL: RecursiveIteratorIterator - Exception thrown in endchildren which should be handled in next() +--SKIPIF-- + +--FILE-- +getIterator()); + +class MyRecursiveIteratorIterator extends RecursiveIteratorIterator { + + function endchildren() { + throw new Exception; + } +} + + +$recItIt = new MyRecursiveIteratorIterator($recArrIt, RecursiveIteratorIterator::LEAVES_ONLY, RecursiveIteratorIterator::CATCH_GET_CHILD); + +foreach ($recItIt as $val) echo "$val\n"; + +$recItIt2 = new MyRecursiveIteratorIterator($recArrIt, RecursiveIteratorIterator::LEAVES_ONLY); + +echo "===NEXT LOOP===\n"; + +foreach ($recItIt2 as $val) echo "$val\n"; + +?> +--EXPECTF-- +1 +2 +===NEXT LOOP=== +1 +2 + +Fatal error: Uncaught exception 'Exception' in %s +Stack trace: +#0 [internal function]: MyRecursiveIteratorIterator->endchildren() +#1 %s: RecursiveIteratorIterator->next() +#2 {main} + thrown in %s on line %d diff --git a/ext/spl/tests/recursiveIteratorIterator_nextelement_error.phpt b/ext/spl/tests/recursiveIteratorIterator_nextelement_error.phpt new file mode 100644 index 0000000000..25cf70937a --- /dev/null +++ b/ext/spl/tests/recursiveIteratorIterator_nextelement_error.phpt @@ -0,0 +1,38 @@ +--TEST-- +SPL: RecursiveIteratorIterator - Exception thrown in nextelement which should be handled in next() +--SKIPIF-- + +--FILE-- +getIterator()); + +class MyRecursiveIteratorIterator extends RecursiveIteratorIterator { + + function nextelement() { + throw new Exception; + } +} + + +$recItIt = new MyRecursiveIteratorIterator($recArrIt, RecursiveIteratorIterator::LEAVES_ONLY, RecursiveIteratorIterator::CATCH_GET_CHILD); + +var_dump($recItIt->next()); + +$recItIt = new MyRecursiveIteratorIterator($recArrIt, RecursiveIteratorIterator::LEAVES_ONLY); + +var_dump($recItIt->next()); + +?> +--EXPECTF-- +NULL + +Fatal error: Uncaught exception 'Exception' in %s +Stack trace: +#0 [internal function]: MyRecursiveIteratorIterator->nextelement() +#1 %s: RecursiveIteratorIterator->next() +#2 {main} + thrown in %s on line %d -- 2.40.0