]> granicus.if.org Git - php/commitdiff
- New tests (testfet LondonUG)
authorFelipe Pena <felipe@php.net>
Sun, 17 May 2009 15:46:37 +0000 (15:46 +0000)
committerFelipe Pena <felipe@php.net>
Sun, 17 May 2009 15:46:37 +0000 (15:46 +0000)
33 files changed:
ext/spl/tests/iterator_044.phpt.orig [new file with mode: 0755]
ext/spl/tests/iterator_count.phpt [new file with mode: 0644]
ext/spl/tests/iterator_to_array.phpt [new file with mode: 0644]
ext/spl/tests/limititerator_seek.phpt [new file with mode: 0644]
ext/spl/tests/recursiveiteratoriterator_beginiteration_basic.phpt [new file with mode: 0644]
ext/spl/tests/recursiveiteratoriterator_enditeration_basic.phpt [new file with mode: 0644]
ext/spl/tests/recursiveiteratoriterator_getsubiterator_basic.phpt [new file with mode: 0644]
ext/spl/tests/recursiveiteratoriterator_getsubiterator_error.phpt [new file with mode: 0644]
ext/spl/tests/recursiveiteratoriterator_getsubiterator_variation.phpt [new file with mode: 0644]
ext/spl/tests/recursiveiteratoriterator_getsubiterator_variation_002.phpt [new file with mode: 0644]
ext/spl/tests/recursiveiteratoriterator_getsubiterator_variation_003.phpt [new file with mode: 0644]
ext/spl/tests/recursiveiteratoriterator_nextelement_basic.phpt [new file with mode: 0644]
ext/spl/tests/regexiterator_getpregflags.phpt [new file with mode: 0644]
ext/spl/tests/regexiterator_setflags_exception.phpt [new file with mode: 0644]
ext/spl/tests/regexiterator_setpregflags.phpt [new file with mode: 0644]
ext/spl/tests/regexiterator_setpregflags_exception.phpt [new file with mode: 0644]
ext/spl/tests/spl_caching_iterator_constructor_flags.phpt [new file with mode: 0644]
ext/spl/tests/spl_cachingiterator___toString_basic.phpt [new file with mode: 0644]
ext/spl/tests/spl_cachingiterator_setFlags_basic.phpt [new file with mode: 0644]
ext/spl/tests/spl_fileinfo_getlinktarget_basic.phpt [new file with mode: 0755]
ext/spl/tests/spl_iterator_apply_error.phpt [new file with mode: 0755]
ext/spl/tests/spl_iterator_apply_error_001.phpt [new file with mode: 0755]
ext/spl/tests/spl_iterator_caching_count_basic.phpt [new file with mode: 0644]
ext/spl/tests/spl_iterator_caching_count_error.phpt [new file with mode: 0644]
ext/spl/tests/spl_iterator_caching_getcache_error.phpt [new file with mode: 0644]
ext/spl/tests/spl_iterator_getcallchildren.phpt [new file with mode: 0644]
ext/spl/tests/spl_iterator_iterator_constructor.phpt [new file with mode: 0644]
ext/spl/tests/spl_iterator_recursive_getiterator_error.phpt [new file with mode: 0644]
ext/spl/tests/spl_iterator_to_array_basic.phpt [new file with mode: 0644]
ext/spl/tests/spl_iterator_to_array_error.phpt [new file with mode: 0755]
ext/spl/tests/spl_limit_iterator_check_limits.phpt [new file with mode: 0644]
ext/spl/tests/spl_recursiveIteratorIterator_setMaxDepth_parameter_count.phpt [new file with mode: 0644]
ext/spl/tests/spl_recursive_iterator_iterator_key_case.phpt [new file with mode: 0644]

diff --git a/ext/spl/tests/iterator_044.phpt.orig b/ext/spl/tests/iterator_044.phpt.orig
new file mode 100755 (executable)
index 0000000..d3c6253
--- /dev/null
@@ -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 %siterator_044.php on line %d
+NULL
+
+Warning: CachingIterator::offsetGet() expects exactly 1 parameter, 0 given in %siterator_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_count.phpt b/ext/spl/tests/iterator_count.phpt
new file mode 100644 (file)
index 0000000..9aa4e11
--- /dev/null
@@ -0,0 +1,26 @@
+--TEST--
+SPL: iterator_count() exceptions test
+--CREDITS--
+Lance Kesson jac_kesson@hotmail.com
+#testfest London 2009-05-09
+--FILE--
+<?php
+$array=array('a','b');
+
+$iterator = new ArrayIterator($array);
+
+iterator_count();
+
+
+iterator_count($iterator,'1');
+
+iterator_count('1');
+
+
+?>
+--EXPECTF--
+Warning: iterator_count() expects exactly 1 parameter, 0 given in %s
+
+Warning: iterator_count() expects exactly 1 parameter, 2 given in %s
+
+Catchable fatal error: Argument 1 passed to iterator_count() must implement interface Traversable, %unicode_string_optional% given %s
diff --git a/ext/spl/tests/iterator_to_array.phpt b/ext/spl/tests/iterator_to_array.phpt
new file mode 100644 (file)
index 0000000..958d370
--- /dev/null
@@ -0,0 +1,25 @@
+--TEST--
+SPL: iterator_to_array() exceptions test
+--CREDITS--
+Lance Kesson jac_kesson@hotmail.com
+#testfest London 2009-05-09
+--FILE--
+<?php
+$array=array('a','b');
+
+$iterator = new ArrayIterator($array);
+
+iterator_to_array();
+
+
+iterator_to_array($iterator,'test','test');
+
+iterator_to_array('test','test');
+
+?>
+--EXPECTF--
+Warning: iterator_to_array() expects at least 1 parameter, 0 given in %s
+
+Warning: iterator_to_array() expects at most 2 parameters, 3 given in %s
+
+Catchable fatal error: Argument 1 passed to iterator_to_array() must implement interface Traversable, %unicode_string_optional% given %s
diff --git a/ext/spl/tests/limititerator_seek.phpt b/ext/spl/tests/limititerator_seek.phpt
new file mode 100644 (file)
index 0000000..a59a49b
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--
+SPL: LimitIterator seek() arguments
+--CREDITS--
+Roshan Abraham (roshanabrahams@gmail.com)
+TestFest London May 2009
+--FILE--
+<?php
+
+$a = array(1,2,3);
+$lt = new LimitIterator(new ArrayIterator($a));
+
+$lt->seek(1,1); // Should throw a warning as seek expects only 1 argument
+
+?>
+--EXPECTF--
+
+Warning: LimitIterator::seek() expects exactly 1 parameter, 2 given in %s on line %d
+
diff --git a/ext/spl/tests/recursiveiteratoriterator_beginiteration_basic.phpt b/ext/spl/tests/recursiveiteratoriterator_beginiteration_basic.phpt
new file mode 100644 (file)
index 0000000..c9476e0
--- /dev/null
@@ -0,0 +1,32 @@
+--TEST--
+SPL: RecursiveIteratorIterator::beginIteration() is called by RecursiveIteratorIterator::rewind()
+--CREDITS--
+Matt Raines matt@raines.me.uk
+#testfest London 2009-05-09
+--FILE--
+<?php
+$sample_array = array(1, 2);
+$sub_iterator = new RecursiveArrayIterator($sample_array);
+
+$iterator = new RecursiveIteratorIterator($sub_iterator);
+foreach ($iterator as $element) {
+  var_dump($element);
+}
+
+class SkipsFirstElementRecursiveIteratorIterator extends RecursiveIteratorIterator {
+  public function beginIteration() {
+    echo "::beginIteration() was invoked\n";
+    $this->next();
+  }
+}
+$iterator = new SkipsFirstElementRecursiveIteratorIterator($sub_iterator);
+foreach ($iterator as $element) {
+  var_dump($element);
+}
+?>
+--EXPECT--
+int(1)
+int(2)
+::beginIteration() was invoked
+int(2)
+
diff --git a/ext/spl/tests/recursiveiteratoriterator_enditeration_basic.phpt b/ext/spl/tests/recursiveiteratoriterator_enditeration_basic.phpt
new file mode 100644 (file)
index 0000000..0355401
--- /dev/null
@@ -0,0 +1,32 @@
+--TEST--
+SPL: RecursiveIteratorIterator::endIteration() is called when ::valid() first returns false
+--CREDITS--
+Matt Raines matt@raines.me.uk
+#testfest London 2009-05-09
+--FILE--
+<?php
+$sample_array = array(1, 2);
+$sub_iterator = new RecursiveArrayIterator($sample_array);
+
+$iterator = new RecursiveIteratorIterator($sub_iterator);
+foreach ($iterator as $element) {
+  var_dump($element);
+}
+
+class EndIterationRecursiveIteratorIterator extends RecursiveIteratorIterator {
+  public function endIteration() {
+    echo "::endIteration() was invoked\n";
+  }
+}
+$iterator = new EndIterationRecursiveIteratorIterator($sub_iterator);
+foreach ($iterator as $element) {
+  var_dump($element);
+}
+?>
+--EXPECT--
+int(1)
+int(2)
+int(1)
+int(2)
+::endIteration() was invoked
+
diff --git a/ext/spl/tests/recursiveiteratoriterator_getsubiterator_basic.phpt b/ext/spl/tests/recursiveiteratoriterator_getsubiterator_basic.phpt
new file mode 100644 (file)
index 0000000..5d1c958
--- /dev/null
@@ -0,0 +1,20 @@
+--TEST--
+SPL: RecursiveIteratorIterator::getSubIterator() returns iterator passed in constructor
+--CREDITS--
+Matt Raines matt@raines.me.uk
+#testfest London 2009-05-09
+--FILE--
+<?php
+$sample_array = array(1, 2, array(3, 4));
+
+$sub_iterator = new RecursiveArrayIterator($sample_array);
+$not_sub_iterator = new RecursiveArrayIterator($sample_array);
+$iterator = new RecursiveIteratorIterator($sub_iterator);
+
+var_dump($iterator->getSubIterator() === $sub_iterator);
+var_dump($iterator->getSubIterator() === $not_sub_iterator);
+?>
+--EXPECT--
+bool(true)
+bool(false)
+
diff --git a/ext/spl/tests/recursiveiteratoriterator_getsubiterator_error.phpt b/ext/spl/tests/recursiveiteratoriterator_getsubiterator_error.phpt
new file mode 100644 (file)
index 0000000..760082f
--- /dev/null
@@ -0,0 +1,15 @@
+--TEST--
+SPL: RecursiveIteratorIterator::getSubIterator() expects at most 1 parameter
+--CREDITS--
+Matt Raines matt@raines.me.uk
+#testfest London 2009-05-09
+--FILE--
+<?php
+$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator(array()));
+$iterator->getSubIterator();
+$iterator->getSubIterator(0);
+$iterator->getSubIterator(0, 0);
+?>
+--EXPECTF--
+Warning: RecursiveIteratorIterator::getSubIterator() expects at most 1 parameter, 2 given in %s on line 5
+
diff --git a/ext/spl/tests/recursiveiteratoriterator_getsubiterator_variation.phpt b/ext/spl/tests/recursiveiteratoriterator_getsubiterator_variation.phpt
new file mode 100644 (file)
index 0000000..a7b84c4
--- /dev/null
@@ -0,0 +1,42 @@
+--TEST--
+SPL: RecursiveIteratorIterator::getSubIterator() returns different iterators depending on the current element
+--CREDITS--
+Matt Raines matt@raines.me.uk
+#testfest London 2009-05-09
+--FILE--
+<?php
+$sample_array = array(1, 2, array(3, 4));
+
+$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($sample_array));
+
+$iterator->next();
+$iterator->next();
+var_dump(get_class($iterator->getSubIterator()));
+var_dump($iterator->getSubIterator()->getArrayCopy());
+$iterator->next();
+var_dump(get_class($iterator->getSubIterator()));
+var_dump($iterator->getSubIterator()->getArrayCopy());
+?>
+--EXPECTF--
+%unicode|string%(22) "RecursiveArrayIterator"
+array(3) {
+  [0]=>
+  int(1)
+  [1]=>
+  int(2)
+  [2]=>
+  array(2) {
+    [0]=>
+    int(3)
+    [1]=>
+    int(4)
+  }
+}
+%unicode|string%(22) "RecursiveArrayIterator"
+array(2) {
+  [0]=>
+  int(3)
+  [1]=>
+  int(4)
+}
+
diff --git a/ext/spl/tests/recursiveiteratoriterator_getsubiterator_variation_002.phpt b/ext/spl/tests/recursiveiteratoriterator_getsubiterator_variation_002.phpt
new file mode 100644 (file)
index 0000000..aac4e65
--- /dev/null
@@ -0,0 +1,20 @@
+--TEST--
+SPL: RecursiveIteratorIterator::getSubIterator() returns NULL if there's no current element
+--CREDITS--
+Matt Raines matt@raines.me.uk
+#testfest London 2009-05-09
+--FILE--
+<?php
+$sample_array = array(1);
+
+$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($sample_array));
+
+$iterator->next();
+var_dump(is_null($iterator->getSubIterator()));
+$iterator->next();
+var_dump(is_null($iterator->getSubIterator()));
+?>
+--EXPECT--
+bool(false)
+bool(false)
+
diff --git a/ext/spl/tests/recursiveiteratoriterator_getsubiterator_variation_003.phpt b/ext/spl/tests/recursiveiteratoriterator_getsubiterator_variation_003.phpt
new file mode 100644 (file)
index 0000000..ff18840
--- /dev/null
@@ -0,0 +1,42 @@
+--TEST--
+SPL: RecursiveIteratorIterator::getSubIterator() with explicit level parameter
+--CREDITS--
+Matt Raines matt@raines.me.uk
+#testfest London 2009-05-09
+--FILE--
+<?php
+$sample_array = array(1, 2, array(3, 4));
+
+$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($sample_array));
+
+$iterator->next();
+$iterator->next();
+$iterator->next();
+var_dump($iterator->getSubIterator(-1));
+var_dump($iterator->getSubIterator(0)->getArrayCopy());
+var_dump($iterator->getSubIterator(1)->getArrayCopy());
+var_dump($iterator->getSubIterator(2));
+?>
+--EXPECT--
+NULL
+array(3) {
+  [0]=>
+  int(1)
+  [1]=>
+  int(2)
+  [2]=>
+  array(2) {
+    [0]=>
+    int(3)
+    [1]=>
+    int(4)
+  }
+}
+array(2) {
+  [0]=>
+  int(3)
+  [1]=>
+  int(4)
+}
+NULL
+
diff --git a/ext/spl/tests/recursiveiteratoriterator_nextelement_basic.phpt b/ext/spl/tests/recursiveiteratoriterator_nextelement_basic.phpt
new file mode 100644 (file)
index 0000000..0bf4f19
--- /dev/null
@@ -0,0 +1,39 @@
+--TEST--
+SPL: RecursiveIteratorIterator::nextElement() is called when the next element is ready
+--CREDITS--
+Matt Raines matt@raines.me.uk
+#testfest London 2009-05-09
+--FILE--
+<?php
+$sample_array = array(1, 2, array(3, 4));
+$sub_iterator = new RecursiveArrayIterator($sample_array);
+
+$iterator = new RecursiveIteratorIterator($sub_iterator);
+foreach ($iterator as $element) {
+  var_dump($element);
+}
+
+class NextElementRecursiveIteratorIterator extends RecursiveIteratorIterator {
+  public function nextElement() {
+    echo "::nextElement() was invoked\n";
+  }
+}
+$iterator = new NextElementRecursiveIteratorIterator($sub_iterator);
+foreach ($iterator as $element) {
+  var_dump($element);
+}
+?>
+--EXPECT--
+int(1)
+int(2)
+int(3)
+int(4)
+::nextElement() was invoked
+int(1)
+::nextElement() was invoked
+int(2)
+::nextElement() was invoked
+int(3)
+::nextElement() was invoked
+int(4)
+
diff --git a/ext/spl/tests/regexiterator_getpregflags.phpt b/ext/spl/tests/regexiterator_getpregflags.phpt
new file mode 100644 (file)
index 0000000..58a4dc4
--- /dev/null
@@ -0,0 +1,33 @@
+--TEST--
+SPL: RegexIterator::getPregFlags()
+--CREDITS--
+Lance Kesson jac_kesson@hotmail.com
+#testfest London 2009-05-09
+--FILE--
+<?php
+
+class myIterator implements Iterator {
+
+function current (){}
+function key ( ){}
+function next ( ){}
+function rewind ( ){}
+function valid ( ){}
+
+
+}
+
+class TestRegexIterator extends RegexIterator{}
+
+$rege = '/^a/';
+
+
+$r = new TestRegexIterator(new myIterator, $rege);
+
+$r->setPregFlags(PREG_OFFSET_CAPTURE);
+
+echo is_long($r->getPregFlags());
+
+?>
+--EXPECTF--
+1
\ No newline at end of file
diff --git a/ext/spl/tests/regexiterator_setflags_exception.phpt b/ext/spl/tests/regexiterator_setflags_exception.phpt
new file mode 100644 (file)
index 0000000..fdc8bca
--- /dev/null
@@ -0,0 +1,35 @@
+--TEST--
+SPL: RegexIterator::setFlags() exceptions test
+--CREDITS--
+Lance Kesson jac_kesson@hotmail.com
+#testfest London 2009-05-09
+--FILE--
+<?php
+
+class myIterator implements Iterator {
+
+function current (){}
+function key ( ){}
+function next ( ){}
+function rewind ( ){}
+function valid ( ){}
+
+
+}
+
+class TestRegexIterator extends RegexIterator{}
+
+$rege = '/^a/';
+
+
+$r = new TestRegexIterator(new myIterator, $rege);
+
+try{   
+       $r->setFlags();
+}catch (Exception $e) {
+       echo $e->getMessage();
+}
+
+?>
+--EXPECTF--
+Warning: RegexIterator::setFlags() expects exactly 1 parameter, 0 given in %s
\ No newline at end of file
diff --git a/ext/spl/tests/regexiterator_setpregflags.phpt b/ext/spl/tests/regexiterator_setpregflags.phpt
new file mode 100644 (file)
index 0000000..ea1b455
--- /dev/null
@@ -0,0 +1,34 @@
+--TEST--
+SPL: RegexIterator::setPregFlags()
+--CREDITS--
+Lance Kesson jac_kesson@hotmail.com
+#testfest London 2009-05-09
+--FILE--
+<?php
+
+class myIterator implements Iterator {
+
+function current (){}
+function key ( ){}
+function next ( ){}
+function rewind ( ){}
+function valid ( ){}
+
+
+}
+
+class TestRegexIterator extends RegexIterator{}
+
+$rege = '/^a/';
+
+
+$r = new TestRegexIterator(new myIterator, $rege);
+
+$r->setPregFlags(PREG_OFFSET_CAPTURE);
+
+echo $r->getPregFlags();
+
+
+?>
+--EXPECTF--
+256
\ No newline at end of file
diff --git a/ext/spl/tests/regexiterator_setpregflags_exception.phpt b/ext/spl/tests/regexiterator_setpregflags_exception.phpt
new file mode 100644 (file)
index 0000000..cc7c17c
--- /dev/null
@@ -0,0 +1,36 @@
+--TEST--
+SPL: RegexIterator::getPregFlags() exception test
+--CREDITS--
+Lance Kesson jac_kesson@hotmail.com
+#testfest London 2009-05-09
+--FILE--
+<?php
+
+class myIterator implements Iterator {
+
+function current (){}
+function key ( ){}
+function next ( ){}
+function rewind ( ){}
+function valid ( ){}
+
+
+}
+
+class TestRegexIterator extends RegexIterator{}
+
+$rege = '/^a/';
+
+
+$r = new TestRegexIterator(new myIterator, $rege);
+
+
+try{   
+       $r->setPregFlags();
+}catch (Exception $e) {
+       echo $e->getMessage();
+}
+
+?>
+--EXPECTF--
+Warning: RegexIterator::setPregFlags() expects exactly 1 parameter, 0 given in %s
\ No newline at end of file
diff --git a/ext/spl/tests/spl_caching_iterator_constructor_flags.phpt b/ext/spl/tests/spl_caching_iterator_constructor_flags.phpt
new file mode 100644 (file)
index 0000000..499cd67
--- /dev/null
@@ -0,0 +1,25 @@
+--TEST--
+SPL: CachingInterator constructor flag checks 
+--CREDITS--
+Sean Burlington www.practicalweb.co.uk
+TestFest London May 2009
+--FILE--
+<?php
+  //line 681 ...
+  $array = array(array(7,8,9),1,2,3,array(4,5,6));
+$arrayIterator = new ArrayIterator($array);
+try {
+$test = new CachingIterator($arrayIterator, 0);
+$test = new CachingIterator($arrayIterator, 1);
+$test = new CachingIterator($arrayIterator, 2);
+$test = new CachingIterator($arrayIterator, 3); // this throws an exception
+} catch (InvalidArgumentException $e){
+  print  $e->getMessage() . "\n";
+}
+
+
+?>
+===DONE===
+--EXPECTF--
+Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_CURRENT
+===DONE===
diff --git a/ext/spl/tests/spl_cachingiterator___toString_basic.phpt b/ext/spl/tests/spl_cachingiterator___toString_basic.phpt
new file mode 100644 (file)
index 0000000..0395b37
--- /dev/null
@@ -0,0 +1,16 @@
+--TEST--
+SPL: SplCachingIterator, Test method to convert current element to string
+--CREDITS--
+Chris Scott chris.scott@nstein.com
+#testfest London 2009-05-09
+--FILE--
+<?php
+
+$ai = new ArrayIterator(array(new stdClass(), new stdClass()));
+$ci = new CachingIterator($ai);
+var_dump(
+$ci->__toString() // if conversion to string is done by echo, for example, an exeption is thrown. Invoking __toString explicitly covers different code.
+);
+?>
+--EXPECTF--
+NULL
diff --git a/ext/spl/tests/spl_cachingiterator_setFlags_basic.phpt b/ext/spl/tests/spl_cachingiterator_setFlags_basic.phpt
new file mode 100644 (file)
index 0000000..126586b
--- /dev/null
@@ -0,0 +1,16 @@
+--TEST--
+SPL: SplCachingIterator, Test method to set flags for caching iterator
+--CREDITS--
+Chris Scott chris.scott@nstein.com
+#testfest London 2009-05-09
+--FILE--
+<?php
+
+$ai = new ArrayIterator(array('foo', 'bar'));
+
+$ci = new CachingIterator($ai);
+$ci->setFlags(); //expects arg
+
+?>
+--EXPECTF--
+Warning: CachingIterator::setFlags() expects exactly 1 parameter, %s
diff --git a/ext/spl/tests/spl_fileinfo_getlinktarget_basic.phpt b/ext/spl/tests/spl_fileinfo_getlinktarget_basic.phpt
new file mode 100755 (executable)
index 0000000..399d9a3
--- /dev/null
@@ -0,0 +1,22 @@
+--TEST--
+SPL: Spl File Info test getLinkTarget
+--CREDITS--
+Nataniel McHugh nat@fishtrap.co.uk
+--SKIPIF--
+<?php
+if (substr(PHP_OS, 0, 3) == 'WIN') die("skip this test not for Windows platforms");
+?>
+--FILE--
+<?php
+$link = 'test_link';
+symlink(__FILE__, $link );
+$fileInfo = new SplFileInfo($link);
+
+if ($fileInfo->isLink()) {
+       echo $fileInfo->getLinkTarget() == __FILE__ ? 'same' : 'different',PHP_EOL;
+}
+var_dump(unlink($link));
+?>
+--EXPECT--
+same
+bool(true)
diff --git a/ext/spl/tests/spl_iterator_apply_error.phpt b/ext/spl/tests/spl_iterator_apply_error.phpt
new file mode 100755 (executable)
index 0000000..8e7cba4
--- /dev/null
@@ -0,0 +1,26 @@
+--TEST--
+SPL: Error: iterator_apply when an iterator method (eg rewind) throws exception
+--FILE--
+<?php
+
+class MyArrayIterator extends ArrayIterator {
+       public function rewind() {
+               throw new Exception('Make the iterator break');
+       }
+}
+
+function test() {}
+
+$it = new MyArrayIterator(array(1, 21, 22));
+
+try {
+       $res = iterator_apply($it, 'test');
+} catch (Exception $e) {
+       echo $e->getMessage();
+}
+
+?>
+
+<?php exit(0); ?>
+--EXPECT--
+Make the iterator break
diff --git a/ext/spl/tests/spl_iterator_apply_error_001.phpt b/ext/spl/tests/spl_iterator_apply_error_001.phpt
new file mode 100755 (executable)
index 0000000..54663c0
--- /dev/null
@@ -0,0 +1,20 @@
+--TEST--
+SPL: Error: iterator_apply when the callback throws an exception
+--FILE--
+<?php
+
+function test() {
+       throw new Exception('Broken callback');
+}
+
+$it = new RecursiveArrayIterator(array(1, 21, 22));
+
+try {
+       iterator_apply($it, 'test');
+} catch (Exception $e) {
+       echo $e->getMessage();
+}
+
+?>
+--EXPECT--
+Broken callback
diff --git a/ext/spl/tests/spl_iterator_caching_count_basic.phpt b/ext/spl/tests/spl_iterator_caching_count_basic.phpt
new file mode 100644 (file)
index 0000000..b11eb7b
--- /dev/null
@@ -0,0 +1,21 @@
+--TEST--
+SPL: Caching iterator count() cache contents
+--CREDITS--
+Lukasz Andrzejak meltir@meltir.com
+#testfest London 2009-05-09
+--FILE--
+<?php
+$i = new ArrayIterator(array(1,1,1,1,1));
+$i = new CachingIterator($i,CachingIterator::FULL_CACHE);
+foreach ($i as $value) {
+  echo $i->count()."\n";
+}
+?>
+===DONE===
+--EXPECT--
+1
+2
+3
+4
+5
+===DONE===
\ No newline at end of file
diff --git a/ext/spl/tests/spl_iterator_caching_count_error.phpt b/ext/spl/tests/spl_iterator_caching_count_error.phpt
new file mode 100644 (file)
index 0000000..70aa2be
--- /dev/null
@@ -0,0 +1,21 @@
+--TEST--
+SPL: Caching iterator count() cache failure
+--CREDITS--
+Lukasz Andrzejak meltir@meltir.com
+#testfest London 2009-05-09
+--FILE--
+<?php
+$i = new ArrayIterator(array(1,1,1,1,1));
+$i = new CachingIterator($i);
+try {
+  $i->count();
+  echo "Should have caused an exception";
+} catch (BadMethodCallException $e) {
+  echo "Exception raised\n";
+}
+
+?>
+===DONE===
+--EXPECT--
+Exception raised
+===DONE===
\ No newline at end of file
diff --git a/ext/spl/tests/spl_iterator_caching_getcache_error.phpt b/ext/spl/tests/spl_iterator_caching_getcache_error.phpt
new file mode 100644 (file)
index 0000000..2ea4bd8
--- /dev/null
@@ -0,0 +1,21 @@
+--TEST--
+SPL: Caching iterator getCache failure
+--CREDITS--
+Lukasz Andrzejak meltir@meltir.com
+#testfest London 2009-05-09
+--FILE--
+<?php
+$i = new ArrayIterator(array(1,1,1,1,1));
+$i = new CachingIterator($i);
+try {
+  $i->getCache();
+  echo "Should have caused an exception";
+} catch (BadMethodCallException $e) {
+  echo "Exception raised\n";
+}
+
+?>
+===DONE===
+--EXPECT--
+Exception raised
+===DONE===
\ No newline at end of file
diff --git a/ext/spl/tests/spl_iterator_getcallchildren.phpt b/ext/spl/tests/spl_iterator_getcallchildren.phpt
new file mode 100644 (file)
index 0000000..77b03b6
--- /dev/null
@@ -0,0 +1,39 @@
+--TEST--
+SPL: RecursiveIteratorIterator, getCallChildren
+--CREDITS--
+Sean Burlington www.practicalweb.co.uk
+TestFest London May 2009
+--FILE--
+<?php
+  //line 681 ...
+  $array = array(array(7,8,9),1,2,3,array(4,5,6));
+$recursiveArrayIterator = new RecursiveArrayIterator($array);
+$test = new RecursiveIteratorIterator($recursiveArrayIterator);
+
+var_dump($test->current());
+$test->next();
+var_dump($test->current());
+try {
+  $output = $test->callGetChildren();
+} catch (InvalidArgumentException $ilae){
+  $output = null;  
+  print "invalid argument exception\n";
+}
+var_dump($output);
+
+
+?>
+===DONE===
+--EXPECTF--
+  array(3) {
+  [0]=>
+  int(7)
+  [1]=>
+  int(8)
+  [2]=>
+  int(9)
+}
+int(7)
+invalid argument exception
+NULL
+===DONE===
diff --git a/ext/spl/tests/spl_iterator_iterator_constructor.phpt b/ext/spl/tests/spl_iterator_iterator_constructor.phpt
new file mode 100644 (file)
index 0000000..d4fdb14
--- /dev/null
@@ -0,0 +1,30 @@
+--TEST--
+SPL: IteratorInterator constructor checks 
+--CREDITS--
+Sean Burlington www.practicalweb.co.uk
+TestFest London May 2009
+--FILE--
+<?php
+
+  //I think this is testing line 1297 of spl_iterators.c
+
+  $array = array(array(7,8,9),1,2,3,array(4,5,6));
+$arrayIterator = new ArrayIterator($array);
+try {
+$test = new IteratorIterator($arrayIterator);
+
+$test = new IteratorIterator($arrayIterator, 1);
+$test = new IteratorIterator($arrayIterator, 1, 1);
+$test = new IteratorIterator($arrayIterator, 1, 1, 1);
+$test = new IteratorIterator($arrayIterator, 1, 1, 1, 1);
+
+} catch (InvalidArgumentException $e){
+  print  $e->getMessage() . "\n";
+}
+
+
+?>
+===DONE===
+--EXPECTF--
+IteratorIterator::__construct() expects at most 2 parameters, 3 given
+===DONE===
diff --git a/ext/spl/tests/spl_iterator_recursive_getiterator_error.phpt b/ext/spl/tests/spl_iterator_recursive_getiterator_error.phpt
new file mode 100644 (file)
index 0000000..0d45c31
--- /dev/null
@@ -0,0 +1,16 @@
+--TEST--
+SPL: IteratorIterator foreach by reference failure
+--CREDITS--
+Lukasz Andrzejak meltir@meltir.com
+#testfest London 2009-05-09
+--FILE--
+<?php
+$i = new ArrayIterator(array(1,1,1,1,1));
+$iii = new IteratorIterator($i);
+p($iii);
+function p ($i) {
+  foreach ($i as &$value) {}
+}
+?>
+--EXPECTF--
+Fatal error: An iterator cannot be used with foreach by reference in %s
\ No newline at end of file
diff --git a/ext/spl/tests/spl_iterator_to_array_basic.phpt b/ext/spl/tests/spl_iterator_to_array_basic.phpt
new file mode 100644 (file)
index 0000000..68cb879
--- /dev/null
@@ -0,0 +1,13 @@
+--TEST--
+SPL: iterator_to_array, Test function to convert iterator to array
+--CREDITS--
+Chris Scott chris.scott@nstein.com
+#testfest London 2009-05-09
+--FILE--
+<?php
+
+iterator_to_array();//requires iterator as arg
+
+?>
+--EXPECTF--
+Warning: iterator_to_array() expects at least 1 parameter, %s
diff --git a/ext/spl/tests/spl_iterator_to_array_error.phpt b/ext/spl/tests/spl_iterator_to_array_error.phpt
new file mode 100755 (executable)
index 0000000..755ef7b
--- /dev/null
@@ -0,0 +1,33 @@
+--TEST--
+SPL: Error: iterator_to_array when the current operation throws an exception
+--FILE--
+<?php
+
+class MyArrayIterator extends ArrayIterator {
+       public function current() {
+               throw new Exception('Make the iterator break');
+       }
+}
+
+$it = new MyArrayIterator(array(4, 6, 2));
+
+try {
+       // get keys
+       $ar = iterator_to_array($it);
+} catch (Exception $e) {
+       echo $e->getMessage() . PHP_EOL;
+}
+
+try {
+       // get values
+       $ar = iterator_to_array($it, false);
+} catch (Exception $e) {
+       echo $e->getMessage() . PHP_EOL;
+}
+
+?>
+
+<?php exit(0); ?>
+--EXPECT--
+Make the iterator break
+Make the iterator break
diff --git a/ext/spl/tests/spl_limit_iterator_check_limits.phpt b/ext/spl/tests/spl_limit_iterator_check_limits.phpt
new file mode 100644 (file)
index 0000000..01436a8
--- /dev/null
@@ -0,0 +1,37 @@
+--TEST--
+SPL: LimitIterator check limits are valid
+--CREDITS--
+Sean Burlington www.practicalweb.co.uk
+TestFest London May 2009
+--FILE--
+<?php
+  $array = array(array(7,8,9),1,2,3,array(4,5,6));
+$arrayIterator = new ArrayIterator($array);
+
+try {
+  $limitIterator = new LimitIterator($arrayIterator, -1);
+} catch (OutOfRangeException $e){
+  print $e->getMessage(). "\n";
+}
+
+
+try {
+  $limitIterator = new LimitIterator($arrayIterator, 0, -2);
+} catch (OutOfRangeException $e){
+  print $e->getMessage() . "\n";
+}
+
+try {
+  $limitIterator = new LimitIterator($arrayIterator, 0, -1);
+} catch (OutOfRangeException $e){
+  print $e->getMessage() . "\n";
+}
+
+
+
+?>
+===DONE===
+--EXPECTF--
+Parameter offset must be > 0
+Parameter count must either be -1 or a value greater than or equal 0
+===DONE===
diff --git a/ext/spl/tests/spl_recursiveIteratorIterator_setMaxDepth_parameter_count.phpt b/ext/spl/tests/spl_recursiveIteratorIterator_setMaxDepth_parameter_count.phpt
new file mode 100644 (file)
index 0000000..d52a320
--- /dev/null
@@ -0,0 +1,28 @@
+--TEST--
+SPL: RecursiveIteratorIterator, setMaxDepth check parameter count
+--CREDITS--
+Sean Burlington www.practicalweb.co.uk
+TestFest London May 2009
+--FILE--
+<?php
+  //line 681 ...
+  $array = array(array(7,8,9),1,2,3,array(4,5,6));
+$recursiveArrayIterator = new RecursiveArrayIterator($array);
+$test = new RecursiveIteratorIterator($recursiveArrayIterator);
+
+//var_dump($test->current());
+$test->setMaxDepth();
+$test->setMaxDepth(1);
+$test->setMaxDepth(1,2);
+$test->setMaxDepth(1,2,3);
+
+//var_dump($test->current());
+
+
+?>
+===DONE===
+--EXPECTF--
+Warning: RecursiveIteratorIterator::setMaxDepth() expects at most 1 parameter, 2 given in %s on line 10
+
+Warning: RecursiveIteratorIterator::setMaxDepth() expects at most 1 parameter, 3 given in %s on line 11
+===DONE===
diff --git a/ext/spl/tests/spl_recursive_iterator_iterator_key_case.phpt b/ext/spl/tests/spl_recursive_iterator_iterator_key_case.phpt
new file mode 100644 (file)
index 0000000..1262ec0
--- /dev/null
@@ -0,0 +1,33 @@
+--TEST--
+SPL: Test on RecursiveIteratorIterator key function checking switch statements 
+--CREDITS--
+Rohan Abraham (rohanabrahams@gmail.com)
+TestFest London May 2009
+--FILE--
+<?php
+  $ar = array("one"=>1, "two"=>2, "three"=>array("four"=>4, "five"=>5, "six"=>array("seven"=>7)), "eight"=>8, -100 => 10, NULL => "null");
+  $it = new RecursiveArrayIterator($ar);
+  $it = new RecursiveIteratorIterator($it);
+  foreach($it as $k=>$v)
+  {
+    echo "$k=>$v\n";
+    var_dump($k);
+  }
+?>
+--EXPECTF--
+one=>1
+%unicode|string%(3) "one"
+two=>2
+%unicode|string%(3) "two"
+four=>4
+%unicode|string%(4) "four"
+five=>5
+%unicode|string%(4) "five"
+seven=>7
+%unicode|string%(5) "seven"
+eight=>8
+%unicode|string%(5) "eight"
+-100=>10
+int(-100)
+=>null
+%unicode|string%(0) ""