diff options
Diffstat (limited to 'ext/spl/tests')
| -rw-r--r-- | ext/spl/tests/SplDoublyLinkedList_add_invalid_offset.phpt | 13 | ||||
| -rw-r--r-- | ext/spl/tests/SplDoublyLinkedList_add_missing_parameter1.phpt | 11 | ||||
| -rw-r--r-- | ext/spl/tests/SplDoublyLinkedList_add_missing_parameter2.phpt | 11 | ||||
| -rw-r--r-- | ext/spl/tests/SplDoublyLinkedList_add_null_offset.phpt | 13 | ||||
| -rw-r--r-- | ext/spl/tests/bug61697.phpt | 24 | ||||
| -rw-r--r-- | ext/spl/tests/bug64782.phpt | 21 | ||||
| -rw-r--r-- | ext/spl/tests/dllist_013.phpt | 45 | ||||
| -rw-r--r-- | ext/spl/tests/iterator_to_array_nonscalar_keys.phpt | 31 | ||||
| -rw-r--r-- | ext/spl/tests/multiple_iterator_001.phpt | 20 | ||||
| -rw-r--r-- | ext/spl/tests/recursive_tree_iterator_setpostfix.phpt | 88 |
10 files changed, 267 insertions, 10 deletions
diff --git a/ext/spl/tests/SplDoublyLinkedList_add_invalid_offset.phpt b/ext/spl/tests/SplDoublyLinkedList_add_invalid_offset.phpt new file mode 100644 index 0000000000..b94b067f4d --- /dev/null +++ b/ext/spl/tests/SplDoublyLinkedList_add_invalid_offset.phpt @@ -0,0 +1,13 @@ +--TEST-- +Check that SplDoublyLinkedList::add throws an exception with an invalid offset argument +--FILE-- +<?php +try { + $dll = new SplDoublyLinkedList(); + var_dump($dll->add(12,'Offset 12 should not exist')); +} catch (OutOfRangeException $e) { + echo "Exception: ".$e->getMessage()."\n"; +} +?> +--EXPECTF-- +Exception: Offset invalid or out of range diff --git a/ext/spl/tests/SplDoublyLinkedList_add_missing_parameter1.phpt b/ext/spl/tests/SplDoublyLinkedList_add_missing_parameter1.phpt new file mode 100644 index 0000000000..12cfe40008 --- /dev/null +++ b/ext/spl/tests/SplDoublyLinkedList_add_missing_parameter1.phpt @@ -0,0 +1,11 @@ +--TEST-- +Check that SplDoublyLinkedList::add generate a warning and returns a NULL with missing arguments +--FILE-- +<?php +$dll = new SplDoublyLinkedList(); +var_dump($dll->add()); +?> +--EXPECTF-- +Warning: SplDoublyLinkedList::add() expects exactly 2 parameters, 0 given in %s on line %d +NULL + diff --git a/ext/spl/tests/SplDoublyLinkedList_add_missing_parameter2.phpt b/ext/spl/tests/SplDoublyLinkedList_add_missing_parameter2.phpt new file mode 100644 index 0000000000..c9c319316f --- /dev/null +++ b/ext/spl/tests/SplDoublyLinkedList_add_missing_parameter2.phpt @@ -0,0 +1,11 @@ +--TEST-- +Check that SplDoublyLinkedList::add generate a warning and returns a NULL with a missing value argument +--FILE-- +<?php +$dll = new SplDoublyLinkedList(); +var_dump($dll->add(2)); +?> +--EXPECTF-- +Warning: SplDoublyLinkedList::add() expects exactly 2 parameters, 1 given in %s on line %d +NULL + diff --git a/ext/spl/tests/SplDoublyLinkedList_add_null_offset.phpt b/ext/spl/tests/SplDoublyLinkedList_add_null_offset.phpt new file mode 100644 index 0000000000..396f89b491 --- /dev/null +++ b/ext/spl/tests/SplDoublyLinkedList_add_null_offset.phpt @@ -0,0 +1,13 @@ +--TEST-- +Check that SplDoublyLinkedList::add throws an exception with an invalid offset argument +--FILE-- +<?php +try { + $dll = new SplDoublyLinkedList(); + var_dump($dll->add(NULL,2)); +} catch (OutOfRangeException $e) { + echo "Exception: ".$e->getMessage()."\n"; +} +?> +--EXPECTF-- +Exception: Offset invalid or out of range diff --git a/ext/spl/tests/bug61697.phpt b/ext/spl/tests/bug61697.phpt new file mode 100644 index 0000000000..064aaa2e2b --- /dev/null +++ b/ext/spl/tests/bug61697.phpt @@ -0,0 +1,24 @@ +--TEST-- +Bug #61697 (spl_autoload_functions returns lambda functions incorrectly) +--FILE-- +<?php + +function f1($class) { echo "f1: [[$class]]\n"; } +function f2($class) { echo "f2: [[$class]]\n"; } + +spl_autoload_register('f1'); +spl_autoload_register('f2'); +spl_autoload_register(create_function('$class', 'echo "cf1: [[$class]]\n";')); +spl_autoload_register(create_function('$class', 'echo "cf2: [[$class]]\n";')); + +foreach (spl_autoload_functions() AS $func) +{ + spl_autoload_unregister($func); +} + +print_r(spl_autoload_functions()); +?> +--EXPECTF-- +Array +( +) diff --git a/ext/spl/tests/bug64782.phpt b/ext/spl/tests/bug64782.phpt new file mode 100644 index 0000000000..ac5d08d7d1 --- /dev/null +++ b/ext/spl/tests/bug64782.phpt @@ -0,0 +1,21 @@ +--TEST-- +Bug #64782: SplFileObject constructor make $context optional / give it a default value +--FILE-- +<?php + +var_dump(new SplFileObject(__FILE__, "r", false, null)); + +?> +--EXPECTF-- +object(SplFileObject)#1 (%d) { + ["pathName":"SplFileInfo":private]=> + string(%d) "%s/bug64782.php" + ["fileName":"SplFileInfo":private]=> + string(12) "bug64782.php" + ["openMode":"SplFileObject":private]=> + string(1) "r" + ["delimiter":"SplFileObject":private]=> + string(1) "," + ["enclosure":"SplFileObject":private]=> + string(1) """ +} diff --git a/ext/spl/tests/dllist_013.phpt b/ext/spl/tests/dllist_013.phpt new file mode 100644 index 0000000000..b60f063924 --- /dev/null +++ b/ext/spl/tests/dllist_013.phpt @@ -0,0 +1,45 @@ +--TEST-- +SPL: DoublyLinkedList: insert operations +--FILE-- +<?php +$dll = new SplDoublyLinkedList(); +// errors +try { + $dll->add(2,5); +} catch (OutOfRangeException $e) { + echo "Exception: ".$e->getMessage()."\n"; +} + +$dll->add(0,6); // 6 +$dll->add(0,3); // 3 6 +// Insert in the middle of the DLL +$dll->add(1,4); // 3 4 6 +$dll->add(2,5); // 3 4 5 6 +$dll->unshift(2); // 2 3 5 4 6 +// Insert at the beginning and end of the DLL +$dll->add(0,1); // 1 2 3 4 5 6 +$dll->add(6,7); // 1 2 3 4 5 6 7 + +echo count($dll)."\n"; + +echo $dll->pop()."\n"; +echo $dll->pop()."\n"; +echo $dll->pop()."\n"; +echo $dll->pop()."\n"; +echo $dll->pop()."\n"; +echo $dll->pop()."\n"; +echo $dll->pop()."\n"; +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +Exception: Offset invalid or out of range +7 +7 +6 +5 +4 +3 +2 +1 +===DONE=== diff --git a/ext/spl/tests/iterator_to_array_nonscalar_keys.phpt b/ext/spl/tests/iterator_to_array_nonscalar_keys.phpt new file mode 100644 index 0000000000..4ca9485faf --- /dev/null +++ b/ext/spl/tests/iterator_to_array_nonscalar_keys.phpt @@ -0,0 +1,31 @@ +--TEST-- +Tests iterator_to_array() with non-scalar keys +--FILE-- +<?php + +function gen() { + yield "foo" => 0; + yield 1 => 1; + yield 2.5 => 2; + yield null => 3; + yield [] => 4; + yield new stdClass => 5; +} + +var_dump(iterator_to_array(gen())); + +?> +--EXPECTF-- +Warning: Illegal offset type in %s on line %d + +Warning: Illegal offset type in %s on line %d +array(4) { + ["foo"]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [""]=> + int(3) +} diff --git a/ext/spl/tests/multiple_iterator_001.phpt b/ext/spl/tests/multiple_iterator_001.phpt index edd03f5040..eb77f79371 100644 --- a/ext/spl/tests/multiple_iterator_001.phpt +++ b/ext/spl/tests/multiple_iterator_001.phpt @@ -23,8 +23,8 @@ echo "-- Default flags, MultipleIterator::MIT_NEED_ALL | MultipleIterator::MIT_K var_dump($m->getFlags() === (MultipleIterator::MIT_NEED_ALL | MultipleIterator::MIT_KEYS_NUMERIC)); -foreach($m as $value) { - var_dump($m->key(), $value); +foreach($m as $key => $value) { + var_dump($key, $value); } try { $m->current(); @@ -42,8 +42,8 @@ echo "-- Flags = MultipleIterator::MIT_NEED_ANY | MultipleIterator::MIT_KEYS_NUM $m->setFlags(MultipleIterator::MIT_NEED_ANY | MultipleIterator::MIT_KEYS_NUMERIC); var_dump($m->getFlags() === (MultipleIterator::MIT_NEED_ANY | MultipleIterator::MIT_KEYS_NUMERIC)); -foreach($m as $value) { - var_dump($m->key(), $value); +foreach($m as $key => $value) { + var_dump($key, $value); } echo "-- Default flags, added element --\n"; @@ -51,8 +51,8 @@ echo "-- Default flags, added element --\n"; $m->setFlags(MultipleIterator::MIT_NEED_ALL | MultipleIterator::MIT_KEYS_NUMERIC); $iter2[] = 3; -foreach($m as $value) { - var_dump($m->key(), $value); +foreach($m as $key => $value) { + var_dump($key, $value); } echo "-- Flags |= MultipleIterator::MIT_KEYS_ASSOC, with iterator associated with NULL --\n"; @@ -71,8 +71,8 @@ $m->attachIterator($iter1, "iter1"); $m->attachIterator($iter2, b"iter2"); $m->attachIterator($iter3, 3); -foreach($m as $value) { - var_dump($m->key(), $value); +foreach($m as $key => $value) { + var_dump($key, $value); } echo "-- Associate with invalid value --\n"; @@ -98,8 +98,8 @@ var_dump($m->containsIterator($iter2)); var_dump($m->detachIterator($iter2)); var_dump($m->countIterators()); var_dump($m->containsIterator($iter2)); -foreach($m as $value) { - var_dump($m->key(), $value); +foreach($m as $key => $value) { + var_dump($key, $value); } ?> diff --git a/ext/spl/tests/recursive_tree_iterator_setpostfix.phpt b/ext/spl/tests/recursive_tree_iterator_setpostfix.phpt new file mode 100644 index 0000000000..d59e278fd6 --- /dev/null +++ b/ext/spl/tests/recursive_tree_iterator_setpostfix.phpt @@ -0,0 +1,88 @@ +--TEST-- +SPL: RecursiveTreeIterator::setPostfix() +--CREDITS-- +Joshua Thijssen (jthijssen@noxlogic.nl) +--FILE-- +<?php + +$arr = array( + 0 => array( + "a", + 1, + ), + "a" => array( + 2, + "b", + 3 => array( + 4, + "c", + ), + "3" => array( + 4, + "c", + ), + ), +); + +$it = new RecursiveArrayIterator($arr); +$it = new RecursiveTreeIterator($it); + +echo "----\n"; +echo $it->getPostfix(); +echo "\n\n"; + +echo "----\n"; +$it->setPostfix("POSTFIX"); +echo $it->getPostfix(); +echo "\n\n"; + +echo "----\n"; +foreach($it as $k => $v) { + echo "[$k] => $v\n"; +} + +echo "----\n"; +$it->setPostfix(""); +echo $it->getPostfix(); +echo "\n\n"; + +echo "----\n"; +foreach($it as $k => $v) { + echo "[$k] => $v\n"; +} + + + +?> +===DONE=== +--EXPECTF-- +---- + + +---- +POSTFIX + +---- +[0] => |-ArrayPOSTFIX +[0] => | |-aPOSTFIX +[1] => | \-1POSTFIX +[a] => \-ArrayPOSTFIX +[0] => |-2POSTFIX +[1] => |-bPOSTFIX +[3] => \-ArrayPOSTFIX +[0] => |-4POSTFIX +[1] => \-cPOSTFIX +---- + + +---- +[0] => |-Array +[0] => | |-a +[1] => | \-1 +[a] => \-Array +[0] => |-2 +[1] => |-b +[3] => \-Array +[0] => |-4 +[1] => \-c +===DONE=== |
