summaryrefslogtreecommitdiff
path: root/ext/spl/tests
diff options
context:
space:
mode:
Diffstat (limited to 'ext/spl/tests')
-rwxr-xr-xext/spl/tests/.htaccess3
-rwxr-xr-xext/spl/tests/array_access_001.phpt127
-rwxr-xr-xext/spl/tests/array_access_002.phpt137
-rwxr-xr-xext/spl/tests/array_access_ex.phpt154
-rwxr-xr-xext/spl/tests/array_read.phpt208
-rwxr-xr-xext/spl/tests/foreach.phpt184
-rwxr-xr-xext/spl/tests/forward.phpt115
-rwxr-xr-xext/spl/tests/sequence.phpt138
8 files changed, 1066 insertions, 0 deletions
diff --git a/ext/spl/tests/.htaccess b/ext/spl/tests/.htaccess
new file mode 100755
index 0000000000..5a01a1c16e
--- /dev/null
+++ b/ext/spl/tests/.htaccess
@@ -0,0 +1,3 @@
+<IfModule mod_autoindex.c>
+ IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t *.php
+</IfModule>
diff --git a/ext/spl/tests/array_access_001.phpt b/ext/spl/tests/array_access_001.phpt
new file mode 100755
index 0000000000..5748a5c594
--- /dev/null
+++ b/ext/spl/tests/array_access_001.phpt
@@ -0,0 +1,127 @@
+--TEST--
+SPL: array_access
+--SKIPIF--
+<?php
+ if (!extension_loaded("spl")) die("skip");
+ if (!in_array("spl::array_access",spl_classes())) die("skip spl::array_access not present");
+?>
+--FILE--
+<?php
+class c implements spl::array_access {
+
+ public $a = array('1st', 1, 2=>'3rd', '4th'=>4);
+ function exists($index) {
+ echo __METHOD__ . "($index)\n";
+ return array_key_exists($index, $this->a);
+ }
+ function get($index) {
+ echo __METHOD__ . "($index)\n";
+ return $this->a[$index];
+ }
+ function set($index, $newval) {
+ echo __METHOD__ . "($index,$newval)\n";
+ return $this->a[$index] = $newval;
+ }
+}
+
+$obj = new c();
+
+var_dump($obj->a);
+
+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 "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);
+
+print "Done\n";
+?>
+--EXPECTF--
+array(4) {
+ [0]=>
+ string(3) "1st"
+ [1]=>
+ int(1)
+ [2]=>
+ string(3) "3rd"
+ ["4th"]=>
+ int(4)
+}
+c::exists(0)
+c::get(0)
+string(3) "1st"
+c::exists(1)
+c::get(1)
+int(1)
+c::exists(2)
+c::get(2)
+string(3) "3rd"
+c::exists(4th)
+c::get(4th)
+int(4)
+c::exists(5th)
+
+Notice: Undefined index: 5th in %s on line %d
+NULL
+c::exists(6)
+
+Notice: Undefined index: 6 in %s on line %d
+NULL
+WRITE 1
+c::exists(1)
+c::set(1,Changed 1)
+c::exists(1)
+c::get(1)
+string(9) "Changed 1"
+WRITE 2
+c::exists(4th)
+c::set(4th,Changed 4th)
+c::exists(4th)
+c::get(4th)
+string(11) "Changed 4th"
+WRITE 3
+c::exists(5th)
+c::set(5th,Added 5th)
+c::exists(5th)
+c::get(5th)
+string(9) "Added 5th"
+WRITE 4
+c::exists(6)
+c::set(6,Added 6)
+c::exists(6)
+c::get(6)
+string(7) "Added 6"
+c::exists(0)
+c::get(0)
+string(3) "1st"
+c::exists(2)
+c::get(2)
+string(3) "3rd"
+c::exists(6)
+c::set(6,changed 6)
+c::exists(6)
+c::get(6)
+string(9) "changed 6"
+string(9) "changed 6"
+Done
diff --git a/ext/spl/tests/array_access_002.phpt b/ext/spl/tests/array_access_002.phpt
new file mode 100755
index 0000000000..d415b19248
--- /dev/null
+++ b/ext/spl/tests/array_access_002.phpt
@@ -0,0 +1,137 @@
+--TEST--
+SPL: array_access without return in set()
+--SKIPIF--
+<?php
+ if (!extension_loaded("spl")) die("skip");
+ if (!in_array("spl::array_access",spl_classes())) die("skip spl::array_access not present");
+?>
+--FILE--
+<?php
+class c implements spl::array_access {
+
+ public $a = array('1st', 1, 2=>'3rd', '4th'=>4);
+ function exists($index) {
+ echo __METHOD__ . "($index)\n";
+ return array_key_exists($index, $this->a);
+ }
+ function get($index) {
+ echo __METHOD__ . "($index)\n";
+ return $this->a[$index];
+ }
+ function set($index, $newval) {
+ echo __METHOD__ . "($index,$newval)\n";
+ /* return */ $this->a[$index] = $newval;
+ }
+}
+
+$obj = new c();
+
+var_dump($obj->a);
+
+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 "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);
+
+print "Done\n";
+?>
+--EXPECTF--
+array(4) {
+ [0]=>
+ string(3) "1st"
+ [1]=>
+ int(1)
+ [2]=>
+ string(3) "3rd"
+ ["4th"]=>
+ int(4)
+}
+c::exists(0)
+c::get(0)
+string(3) "1st"
+c::exists(1)
+c::get(1)
+int(1)
+c::exists(2)
+c::get(2)
+string(3) "3rd"
+c::exists(4th)
+c::get(4th)
+int(4)
+c::exists(5th)
+
+Notice: Undefined index: 5th in %s on line %d
+NULL
+c::exists(6)
+
+Notice: Undefined index: 6 in %s on line %d
+NULL
+WRITE 1
+c::exists(1)
+c::set(1,Changed 1)
+
+Warning: Method c::set() did not return a value, using NULL in %s on line %d
+c::exists(1)
+c::get(1)
+string(9) "Changed 1"
+WRITE 2
+c::exists(4th)
+c::set(4th,Changed 4th)
+
+Warning: Method c::set() did not return a value, using NULL in %s on line %d
+c::exists(4th)
+c::get(4th)
+string(11) "Changed 4th"
+WRITE 3
+c::exists(5th)
+c::set(5th,Added 5th)
+
+Warning: Method c::set() did not return a value, using NULL in %s on line %d
+c::exists(5th)
+c::get(5th)
+string(9) "Added 5th"
+WRITE 4
+c::exists(6)
+c::set(6,Added 6)
+
+Warning: Method c::set() did not return a value, using NULL in %s on line %d
+c::exists(6)
+c::get(6)
+string(7) "Added 6"
+c::exists(0)
+c::get(0)
+string(3) "1st"
+c::exists(2)
+c::get(2)
+string(3) "3rd"
+c::exists(6)
+c::set(6,changed 6)
+
+Warning: Method c::set() did not return a value, using NULL in %s on line %d
+c::exists(6)
+c::get(6)
+string(9) "changed 6"
+NULL
+Done
diff --git a/ext/spl/tests/array_access_ex.phpt b/ext/spl/tests/array_access_ex.phpt
new file mode 100755
index 0000000000..2800c0508e
--- /dev/null
+++ b/ext/spl/tests/array_access_ex.phpt
@@ -0,0 +1,154 @@
+--TEST--
+SPL: array_access
+--SKIPIF--
+<?php
+ if (!extension_loaded("spl")) die("skip");
+ if (!in_array("spl::array_access",spl_classes())) die("skip spl::array_access not present");
+?>
+--FILE--
+<?php
+class array_write implements spl::array_writer {
+ private $obj;
+ private $idx;
+
+ function __construct(&$obj, $index = null) {
+ $this->obj = &$obj;
+ $this->idx = $index;
+ }
+
+ function set($value) {
+ echo __METHOD__ . "($value,".$this->idx.")\n";
+ return $this->obj->set($this->idx, $value);
+ }
+}
+
+class c implements spl::array_access_ex {
+
+ public $a = array('1st', 1, 2=>'3rd', '4th'=>4);
+
+ function new_writer($index) {
+ return new array_write(&$this, $index);
+ }
+
+ function exists($index) {
+ echo __METHOD__ . "($index)\n";
+ return array_key_exists($index, $this->a);
+ }
+
+ function get($index) {
+ echo __METHOD__ . "($index)\n";
+ return $this->a[$index];
+ }
+
+ function set($index, $newval) {
+ echo __METHOD__ . "($index,$newval)\n";
+ return $this->a[$index] = $newval;
+ }
+}
+
+$obj = new c();
+
+var_dump($obj->a);
+
+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 "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);
+
+print "Done\n";
+?>
+--EXPECTF--
+array(4) {
+ [0]=>
+ string(3) "1st"
+ [1]=>
+ int(1)
+ [2]=>
+ string(3) "3rd"
+ ["4th"]=>
+ int(4)
+}
+c::exists(0)
+c::get(0)
+string(3) "1st"
+c::exists(1)
+c::get(1)
+int(1)
+c::exists(2)
+c::get(2)
+string(3) "3rd"
+c::exists(4th)
+c::get(4th)
+int(4)
+c::exists(5th)
+
+Notice: Undefined index: 5th in /usr/src/php5/ext/spl/tests/array_access_ex.php on line 49
+NULL
+c::exists(6)
+
+Notice: Undefined index: 6 in /usr/src/php5/ext/spl/tests/array_access_ex.php on line 50
+NULL
+WRITE 1
+c::exists(1)
+array_write::set(Changed 1,1)
+c::set(1,Changed 1)
+c::exists(1)
+c::get(1)
+string(9) "Changed 1"
+WRITE 2
+c::exists(4th)
+array_write::set(Changed 4th,4th)
+c::set(4th,Changed 4th)
+c::exists(4th)
+c::get(4th)
+string(11) "Changed 4th"
+WRITE 3
+c::exists(5th)
+array_write::set(Added 5th,5th)
+c::set(5th,Added 5th)
+c::exists(5th)
+c::get(5th)
+string(9) "Added 5th"
+WRITE 4
+c::exists(6)
+array_write::set(Added 6,6)
+c::set(6,Added 6)
+c::exists(6)
+c::get(6)
+string(7) "Added 6"
+c::exists(0)
+c::get(0)
+string(3) "1st"
+c::exists(2)
+c::get(2)
+string(3) "3rd"
+c::exists(6)
+array_write::set(changed 6,6)
+c::set(6,changed 6)
+c::exists(6)
+c::get(6)
+string(9) "changed 6"
+string(9) "changed 6"
+Done
diff --git a/ext/spl/tests/array_read.phpt b/ext/spl/tests/array_read.phpt
new file mode 100755
index 0000000000..b1e95fd6a1
--- /dev/null
+++ b/ext/spl/tests/array_read.phpt
@@ -0,0 +1,208 @@
+--TEST--
+SPL: array_read
+--SKIPIF--
+<?php if (!extension_loaded("spl")) print "skip"; ?>
+--FILE--
+<?php
+
+echo "EXTERNAL\n";
+
+$a = array('1st', 1, 2=>'3rd', '4th'=>4);
+var_dump($a);
+
+class external implements spl::array_read {
+
+ function exists($index) {
+ echo __METHOD__ . "($index)\n";
+ return array_key_exists($index, $GLOBALS['a']);
+ }
+
+ function get($index) {
+ echo __METHOD__ . "($index)\n";
+ return $GLOBALS['a'][$index];
+ }
+}
+
+$obj = new external();
+
+var_dump($obj->get(0));
+var_dump($obj->get(1));
+var_dump($obj->get(2));
+var_dump($obj->get('4th'));
+var_dump($obj->get('5th'));
+var_dump($obj->get(6));
+
+var_dump($obj[0]);
+var_dump($obj[1]);
+var_dump($obj[2]);
+var_dump($obj['4th']);
+var_dump($obj['5th']);
+var_dump($obj[6]);
+
+$out = $obj[0]; echo "$out\n";
+$out = $obj[1]; echo "$out\n";
+$out = $obj[2]; echo "$out\n";
+$out = $obj['4th']; echo "$out\n";
+
+echo "INTERNAL\n";
+
+class internal implements spl::array_read {
+
+ public $a = array('1st', 1, 2=>'3rd', '4th'=>4);
+
+ function exists($index) {
+ echo __METHOD__ . "($index)\n";
+ return array_key_exists($index, $GLOBALS['a']);
+ }
+
+ function get($index) {
+ echo __METHOD__ . "($index)\n";
+ return $GLOBALS['a'][$index];
+ }
+}
+
+$obj = new internal();
+
+var_dump($obj->a);
+
+var_dump($obj->get(0));
+var_dump($obj->get(1));
+var_dump($obj->get(2));
+var_dump($obj->get('4th'));
+var_dump($obj->get('5th'));
+var_dump($obj->get(6));
+
+var_dump($obj[0]);
+var_dump($obj[1]);
+var_dump($obj[2]);
+var_dump($obj['4th']);
+var_dump($obj['5th']);
+var_dump($obj[6]);
+
+$out = $obj[0]; echo "$out\n";
+$out = $obj[1]; echo "$out\n";
+$out = $obj[2]; echo "$out\n";
+$out = $obj['4th']; echo "$out\n";
+
+print "Done\n";
+?>
+--EXPECTF--
+EXTERNAL
+array(4) {
+ [0]=>
+ string(3) "1st"
+ [1]=>
+ int(1)
+ [2]=>
+ string(3) "3rd"
+ ["4th"]=>
+ int(4)
+}
+external::get(0)
+string(3) "1st"
+external::get(1)
+int(1)
+external::get(2)
+string(3) "3rd"
+external::get(4th)
+int(4)
+external::get(5th)
+
+Notice: Undefined index: 5th in %s on line %d
+NULL
+external::get(6)
+
+Notice: Undefined offset: 6 in %s on line %d
+NULL
+external::exists(0)
+external::get(0)
+string(3) "1st"
+external::exists(1)
+external::get(1)
+int(1)
+external::exists(2)
+external::get(2)
+string(3) "3rd"
+external::exists(4th)
+external::get(4th)
+int(4)
+external::exists(5th)
+
+Notice: Undefined index: 5th in %s on line %d
+NULL
+external::exists(6)
+
+Notice: Undefined index: 6 in %s on line %d
+NULL
+external::exists(0)
+external::get(0)
+1st
+external::exists(1)
+external::get(1)
+1
+external::exists(2)
+external::get(2)
+3rd
+external::exists(4th)
+external::get(4th)
+4
+INTERNAL
+array(4) {
+ [0]=>
+ string(3) "1st"
+ [1]=>
+ int(1)
+ [2]=>
+ string(3) "3rd"
+ ["4th"]=>
+ int(4)
+}
+internal::get(0)
+string(3) "1st"
+internal::get(1)
+int(1)
+internal::get(2)
+string(3) "3rd"
+internal::get(4th)
+int(4)
+internal::get(5th)
+
+Notice: Undefined index: 5th in %s on line %d
+NULL
+internal::get(6)
+
+Notice: Undefined offset: 6 in %s on line %d
+NULL
+internal::exists(0)
+internal::get(0)
+string(3) "1st"
+internal::exists(1)
+internal::get(1)
+int(1)
+internal::exists(2)
+internal::get(2)
+string(3) "3rd"
+internal::exists(4th)
+internal::get(4th)
+int(4)
+internal::exists(5th)
+
+Notice: Undefined index: 5th in %s on line %d
+NULL
+internal::exists(6)
+
+Notice: Undefined index: 6 in %s on line %d
+NULL
+internal::exists(0)
+internal::get(0)
+1st
+internal::exists(1)
+internal::get(1)
+1
+internal::exists(2)
+internal::get(2)
+3rd
+internal::exists(4th)
+internal::get(4th)
+4
+Done
diff --git a/ext/spl/tests/foreach.phpt b/ext/spl/tests/foreach.phpt
new file mode 100755
index 0000000000..6803e44c27
--- /dev/null
+++ b/ext/spl/tests/foreach.phpt
@@ -0,0 +1,184 @@
+--TEST--
+SPL: foreach and iterator
+--SKIPIF--
+<?php if (!extension_loaded("spl")) print "skip"; ?>
+--FILE--
+<?php
+class c_iter implements spl::forward_assoc {
+
+ private $obj;
+ private $num = 0;
+
+ function __construct($obj) {
+ $this->obj = $obj;
+ }
+ function current() {
+ echo __CLASS__ . '::' . __FUNCTION__ . "\n";
+ return $this->num;
+ }
+ function next() {
+ echo __CLASS__ . '::' . __FUNCTION__ . "\n";
+ $this->num++;
+ }
+ function has_more() {
+ echo __CLASS__ . '::' . __FUNCTION__ . "\n";
+ return $this->num < $this->obj->max;
+ }
+ function key() {
+ echo __CLASS__ . '::' . __FUNCTION__ . "\n";
+ switch($this->num) {
+ case 0: return "1st";
+ case 1: return "2nd";
+ case 2: return "3rd";
+ default: return "???";
+ }
+ }
+}
+
+class c implements spl::iterator {
+
+ public $max = 3;
+
+ function new_iterator() {
+ echo __CLASS__ . '::' . __FUNCTION__ . "\n";
+ return new c_iter($this);
+ }
+}
+
+$t = new c();
+
+for ($iter = $t->new_iterator(); $iter->has_more(); $iter->next()) {
+ echo $iter->current() . "\n";
+}
+
+$a = array(0,1,2);
+foreach($a as $v) {
+ echo "array:$v\n";
+}
+
+foreach($t as $v) {
+ echo "object:$v\n";
+}
+
+foreach($t as $v) {
+ foreach($t as $w) {
+ echo "double:$v:$w\n";
+ }
+}
+
+foreach($t as $i => $v) {
+ echo "object:$i=>$v\n";
+}
+
+print "Done\n";
+?>
+--EXPECT--
+c::new_iterator
+c_iter::has_more
+c_iter::current
+0
+c_iter::next
+c_iter::has_more
+c_iter::current
+1
+c_iter::next
+c_iter::has_more
+c_iter::current
+2
+c_iter::next
+c_iter::has_more
+array:0
+array:1
+array:2
+c::new_iterator
+c_iter::has_more
+c_iter::current
+c_iter::key
+object:0
+c_iter::next
+c_iter::has_more
+c_iter::current
+c_iter::key
+object:1
+c_iter::next
+c_iter::has_more
+c_iter::current
+c_iter::key
+object:2
+c_iter::next
+c_iter::has_more
+c::new_iterator
+c_iter::has_more
+c_iter::current
+c_iter::key
+c::new_iterator
+c_iter::has_more
+c_iter::current
+c_iter::key
+double:0:0
+c_iter::next
+c_iter::has_more
+c_iter::current
+c_iter::key
+double:0:1
+c_iter::next
+c_iter::has_more
+c_iter::current
+c_iter::key
+double:0:2
+c_iter::next
+c_iter::has_more
+c_iter::next
+c_iter::has_more
+c_iter::current
+c_iter::key
+c::new_iterator
+c_iter::next
+c_iter::has_more
+c_iter::current
+c_iter::key
+double:1:1
+c_iter::next
+c_iter::has_more
+c_iter::current
+c_iter::key
+double:1:2
+c_iter::next
+c_iter::has_more
+c_iter::next
+c_iter::has_more
+c_iter::current
+c_iter::key
+c::new_iterator
+c_iter::next
+c_iter::has_more
+c_iter::current
+c_iter::key
+double:2:1
+c_iter::next
+c_iter::has_more
+c_iter::current
+c_iter::key
+double:2:2
+c_iter::next
+c_iter::has_more
+c_iter::next
+c_iter::has_more
+c::new_iterator
+c_iter::has_more
+c_iter::current
+c_iter::key
+object:1st=>0
+c_iter::next
+c_iter::has_more
+c_iter::current
+c_iter::key
+object:2nd=>1
+c_iter::next
+c_iter::has_more
+c_iter::current
+c_iter::key
+object:3rd=>2
+c_iter::next
+c_iter::has_more
+Done \ No newline at end of file
diff --git a/ext/spl/tests/forward.phpt b/ext/spl/tests/forward.phpt
new file mode 100755
index 0000000000..2c8a584b8a
--- /dev/null
+++ b/ext/spl/tests/forward.phpt
@@ -0,0 +1,115 @@
+--TEST--
+SPL: forward
+--SKIPIF--
+<?php if (!extension_loaded("spl")) print "skip"; ?>
+--FILE--
+<?php
+class c implements spl::forward_assoc {
+
+ public $max = 3;
+ public $num = 0;
+
+ function current() {
+ echo __CLASS__ . '::' . __FUNCTION__ . "\n";
+ return $this->num;
+ }
+ function next() {
+ echo __CLASS__ . '::' . __FUNCTION__ . "\n";
+ $this->num++;
+ }
+ function has_more() {
+ echo __CLASS__ . '::' . __FUNCTION__ . "\n";
+ return $this->num < $this->max;
+ }
+ function key() {
+ echo __CLASS__ . '::' . __FUNCTION__ . "\n";
+ switch($this->num) {
+ case 0: return "1st";
+ case 1: return "2nd";
+ case 2: return "3rd";
+ default: return "???";
+ }
+ }
+}
+
+$i = new c();
+
+$c_info = array(class_name($i) => array('inheits' => class_parents($i), 'implements' => class_implements($i)));
+print_r($c_info);
+
+echo "1st try\n";
+foreach($i as $w) {
+ echo "object:$w\n";
+}
+
+echo "2nd try\n";
+
+foreach($i as $v => $w) {
+ echo "object:$v=>$w\n";
+}
+
+echo "3rd try\n";
+$i->num = 0;
+
+foreach($i as $v => $w) {
+ echo "object:$v=>$w\n";
+}
+
+print "Done\n";
+?>
+--EXPECT--
+Array
+(
+ [c] => Array
+ (
+ [inheits] => Array
+ (
+ )
+
+ [implements] => Array
+ (
+ [spl::forward_assoc] => spl::forward_assoc
+ [spl::assoc] => spl::assoc
+ [spl::forward] => spl::forward
+ )
+
+ )
+
+)
+1st try
+c::has_more
+c::current
+c::key
+object:0
+c::next
+c::has_more
+c::current
+c::key
+object:1
+c::next
+c::has_more
+c::current
+c::key
+object:2
+c::next
+c::has_more
+2nd try
+c::has_more
+3rd try
+c::has_more
+c::current
+c::key
+object:1st=>0
+c::next
+c::has_more
+c::current
+c::key
+object:2nd=>1
+c::next
+c::has_more
+c::current
+c::key
+object:3rd=>2
+c::next
+c::has_more
+Done \ No newline at end of file
diff --git a/ext/spl/tests/sequence.phpt b/ext/spl/tests/sequence.phpt
new file mode 100755
index 0000000000..3608e15c41
--- /dev/null
+++ b/ext/spl/tests/sequence.phpt
@@ -0,0 +1,138 @@
+--TEST--
+SPL: sequence
+--SKIPIF--
+<?php if (!extension_loaded("spl")) print "skip"; ?>
+--FILE--
+<?php
+class c implements spl::iterator {
+
+ public $max = 3;
+
+ function new_iterator() {
+ echo __CLASS__ . '::' . __FUNCTION__ . "\n";
+ return new c_iter($this);
+ }
+}
+
+class c_iter implements spl::sequence_assoc {
+
+ private $obj;
+ private $num = 0;
+
+ function __construct($obj) {
+ $this->obj = $obj;
+ }
+ function rewind() {
+ echo __CLASS__ . '::' . __FUNCTION__ . "\n";
+ $this->num = 0;
+ }
+ function current() {
+ echo __CLASS__ . '::' . __FUNCTION__ . "\n";
+ return $this->num;
+ }
+ function next() {
+ echo __CLASS__ . '::' . __FUNCTION__ . "\n";
+ $this->num++;
+ }
+ function has_more() {
+ echo __CLASS__ . '::' . __FUNCTION__ . "\n";
+ return $this->num < $this->obj->max;
+ }
+ function key() {
+ echo __CLASS__ . '::' . __FUNCTION__ . "\n";
+ switch($this->num) {
+ case 0: return "1st";
+ case 1: return "2nd";
+ case 2: return "3rd";
+ default: return "???";
+ }
+ }
+}
+
+$t = new c();
+$i = $t->new_iterator();
+
+$c_info = array(class_name($t) => array('inheits' => class_parents($t), 'implements' => class_implements($t)),
+ class_name($i) => array('inheits' => class_parents($i), 'implements' => class_implements($i)));
+print_r($c_info);
+
+foreach($i as $w) {
+ echo "object:$w\n";
+}
+
+foreach($i as $v => $w) {
+ echo "object:$v=>$w\n";
+}
+
+print "Done\n";
+?>
+--EXPECT--
+c::new_iterator
+Array
+(
+ [c] => Array
+ (
+ [inheits] => Array
+ (
+ )
+
+ [implements] => Array
+ (
+ [spl::iterator] => spl::iterator
+ )
+
+ )
+
+ [c_iter] => Array
+ (
+ [inheits] => Array
+ (
+ )
+
+ [implements] => Array
+ (
+ [spl::sequence_assoc] => spl::sequence_assoc
+ [spl::forward_assoc] => spl::forward_assoc
+ [spl::assoc] => spl::assoc
+ [spl::forward] => spl::forward
+ [spl::sequence] => spl::sequence
+ )
+
+ )
+
+)
+c_iter::rewind
+c_iter::has_more
+c_iter::current
+c_iter::key
+object:0
+c_iter::next
+c_iter::has_more
+c_iter::current
+c_iter::key
+object:1
+c_iter::next
+c_iter::has_more
+c_iter::current
+c_iter::key
+object:2
+c_iter::next
+c_iter::has_more
+c_iter::rewind
+c_iter::has_more
+c_iter::current
+c_iter::key
+object:1st=>0
+c_iter::next
+c_iter::has_more
+c_iter::current
+c_iter::key
+object:2nd=>1
+c_iter::next
+c_iter::has_more
+c_iter::current
+c_iter::key
+object:3rd=>2
+c_iter::next
+c_iter::has_more
+Done \ No newline at end of file