diff options
| author | Mark A. Hershberger <mah@debian.(none)> | 2009-03-25 00:36:21 -0400 |
|---|---|---|
| committer | Mark A. Hershberger <mah@debian.(none)> | 2009-03-25 00:36:21 -0400 |
| commit | d29a4fd2dd3b5d4cf6e80b602544d7b71d794e76 (patch) | |
| tree | b38e2e5c6974b9a15f103e5cf884cba9fff90ef4 /ext/spl/tests | |
| parent | a88a88d0986a4a32288c102cdbfebd78d7e91d99 (diff) | |
| download | php-d29a4fd2dd3b5d4cf6e80b602544d7b71d794e76.tar.gz | |
Imported Upstream version 5.2.0upstream/5.2.0
Diffstat (limited to 'ext/spl/tests')
35 files changed, 2759 insertions, 28 deletions
diff --git a/ext/spl/tests/array_013.phpt b/ext/spl/tests/array_013.phpt index 6d74bcb41..905b8339c 100755 --- a/ext/spl/tests/array_013.phpt +++ b/ext/spl/tests/array_013.phpt @@ -78,4 +78,4 @@ one=>1 two=>2 ===Append=== -Fatal error: ArrayIterator::append(): Cannot append properties to objects, use ArrayIterator::offsetSet() instead in %sarray_013.php on line %d +Catchable fatal error: ArrayIterator::append(): Cannot append properties to objects, use ArrayIterator::offsetSet() instead in %sarray_013.php on line %d diff --git a/ext/spl/tests/array_019.phpt b/ext/spl/tests/array_019.phpt index 1416d8407..43d53b127 100755 --- a/ext/spl/tests/array_019.phpt +++ b/ext/spl/tests/array_019.phpt @@ -28,5 +28,5 @@ int(1) int(2) int(3) int(4) -int(5) -===DONE=== + +Fatal error: An iterator cannot be used with foreach by reference in %sarray_019.php on line %d diff --git a/ext/spl/tests/array_021.phpt b/ext/spl/tests/array_021.phpt index f2ae0c87e..b38cedf0c 100755 --- a/ext/spl/tests/array_021.phpt +++ b/ext/spl/tests/array_021.phpt @@ -1,5 +1,7 @@ --TEST-- SPL: ArrayObject::seek() and exceptions +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> --FILE-- <?php diff --git a/ext/spl/tests/array_022.phpt b/ext/spl/tests/array_022.phpt index d1eafd677..9cb2193f1 100755 --- a/ext/spl/tests/array_022.phpt +++ b/ext/spl/tests/array_022.phpt @@ -1,5 +1,7 @@ --TEST-- SPL: ArrayObject/Iterator and reference to self +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> --FILE-- ==ArrayObject=== <?php @@ -68,27 +70,3 @@ object(MyArrayIterator)#%d (2) { 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/bug36941.phpt b/ext/spl/tests/bug36941.phpt index 528ba4a46..2ae03b448 100755 --- a/ext/spl/tests/bug36941.phpt +++ b/ext/spl/tests/bug36941.phpt @@ -1,5 +1,7 @@ --TEST-- Bug #36941 (ArrayIterator does not clone itself) +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> --FILE-- ===ArrayObject=== <?php diff --git a/ext/spl/tests/bug37457.phpt b/ext/spl/tests/bug37457.phpt new file mode 100755 index 000000000..4395287bc --- /dev/null +++ b/ext/spl/tests/bug37457.phpt @@ -0,0 +1,82 @@ +--TEST-- +Bug #37457 (Crash when an exception is thrown in accept() method of FilterIterator) +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +class Collection implements Iterator +{ + protected $array, $valid = false; + + public function __construct(array $a) + { + echo __METHOD__ . "\n"; + $this->array = $a; + } + + public function current() + { + echo __METHOD__ . "\n"; + return current($this->array); + } + + public function key() + { + echo __METHOD__ . "\n"; + return key($this->array); + } + + public function next() + { + echo __METHOD__ . "\n"; + $this->valid = (false !== next($this->array)); + } + + public function valid() + { + echo __METHOD__ . "\n"; + return $this->valid; + } + + public function rewind() + { + echo __METHOD__ . "\n"; + $this->valid = (false !== reset($this->array)); + } +} + +class TestFilter extends FilterIterator +{ + public function accept() + { + echo __METHOD__ . "\n"; + throw new Exception("Failure in Accept"); + } +} + +$test = new TestFilter(new Collection(array(0))); + +try +{ + foreach ($test as $item) + { + echo $item; + } +} +catch (Exception $e) +{ + var_dump($e->getMessage()); +} + +?> +===DONE=== +--EXPECTF-- +Collection::__construct +Collection::rewind +Collection::valid +Collection::current +Collection::key +TestFilter::accept +string(17) "Failure in Accept" +===DONE=== diff --git a/ext/spl/tests/fileobject_003.phpt b/ext/spl/tests/fileobject_003.phpt new file mode 100755 index 000000000..74f2002d0 --- /dev/null +++ b/ext/spl/tests/fileobject_003.phpt @@ -0,0 +1,89 @@ +--TEST-- +SPL: SplFileInfo cloning +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +function test($name, $lc, $lp) +{ + static $i = 0; + echo "===$i===\n"; + $i++; + + $o = new SplFileInfo($name); + + var_dump($o); + $c = clone $o; + var_dump($c); + var_dump($o === $c); + var_dump($o == $c); + var_dump($o->getPathname() == $c->getPathname()); + + $f = new SplFileObject($name); + var_dump($name); + var_dump($f->getPathName()); + $l = substr($f->getPathName(), -1); + var_dump($l != '/' && $l != '\\' && $l == $lc); + var_dump($f->getFileName()); + $l = substr($f->getFileName(), -1); + var_dump($l != '/' && $l != '\\' && $l == $lc); + var_dump($f->getPath()); + $l = substr($f->getPath(), -1); + var_dump($l != '/' && $l != '\\' && $l == $lp); +} + +test(dirname(__FILE__) . '/' . 'fileobject_001a.txt', 't', substr(dirname(__FILE__),-1)); +test(dirname(__FILE__) . '/', substr(dirname(__FILE__),-1), 'l'); +test(dirname(__FILE__), substr(dirname(__FILE__),-1), 'l'); + +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +===0=== +object(SplFileInfo)#%d (0) { +} +object(SplFileInfo)#%d (0) { +} +bool(false) +bool(true) +bool(true) +string(%d) "%sfileobject_001a.txt" +string(%d) "%sfileobject_001a.txt" +bool(true) +string(%d) "%sfileobject_001a.txt" +bool(true) +string(%d) "%stests" +bool(true) +===1=== +object(SplFileInfo)#%d (0) { +} +object(SplFileInfo)#%d (0) { +} +bool(false) +bool(true) +bool(true) +string(%d) "%stests/" +string(%d) "%stests" +bool(true) +string(%d) "%stests" +bool(true) +string(%d) "%sspl" +bool(true) +===2=== +object(SplFileInfo)#1 (0) { +} +object(SplFileInfo)#2 (0) { +} +bool(false) +bool(true) +bool(true) +string(%d) "%stests" +string(%d) "%stests" +bool(true) +string(%d) "%stests" +bool(true) +string(%d) "%sspl" +bool(true) +===DONE=== diff --git a/ext/spl/tests/iterator_027.phpt b/ext/spl/tests/iterator_027.phpt new file mode 100755 index 000000000..601515e8f --- /dev/null +++ b/ext/spl/tests/iterator_027.phpt @@ -0,0 +1,85 @@ +--TEST-- +SPL: CachingIterator::FULL_CACHE +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +$ar = array(1, 2, array(31, 32, array(331)), 4); + +$it = new RecursiveArrayIterator($ar); +$it = new RecursiveIteratorIterator($it); +$it = new CachingIterator($it, CachingIterator::FULL_CACHE); + +foreach($it as $k=>$v) +{ + echo "$k=>$v\n"; +} + +echo "===CHECK===\n"; + +for ($i = 0; $i < 4; $i++) +{ + if (isset($it[$i])) + { + var_dump($i, $it[$i]); + } +} + +$it[2] = 'foo'; +$it[3] = 'bar'; +$it['baz'] = '25'; + +var_dump($it[2]); +var_dump($it[3]); +var_dump($it['baz']); + +unset($it[0]); +unset($it[2]); +unset($it['baz']); + +var_dump(isset($it[0])); // unset +var_dump(isset($it[1])); // still present +var_dump(isset($it[2])); // unset +var_dump(isset($it[3])); // still present +var_dump(isset($it['baz'])); + +echo "===REWIND===\n"; + +$it->rewind(); // cleans and reads first element +var_dump(isset($it[0])); // pre-fetched +var_dump(isset($it[1])); // deleted +var_dump(isset($it[2])); // unset +var_dump(isset($it[3])); // deleted + +?> +===DONE=== +<?php exit(0); ?> +--EXPECT-- +0=>1 +1=>2 +0=>31 +1=>32 +0=>331 +3=>4 +===CHECK=== +int(0) +int(331) +int(1) +int(32) +int(3) +int(4) +string(3) "foo" +string(3) "bar" +string(2) "25" +bool(false) +bool(true) +bool(false) +bool(true) +bool(false) +===REWIND=== +bool(true) +bool(false) +bool(false) +bool(false) +===DONE=== diff --git a/ext/spl/tests/iterator_029.phpt b/ext/spl/tests/iterator_029.phpt new file mode 100755 index 000000000..3e836adef --- /dev/null +++ b/ext/spl/tests/iterator_029.phpt @@ -0,0 +1,40 @@ +--TEST-- +SPL: RegexIterator +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +$ar = array(0, "123", 123, 22 => "abc", "a2b", 22, "a2d" => 7, 42); + +foreach(new RegexIterator(new ArrayIterator($ar), "/2/") as $k => $v) +{ + echo "$k=>$v\n"; +} + +?> +===KEY=== +<?php + +foreach(new RegexIterator(new ArrayIterator($ar), "/2/", 0, RegexIterator::USE_KEY) as $k => $v) +{ + echo "$k=>$v\n"; +} + +?> +===DONE=== +<?php exit(0); ?> +--EXPECT-- +1=>123 +2=>123 +23=>a2b +24=>22 +25=>42 +===KEY=== +2=>123 +22=>abc +23=>a2b +24=>22 +a2d=>7 +25=>42 +===DONE=== diff --git a/ext/spl/tests/iterator_035.phpt b/ext/spl/tests/iterator_035.phpt index eebc7f22a..9dfe35d5f 100644 --- a/ext/spl/tests/iterator_035.phpt +++ b/ext/spl/tests/iterator_035.phpt @@ -14,4 +14,4 @@ $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 +Fatal error: Cannot assign by reference to overloaded object in %s on line %d diff --git a/ext/spl/tests/iterator_036.phpt b/ext/spl/tests/iterator_036.phpt new file mode 100755 index 000000000..3eb0eefa6 --- /dev/null +++ b/ext/spl/tests/iterator_036.phpt @@ -0,0 +1,24 @@ +--TEST-- +SPL: CachingIterator and __toString and flags = 0 +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +function test($it) +{ + foreach($it as $v) + { + var_dump((string)$it); + } +} + +$ar = new ArrayIterator(array(1, 2, 3)); + +test(new CachingIterator($ar, 0)); + +?> +===DONE=== +--EXPECTF-- + +Fatal error: Method CachingIterator::__toString() must not throw an exception in %siterator_036.php on line %d diff --git a/ext/spl/tests/iterator_037.phpt b/ext/spl/tests/iterator_037.phpt new file mode 100755 index 000000000..be79468f3 --- /dev/null +++ b/ext/spl/tests/iterator_037.phpt @@ -0,0 +1,133 @@ +--TEST-- +SPL: CachingIterator and __toString +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +function test($ar, $flags) +{ + echo "===$flags===\n"; + $it = new CachingIterator($ar, 0); + try + { + $it->setFlags($flags); + } + catch (Exception $e) + { + echo 'Exception: ' . $e->getMessage() . "\n"; + var_dump($it->getFlags()); + return; + } + var_dump($it->getFlags()); + try + { + foreach($it as $v) + { + var_dump((string)$it); + } + } + catch (Exception $e) + { + echo 'Exception: ' . $e->getMessage() . "\n"; + } +} + +class MyItem +{ + function __construct($value) + { + $this->value = $value; + } + + function __toString() + { + return (string)$this->value; + } +} + +class MyArrayIterator extends ArrayIterator +{ + function __toString() + { + return $this->key() . ':' . $this->current(); + } +} + +$ar = new MyArrayIterator(array(1, 2, 3)); + +test($ar, CachingIterator::CALL_TOSTRING); +test($ar, CachingIterator::TOSTRING_USE_KEY); +test($ar, CachingIterator::TOSTRING_USE_CURRENT); + +$ar = new MyArrayIterator(array(new MyItem(1), new MyItem(2), new MyItem(3))); + +test($ar, CachingIterator::TOSTRING_USE_INNER); +test($ar, CachingIterator::CALL_TOSTRING | CachingIterator::TOSTRING_USE_KEY); +test($ar, CachingIterator::CALL_TOSTRING | CachingIterator::TOSTRING_USE_CURRENT); +test($ar, CachingIterator::CALL_TOSTRING | CachingIterator::TOSTRING_USE_INNER); +test($ar, CachingIterator::TOSTRING_USE_KEY | CachingIterator::TOSTRING_USE_CURRENT); +test($ar, CachingIterator::TOSTRING_USE_KEY | CachingIterator::TOSTRING_USE_INNER); + +echo "===X===\n"; +try +{ + $it = new CachingIterator($ar, CachingIterator::CALL_TOSTRING); + $it->setFlags(0); +} +catch (Exception $e) +{ + echo 'Exception: ' . $e->getMessage() . "\n"; +} +try +{ + $it = new CachingIterator($ar, CachingIterator::TOSTRING_USE_INNER); + $it->setFlags(0); +} +catch (Exception $e) +{ + echo 'Exception: ' . $e->getMessage() . "\n"; +} + +?> +===DONE=== +--EXPECTF-- +===1=== +int(1) +string(1) "1" +string(1) "2" +string(1) "3" +===2=== +int(2) +string(1) "0" +string(1) "1" +string(1) "2" +===4=== +int(4) +string(1) "1" +string(1) "2" +string(1) "3" +===8=== +int(8) +string(3) "0:1" +string(3) "1:2" +string(3) "2:3" +===3=== +Exception: Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER +int(0) +===5=== +Exception: Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER +int(0) +===9=== +Exception: Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER +int(0) +===6=== +Exception: Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER +int(0) +===10=== +Exception: Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER +int(0) +===X=== +Exception: Unsetting flag CALL_TO_STRING is not possible +Exception: Unsetting flag TOSTRING_USE_INNER is not possible +===DONE=== diff --git a/ext/spl/tests/iterator_038.phpt b/ext/spl/tests/iterator_038.phpt new file mode 100755 index 000000000..71f911c57 --- /dev/null +++ b/ext/spl/tests/iterator_038.phpt @@ -0,0 +1,21 @@ +--TEST-- +SPL: RoRewindIterator and string keys +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +foreach(new NoRewindIterator(new ArrayIterator(array('Hello'=>0, 'World'=>1))) as $k => $v) +{ + var_dump($v); + var_dump($k); +} + +?> +===DONE=== +--EXPECT-- +int(0) +string(5) "Hello" +int(1) +string(5) "World" +===DONE=== diff --git a/ext/spl/tests/iterator_039.phpt b/ext/spl/tests/iterator_039.phpt new file mode 100755 index 000000000..5dcaaa226 --- /dev/null +++ b/ext/spl/tests/iterator_039.phpt @@ -0,0 +1,123 @@ +--TEST-- +SPL: LimitIterator and backward seeking +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +class NumericArrayIterator implements Iterator +{ + protected $a; + protected $i = 0; + + public function __construct($a) + { + echo __METHOD__ . "\n"; + $this->a = $a; + } + + public function valid() + { + echo __METHOD__ . "\n"; + return $this->i < count($this->a); + } + + public function rewind() + { + echo __METHOD__ . "\n"; + $this->i = 0; + } + + public function key() + { + echo __METHOD__ . "\n"; + return $this->i; + } + + public function current() + { + echo __METHOD__ . "\n"; + return $this->a[$this->i]; + } + + public function next() + { + echo __METHOD__ . "\n"; + $this->i++; + } +} + +$it = new LimitIterator(new NumericArrayIterator(array(12, 25, 42, 56))); + +foreach($it as $k => $v) +{ + var_dump($k); + var_dump($v); +} + +echo "===SEEK===\n"; + +$it->seek(2); + +echo "===LOOP===\n"; + +foreach(new NoRewindIterator($it) as $k => $v) +{ + var_dump($k); + var_dump($v); +} + +?> +===DONE=== +<?php exit(0); ?> +--EXPECT-- +NumericArrayIterator::__construct +NumericArrayIterator::rewind +NumericArrayIterator::valid +NumericArrayIterator::valid +NumericArrayIterator::current +NumericArrayIterator::key +int(0) +int(12) +NumericArrayIterator::next +NumericArrayIterator::valid +NumericArrayIterator::current +NumericArrayIterator::key +int(1) +int(25) +NumericArrayIterator::next +NumericArrayIterator::valid +NumericArrayIterator::current +NumericArrayIterator::key +int(2) +int(42) +NumericArrayIterator::next +NumericArrayIterator::valid +NumericArrayIterator::current +NumericArrayIterator::key +int(3) +int(56) +NumericArrayIterator::next +NumericArrayIterator::valid +===SEEK=== +NumericArrayIterator::rewind +NumericArrayIterator::valid +NumericArrayIterator::next +NumericArrayIterator::valid +NumericArrayIterator::next +NumericArrayIterator::valid +NumericArrayIterator::valid +NumericArrayIterator::current +NumericArrayIterator::key +===LOOP=== +int(2) +int(42) +NumericArrayIterator::next +NumericArrayIterator::valid +NumericArrayIterator::current +NumericArrayIterator::key +int(3) +int(56) +NumericArrayIterator::next +NumericArrayIterator::valid +===DONE=== diff --git a/ext/spl/tests/iterator_040.phpt b/ext/spl/tests/iterator_040.phpt new file mode 100755 index 000000000..a162cac68 --- /dev/null +++ b/ext/spl/tests/iterator_040.phpt @@ -0,0 +1,49 @@ +--TEST-- +SPL: RecursiveFilterIterator +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +class MyRecursiveFilterIterator extends RecursiveFilterIterator +{ + function accept() + { + return true; + } +} + +$ar = array(1, array(21, 22), 3); +$it = new RecursiveArrayIterator($ar); +$it = new MyRecursiveFilterIterator($it); +$it = new RecursiveIteratorIterator($it); + +foreach($it as $k => $v) +{ + echo "===\n"; + var_dump($it->getDepth()); + var_dump($k); + var_dump($v); +} + +?> +===DONE=== +<?php exit(0); ?> +--EXPECT-- +=== +int(0) +int(0) +int(1) +=== +int(1) +int(0) +int(21) +=== +int(1) +int(1) +int(22) +=== +int(0) +int(2) +int(3) +===DONE=== diff --git a/ext/spl/tests/iterator_041.phpt b/ext/spl/tests/iterator_041.phpt new file mode 100755 index 000000000..af42b1cde --- /dev/null +++ b/ext/spl/tests/iterator_041.phpt @@ -0,0 +1,119 @@ +--TEST-- +SPL: iterator_to_array() and exceptions +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +class MyArrayIterator extends ArrayIterator +{ + static protected $fail = 0; + public $state; + + static function fail($state, $method) + { + if (self::$fail == $state) + { + throw new Exception("State $state: $method()"); + } + } + + function __construct() + { + $this->state = MyArrayIterator::$fail; + self::fail(0, __FUNCTION__); + parent::__construct(array(1, 2)); + self::fail(1, __FUNCTION__); + } + + function rewind() + { + self::fail(2, __FUNCTION__); + return parent::rewind(); + } + + function valid() + { + self::fail(3, __FUNCTION__); + return parent::valid(); + } + + function current() + { + self::fail(4, __FUNCTION__); + return parent::current(); + } + + function key() + { + self::fail(5, __FUNCTION__); + return parent::key(); + } + + function next() + { + self::fail(6, __FUNCTION__); + return parent::next(); + } + + function __destruct() + { +// self::fail(7, __FUNCTION__); + } + + static function test($func, $skip = null) + { + echo "===$func===\n"; + self::$fail = 0; + while(self::$fail < 10) + { + try + { + var_dump($func(new MyArrayIterator())); + break; + } + catch (Exception $e) + { + echo $e->getMessage() . "\n"; + } + if (isset($skip[self::$fail])) + { + self::$fail = $skip[self::$fail]; + } + else + { + self::$fail++; + } + } + } +} + +MyArrayIterator::test('iterator_to_array'); +MyArrayIterator::test('iterator_count', array(3 => 6)); + +?> +===DONE=== +<?php exit(0); ?> +--EXPECT-- +===iterator_to_array=== +State 0: __construct() +State 1: __construct() +State 2: rewind() +State 3: valid() +State 4: current() +State 5: key() +State 6: next() +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +===iterator_count=== +State 0: __construct() +State 1: __construct() +State 2: rewind() +State 3: valid() +State 6: next() +int(2) +===DONE=== diff --git a/ext/spl/tests/iterator_041a.phpt b/ext/spl/tests/iterator_041a.phpt new file mode 100755 index 000000000..d03cbba9d --- /dev/null +++ b/ext/spl/tests/iterator_041a.phpt @@ -0,0 +1,109 @@ +--TEST-- +SPL: iterator_to_array() and exceptions from destruct +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +class MyArrayIterator extends ArrayIterator +{ + static protected $fail = 0; + public $state; + + static function fail($state, $method) + { + if (self::$fail == $state) + { + throw new Exception("State $state: $method()"); + } + } + + function __construct() + { + $this->state = MyArrayIterator::$fail; + self::fail(0, __FUNCTION__); + parent::__construct(array(1, 2)); + self::fail(1, __FUNCTION__); + } + + function rewind() + { + self::fail(2, __FUNCTION__); + return parent::rewind(); + } + + function valid() + { + self::fail(3, __FUNCTION__); + return parent::valid(); + } + + function current() + { + self::fail(4, __FUNCTION__); + return parent::current(); + } + + function key() + { + self::fail(5, __FUNCTION__); + return parent::key(); + } + + function next() + { + self::fail(6, __FUNCTION__); + return parent::next(); + } + + function __destruct() + { + self::fail(7, __FUNCTION__); + } + + static function test($func, $skip = null) + { + echo "===$func===\n"; + self::$fail = 7; + while(self::$fail < 10) + { + try + { + var_dump($func(new MyArrayIterator())); + break; + } + catch (Exception $e) + { + echo $e->getMessage() . "\n"; + } + if (isset($skip[self::$fail])) + { + self::$fail = $skip[self::$fail]; + } + else + { + self::$fail++; + } + } + } +} + +MyArrayIterator::test('iterator_to_array'); +MyArrayIterator::test('iterator_count', array(3 => 6)); + +?> +===DONE=== +<?php exit(0); ?> +--EXPECT-- +===iterator_to_array=== +State 7: __destruct() +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +===iterator_count=== +State 7: __destruct() +int(2) +===DONE=== diff --git a/ext/spl/tests/iterator_041b.phpt b/ext/spl/tests/iterator_041b.phpt new file mode 100755 index 000000000..9afb93526 --- /dev/null +++ b/ext/spl/tests/iterator_041b.phpt @@ -0,0 +1,107 @@ +--TEST-- +SPL: iterator_to_array() and exceptions from delayed destruct +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +class MyArrayIterator extends ArrayIterator +{ + static protected $fail = 0; + public $state; + + static function fail($state, $method) + { + if (self::$fail == $state) + { + throw new Exception("State $state: $method()"); + } + } + + function __construct() + { + $this->state = MyArrayIterator::$fail; + self::fail(0, __FUNCTION__); + parent::__construct(array(1, 2)); + self::fail(1, __FUNCTION__); + } + + function rewind() + { + self::fail(2, __FUNCTION__); + return parent::rewind(); + } + + function valid() + { + self::fail(3, __FUNCTION__); + return parent::valid(); + } + + function current() + { + self::fail(4, __FUNCTION__); + return parent::current(); + } + + function key() + { + self::fail(5, __FUNCTION__); + return parent::key(); + } + + function next() + { + self::fail(6, __FUNCTION__); + return parent::next(); + } + + function __destruct() + { + self::fail(7, __FUNCTION__); + } + + static function test($func, $skip = null) + { + echo "===$func===\n"; + self::$fail = 0; + while(self::$fail < 10) + { + try + { + var_dump($func(new MyArrayIterator())); + break; + } + catch (Exception $e) + { + echo $e->getMessage() . "\n"; + } + if (isset($skip[self::$fail])) + { + self::$fail = $skip[self::$fail]; + } + else + { + self::$fail++; + } + } + } +} + +MyArrayIterator::test('iterator_to_array'); +MyArrayIterator::test('iterator_count', array(3 => 6)); + +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +===iterator_to_array=== +State 0: __construct() +State 1: __construct() +State 2: rewind() +State 3: valid() +State 4: current() +State 5: key() +State 6: next() + +Fatal error: Ignoring exception from MyArrayIterator::__destruct() while an exception is already active (Uncaught Exception in %s on line %d) in %siterator_041b.php on line %d diff --git a/ext/spl/tests/iterator_042.phpt b/ext/spl/tests/iterator_042.phpt new file mode 100755 index 000000000..861545065 --- /dev/null +++ b/ext/spl/tests/iterator_042.phpt @@ -0,0 +1,104 @@ +--TEST-- +SPL: AppendIterator and its ArrayIterator +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +function test_error_handler($errno, $msg, $filename, $linenum, $vars) +{ + echo "Error $msg in $filename on line $linenum\n"; + return true; +} + +set_error_handler('test_error_handler'); + +$it = new AppendIterator; + +$it->append(array()); +$it->append(new ArrayIterator(array(1))); +$it->append(new ArrayIterator(array(21, 22))); + +var_dump($it->getArrayIterator()); + +$it->append(new ArrayIterator(array(31, 32, 33))); + +var_dump($it->getArrayIterator()); + +$idx = 0; + +foreach($it as $k => $v) +{ + echo '===' . $idx++ . "===\n"; + var_dump($it->getIteratorIndex()); + var_dump($k); + var_dump($v); +} + +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +Error Argument 1 passed to AppendIterator::append() must implement interface Iterator, array given in %siterator_042.php on line %d +object(ArrayIterator)#%d (2) { + [0]=> + object(ArrayIterator)#%d (1) { + [0]=> + int(1) + } + [1]=> + object(ArrayIterator)#%d (2) { + [0]=> + int(21) + [1]=> + int(22) + } +} +object(ArrayIterator)#%d (3) { + [0]=> + object(ArrayIterator)#%d (1) { + [0]=> + int(1) + } + [1]=> + object(ArrayIterator)#%d (2) { + [0]=> + int(21) + [1]=> + int(22) + } + [2]=> + object(ArrayIterator)#5 (3) { + [0]=> + int(31) + [1]=> + int(32) + [2]=> + int(33) + } +} +===0=== +int(0) +int(0) +int(1) +===1=== +int(1) +int(0) +int(21) +===2=== +int(1) +int(1) +int(22) +===3=== +int(2) +int(0) +int(31) +===4=== +int(2) +int(1) +int(32) +===5=== +int(2) +int(2) +int(33) +===DONE=== diff --git a/ext/spl/tests/iterator_043.phpt b/ext/spl/tests/iterator_043.phpt new file mode 100755 index 000000000..c49e33473 --- /dev/null +++ b/ext/spl/tests/iterator_043.phpt @@ -0,0 +1,20 @@ +--TEST-- +SPL: RecursiveCachingIterator and uninitialized getChildren() +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +$it = new RecursiveCachingIterator(new RecursiveArrayIterator(array(1,2))); + +var_dump($it->getChildren()); +$it->rewind(); +var_dump($it->getChildren()); + +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +NULL +NULL +===DONE=== diff --git a/ext/spl/tests/iterator_044.phpt b/ext/spl/tests/iterator_044.phpt new file mode 100755 index 000000000..e25e0d1dd --- /dev/null +++ b/ext/spl/tests/iterator_044.phpt @@ -0,0 +1,169 @@ +--TEST-- +SPL: CachingIterator and offsetGet/Exists using flag FULL_CACHE +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +class MyFoo +{ + function __toString() + { + return 'foo'; + } +} + +class MyCachingIterator extends CachingIterator +{ + function __construct(Iterator $it, $flags = 0) + { + parent::__construct($it, $flags); + } + + function test($ar) + { + foreach($ar as $k => $v) + { + echo "===$k===\n"; + var_dump($v); + var_dump($this->offsetExists($v)); + var_dump($this->offsetGet($v)); + } + } +} + +$it = new MyCachingIterator(new ArrayIterator(array(0, 'foo'=>1, 2, 'bar'=>3, 4))); + +try +{ + var_dump($it->offsetExists(0)); +} +catch(Exception $e) +{ + echo "Exception: " . $e->getMessage() . "\n"; +} + +try +{ + var_dump($it->offsetGet(0)); +} +catch(Exception $e) +{ + echo "Exception: " . $e->getMessage() . "\n"; +} + +$it = new MyCachingIterator(new ArrayIterator(array(0, 'foo'=>1, 2, 'bar'=>3, 4)), CachingIterator::FULL_CACHE); + +var_dump($it->offsetExists()); +var_dump($it->offsetGet()); + +$checks = array(0, new stdClass, new MyFoo, NULL, 2, 'foo', 3); + +$it->test($checks); + +echo "===FILL===\n"; + +foreach($it as $v); // read all into cache + +$it->test($checks); + +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +Exception: MyCachingIterator does not use a full cache (see CachingIterator::__construct) + +Notice: Undefined index: 0 in %siterator_044.php on line %d +Exception: MyCachingIterator does not use a full cache (see CachingIterator::__construct) + +Warning: CachingIterator::offsetExists() expects exactly 1 parameter, 0 given in %s/iterator_044.php on line %d +NULL + +Warning: CachingIterator::offsetGet() expects exactly 1 parameter, 0 given in %s/iterator_044.php on line %d +NULL +===0=== +int(0) +bool(false) + +Notice: Undefined index: 0 in %siterator_044.php on line %d +NULL +===1=== +object(stdClass)#%d (0) { +} + +Warning: CachingIterator::offsetExists() expects parameter 1 to be string, object given in %siterator_044.php on line %d +NULL + +Warning: CachingIterator::offsetGet() expects parameter 1 to be string, object given in %siterator_044.php on line %d +NULL +===2=== +object(MyFoo)#%d (0) { +} +bool(false) + +Notice: Undefined index: foo in %siterator_044.php on line %d +NULL +===3=== +NULL +bool(false) + +Notice: Undefined index: in %siterator_044.php on line %d +NULL +===4=== +int(2) +bool(false) + +Notice: Undefined index: 2 in %siterator_044.php on line %d +NULL +===5=== +string(3) "foo" +bool(false) + +Notice: Undefined index: foo in %siterator_044.php on line %d +NULL +===6=== +int(3) +bool(false) + +Notice: Undefined index: 3 in %siterator_044.php on line %d +NULL +===FILL=== +===0=== +int(0) +bool(true) +int(0) +===1=== +object(stdClass)#1 (0) { +} + +Warning: CachingIterator::offsetExists() expects parameter 1 to be string, object given in %siterator_044.php on line %d +NULL + +Warning: CachingIterator::offsetGet() expects parameter 1 to be string, object given in %siterator_044.php on line %d +NULL +===2=== +object(MyFoo)#2 (0) { +} +bool(true) +int(1) +===3=== +NULL +bool(false) + +Notice: Undefined index: in %siterator_044.php on line %d +NULL +===4=== +int(2) +bool(true) +int(4) +===5=== +string(3) "foo" +bool(true) +int(1) +===6=== +int(3) +bool(false) + +Notice: Undefined index: 3 in %siterator_044.php on line %d +NULL +===DONE=== diff --git a/ext/spl/tests/iterator_045.phpt b/ext/spl/tests/iterator_045.phpt new file mode 100755 index 000000000..ce29349cf --- /dev/null +++ b/ext/spl/tests/iterator_045.phpt @@ -0,0 +1,171 @@ +--TEST-- +SPL: CachingIterator and offsetSet/Unset, getCache using flag FULL_CACHE +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +class MyFoo +{ + function __toString() + { + return 'foo'; + } +} + +class MyCachingIterator extends CachingIterator +{ + function __construct(Iterator $it, $flags = 0) + { + parent::__construct($it, $flags); + } + + function testSet($ar) + { + echo __METHOD__ . "()\n"; + foreach($ar as $k => $v) + { + echo "set($k,$v)\n"; + $this->offsetSet($k, $v); + } + } + + function testUnset($ar) + { + echo __METHOD__ . "()\n"; + foreach($ar as $k => $v) + { + echo "unset($v)\n"; + $this->offsetUnset($v); + } + } + + function fill() + { + echo __METHOD__ . "()\n"; + foreach($this as $v) ; + } + + function show() + { + echo __METHOD__ . "()\n"; + var_dump($this->getCache()); + } +} + +$it = new MyCachingIterator(new ArrayIterator(array(0, 'foo'=>1, 2, 'bar'=>3, 4))); + +try +{ + var_dump($it->offsetSet(0, 0)); +} +catch(Exception $e) +{ + echo "Exception: " . $e->getMessage() . "\n"; +} + +try +{ + var_dump($it->offsetUnset(0)); +} +catch(Exception $e) +{ + echo "Exception: " . $e->getMessage() . "\n"; +} + +$it = new MyCachingIterator(new ArrayIterator(array(0, 1, 2, 3)), CachingIterator::FULL_CACHE); + +var_dump($it->offsetSet()); +var_dump($it->offsetSet(0)); +var_dump($it->offsetUnset()); + +$checks = array(0 => 25, 1 => 42, 3 => 'FooBar'); +$unsets = array(0, 2); + +$it->testSet($checks); +$it->show(); +$it->testUnset($unsets); +$it->show(); +$it->fill(); +$it->show(); +$it->testSet($checks); +$it->show(); +$it->testUnset($unsets); +$it->show(); + +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +Exception: MyCachingIterator does not use a full cache (see CachingIterator::__construct) +Exception: MyCachingIterator does not use a full cache (see CachingIterator::__construct) + +Warning: CachingIterator::offsetSet() expects exactly 2 parameters, 0 given in %siterator_045.php on line %d +NULL + +Warning: CachingIterator::offsetSet() expects exactly 2 parameters, 1 given in %siterator_045.php on line %d +NULL + +Warning: CachingIterator::offsetUnset() expects exactly 1 parameter, 0 given in %siterator_045.php on line %d +NULL +MyCachingIterator::testSet() +set(0,25) +set(1,42) +set(3,FooBar) +MyCachingIterator::show() +array(3) { + [0]=> + int(25) + [1]=> + int(42) + [3]=> + string(6) "FooBar" +} +MyCachingIterator::testUnset() +unset(0) +unset(2) +MyCachingIterator::show() +array(2) { + [1]=> + int(42) + [3]=> + string(6) "FooBar" +} +MyCachingIterator::fill() +MyCachingIterator::show() +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) +} +MyCachingIterator::testSet() +set(0,25) +set(1,42) +set(3,FooBar) +MyCachingIterator::show() +array(4) { + [0]=> + int(25) + [1]=> + int(42) + [2]=> + int(2) + [3]=> + string(6) "FooBar" +} +MyCachingIterator::testUnset() +unset(0) +unset(2) +MyCachingIterator::show() +array(2) { + [1]=> + int(42) + [3]=> + string(6) "FooBar" +} +===DONE=== diff --git a/ext/spl/tests/iterator_046.phpt b/ext/spl/tests/iterator_046.phpt new file mode 100755 index 000000000..34d9c027b --- /dev/null +++ b/ext/spl/tests/iterator_046.phpt @@ -0,0 +1,53 @@ +--TEST-- +SPL: CachingIterator and __toString using bypassed string keys +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +class MyFoo +{ + function __toString() + { + return 'foo'; + } +} + +class MyCachingIterator extends CachingIterator +{ + function __construct(Iterator $it, $flags = 0) + { + parent::__construct($it, $flags); + } + + function fill() + { + echo __METHOD__ . "()\n"; + foreach($this as $v) ; + } + + function show() + { + echo __METHOD__ . "()\n"; + foreach($this as $v) + { + var_dump((string)$this); + } + } +} + +$it = new MyCachingIterator(new ArrayIterator(array(0, 'foo'=>1, 'bar'=>2)), CachingIterator::TOSTRING_USE_KEY); + +$it->fill(); +$it->show(); + +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +MyCachingIterator::fill() +MyCachingIterator::show() +string(1) "0" +string(3) "foo" +string(3) "bar" +===DONE=== diff --git a/ext/spl/tests/iterator_047.phpt b/ext/spl/tests/iterator_047.phpt new file mode 100755 index 000000000..b313df301 --- /dev/null +++ b/ext/spl/tests/iterator_047.phpt @@ -0,0 +1,119 @@ +--TEST-- +SPL: RecursiveCachingIterator and exception in has/getChildren +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +class MyRecursiveArrayIterator extends RecursiveArrayIterator +{ + static public $fail = 0; + + static function fail($state, $method) + { + if (self::$fail == $state) + { + throw new Exception("State $state: $method()"); + } + } + + function hasChildren() + { + echo __METHOD__ . "()\n"; + self::fail(1, __METHOD__); + return parent::hasChildren(); + } + + function getChildren() + { + echo __METHOD__ . "()\n"; + self::fail(2, __METHOD__); + return parent::getChildren(); + } +} + +class MyRecursiveCachingIterator extends RecursiveCachingIterator +{ + function show() + { + MyRecursiveArrayIterator::$fail = 0; + while(MyRecursiveArrayIterator::$fail < 4) + { + echo "===" . MyRecursiveArrayIterator::$fail . "===\n"; + try + { + foreach(new RecursiveIteratorIterator($this) as $k => $v) + { + var_dump($k); + var_dump($v); + } + } + catch (Exception $e) + { + echo "Exception: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . "\n"; + } + MyRecursiveArrayIterator::$fail++; + } + } +} + +$it = new MyRecursiveArrayIterator(array(0, array(10), 2, array(30), 4)); +$it = new MyRecursiveCachingIterator($it); + +$it->show(); + +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +===0=== +MyRecursiveArrayIterator::hasChildren() +int(0) +int(0) +MyRecursiveArrayIterator::hasChildren() +MyRecursiveArrayIterator::getChildren() +MyRecursiveArrayIterator::hasChildren() +int(0) +int(10) +MyRecursiveArrayIterator::hasChildren() +int(2) +int(2) +MyRecursiveArrayIterator::hasChildren() +MyRecursiveArrayIterator::getChildren() +MyRecursiveArrayIterator::hasChildren() +int(0) +int(30) +MyRecursiveArrayIterator::hasChildren() +int(4) +int(4) +===1=== +MyRecursiveArrayIterator::hasChildren() +Exception: State 1: MyRecursiveArrayIterator::hasChildren() in %siterator_047.php on line %d +===2=== +MyRecursiveArrayIterator::hasChildren() +int(0) +int(0) +MyRecursiveArrayIterator::hasChildren() +MyRecursiveArrayIterator::getChildren() +Exception: State 2: MyRecursiveArrayIterator::getChildren() in %siterator_047.php on line %d +===3=== +MyRecursiveArrayIterator::hasChildren() +int(0) +int(0) +MyRecursiveArrayIterator::hasChildren() +MyRecursiveArrayIterator::getChildren() +MyRecursiveArrayIterator::hasChildren() +int(0) +int(10) +MyRecursiveArrayIterator::hasChildren() +int(2) +int(2) +MyRecursiveArrayIterator::hasChildren() +MyRecursiveArrayIterator::getChildren() +MyRecursiveArrayIterator::hasChildren() +int(0) +int(30) +MyRecursiveArrayIterator::hasChildren() +int(4) +int(4) +===DONE=== diff --git a/ext/spl/tests/iterator_048.phpt b/ext/spl/tests/iterator_048.phpt new file mode 100755 index 000000000..5e141d9c7 --- /dev/null +++ b/ext/spl/tests/iterator_048.phpt @@ -0,0 +1,38 @@ +--TEST-- +SPL: RecursiveRegexIterator and exception in has/getChildren +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +class MyRecursiveRegexIterator extends RecursiveRegexIterator +{ + function show() + { + foreach(new RecursiveIteratorIterator($this) as $k => $v) + { + var_dump($k); + var_dump($v); + } + } + + function accept() + { + return $this->hasChildren() || parent::accept(); + } +} + +$ar = new RecursiveArrayIterator(array('Foo', array('Bar'), 'FooBar', array('Baz'), 'Biz')); +$it = new MyRecursiveRegexIterator($ar, '/Bar/'); + +$it->show(); + +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +int(0) +string(3) "Bar" +int(2) +string(6) "FooBar" +===DONE=== diff --git a/ext/spl/tests/iterator_049.phpt b/ext/spl/tests/iterator_049.phpt new file mode 100755 index 000000000..8e2564380 --- /dev/null +++ b/ext/spl/tests/iterator_049.phpt @@ -0,0 +1,24 @@ +--TEST-- +SPL: ArrayIterator with NULL key +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +$ar = new ArrayIterator(array(NULL=>NULL)); +@var_dump($ar); +var_dump($ar->getArrayCopy()); + +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +object(ArrayIterator)#%d (1) { + [""]=> + NULL +} +array(1) { + [""]=> + NULL +} +===DONE=== diff --git a/ext/spl/tests/iterator_049b.phpt b/ext/spl/tests/iterator_049b.phpt Binary files differnew file mode 100755 index 000000000..9b894cd1c --- /dev/null +++ b/ext/spl/tests/iterator_049b.phpt diff --git a/ext/spl/tests/iterator_050.phpt b/ext/spl/tests/iterator_050.phpt new file mode 100755 index 000000000..6bd84a3a8 --- /dev/null +++ b/ext/spl/tests/iterator_050.phpt @@ -0,0 +1,93 @@ +--TEST-- +SPL: RegexIterator::GET_MATCH +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +class MyRegexIterator extends RegexIterator +{ + function show() + { + foreach($this as $k => $v) + { + var_dump($k); + var_dump($v); + } + } +} + +$ar = new ArrayIterator(array('1','1,2','1,2,3','',NULL,array(),'FooBar',',',',,')); +$it = new MyRegexIterator($ar, '/(\d),(\d)/', RegexIterator::GET_MATCH); +$it->show(); + +$it = new MyRegexIterator($ar, '/(\d)/', RegexIterator::GET_MATCH); +$it->show(); + +var_dump($ar); + +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +int(1) +array(3) { + [0]=> + string(3) "1,2" + [1]=> + string(1) "1" + [2]=> + string(1) "2" +} +int(2) +array(3) { + [0]=> + string(3) "1,2" + [1]=> + string(1) "1" + [2]=> + string(1) "2" +} +int(0) +array(2) { + [0]=> + string(1) "1" + [1]=> + string(1) "1" +} +int(1) +array(2) { + [0]=> + string(1) "1" + [1]=> + string(1) "1" +} +int(2) +array(2) { + [0]=> + string(1) "1" + [1]=> + string(1) "1" +} +object(ArrayIterator)#%d (9) { + [0]=> + %s(1) "1" + [1]=> + %s(3) "1,2" + [2]=> + %s(5) "1,2,3" + [3]=> + %s(0) "" + [4]=> + NULL + [5]=> + array(0) { + } + [6]=> + %s(6) "FooBar" + [7]=> + %s(1) "," + [8]=> + %s(2) ",," +} +===DONE=== diff --git a/ext/spl/tests/iterator_051.phpt b/ext/spl/tests/iterator_051.phpt new file mode 100755 index 000000000..626d27474 --- /dev/null +++ b/ext/spl/tests/iterator_051.phpt @@ -0,0 +1,95 @@ +--TEST-- +SPL: RegexIterator::GET_MATCH, USE_KEY +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +class MyRegexIterator extends RegexIterator +{ + function show() + { + foreach($this as $k => $v) + { + var_dump($k); + var_dump($v); + } + } +} + +$ar = new ArrayIterator(array('1'=>0,'1,2'=>1,'1,2,3'=>2,0=>3,'FooBar'=>4,','=>5,',,'=>6)); +$it = new MyRegexIterator($ar, '/(\d),(\d)/', RegexIterator::GET_MATCH, RegexIterator::USE_KEY); +$it->show(); + +$it = new MyRegexIterator($ar, '/(\d)/', RegexIterator::GET_MATCH, RegexIterator::USE_KEY); +$it->show(); + +var_dump($ar); + +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +string(3) "1,2" +array(3) { + [0]=> + string(3) "1,2" + [1]=> + string(1) "1" + [2]=> + string(1) "2" +} +string(5) "1,2,3" +array(3) { + [0]=> + string(3) "1,2" + [1]=> + string(1) "1" + [2]=> + string(1) "2" +} +int(1) +array(2) { + [0]=> + string(1) "1" + [1]=> + string(1) "1" +} +string(3) "1,2" +array(2) { + [0]=> + string(1) "1" + [1]=> + string(1) "1" +} +string(5) "1,2,3" +array(2) { + [0]=> + string(1) "1" + [1]=> + string(1) "1" +} +int(0) +array(2) { + [0]=> + string(1) "0" + [1]=> + string(1) "0" +} +object(ArrayIterator)#%d (7) { + [1]=> + int(0) + ["1,2"]=> + int(1) + ["1,2,3"]=> + int(2) + [0]=> + int(3) + ["FooBar"]=> + int(4) + [","]=> + int(5) + [",,"]=> + int(6) +} +===DONE=== diff --git a/ext/spl/tests/iterator_052.phpt b/ext/spl/tests/iterator_052.phpt new file mode 100755 index 000000000..9bd7d899e --- /dev/null +++ b/ext/spl/tests/iterator_052.phpt @@ -0,0 +1,314 @@ +--TEST-- +SPL: RegexIterator::ALL_MATCHES +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +class MyRegexIterator extends RegexIterator +{ + public $uk, $re; + + function __construct($it, $re, $mode, $flags = 0) + { + $this->uk = $flags & self::USE_KEY; + $this->re = $re; + parent::__construct($it, $re, $mode, $flags); + } + + function show() + { + foreach($this as $k => $v) + { + var_dump($k); + var_dump($v); + } + } + + function accept() + { + @preg_match_all($this->re, (string)($this->uk ? $this->key() : $this->current()), $sub); + $ret = parent::accept(); + var_dump($sub == $this->current()); + return $ret; + } +} + +$ar = new ArrayIterator(array('1','1,2','1,2,3','',NULL,array(),'FooBar',',',',,')); +$it = new MyRegexIterator($ar, '/(\d),(\d)/', RegexIterator::ALL_MATCHES); +$it->show(); + +$it = new MyRegexIterator($ar, '/(\d)/', RegexIterator::ALL_MATCHES); +$it->show(); + +var_dump($ar); + +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +bool(true) +int(0) +array(3) { + [0]=> + array(0) { + } + [1]=> + array(0) { + } + [2]=> + array(0) { + } +} +bool(true) +int(1) +array(3) { + [0]=> + array(1) { + [0]=> + string(3) "1,2" + } + [1]=> + array(1) { + [0]=> + string(1) "1" + } + [2]=> + array(1) { + [0]=> + string(1) "2" + } +} +bool(true) +int(2) +array(3) { + [0]=> + array(1) { + [0]=> + string(3) "1,2" + } + [1]=> + array(1) { + [0]=> + string(1) "1" + } + [2]=> + array(1) { + [0]=> + string(1) "2" + } +} +bool(true) +int(3) +array(3) { + [0]=> + array(0) { + } + [1]=> + array(0) { + } + [2]=> + array(0) { + } +} +bool(true) +int(4) +array(3) { + [0]=> + array(0) { + } + [1]=> + array(0) { + } + [2]=> + array(0) { + } +} +bool(true) +int(5) +array(3) { + [0]=> + array(0) { + } + [1]=> + array(0) { + } + [2]=> + array(0) { + } +} +bool(true) +int(6) +array(3) { + [0]=> + array(0) { + } + [1]=> + array(0) { + } + [2]=> + array(0) { + } +} +bool(true) +int(7) +array(3) { + [0]=> + array(0) { + } + [1]=> + array(0) { + } + [2]=> + array(0) { + } +} +bool(true) +int(8) +array(3) { + [0]=> + array(0) { + } + [1]=> + array(0) { + } + [2]=> + array(0) { + } +} +bool(true) +int(0) +array(2) { + [0]=> + array(1) { + [0]=> + string(1) "1" + } + [1]=> + array(1) { + [0]=> + string(1) "1" + } +} +bool(true) +int(1) +array(2) { + [0]=> + array(2) { + [0]=> + string(1) "1" + [1]=> + string(1) "2" + } + [1]=> + array(2) { + [0]=> + string(1) "1" + [1]=> + string(1) "2" + } +} +bool(true) +int(2) +array(2) { + [0]=> + array(3) { + [0]=> + string(1) "1" + [1]=> + string(1) "2" + [2]=> + string(1) "3" + } + [1]=> + array(3) { + [0]=> + string(1) "1" + [1]=> + string(1) "2" + [2]=> + string(1) "3" + } +} +bool(true) +int(3) +array(2) { + [0]=> + array(0) { + } + [1]=> + array(0) { + } +} +bool(true) +int(4) +array(2) { + [0]=> + array(0) { + } + [1]=> + array(0) { + } +} +bool(true) +int(5) +array(2) { + [0]=> + array(0) { + } + [1]=> + array(0) { + } +} +bool(true) +int(6) +array(2) { + [0]=> + array(0) { + } + [1]=> + array(0) { + } +} +bool(true) +int(7) +array(2) { + [0]=> + array(0) { + } + [1]=> + array(0) { + } +} +bool(true) +int(8) +array(2) { + [0]=> + array(0) { + } + [1]=> + array(0) { + } +} +object(ArrayIterator)#%d (9) { + [0]=> + %s(1) "1" + [1]=> + %s(3) "1,2" + [2]=> + %s(5) "1,2,3" + [3]=> + %s(0) "" + [4]=> + NULL + [5]=> + array(0) { + } + [6]=> + %s(6) "FooBar" + [7]=> + %s(1) "," + [8]=> + %s(2) ",," +} +===DONE=== diff --git a/ext/spl/tests/iterator_053.phpt b/ext/spl/tests/iterator_053.phpt new file mode 100755 index 000000000..4d68b0113 --- /dev/null +++ b/ext/spl/tests/iterator_053.phpt @@ -0,0 +1,314 @@ +--TEST-- +SPL: RegexIterator::ALL_MATCHES +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +class MyRegexIterator extends RegexIterator +{ + public $uk, $re; + + function __construct($it, $re, $mode, $flags = 0) + { + $this->uk = $flags & self::USE_KEY; + $this->re = $re; + parent::__construct($it, $re, $mode, $flags); + } + + function show() + { + foreach($this as $k => $v) + { + var_dump($k); + var_dump($v); + } + } + + function accept() + { + @preg_match_all($this->re, (string)($this->uk ? $this->key() : $this->current()), $sub); + $ret = parent::accept(); + var_dump($sub == $this->current()); + return $ret; + } +} + +$ar = new ArrayIterator(array('1','1,2','1,2,3','',NULL,array(),'FooBar',',',',,')); +$it = new MyRegexIterator($ar, '/(\d),(\d)/', RegexIterator::ALL_MATCHES, RegexIterator::USE_KEY); +$it->show(); + +$it = new MyRegexIterator($ar, '/(\d)/', RegexIterator::ALL_MATCHES, RegexIterator::USE_KEY); +$it->show(); + +var_dump($ar); + +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +bool(true) +int(0) +array(3) { + [0]=> + array(0) { + } + [1]=> + array(0) { + } + [2]=> + array(0) { + } +} +bool(true) +int(1) +array(3) { + [0]=> + array(0) { + } + [1]=> + array(0) { + } + [2]=> + array(0) { + } +} +bool(true) +int(2) +array(3) { + [0]=> + array(0) { + } + [1]=> + array(0) { + } + [2]=> + array(0) { + } +} +bool(true) +int(3) +array(3) { + [0]=> + array(0) { + } + [1]=> + array(0) { + } + [2]=> + array(0) { + } +} +bool(true) +int(4) +array(3) { + [0]=> + array(0) { + } + [1]=> + array(0) { + } + [2]=> + array(0) { + } +} +bool(true) +int(5) +array(3) { + [0]=> + array(0) { + } + [1]=> + array(0) { + } + [2]=> + array(0) { + } +} +bool(true) +int(6) +array(3) { + [0]=> + array(0) { + } + [1]=> + array(0) { + } + [2]=> + array(0) { + } +} +bool(true) +int(7) +array(3) { + [0]=> + array(0) { + } + [1]=> + array(0) { + } + [2]=> + array(0) { + } +} +bool(true) +int(8) +array(3) { + [0]=> + array(0) { + } + [1]=> + array(0) { + } + [2]=> + array(0) { + } +} +bool(true) +int(0) +array(2) { + [0]=> + array(1) { + [0]=> + string(1) "0" + } + [1]=> + array(1) { + [0]=> + string(1) "0" + } +} +bool(true) +int(1) +array(2) { + [0]=> + array(1) { + [0]=> + string(1) "1" + } + [1]=> + array(1) { + [0]=> + string(1) "1" + } +} +bool(true) +int(2) +array(2) { + [0]=> + array(1) { + [0]=> + string(1) "2" + } + [1]=> + array(1) { + [0]=> + string(1) "2" + } +} +bool(true) +int(3) +array(2) { + [0]=> + array(1) { + [0]=> + string(1) "3" + } + [1]=> + array(1) { + [0]=> + string(1) "3" + } +} +bool(true) +int(4) +array(2) { + [0]=> + array(1) { + [0]=> + string(1) "4" + } + [1]=> + array(1) { + [0]=> + string(1) "4" + } +} +bool(true) +int(5) +array(2) { + [0]=> + array(1) { + [0]=> + string(1) "5" + } + [1]=> + array(1) { + [0]=> + string(1) "5" + } +} +bool(true) +int(6) +array(2) { + [0]=> + array(1) { + [0]=> + string(1) "6" + } + [1]=> + array(1) { + [0]=> + string(1) "6" + } +} +bool(true) +int(7) +array(2) { + [0]=> + array(1) { + [0]=> + string(1) "7" + } + [1]=> + array(1) { + [0]=> + string(1) "7" + } +} +bool(true) +int(8) +array(2) { + [0]=> + array(1) { + [0]=> + string(1) "8" + } + [1]=> + array(1) { + [0]=> + string(1) "8" + } +} +object(ArrayIterator)#%d (9) { + [0]=> + %s(1) "1" + [1]=> + %s(3) "1,2" + [2]=> + %s(5) "1,2,3" + [3]=> + %s(0) "" + [4]=> + NULL + [5]=> + array(0) { + } + [6]=> + %s(6) "FooBar" + [7]=> + %s(1) "," + [8]=> + %s(2) ",," +} +===DONE=== diff --git a/ext/spl/tests/iterator_054.phpt b/ext/spl/tests/iterator_054.phpt new file mode 100755 index 000000000..3f724697a --- /dev/null +++ b/ext/spl/tests/iterator_054.phpt @@ -0,0 +1,84 @@ +--TEST-- +SPL: RegexIterator::SPLIT +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +class MyRegexIterator extends RegexIterator +{ + function show() + { + foreach($this as $k => $v) + { + var_dump($k); + var_dump($v); + } + } +} + +$ar = new ArrayIterator(array('1','1,2','1,2,3','',NULL,array(),'FooBar',',',',,')); +$it = new MyRegexIterator($ar, '/,/', RegexIterator::SPLIT); + +$it->show(); + +var_dump($ar); + +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +int(1) +array(2) { + [0]=> + string(1) "1" + [1]=> + string(1) "2" +} +int(2) +array(3) { + [0]=> + string(1) "1" + [1]=> + string(1) "2" + [2]=> + string(1) "3" +} +int(7) +array(2) { + [0]=> + string(0) "" + [1]=> + string(0) "" +} +int(8) +array(3) { + [0]=> + string(0) "" + [1]=> + string(0) "" + [2]=> + string(0) "" +} +object(ArrayIterator)#%d (9) { + [0]=> + %s(1) "1" + [1]=> + %s(3) "1,2" + [2]=> + %s(5) "1,2,3" + [3]=> + %s(0) "" + [4]=> + NULL + [5]=> + array(0) { + } + [6]=> + %s(6) "FooBar" + [7]=> + %s(1) "," + [8]=> + %s(2) ",," +} +===DONE=== diff --git a/ext/spl/tests/iterator_055.phpt b/ext/spl/tests/iterator_055.phpt new file mode 100755 index 000000000..35a050c39 --- /dev/null +++ b/ext/spl/tests/iterator_055.phpt @@ -0,0 +1,61 @@ +--TEST-- +SPL: RegexIterator::SPLIT, USE_KEY +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +class MyRegexIterator extends RegexIterator +{ + function show() + { + foreach($this as $k => $v) + { + var_dump($k); + var_dump($v); + } + } +} + +$ar = new ArrayIterator(array('1'=>0,'1,2'=>1,'1,2,3'=>2,0=>3,'FooBar'=>4,','=>5,',,'=>6)); +$it = new MyRegexIterator($ar, '/(\d),(\d)/', RegexIterator::SPLIT, RegexIterator::USE_KEY); + +$it->show(); + +var_dump($ar); + +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +string(3) "1,2" +array(2) { + [0]=> + string(0) "" + [1]=> + string(0) "" +} +string(5) "1,2,3" +array(2) { + [0]=> + string(0) "" + [1]=> + string(2) ",3" +} +object(ArrayIterator)#%d (7) { + [1]=> + int(0) + ["1,2"]=> + int(1) + ["1,2,3"]=> + int(2) + [0]=> + int(3) + ["FooBar"]=> + int(4) + [","]=> + int(5) + [",,"]=> + int(6) +} +===DONE=== diff --git a/ext/spl/tests/spl_004.phpt b/ext/spl/tests/spl_004.phpt new file mode 100755 index 000000000..60da28042 --- /dev/null +++ b/ext/spl/tests/spl_004.phpt @@ -0,0 +1,86 @@ +--TEST-- +SPL: iterator_apply() +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +function my_error_handler($errno, $errstr, $errfile, $errline) { + echo "Error: $errstr\n"; +} + +set_error_handler('my_error_handler'); + +function test_arg($arg) +{ + if ($arg instanceof Iterator) + { + var_dump($arg->key()); + var_dump($arg->current()); + } + else + { + var_dump($arg); + } + return true; +} + +function test() +{ + static $arg = 0; + var_dump($arg++); + return true; +} + +$it = new RecursiveArrayIterator(array(1, array(21, 22), 3)); + +var_dump(iterator_apply($it, 'test', NULL)); + +echo "===ARGS===\n"; +var_dump(iterator_apply($it, 'test_arg', array($it))); + +echo "===RECURSIVE===\n"; +$it = new RecursiveIteratorIterator($it); +var_dump(iterator_apply($it, 'test')); + +echo "===ERRORS===\n"; +var_dump(iterator_apply($it, 'test', 1)); +var_dump(iterator_apply($it, 'non_existing_functon')); +var_dump(iterator_apply($it, 'non_existing_functon', NULL, 2)); + +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +int(0) +int(1) +int(2) +int(3) +===ARGS=== +int(0) +int(1) +int(1) +array(2) { + [0]=> + int(21) + [1]=> + int(22) +} +int(2) +int(3) +int(3) +===RECURSIVE=== +int(3) +int(4) +int(5) +int(6) +int(4) +===ERRORS=== +Error: Argument 3 passed to iterator_apply() must be an array, integer given +Error: iterator_apply() expects parameter 3 to be array, integer given +NULL +Error: iterator_apply() expects parameter 2 to be function,%sstring given +NULL +Error: iterator_apply() expects at most 3 parameters, 4 given +NULL +===DONE=== diff --git a/ext/spl/tests/spl_005.phpt b/ext/spl/tests/spl_005.phpt new file mode 100755 index 000000000..bb297bb6b --- /dev/null +++ b/ext/spl/tests/spl_005.phpt @@ -0,0 +1,23 @@ +--TEST-- +SPL: spl_object_hash() +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +var_dump(spl_object_hash(new stdClass)); +var_dump(spl_object_hash(42)); +var_dump(spl_object_hash()); + +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +string(32) "%s" + +Warning: spl_object_hash() expects parameter 1 to be object, integer given in %sspl_005.php on line %d +NULL + +Warning: spl_object_hash() expects exactly 1 parameter, 0 given in %sspl_005.php on line %d +NULL +===DONE=== |
