summaryrefslogtreecommitdiff
path: root/ext/spl/tests
diff options
context:
space:
mode:
authorMarcus Boerger <helly@php.net>2004-04-25 11:14:11 +0000
committerMarcus Boerger <helly@php.net>2004-04-25 11:14:11 +0000
commit5b755c40ea640c03006bb5ae79bc8c23b1761753 (patch)
tree1eedbe3e51a5dc24a89183fd9b3752f8bea281bd /ext/spl/tests
parent87a9f7bdbbc7738667ad5c6786a504108a20261c (diff)
downloadphp-git-5b755c40ea640c03006bb5ae79bc8c23b1761753.tar.gz
Fix several issues
- bugfix #27063 - bugfix #27929 - bugfix #28099 - bugfix #28125 # The amount of code is needed to solve the return by reference problem. # dual_it and derived also need their own iterator handlers to be able # to return by reference.
Diffstat (limited to 'ext/spl/tests')
-rwxr-xr-xext/spl/tests/array_003.phpt12
-rwxr-xr-xext/spl/tests/array_004.phpt12
-rwxr-xr-xext/spl/tests/array_006.phpt32
-rwxr-xr-xext/spl/tests/array_007.phpt65
-rwxr-xr-xext/spl/tests/array_008.phpt62
-rwxr-xr-xext/spl/tests/array_009.phpt37
-rwxr-xr-xext/spl/tests/array_010.phpt148
-rwxr-xr-xext/spl/tests/array_011.phpt37
-rwxr-xr-xext/spl/tests/iterator_get_inner.phpt55
-rwxr-xr-xext/spl/tests/limititerator.phpt2
10 files changed, 455 insertions, 7 deletions
diff --git a/ext/spl/tests/array_003.phpt b/ext/spl/tests/array_003.phpt
index b7de6a78ae..386c7bcf7d 100755
--- a/ext/spl/tests/array_003.phpt
+++ b/ext/spl/tests/array_003.phpt
@@ -5,6 +5,10 @@ SPL: ArrayObject from object
--FILE--
<?php
+// This test also needs to exclude the protected and private variables
+// since they cannot be accessed from the external object which iterates
+// them.
+
class test
{
public $pub = "public";
@@ -26,6 +30,11 @@ $object = new ArrayObject($test);
print_r($object);
+foreach($test as $key => $val)
+{
+ echo "$key => $val\n";
+}
+
?>
===DONE===
<?php exit(0); ?>
@@ -46,4 +55,7 @@ ArrayObject Object
[imp] => implicit
[dyn] => dynamic
)
+pub => public
+imp => implicit
+dyn => dynamic
===DONE===
diff --git a/ext/spl/tests/array_004.phpt b/ext/spl/tests/array_004.phpt
index a10386befc..4c850329ae 100755
--- a/ext/spl/tests/array_004.phpt
+++ b/ext/spl/tests/array_004.phpt
@@ -117,11 +117,11 @@ echo "Done\n";
1=>1 - 0=>0
1=>1 - 1=>1
-Notice: ArrayIterator::next(): Array was modified outside object and internal position is no longer valid in %sarray_004.php on line %d
+Notice: main(): ArrayIterator::next(): Array was modified outside object and internal position is no longer valid in %sarray_004.php on line %d
1=>1 - 0=>0
1=>1 - 2=>2
-Notice: ArrayIterator::next(): Array was modified outside object and internal position is no longer valid in %sarray_004.php on line %d
+Notice: main(): ArrayIterator::next(): Array was modified outside object and internal position is no longer valid in %sarray_004.php on line %d
0=>0 - 0=>0
0=>0 - 2=>2
2=>2 - 0=>0
@@ -133,11 +133,11 @@ Notice: ArrayIterator::next(): Array was modified outside object and internal po
1=>1 - 0=>0
1=>1 - 1=>1
-Notice: ArrayIterator::next(): Array was modified outside object and is no longer an array in %sarray_004.php on line %d
+Notice: main(): ArrayIterator::next(): Array was modified outside object and is no longer an array in %sarray_004.php on line %d
-Notice: ArrayIterator::valid(): Array was modified outside object and is no longer an array in %sarray_004.php on line %d
+Notice: main(): ArrayIterator::valid(): Array was modified outside object and is no longer an array in %sarray_004.php on line %d
-Notice: ArrayIterator::next(): Array was modified outside object and is no longer an array in %sarray_004.php on line %d
+Notice: main(): ArrayIterator::next(): Array was modified outside object and is no longer an array in %sarray_004.php on line %d
-Notice: ArrayIterator::valid(): Array was modified outside object and is no longer an array in %sarray_004.php on line %d
+Notice: main(): ArrayIterator::valid(): Array was modified outside object and is no longer an array in %sarray_004.php on line %d
Done
diff --git a/ext/spl/tests/array_006.phpt b/ext/spl/tests/array_006.phpt
new file mode 100755
index 0000000000..5dd9bdec7a
--- /dev/null
+++ b/ext/spl/tests/array_006.phpt
@@ -0,0 +1,32 @@
+--TEST--
+SPL: ArrayIterator without ArrayObject
+--SKIPIF--
+<?php if (!extension_loaded("spl")) print "skip"; ?>
+--INI--
+allow_call_time_pass_reference=1
+--FILE--
+<?php
+
+echo "==Normal==\n";
+
+$arr = array(0=>0, 1=>1, 2=>2);
+$obj = new ArrayIterator($arr);
+
+foreach($obj as $ak=>$av) {
+ foreach($obj as $bk=>$bv) {
+ if ($ak==0 && $bk==0) {
+ $arr[0] = "modify";
+ }
+ echo "$ak=>$av - $bk=>$bv\n";
+ }
+}
+
+?>
+===DONE===
+<?php exit(0); ?>
+--EXPECTF--
+==Normal==
+0=>0 - 0=>0
+0=>0 - 1=>1
+0=>0 - 2=>2
+===DONE===
diff --git a/ext/spl/tests/array_007.phpt b/ext/spl/tests/array_007.phpt
new file mode 100755
index 0000000000..3e74e00da4
--- /dev/null
+++ b/ext/spl/tests/array_007.phpt
@@ -0,0 +1,65 @@
+--TEST--
+SPL: ArrayObject/Iterator from IteratorAggregate
+--SKIPIF--
+<?php if (!extension_loaded("spl")) print "skip"; ?>
+--FILE--
+<?php
+
+// This test also needs to exclude the protected and private variables
+// since they cannot be accessed from the external object which iterates
+// them.
+
+class test implements IteratorAggregate
+{
+ public $pub = "public";
+ protected $pro = "protected";
+ private $pri = "private";
+
+ function __construct()
+ {
+ $this->imp = "implicit";
+ }
+
+ function getIterator()
+ {
+ $it = new ArrayObject($this);
+ return $it->getIterator();
+ }
+};
+
+$test = new test;
+$test->dyn = "dynamic";
+
+print_r($test);
+
+print_r($test->getIterator());
+
+foreach($test as $key => $val)
+{
+ echo "$key => $val\n";
+}
+
+?>
+===DONE===
+<?php exit(0); ?>
+--EXPECTF--
+test Object
+(
+ [pub] => public
+ [pro:protected] => protected
+ [pri:private] => private
+ [imp] => implicit
+ [dyn] => dynamic
+)
+ArrayIterator Object
+(
+ [pub] => public
+ [pro:protected] => protected
+ [pri:private] => private
+ [imp] => implicit
+ [dyn] => dynamic
+)
+pub => public
+imp => implicit
+dyn => dynamic
+===DONE===
diff --git a/ext/spl/tests/array_008.phpt b/ext/spl/tests/array_008.phpt
new file mode 100755
index 0000000000..613e324776
--- /dev/null
+++ b/ext/spl/tests/array_008.phpt
@@ -0,0 +1,62 @@
+--TEST--
+SPL: ArrayIterator and foreach reference
+--SKIPIF--
+<?php if (!extension_loaded("spl")) print "skip"; ?>
+--INI--
+allow_call_time_pass_reference=1
+--FILE--
+<?php
+
+echo "==Normal==\n";
+
+$arr = array(0=>0, 1=>1, 2=>2);
+$obj = new ArrayObject($arr);
+
+foreach($obj as $ak=>&$av) {
+ foreach($obj as $bk=>&$bv) {
+ if ($ak==0 && $bk==0) {
+ $bv = "modify";
+ }
+ echo "$ak=>$av - $bk=>$bv\n";
+ }
+}
+
+echo "==UseRef==\n";
+
+$arr = array(0=>0, 1=>1, 2=>2);
+$obj = new ArrayObject(&$arr);
+
+foreach($obj as $ak=>&$av) {
+ foreach($obj as $bk=>&$bv) {
+ if ($ak==0 && $bk==0) {
+ $bv = "modify";
+ }
+ echo "$ak=>$av - $bk=>$bv\n";
+ }
+}
+
+?>
+===DONE===
+<?php exit(0); ?>
+--EXPECTF--
+==Normal==
+0=>modify - 0=>modify
+0=>modify - 1=>1
+0=>modify - 2=>2
+1=>1 - 0=>modify
+1=>1 - 1=>1
+1=>1 - 2=>2
+2=>2 - 0=>modify
+2=>2 - 1=>1
+2=>2 - 2=>2
+==UseRef==
+0=>modify - 0=>modify
+0=>modify - 1=>1
+0=>modify - 2=>2
+1=>1 - 0=>modify
+1=>1 - 1=>1
+1=>1 - 2=>2
+2=>2 - 0=>modify
+2=>2 - 1=>1
+2=>2 - 2=>2
+===DONE===
diff --git a/ext/spl/tests/array_009.phpt b/ext/spl/tests/array_009.phpt
new file mode 100755
index 0000000000..f9c5fe1c73
--- /dev/null
+++ b/ext/spl/tests/array_009.phpt
@@ -0,0 +1,37 @@
+--TEST--
+SPL: ArrayIterator implementing RecursiveIterator
+--FILE--
+<?php
+
+class RecursiceArrayIterator extends ArrayIterator implements RecursiveIterator
+{
+ function hasChildren()
+ {
+ return is_array($this->current());
+ }
+
+ function getChildren()
+ {
+ return new RecursiceArrayIterator($this->current());
+ }
+}
+
+$array = array(1, 2 => array(21, 22 => array(221, 222), 23 => array(231)), 3);
+
+$dir = new RecursiveIteratorIterator(new RecursiceArrayIterator($array), RIT_LEAVES_ONLY);
+
+foreach ($dir as $file) {
+ print "$file\n";
+}
+
+?>
+===DONE===
+<?php exit(0); ?>
+--EXPECT--
+1
+21
+221
+222
+231
+3
+===DONE===
diff --git a/ext/spl/tests/array_010.phpt b/ext/spl/tests/array_010.phpt
new file mode 100755
index 0000000000..2c59b3be18
--- /dev/null
+++ b/ext/spl/tests/array_010.phpt
@@ -0,0 +1,148 @@
+--TEST--
+SPL: ArrayIterator implements ArrayAccess
+--SKIPIF--
+<?php
+ if (!class_exists('ArrayAccess')) die('skip ArrayAccess not present');
+?>
+--FILE--
+<?php
+
+$obj = new ArrayObject(array('1st', 1, 2=>'3rd', '4th'=>4));
+
+var_dump($obj->getArrayCopy());
+
+echo "===EMPTY===\n";
+var_dump(empty($obj[0]));
+var_dump(empty($obj[1]));
+var_dump(empty($obj[2]));
+var_dump(empty($obj['4th']));
+var_dump(empty($obj['5th']));
+var_dump(empty($obj[6]));
+
+echo "===isset===\n";
+var_dump(isset($obj[0]));
+var_dump(isset($obj[1]));
+var_dump(isset($obj[2]));
+var_dump(isset($obj['4th']));
+var_dump(isset($obj['5th']));
+var_dump(isset($obj[6]));
+
+echo "===offsetGet===\n";
+var_dump($obj[0]);
+var_dump($obj[1]);
+var_dump($obj[2]);
+var_dump($obj['4th']);
+var_dump($obj['5th']);
+var_dump($obj[6]);
+
+echo "===offsetSet===\n";
+echo "WRITE 1\n";
+$obj[1] = 'Changed 1';
+var_dump($obj[1]);
+echo "WRITE 2\n";
+$obj['4th'] = 'Changed 4th';
+var_dump($obj['4th']);
+echo "WRITE 3\n";
+$obj['5th'] = 'Added 5th';
+var_dump($obj['5th']);
+echo "WRITE 4\n";
+$obj[6] = 'Added 6';
+var_dump($obj[6]);
+
+var_dump($obj[0]);
+var_dump($obj[2]);
+
+$x = $obj[6] = 'changed 6';
+var_dump($obj[6]);
+var_dump($x);
+
+echo "===unset===\n";
+var_dump($obj->getArrayCopy());
+unset($obj[2]);
+unset($obj['4th']);
+unset($obj[7]);
+unset($obj['8th']);
+var_dump($obj->getArrayCopy());
+
+?>
+===DONE===
+<?php exit(0); ?>
+--EXPECTF--
+array(4) {
+ [0]=>
+ string(3) "1st"
+ [1]=>
+ int(1)
+ [2]=>
+ string(3) "3rd"
+ ["4th"]=>
+ int(4)
+}
+===EMPTY===
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+bool(true)
+bool(true)
+===isset===
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(false)
+bool(false)
+===offsetGet===
+string(3) "1st"
+int(1)
+string(3) "3rd"
+int(4)
+
+Notice: Undefined index: 5th in %sarray_010.php on line %d
+NULL
+
+Notice: Undefined offset: 6 in %sarray_010.php on line %d
+NULL
+===offsetSet===
+WRITE 1
+string(9) "Changed 1"
+WRITE 2
+string(11) "Changed 4th"
+WRITE 3
+string(9) "Added 5th"
+WRITE 4
+string(7) "Added 6"
+string(3) "1st"
+string(3) "3rd"
+string(9) "changed 6"
+string(9) "changed 6"
+===unset===
+array(6) {
+ [0]=>
+ string(3) "1st"
+ [1]=>
+ string(9) "Changed 1"
+ [2]=>
+ string(3) "3rd"
+ ["4th"]=>
+ string(11) "Changed 4th"
+ ["5th"]=>
+ string(9) "Added 5th"
+ [6]=>
+ string(9) "changed 6"
+}
+
+Notice: Undefined offset: 7 in %sarray_010.php on line %d
+
+Notice: Undefined index: 8th in %sarray_010.php on line %d
+array(4) {
+ [0]=>
+ string(3) "1st"
+ [1]=>
+ string(9) "Changed 1"
+ ["5th"]=>
+ string(9) "Added 5th"
+ [6]=>
+ string(9) "changed 6"
+}
+===DONE===
diff --git a/ext/spl/tests/array_011.phpt b/ext/spl/tests/array_011.phpt
new file mode 100755
index 0000000000..09b132cfef
--- /dev/null
+++ b/ext/spl/tests/array_011.phpt
@@ -0,0 +1,37 @@
+--TEST--
+SPL: ArrayIterator, LimitIterator and string keys
+--SKIPIF--
+<?php if (!extension_loaded("spl")) print "skip"; ?>
+--FILE--
+<?php
+
+$a = array('zero' => 0, 'one' => 1, 'two' => 2, 'three' => 3, 'four' => 4, 'five' => 5);
+//foreach (new ArrayIterator($a) as $k => $v)
+foreach (new LimitIterator(new ArrayIterator($a), 1, 3) as $k => $v)
+{
+ var_dump(array($k, $v));
+}
+
+?>
+===DONE===
+<?php exit(0); ?>
+--EXPECT--
+array(2) {
+ [0]=>
+ string(3) "one"
+ [1]=>
+ int(1)
+}
+array(2) {
+ [0]=>
+ string(3) "two"
+ [1]=>
+ int(2)
+}
+array(2) {
+ [0]=>
+ string(5) "three"
+ [1]=>
+ int(3)
+}
+===DONE===
diff --git a/ext/spl/tests/iterator_get_inner.phpt b/ext/spl/tests/iterator_get_inner.phpt
new file mode 100755
index 0000000000..25a9ce218d
--- /dev/null
+++ b/ext/spl/tests/iterator_get_inner.phpt
@@ -0,0 +1,55 @@
+--TEST--
+SPL: Iterator using getInnerIterator
+--FILE--
+<?php
+
+class RecursiceArrayIterator extends ArrayIterator implements RecursiveIterator
+{
+ function hasChildren()
+ {
+ return is_array($this->current());
+ }
+
+ function getChildren()
+ {
+ return new RecursiceArrayIterator($this->current());
+ }
+}
+
+class CrashIterator extends FilterIterator implements RecursiveIterator
+{
+ function accept()
+ {
+ return true;
+ }
+
+ function hasChildren()
+ {
+ return $this->getInnerIterator()->hasChildren();
+ }
+
+ function getChildren()
+ {
+ return new RecursiceArrayIterator($this->getInnerIterator()->current());
+ }
+}
+
+$array = array(1, 2 => array(21, 22 => array(221, 222), 23 => array(231)), 3);
+
+$dir = new RecursiveIteratorIterator(new CrashIterator(new RecursiceArrayIterator($array)), RIT_LEAVES_ONLY);
+
+foreach ($dir as $file) {
+ print "$file\n";
+}
+
+?>
+===DONE===
+<?php exit(0); ?>
+--EXPECT--
+1
+21
+221
+222
+231
+3
+===DONE===
diff --git a/ext/spl/tests/limititerator.phpt b/ext/spl/tests/limititerator.phpt
index 37ba0cbf1b..4e6006621b 100755
--- a/ext/spl/tests/limititerator.phpt
+++ b/ext/spl/tests/limititerator.phpt
@@ -1,5 +1,5 @@
--TEST--
-SPL: SeekableIterator
+SPL: SeekableIterator and string keys
--SKIPIF--
<?php if (!extension_loaded("spl")) print "skip"; ?>
--FILE--