diff options
Diffstat (limited to 'ext/standard/tests/array')
| -rw-r--r-- | ext/standard/tests/array/bug40709.phpt | 1 | ||||
| -rw-r--r-- | ext/standard/tests/array/bug44929.phpt | 8 | ||||
| -rw-r--r-- | ext/standard/tests/array/bug48854.phpt | 43 | ||||
| -rw-r--r-- | ext/standard/tests/array/key_exists_basic.phpt | 15 | ||||
| -rw-r--r-- | ext/standard/tests/array/key_exists_error.phpt | 23 | ||||
| -rw-r--r-- | ext/standard/tests/array/key_exists_variation1.phpt | 15 | ||||
| -rw-r--r-- | ext/standard/tests/array/key_exists_variation2.phpt | 72 | ||||
| -rw-r--r-- | ext/standard/tests/array/max_basiclong_64bit.phpt | 35 | ||||
| -rw-r--r-- | ext/standard/tests/array/min_basiclong_64bit.phpt | 35 | ||||
| -rwxr-xr-x | ext/standard/tests/array/unexpected_array_mod_bug.phpt | 21 |
10 files changed, 265 insertions, 3 deletions
diff --git a/ext/standard/tests/array/bug40709.phpt b/ext/standard/tests/array/bug40709.phpt index 6ab6bbd41..eb0c71200 100644 --- a/ext/standard/tests/array/bug40709.phpt +++ b/ext/standard/tests/array/bug40709.phpt @@ -1,6 +1,5 @@ --TEST-- Bug #40709 (array_reduce() behaves strange with one item stored arrays) ---SKIPIF-- --FILE-- <?php function CommaSeperatedList($a, $b) { diff --git a/ext/standard/tests/array/bug44929.phpt b/ext/standard/tests/array/bug44929.phpt index f82ecd052..9dc85acd1 100644 --- a/ext/standard/tests/array/bug44929.phpt +++ b/ext/standard/tests/array/bug44929.phpt @@ -2,20 +2,24 @@ Bug #44929 (natsort doesn't handle leading zeros well) --FILE-- <?php -$a = array(b'001',b'008',b'005',b'00011',b'03',b'000014',b'-123',b'0.002',b'00',b'0'); +$a = array(b'001',b'008',b'005',b'00011',b'03',b'000014',b'-123',b'0.002',b'00',b'0',b'0_0',b'0-0'); natsort($a); var_dump($a); ?> --EXPECT-- -array(10) { +array(12) { [6]=> string(4) "-123" [8]=> string(2) "00" [9]=> string(1) "0" + [11]=> + string(3) "0-0" [7]=> string(5) "0.002" + [10]=> + string(3) "0_0" [0]=> string(3) "001" [4]=> diff --git a/ext/standard/tests/array/bug48854.phpt b/ext/standard/tests/array/bug48854.phpt new file mode 100644 index 000000000..090863750 --- /dev/null +++ b/ext/standard/tests/array/bug48854.phpt @@ -0,0 +1,43 @@ +--TEST-- +Bug #48854 (array_merge_recursive modifies arrays after first one) +--FILE-- +<?php + +$array1 = array( + 'friends' => 5, + 'children' => array( + 'dogs' => 0, + ), +); + +$array2 = array( + 'friends' => 10, + 'children' => array( + 'cats' => 5, + ), +); + +$merged = array_merge_recursive($array1, $array2); + +var_dump($array1, $array2); + +?> +--EXPECTF-- +array(2) { + [%u|b%"friends"]=> + int(5) + [%u|b%"children"]=> + array(1) { + [%u|b%"dogs"]=> + int(0) + } +} +array(2) { + [%u|b%"friends"]=> + int(10) + [%u|b%"children"]=> + array(1) { + [%u|b%"cats"]=> + int(5) + } +} diff --git a/ext/standard/tests/array/key_exists_basic.phpt b/ext/standard/tests/array/key_exists_basic.phpt new file mode 100644 index 000000000..40d982da2 --- /dev/null +++ b/ext/standard/tests/array/key_exists_basic.phpt @@ -0,0 +1,15 @@ +--TEST-- +Test function key_exists() by calling it with its expected arguments +--CREDITS-- +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--FILE-- +<?php +echo "*** test key_exists() by calling it with its expected arguments ***\n"; +$a = array('bar' => 1); +var_dump(key_exists('bar', $a)); +var_dump(key_exists('foo', $a)); +--EXPECTF-- +*** test key_exists() by calling it with its expected arguments *** +bool(true) +bool(false) diff --git a/ext/standard/tests/array/key_exists_error.phpt b/ext/standard/tests/array/key_exists_error.phpt new file mode 100644 index 000000000..1bbd41e20 --- /dev/null +++ b/ext/standard/tests/array/key_exists_error.phpt @@ -0,0 +1,23 @@ +--TEST-- +Test function key_exists() by calling it more than or less than its expected arguments +--CREDITS-- +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--FILE-- +<?php + +echo "*** Test by calling method or function with incorrect numbers of arguments ***\n"; + +$a = array('bar' => 1); +var_dump(key_exists()); +var_dump(key_exists('foo', $a, 'baz')); + +?> +--EXPECTF-- +*** Test by calling method or function with incorrect numbers of arguments *** + +Warning: key_exists() expects exactly 2 parameters, 0 given in %s on line %d +NULL + +Warning: key_exists() expects exactly 2 parameters, 3 given in %s on line %d +NULL diff --git a/ext/standard/tests/array/key_exists_variation1.phpt b/ext/standard/tests/array/key_exists_variation1.phpt new file mode 100644 index 000000000..94ea8d45f --- /dev/null +++ b/ext/standard/tests/array/key_exists_variation1.phpt @@ -0,0 +1,15 @@ +--TEST-- +Test function key_exists() by calling it with its expected arguments +--CREDITS-- +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--FILE-- +<?php +echo "*** test key_exists() by calling it with its expected arguments ***\n"; +$a = array('bar' => 1, 'foo' => array('bar' => 2, 'baz' => 3)); +var_dump(key_exists('baz', $a)); +var_dump(key_exists('baz', $a['foo'])); +--EXPECTF-- +*** test key_exists() by calling it with its expected arguments *** +bool(false) +bool(true) diff --git a/ext/standard/tests/array/key_exists_variation2.phpt b/ext/standard/tests/array/key_exists_variation2.phpt new file mode 100644 index 000000000..5f5ab86a4 --- /dev/null +++ b/ext/standard/tests/array/key_exists_variation2.phpt @@ -0,0 +1,72 @@ +--TEST-- +Test function key_exists() by calling it with its expected arguments +--CREDITS-- +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--FILE-- +<?php +echo "*** test key_exists() by using mixed type of arrays ***\n"; + +// there is not a index = 0 element +$a = array(1 => 'bar', 'foo' => 'baz'); +var_dump(key_exists(0, $a)); + +echo "integer\n"; +// 1 has index = 0 +$b = array(1, 'foo' => 'baz'); +var_dump(key_exists(0, $b)); + +// 42 has index = 0, netherless its position is the latest +$c = array('foo' => 'baz', 42); +var_dump(key_exists(0, $c)); + +echo "string\n"; +// 'bar' has index = 0, netherless it is a string +$d = array('bar', 'foo' => 'baz'); +var_dump(key_exists(0, $d)); + +// 'baz' has index = 0, netherless its position is the latest +$e = array('foo' => 'baz', 'baz'); +var_dump(key_exists(0, $e)); + +echo "obj\n"; +class ObjectA +{ + public $foo = 'bar'; +} + +$obj = new ObjectA(); + +// object has index = 0, netherless its position is the latest +$f = array('foo' => 'baz', $obj); +var_dump(key_exists(0, $f)); + +// object has index = 0, netherless its position is the first +$g = array($obj, 'foo' => 'baz'); +var_dump(key_exists(0, $g)); + +echo "stream resource\n"; +// stream resource has index = 0, netherless its position is the first +$st = fopen('php://memory', '+r'); +$h = array($st, 'foo' => 'baz'); +var_dump(key_exists(0, $h)); + +// stream resource has index = 0, netherless its position is the latest +$i = array('foo' => 'baz', $st); +var_dump(key_exists(0, $i)); + +--EXPECTF-- +*** test key_exists() by using mixed type of arrays *** +bool(false) +integer +bool(true) +bool(true) +string +bool(true) +bool(true) +obj +bool(true) +bool(true) +stream resource +bool(true) +bool(true) diff --git a/ext/standard/tests/array/max_basiclong_64bit.phpt b/ext/standard/tests/array/max_basiclong_64bit.phpt new file mode 100644 index 000000000..1eb7e31cd --- /dev/null +++ b/ext/standard/tests/array/max_basiclong_64bit.phpt @@ -0,0 +1,35 @@ +--TEST-- +Test max function : 64bit long tests +--SKIPIF-- +<?php +if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); +?> +--FILE-- +<?php + +define("MAX_64Bit", 9223372036854775807); +define("MAX_32Bit", 2147483647); +define("MIN_64Bit", -MAX_64Bit - 1); +define("MIN_32Bit", -MAX_32Bit - 1); + +$arrayVals = array( + MAX_64Bit, MIN_64Bit, MAX_32Bit, MIN_32Bit, MAX_64Bit - MAX_32Bit, MIN_64Bit - MIN_32Bit, + MAX_32Bit + 1, MIN_32Bit - 1, MAX_32Bit * 2, (MAX_32Bit * 2) + 1, (MAX_32Bit * 2) - 1, + MAX_64Bit -1, MIN_64Bit + 1 +); + +$longVals = array( + MAX_64Bit, MIN_64Bit, MAX_32Bit, MIN_32Bit, MAX_64Bit - MAX_32Bit, MIN_64Bit - MIN_32Bit, + MAX_32Bit + 1, MIN_32Bit - 1, MAX_32Bit * 2, (MAX_32Bit * 2) + 1, (MAX_32Bit * 2) - 1, + MAX_64Bit -1, MAX_64Bit + 1, MIN_64Bit + 1, MIN_64Bit - 1 +); + + var_dump(max($arrayVals)); + var_dump(max($longVals)); + +?> +===DONE=== +--EXPECT-- +int(9223372036854775807) +int(9223372036854775807) +===DONE=== diff --git a/ext/standard/tests/array/min_basiclong_64bit.phpt b/ext/standard/tests/array/min_basiclong_64bit.phpt new file mode 100644 index 000000000..52f63f391 --- /dev/null +++ b/ext/standard/tests/array/min_basiclong_64bit.phpt @@ -0,0 +1,35 @@ +--TEST-- +Test min function : 64bit long tests +--SKIPIF-- +<?php +if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); +?> +--FILE-- +<?php + +define("MAX_64Bit", 9223372036854775807); +define("MAX_32Bit", 2147483647); +define("MIN_64Bit", -MAX_64Bit - 1); +define("MIN_32Bit", -MAX_32Bit - 1); + +$arrayVals = array( + MAX_64Bit, MIN_64Bit, MAX_32Bit, MIN_32Bit, MAX_64Bit - MAX_32Bit, MIN_64Bit - MIN_32Bit, + MAX_32Bit + 1, MIN_32Bit - 1, MAX_32Bit * 2, (MAX_32Bit * 2) + 1, (MAX_32Bit * 2) - 1, + MAX_64Bit -1, MIN_64Bit + 1 +); + +$longVals = array( + MAX_64Bit, MIN_64Bit, MAX_32Bit, MIN_32Bit, MAX_64Bit - MAX_32Bit, MIN_64Bit - MIN_32Bit, + MAX_32Bit + 1, MIN_32Bit - 1, MAX_32Bit * 2, (MAX_32Bit * 2) + 1, (MAX_32Bit * 2) - 1, + MAX_64Bit -1, MAX_64Bit + 1, MIN_64Bit + 1, MIN_64Bit - 1 +); + + var_dump(min($arrayVals)); + var_dump(min($longVals)); + +?> +===DONE=== +--EXPECT-- +int(-9223372036854775808) +int(-9223372036854775808) +===DONE=== diff --git a/ext/standard/tests/array/unexpected_array_mod_bug.phpt b/ext/standard/tests/array/unexpected_array_mod_bug.phpt new file mode 100755 index 000000000..58f224920 --- /dev/null +++ b/ext/standard/tests/array/unexpected_array_mod_bug.phpt @@ -0,0 +1,21 @@ +--TEST-- +Crash when function parameter modified via reference +--FILE-- +<?php +function usercompare($a,$b) { + unset($GLOBALS['my_var'][2]); + return 0; +} +$my_var = array(1 => "entry_1", +2 => "entry_2", +3 => "entry_3", +4 => "entry_4", +5 => "entry_5"); +usort($my_var, "usercompare"); + +echo "Done.\n"; +?> +--EXPECTF-- + +Warning: usort(): Array was modified by the user comparison function in %s on line %d +Done. |
