diff options
| author | Mark A. Hershberger <mah@debian.(none)> | 2009-03-25 00:35:28 -0400 |
|---|---|---|
| committer | Mark A. Hershberger <mah@debian.(none)> | 2009-03-25 00:35:28 -0400 |
| commit | ba50031707469046407a35b77a3cd81351e951b3 (patch) | |
| tree | 5c03e723bdbfabae09d41a3ab1253dff41eeed4a /ext/spl/tests | |
| parent | 0a36161e13484a99ccf69bb38f206462d27cc6d6 (diff) | |
| download | php-upstream/5.1.5.tar.gz | |
Imported Upstream version 5.1.5upstream/5.1.5
Diffstat (limited to 'ext/spl/tests')
| -rwxr-xr-x | ext/spl/tests/array_017.phpt | 2 | ||||
| -rwxr-xr-x | ext/spl/tests/array_019.phpt | 32 | ||||
| -rwxr-xr-x | ext/spl/tests/array_020.phpt | 66 | ||||
| -rwxr-xr-x | ext/spl/tests/array_021.phpt | 31 | ||||
| -rwxr-xr-x | ext/spl/tests/array_022.phpt | 94 | ||||
| -rw-r--r-- | ext/spl/tests/bug34548.phpt | 2 | ||||
| -rw-r--r-- | ext/spl/tests/bug36258.phpt | 21 | ||||
| -rwxr-xr-x | ext/spl/tests/bug36287.phpt | 40 | ||||
| -rw-r--r-- | ext/spl/tests/bug36825.phpt | 33 | ||||
| -rwxr-xr-x | ext/spl/tests/bug36941.phpt | 46 | ||||
| -rwxr-xr-x | ext/spl/tests/iterator_012.phpt | 2 | ||||
| -rwxr-xr-x | ext/spl/tests/iterator_019.phpt | 2 | ||||
| -rwxr-xr-x | ext/spl/tests/iterator_030.phpt | 46 | ||||
| -rwxr-xr-x | ext/spl/tests/iterator_031.phpt | 118 | ||||
| -rwxr-xr-x | ext/spl/tests/iterator_032.phpt | 52 | ||||
| -rwxr-xr-x | ext/spl/tests/iterator_033.phpt | 46 | ||||
| -rwxr-xr-x | ext/spl/tests/iterator_034.phpt | 190 | ||||
| -rw-r--r-- | ext/spl/tests/iterator_035.phpt | 17 | ||||
| -rwxr-xr-x | ext/spl/tests/spl_autoload_008.phpt | 131 | ||||
| -rwxr-xr-x | ext/spl/tests/sxe_005.phpt | 46 |
20 files changed, 1013 insertions, 4 deletions
diff --git a/ext/spl/tests/array_017.phpt b/ext/spl/tests/array_017.phpt index f028a1203..72bf63998 100755 --- a/ext/spl/tests/array_017.phpt +++ b/ext/spl/tests/array_017.phpt @@ -29,7 +29,7 @@ class ArrayIteratorEx extends ArrayIterator function setFlags($flags) { echo __METHOD__ . "($flags)\n"; - ArrayObject::setFlags($flags); + ArrayIterator::setFlags($flags); } } diff --git a/ext/spl/tests/array_019.phpt b/ext/spl/tests/array_019.phpt new file mode 100755 index 000000000..1416d8407 --- /dev/null +++ b/ext/spl/tests/array_019.phpt @@ -0,0 +1,32 @@ +--TEST-- +SPL: ArrayIterator and foreach by reference +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +$ar = new ArrayObject(array(1)); foreach($ar as &$v) var_dump($v); +$ar = new ArrayIterator(array(2)); foreach($ar as &$v) var_dump($v); +$ar = new RecursiveArrayIterator(array(3)); foreach($ar as &$v) var_dump($v); + +class ArrayIteratorEx extends ArrayIterator +{ + function current() + { + return ArrayIterator::current(); + } +} + +$ar = new ArrayIteratorEx(array(4)); foreach($ar as $v) var_dump($v); +$ar = new ArrayIteratorEx(array(5)); foreach($ar as &$v) var_dump($v); + +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +int(1) +int(2) +int(3) +int(4) +int(5) +===DONE=== diff --git a/ext/spl/tests/array_020.phpt b/ext/spl/tests/array_020.phpt new file mode 100755 index 000000000..cdeb4a216 --- /dev/null +++ b/ext/spl/tests/array_020.phpt @@ -0,0 +1,66 @@ +--TEST-- +SPL: ArrayIterator overloading +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +class ArrayIteratorEx extends ArrayIterator +{ + function rewind() + { + echo __METHOD__ . "\n"; + ArrayIterator::rewind(); + } + + function valid() + { + echo __METHOD__ . "\n"; + return ArrayIterator::valid(); + } + + function key() + { + echo __METHOD__ . "\n"; + return ArrayIterator::key(); + } + + function current() + { + echo __METHOD__ . "\n"; + return ArrayIterator::current(); + } + + function next() + { + echo __METHOD__ . "\n"; + return ArrayIterator::next(); + } +} + +$ar = new ArrayIteratorEx(array(1,2)); +foreach($ar as $k => $v) +{ + var_dump($k); + var_dump($v); +} + +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +ArrayIteratorEx::rewind +ArrayIteratorEx::valid +ArrayIteratorEx::current +ArrayIteratorEx::key +int(0) +int(1) +ArrayIteratorEx::next +ArrayIteratorEx::valid +ArrayIteratorEx::current +ArrayIteratorEx::key +int(1) +int(2) +ArrayIteratorEx::next +ArrayIteratorEx::valid +===DONE=== diff --git a/ext/spl/tests/array_021.phpt b/ext/spl/tests/array_021.phpt new file mode 100755 index 000000000..f2ae0c87e --- /dev/null +++ b/ext/spl/tests/array_021.phpt @@ -0,0 +1,31 @@ +--TEST-- +SPL: ArrayObject::seek() and exceptions +--FILE-- +<?php + +class foo extends ArrayObject +{ + public function seek($key) + { + echo __METHOD__ . "($key)\n"; + throw new Exception("hi"); + } +} + +$test = new foo(array(1,2,3)); + +try +{ + $test->seek('bar'); +} +catch (Exception $e) +{ + echo "got exception\n"; +} + +?> +===DONE=== +--EXPECT-- +foo::seek(bar) +got exception +===DONE=== diff --git a/ext/spl/tests/array_022.phpt b/ext/spl/tests/array_022.phpt new file mode 100755 index 000000000..d1eafd677 --- /dev/null +++ b/ext/spl/tests/array_022.phpt @@ -0,0 +1,94 @@ +--TEST-- +SPL: ArrayObject/Iterator and reference to self +--FILE-- +==ArrayObject=== +<?php + +class MyArrayObject extends ArrayObject +{ + public function __construct() + { + parent::__construct($this); + $this['bar'] = 'baz'; + } +} + +$a = new MyArrayObject; + +$b = clone $a; +$b['baz'] = 'Foo'; + +var_dump($a); +var_dump($b); + +?> +==ArrayIterator=== +<?php + +class MyArrayIterator extends ArrayIterator +{ + public function __construct() + { + parent::__construct($this); + $this['bar'] = 'baz'; + } +} + +$a = new MyArrayIterator; + +$b = clone $a; +$b['baz'] = 'Foo'; + +var_dump($a); +var_dump($b); + +?> +===DONE=== +--EXPECTF-- +==ArrayObject=== +object(MyArrayObject)#%d (1) { + ["bar"]=> + string(3) "baz" +} +object(MyArrayObject)#%d (2) { + ["bar"]=> + string(3) "baz" + ["baz"]=> + string(3) "Foo" +} +==ArrayIterator=== +object(MyArrayIterator)#%d (1) { + ["bar"]=> + string(3) "baz" +} +object(MyArrayIterator)#%d (2) { + ["bar"]=> + string(3) "baz" + ["baz"]=> + string(3) "Foo" +} +===DONE=== +--UEXPECTF-- +==ArrayObject=== +object(MyArrayObject)#%d (1) { + [u"bar"]=> + unicode(3) "baz" +} +object(MyArrayObject)#%d (2) { + [u"bar"]=> + unicode(3) "baz" + [u"baz"]=> + unicode(3) "Foo" +} +==ArrayIterator=== +object(MyArrayIterator)#%d (1) { + [u"bar"]=> + unicode(3) "baz" +} +object(MyArrayIterator)#%d (2) { + [u"bar"]=> + unicode(3) "baz" + [u"baz"]=> + unicode(3) "Foo" +} +===DONE=== diff --git a/ext/spl/tests/bug34548.phpt b/ext/spl/tests/bug34548.phpt index 90f2e8f6e..73262a806 100644 --- a/ext/spl/tests/bug34548.phpt +++ b/ext/spl/tests/bug34548.phpt @@ -1,5 +1,5 @@ --TEST-- -bug #34548 (Method append() in class extended from ArrayObject crashes PHP) +Bug #34548 (Method append() in class extended from ArrayObject crashes PHP) --SKIPIF-- <?php if (!extension_loaded("spl")) print "skip"; ?> --FILE-- diff --git a/ext/spl/tests/bug36258.phpt b/ext/spl/tests/bug36258.phpt new file mode 100644 index 000000000..297c7f597 --- /dev/null +++ b/ext/spl/tests/bug36258.phpt @@ -0,0 +1,21 @@ +--TEST-- +Bug #36258 (SplFileObject::getPath() may lead to segfault) +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +$diriter = new RecursiveIteratorIterator( new RecursiveDirectoryIterator('.') ); + +foreach ($diriter as $key => $file) { + var_dump($file->getFilename()); + var_dump($file->getPath()); + break; +} + +echo "Done\n"; +?> +--EXPECTF-- +string(%d) "%s" +string(%d) "%s" +Done diff --git a/ext/spl/tests/bug36287.phpt b/ext/spl/tests/bug36287.phpt new file mode 100755 index 000000000..29ae0e2c9 --- /dev/null +++ b/ext/spl/tests/bug36287.phpt @@ -0,0 +1,40 @@ +--TEST-- +Bug #36287 +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator("."), true); + +$idx = 0; +foreach($it as $file) +{ + echo "First\n"; + if("." != $file && ".." != $file) + { + var_Dump($file->getFilename()); + } + echo "Second\n"; + if($file != "." && $file != "..") + { + var_dump($file->getFilename()); + } + if (++$idx > 1) + { + break; + } +} + +?> +===DONE=== +--EXPECTF-- +First +string(%d) "%s" +Second +string(%d) "%s" +First +string(%d) "%s" +Second +string(%d) "%s" +===DONE=== diff --git a/ext/spl/tests/bug36825.phpt b/ext/spl/tests/bug36825.phpt new file mode 100644 index 000000000..503ec43a4 --- /dev/null +++ b/ext/spl/tests/bug36825.phpt @@ -0,0 +1,33 @@ +--TEST-- +Bug #36825 (Exceptions thrown in ArrayObject::offsetGet cause segfault) +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +class foo extends ArrayObject +{ + public function offsetGet($key) + { + echo __METHOD__ . "($key)\n"; + throw new Exception("hi"); + } +} + +$test = new foo(); + +try +{ + var_dump($test['bar']); +} +catch (Exception $e) +{ + echo "got exception\n"; +} + +?> +===DONE=== +--EXPECT-- +foo::offsetGet(bar) +got exception +===DONE=== diff --git a/ext/spl/tests/bug36941.phpt b/ext/spl/tests/bug36941.phpt new file mode 100755 index 000000000..528ba4a46 --- /dev/null +++ b/ext/spl/tests/bug36941.phpt @@ -0,0 +1,46 @@ +--TEST-- +Bug #36941 (ArrayIterator does not clone itself) +--FILE-- +===ArrayObject=== +<?php +$a = new ArrayObject(); +$a[] = 1; + +$b = clone $a; + +var_dump($a[0], $b[0]); +$b[0] = $b[0] + 1; +var_dump($a[0], $b[0]); +$b[0] = 3; +var_dump($a[0], $b[0]); +?> +===ArrayIterator=== +<?php +$a = new ArrayIterator(); +$a[] = 1; + +$b = clone $a; + +var_dump($a[0], $b[0]); +$b[0] = $b[0] + 1; +var_dump($a[0], $b[0]); +$b[0] = 3; +var_dump($a[0], $b[0]); +?> +===DONE=== +--EXPECT-- +===ArrayObject=== +int(1) +int(1) +int(1) +int(2) +int(1) +int(3) +===ArrayIterator=== +int(1) +int(1) +int(2) +int(2) +int(3) +int(3) +===DONE=== diff --git a/ext/spl/tests/iterator_012.phpt b/ext/spl/tests/iterator_012.phpt index 8195072b5..c6eb86eef 100755 --- a/ext/spl/tests/iterator_012.phpt +++ b/ext/spl/tests/iterator_012.phpt @@ -1,5 +1,5 @@ --TEST-- -SPL: NoRweindIterator +SPL: NoRewindIterator --SKIPIF-- <?php if (!extension_loaded("spl")) print "skip"; ?> --FILE-- diff --git a/ext/spl/tests/iterator_019.phpt b/ext/spl/tests/iterator_019.phpt index 8195072b5..c6eb86eef 100755 --- a/ext/spl/tests/iterator_019.phpt +++ b/ext/spl/tests/iterator_019.phpt @@ -1,5 +1,5 @@ --TEST-- -SPL: NoRweindIterator +SPL: NoRewindIterator --SKIPIF-- <?php if (!extension_loaded("spl")) print "skip"; ?> --FILE-- diff --git a/ext/spl/tests/iterator_030.phpt b/ext/spl/tests/iterator_030.phpt new file mode 100755 index 000000000..6ed8035ac --- /dev/null +++ b/ext/spl/tests/iterator_030.phpt @@ -0,0 +1,46 @@ +--TEST-- +SPL: EmptyIterator access +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +$it = new EmptyIterator; + +var_dump($it->valid()); +$it->rewind(); +var_dump($it->valid()); +$it->next(); +var_dump($it->valid()); + +try +{ + var_dump($it->key()); +} +catch(BadMethodCallException $e) +{ + echo $e->getMessage() . "\n"; +} + +try +{ + var_dump($it->current()); +} +catch(BadMethodCallException $e) +{ + echo $e->getMessage() . "\n"; +} + +var_dump($it->valid()); + +?> +===DONE=== +<?php exit(0); ?> +--EXPECT-- +bool(false) +bool(false) +bool(false) +Accessing the key of an EmptyIterator +Accessing the value of an EmptyIterator +bool(false) +===DONE=== diff --git a/ext/spl/tests/iterator_031.phpt b/ext/spl/tests/iterator_031.phpt new file mode 100755 index 000000000..00afa6185 --- /dev/null +++ b/ext/spl/tests/iterator_031.phpt @@ -0,0 +1,118 @@ +--TEST-- +SPL: AppendIterator::append() rewinds when neccessary +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +class MyArrayIterator extends ArrayIterator +{ + function rewind() + { + echo __METHOD__ . "\n"; + parent::rewind(); + } +} + +$it = new MyArrayIterator(array(1,2)); + +foreach($it as $k=>$v) +{ + echo "$k=>$v\n"; +} + +class MyAppendIterator extends AppendIterator +{ + function __construct() + { + echo __METHOD__ . "\n"; + } + + function rewind() + { + echo __METHOD__ . "\n"; + parent::rewind(); + } + + function valid() + { + echo __METHOD__ . "\n"; + return parent::valid(); + } + + function append(Iterator $what) + { + echo __METHOD__ . "\n"; + parent::append($what); + } + + function parent__construct() + { + parent::__construct(); + } +} + +$ap = new MyAppendIterator; + +try +{ + $ap->append($it); +} +catch(BadMethodCallException $e) +{ + echo $e->getMessage() . "\n"; +} + +$ap->parent__construct(); + +try +{ + $ap->parent__construct($it); +} +catch(BadMethodCallException $e) +{ + echo $e->getMessage() . "\n"; +} + +$ap->append($it); +$ap->append($it); +$ap->append($it); + +foreach($ap as $k=>$v) +{ + echo "$k=>$v\n"; +} + +?> +===DONE=== +<?php exit(0); ?> +--EXPECT-- +MyArrayIterator::rewind +0=>1 +1=>2 +MyAppendIterator::__construct +MyAppendIterator::append +Classes derived from AppendIterator must call AppendIterator::__construct() +AppendIterator::getIterator() must be called exactly once per instance +MyAppendIterator::append +MyArrayIterator::rewind +MyAppendIterator::append +MyAppendIterator::append +MyAppendIterator::rewind +MyArrayIterator::rewind +MyAppendIterator::valid +0=>1 +MyAppendIterator::valid +1=>2 +MyArrayIterator::rewind +MyAppendIterator::valid +0=>1 +MyAppendIterator::valid +1=>2 +MyArrayIterator::rewind +MyAppendIterator::valid +0=>1 +MyAppendIterator::valid +1=>2 +MyAppendIterator::valid +===DONE=== diff --git a/ext/spl/tests/iterator_032.phpt b/ext/spl/tests/iterator_032.phpt new file mode 100755 index 000000000..86695d4af --- /dev/null +++ b/ext/spl/tests/iterator_032.phpt @@ -0,0 +1,52 @@ +--TEST-- +SPL: LimitIterator::getPosition() +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +$it = new LimitIterator(new ArrayIterator(array(1,2,3,4)), 1, 2); + +foreach($it as $k=>$v) +{ + echo "$k=>$v\n"; + var_dump($it->getPosition()); +} + +try +{ + $it->seek(0); +} +catch(OutOfBoundsException $e) +{ + echo $e->getMessage() . "\n"; +} + +$it->seek(2); +var_dump($it->current()); + +try +{ + $it->seek(3); +} +catch(OutOfBoundsException $e) +{ + echo $e->getMessage() . "\n"; +} + +$it->next(); +var_dump($it->valid()); + +?> +===DONE=== +<?php exit(0); ?> +--EXPECT-- +1=>2 +int(1) +2=>3 +int(2) +Cannot seek to 0 which is below the offset 1 +int(3) +Cannot seek to 3 which is behind offest 1 plus count 2 +bool(false) +===DONE=== diff --git a/ext/spl/tests/iterator_033.phpt b/ext/spl/tests/iterator_033.phpt new file mode 100755 index 000000000..c1880cb2f --- /dev/null +++ b/ext/spl/tests/iterator_033.phpt @@ -0,0 +1,46 @@ +--TEST-- +SPL: ParentIterator +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +$it = new ParentIterator(new RecursiveArrayIterator(array(1,array(21,22, array(231)),3))); + +foreach(new RecursiveIteratorIterator($it) as $k=>$v) +{ + var_dump($k); + var_dump($v); +} + +echo "==SECOND==\n"; + +foreach(new RecursiveIteratorIterator($it, 1) as $k=>$v) +{ + var_dump($k); + var_dump($v); +} + +?> +===DONE=== +<?php exit(0); ?> +--EXPECT-- +==SECOND== +int(1) +array(3) { + [0]=> + int(21) + [1]=> + int(22) + [2]=> + array(1) { + [0]=> + int(231) + } +} +int(2) +array(1) { + [0]=> + int(231) +} +===DONE=== diff --git a/ext/spl/tests/iterator_034.phpt b/ext/spl/tests/iterator_034.phpt new file mode 100755 index 000000000..b81c6d970 --- /dev/null +++ b/ext/spl/tests/iterator_034.phpt @@ -0,0 +1,190 @@ +--TEST-- +SPL: RecursiveIteratorIterator and break deep +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +class MyRecursiveArrayIterator extends RecursiveArrayIterator +{ + function valid() + { + if (!parent::valid()) + { + echo __METHOD__ . "() = false\n"; + return false; + } + else + { + return true; + } + } + + function getChildren() + { + echo __METHOD__ . "()\n"; + return parent::getChildren(); + } + + function rewind() + { + echo __METHOD__ . "()\n"; + parent::rewind(); + } +} + +class RecursiveArrayIteratorIterator extends RecursiveIteratorIterator +{ + private $max_depth; + private $over = 0; + + function __construct($it, $max_depth) + { + $this->max_depth = $max_depth; + parent::__construct($it); + } + + function rewind() + { + echo __METHOD__ . "() - BEGIN\n"; + parent::rewind(); + echo __METHOD__ . "() - DONE\n"; + } + + function valid() + { + echo __METHOD__ . "()\n"; + return parent::valid(); + } + + function current() + { + echo __METHOD__ . "()\n"; + return parent::current(); + } + + function key() + { + echo __METHOD__ . "()\n"; + return parent::key(); + } + + function next() + { + echo __METHOD__ . "()\n"; + parent::next(); + } + + function callHasChildren() + { + $has = parent::callHasChildren(); + $res = $this->getDepth() < $this->max_depth && $has; + echo __METHOD__ . "(".$this->getDepth().") = ".($res?"yes":"no")."/".($has?"yes":"no")."\n"; + return $res; + } + + function beginChildren() + { + echo __METHOD__ . "(".$this->getDepth().")\n"; + parent::beginChildren(); + } + + function endChildren() + { + echo __METHOD__ . "(".$this->getDepth().")\n"; + parent::endChildren(); + } +} + +$p = 0; +$it = new RecursiveArrayIteratorIterator(new MyRecursiveArrayIterator(array("a", array("ba", array("bba", "bbb"), array(array("bcaa"), array("bcba"))), array("ca"), "d")), 2); +foreach($it as $k=>$v) +{ + if (is_array($v)) $v = join('',$v); + echo "$k=>$v\n"; + if ($p++ == 5) + { + echo "===BREAK===\n"; + break; + } +} + +echo "===FOREND===\n"; + +$it->rewind(); + +echo "===CHECK===\n"; + +var_dump($it->valid()); +var_dump($it->current() == "a"); + +?> +===DONE=== +<?php exit(0); ?> +--EXPECT-- +RecursiveArrayIteratorIterator::rewind() - BEGIN +MyRecursiveArrayIterator::rewind() +RecursiveArrayIteratorIterator::callHasChildren(0) = no/no +RecursiveArrayIteratorIterator::rewind() - DONE +RecursiveArrayIteratorIterator::valid() +RecursiveArrayIteratorIterator::current() +RecursiveArrayIteratorIterator::key() +0=>a +RecursiveArrayIteratorIterator::next() +RecursiveArrayIteratorIterator::callHasChildren(0) = yes/yes +MyRecursiveArrayIterator::getChildren() +MyRecursiveArrayIterator::rewind() +RecursiveArrayIteratorIterator::beginChildren(1) +RecursiveArrayIteratorIterator::callHasChildren(1) = no/no +RecursiveArrayIteratorIterator::valid() +RecursiveArrayIteratorIterator::current() +RecursiveArrayIteratorIterator::key() +0=>ba +RecursiveArrayIteratorIterator::next() +RecursiveArrayIteratorIterator::callHasChildren(1) = yes/yes +MyRecursiveArrayIterator::getChildren() +MyRecursiveArrayIterator::rewind() +RecursiveArrayIteratorIterator::beginChildren(2) +RecursiveArrayIteratorIterator::callHasChildren(2) = no/no +RecursiveArrayIteratorIterator::valid() +RecursiveArrayIteratorIterator::current() +RecursiveArrayIteratorIterator::key() +0=>bba +RecursiveArrayIteratorIterator::next() +RecursiveArrayIteratorIterator::callHasChildren(2) = no/no +RecursiveArrayIteratorIterator::valid() +RecursiveArrayIteratorIterator::current() +RecursiveArrayIteratorIterator::key() +1=>bbb +RecursiveArrayIteratorIterator::next() +MyRecursiveArrayIterator::valid() = false +RecursiveArrayIteratorIterator::endChildren(2) +RecursiveArrayIteratorIterator::callHasChildren(1) = yes/yes +MyRecursiveArrayIterator::getChildren() +MyRecursiveArrayIterator::rewind() +RecursiveArrayIteratorIterator::beginChildren(2) +RecursiveArrayIteratorIterator::callHasChildren(2) = no/yes +RecursiveArrayIteratorIterator::valid() +RecursiveArrayIteratorIterator::current() +RecursiveArrayIteratorIterator::key() +0=>bcaa +RecursiveArrayIteratorIterator::next() +RecursiveArrayIteratorIterator::callHasChildren(2) = no/yes +RecursiveArrayIteratorIterator::valid() +RecursiveArrayIteratorIterator::current() +RecursiveArrayIteratorIterator::key() +1=>bcba +===BREAK=== +===FOREND=== +RecursiveArrayIteratorIterator::rewind() - BEGIN +RecursiveArrayIteratorIterator::endChildren(1) +RecursiveArrayIteratorIterator::endChildren(0) +MyRecursiveArrayIterator::rewind() +RecursiveArrayIteratorIterator::callHasChildren(0) = no/no +RecursiveArrayIteratorIterator::rewind() - DONE +===CHECK=== +RecursiveArrayIteratorIterator::valid() +bool(true) +RecursiveArrayIteratorIterator::current() +bool(true) +===DONE=== diff --git a/ext/spl/tests/iterator_035.phpt b/ext/spl/tests/iterator_035.phpt new file mode 100644 index 000000000..eebc7f22a --- /dev/null +++ b/ext/spl/tests/iterator_035.phpt @@ -0,0 +1,17 @@ +--TEST-- +SPL: ArrayIterator and values assigned by reference +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +$tmp = 1; + +$a = new ArrayIterator(); +$a[] = $tmp; +$a[] = &$tmp; + +echo "Done\n"; +?> +--EXPECTF-- +Fatal error: Objects used as arrays in post/pre increment/decrement must return values by reference in %s on line %d diff --git a/ext/spl/tests/spl_autoload_008.phpt b/ext/spl/tests/spl_autoload_008.phpt new file mode 100755 index 000000000..a3f24d96c --- /dev/null +++ b/ext/spl/tests/spl_autoload_008.phpt @@ -0,0 +1,131 @@ +--TEST--
+SPL: spl_autoload() with exceptions
+--SKIPIF--
+<?php if (!extension_loaded("spl")) print "skip"; ?>
+--INI--
+include_path=.
+--FILE--
+<?php
+
+function MyAutoLoad($className)
+{
+ echo __METHOD__ . "($className)\n";
+ throw new Exception('Bla');
+}
+
+class MyAutoLoader
+{
+ static function autoLoad($className)
+ {
+ echo __METHOD__ . "($className)\n";
+ throw new Exception('Bla');
+ }
+
+ function dynaLoad($className)
+ {
+ echo __METHOD__ . "($className)\n";
+ throw new Exception('Bla');
+ }
+}
+
+$obj = new MyAutoLoader;
+
+$funcs = array(
+ 'MyAutoLoad',
+ 'MyAutoLoader::autoLoad',
+ 'MyAutoLoader::dynaLoad',
+ array('MyAutoLoader', 'autoLoad'),
+ array('MyAutoLoader', 'dynaLoad'),
+ array($obj, 'autoLoad'),
+ array($obj, 'dynaLoad'),
+);
+
+foreach($funcs as $idx => $func)
+{
+ echo "====$idx====\n";
+
+ try
+ {
+ var_dump($func);
+ spl_autoload_register($func);
+ if (count(spl_autoload_functions()))
+ {
+ echo "registered\n";
+
+ var_dump(class_exists("NoExistingTestClass", true));
+ }
+ }
+ catch (Exception $e)
+ {
+ echo get_class($e) . ": " . $e->getMessage() . "\n";
+ }
+
+ spl_autoload_unregister($func);
+ var_dump(count(spl_autoload_functions()));
+}
+
+?>
+===DONE===
+<?php exit(0); ?>
+--EXPECTF--
+====0====
+string(10) "MyAutoLoad"
+registered
+MyAutoLoad(NoExistingTestClass)
+Exception: Bla
+int(0)
+====1====
+string(22) "MyAutoLoader::autoLoad"
+registered
+MyAutoLoader::autoLoad(NoExistingTestClass)
+Exception: Bla
+int(0)
+====2====
+string(22) "MyAutoLoader::dynaLoad"
+LogicException: Function 'MyAutoLoader::dynaLoad' not callable
+int(0)
+====3====
+array(2) {
+ [0]=>
+ string(12) "MyAutoLoader"
+ [1]=>
+ string(8) "autoLoad"
+}
+registered
+MyAutoLoader::autoLoad(NoExistingTestClass)
+Exception: Bla
+int(0)
+====4====
+array(2) {
+ [0]=>
+ string(12) "MyAutoLoader"
+ [1]=>
+ string(8) "dynaLoad"
+}
+LogicException: Passed array specifies a non static method but no object
+int(0)
+====5====
+array(2) {
+ [0]=>
+ object(MyAutoLoader)#%d (0) {
+ }
+ [1]=>
+ string(8) "autoLoad"
+}
+registered
+MyAutoLoader::autoLoad(NoExistingTestClass)
+Exception: Bla
+int(0)
+====6====
+array(2) {
+ [0]=>
+ object(MyAutoLoader)#%d (0) {
+ }
+ [1]=>
+ string(8) "dynaLoad"
+}
+registered
+MyAutoLoader::dynaLoad(NoExistingTestClass)
+Exception: Bla
+int(0)
+===DONE===
diff --git a/ext/spl/tests/sxe_005.phpt b/ext/spl/tests/sxe_005.phpt new file mode 100755 index 000000000..2efd0a6be --- /dev/null +++ b/ext/spl/tests/sxe_005.phpt @@ -0,0 +1,46 @@ +--TEST-- +SPL: SimpleXMLIterator and getChildren() +--SKIPIF-- +<?php +if (!extension_loaded("spl")) print "skip"; +if (!extension_loaded('simplexml')) print 'skip'; +if (!extension_loaded("libxml")) print "skip LibXML not present"; +if (!class_exists('RecursiveIteratorIterator')) print 'skip RecursiveIteratorIterator not available'; +?> +--FILE-- +<?php + +$xml =<<<EOF +<?xml version='1.0'?> +<sxe> + <elem1/> + <elem2/> + <elem2/> +</sxe> +EOF; + +class SXETest extends SimpleXMLIterator +{ + function count() + { + echo __METHOD__ . "\n"; + return parent::count(); + } +} + +$sxe = new SXETest($xml); + +var_dump(count($sxe)); +var_dump(count($sxe->elem1)); +var_dump(count($sxe->elem2)); + +?> +===DONE=== +--EXPECT-- +SXETest::count +int(3) +SXETest::count +int(1) +SXETest::count +int(2) +===DONE=== |
