diff --git a/tests/std/array/009.phpt b/tests/std/array/009.phpt new file mode 100644 index 00000000..f4aab2fa --- /dev/null +++ b/tests/std/array/009.phpt @@ -0,0 +1,408 @@ +--TEST-- +Test key(), current(), next() & reset() functions +--FILE-- + "apple", "b" => "book", "c" => "cook"), // associative array + array('d' => 'drink', 'p' => 'port', 's' => 'set'), // another associative array + array(1 => 'One', 2 => 'two', 3 => "three") // associative array with key as integers +); + +$varient_arrays = array ( + array(), // empty array + array(""), // array with null string + array(NULL),// array with NULL + array(null),// array with null + array(NULL, true, null, "", 1), // mixed array + array(-1 => "test", -2 => "rest", 2 => "two", + "" => "string", 0 => "zero", "" => "" ) // mixed array +); + +echo "*** Testing basic operations ***\n"; +$loop_count = 1; +foreach ($basic_arrays as $sub_array ) { + echo "-- Iteration $loop_count --\n"; + $loop_count++; + $c = count ($sub_array); + $c++; // increment by one to create the situation of accessing beyond array size + while ( $c ) { + var_dump( current($sub_array)); // current element + var_dump( key($sub_array) ); // key of the current element + var_dump( next($sub_array) ); // move to next element + $c --; + } + var_dump( reset($sub_array) ); // reset the internal pointer to first element + var_dump( key($sub_array) ); // access the array after reset + var_dump( $sub_array ); // dump the array to see that its intact + + echo "\n"; +} + +echo "\n*** Testing possible variations ***\n"; +$loop_count = 1; +foreach ($varient_arrays as $sub_array ) { + echo "-- Iteration $loop_count --\n"; + $loop_count++; + $c = count ($sub_array); + $c++; // increment by one to create the situation of accessing beyond array size + while ( $c ) { + var_dump( current($sub_array)); // current element + var_dump( key($sub_array) ); // key of the current element + var_dump( next($sub_array) ); // move to next element + $c --; + } + var_dump( reset($sub_array) ); // reset the internal pointer to first element + var_dump( key($sub_array) ); // access the array after reset + var_dump( $sub_array ); // dump the array to see that its intact + echo "\n"; +} + +echo "Done\n"; +?> +--EXPECT-- +*** Testing basic operations *** +-- Iteration 1 -- +int(0) +int(0) +bool(false) +bool(false) +NULL +bool(false) +int(0) +int(0) +array(1) { + [0]=> + int(0) +} + +-- Iteration 2 -- +int(1) +int(0) +bool(false) +bool(false) +NULL +bool(false) +int(1) +int(0) +array(1) { + [0]=> + int(1) +} + +-- Iteration 3 -- +int(1) +int(0) +int(2) +int(2) +int(1) +int(3) +int(3) +int(2) +int(-1) +int(-1) +int(3) +int(-2) +int(-2) +int(4) +int(-3) +int(-3) +int(5) +bool(false) +bool(false) +NULL +bool(false) +int(1) +int(0) +array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(-1) + [4]=> + int(-2) + [5]=> + int(-3) +} + +-- Iteration 4 -- +float(1.1) +int(0) +float(2.2) +float(2.2) +int(1) +float(3.3) +float(3.3) +int(2) +float(-1.1) +float(-1.1) +int(3) +float(-2.2) +float(-2.2) +int(4) +float(-3.3) +float(-3.3) +int(5) +bool(false) +bool(false) +NULL +bool(false) +float(1.1) +int(0) +array(6) { + [0]=> + float(1.1) + [1]=> + float(2.2) + [2]=> + float(3.3) + [3]=> + float(-1.1) + [4]=> + float(-2.2) + [5]=> + float(-3.3) +} + +-- Iteration 5 -- +string(1) "a" +int(0) +string(1) "b" +string(1) "b" +int(1) +string(1) "c" +string(1) "c" +int(2) +string(2) "ab" +string(2) "ab" +int(3) +string(2) "ac" +string(2) "ac" +int(4) +string(2) "ad" +string(2) "ad" +int(5) +bool(false) +bool(false) +NULL +bool(false) +string(1) "a" +int(0) +array(6) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + [3]=> + string(2) "ab" + [4]=> + string(2) "ac" + [5]=> + string(2) "ad" +} + +-- Iteration 6 -- +string(5) "apple" +string(1) "a" +string(4) "book" +string(4) "book" +string(1) "b" +string(4) "cook" +string(4) "cook" +string(1) "c" +bool(false) +bool(false) +NULL +bool(false) +string(5) "apple" +string(1) "a" +array(3) { + ["a"]=> + string(5) "apple" + ["b"]=> + string(4) "book" + ["c"]=> + string(4) "cook" +} + +-- Iteration 7 -- +string(5) "drink" +string(1) "d" +string(4) "port" +string(4) "port" +string(1) "p" +string(3) "set" +string(3) "set" +string(1) "s" +bool(false) +bool(false) +NULL +bool(false) +string(5) "drink" +string(1) "d" +array(3) { + ["d"]=> + string(5) "drink" + ["p"]=> + string(4) "port" + ["s"]=> + string(3) "set" +} + +-- Iteration 8 -- +string(3) "One" +int(1) +string(3) "two" +string(3) "two" +int(2) +string(5) "three" +string(5) "three" +int(3) +bool(false) +bool(false) +NULL +bool(false) +string(3) "One" +int(1) +array(3) { + [1]=> + string(3) "One" + [2]=> + string(3) "two" + [3]=> + string(5) "three" +} + + +*** Testing possible variations *** +-- Iteration 1 -- +bool(false) +NULL +bool(false) +bool(false) +NULL +array(0) { +} + +-- Iteration 2 -- +string(0) "" +int(0) +bool(false) +bool(false) +NULL +bool(false) +string(0) "" +int(0) +array(1) { + [0]=> + string(0) "" +} + +-- Iteration 3 -- +NULL +int(0) +bool(false) +bool(false) +NULL +bool(false) +NULL +int(0) +array(1) { + [0]=> + NULL +} + +-- Iteration 4 -- +NULL +int(0) +bool(false) +bool(false) +NULL +bool(false) +NULL +int(0) +array(1) { + [0]=> + NULL +} + +-- Iteration 5 -- +NULL +int(0) +bool(true) +bool(true) +int(1) +NULL +NULL +int(2) +string(0) "" +string(0) "" +int(3) +int(1) +int(1) +int(4) +bool(false) +bool(false) +NULL +bool(false) +NULL +int(0) +array(5) { + [0]=> + NULL + [1]=> + bool(true) + [2]=> + NULL + [3]=> + string(0) "" + [4]=> + int(1) +} + +-- Iteration 6 -- +string(4) "test" +int(-1) +string(4) "rest" +string(4) "rest" +int(-2) +string(3) "two" +string(3) "two" +int(2) +string(0) "" +string(0) "" +string(0) "" +string(4) "zero" +string(4) "zero" +int(0) +bool(false) +bool(false) +NULL +bool(false) +string(4) "test" +int(-1) +array(5) { + [-1]=> + string(4) "test" + [-2]=> + string(4) "rest" + [2]=> + string(3) "two" + [""]=> + string(0) "" + [0]=> + string(4) "zero" +} + +Done diff --git a/tests/std/array/array_all_basic.phpt b/tests/std/array/array_all_basic.phpt new file mode 100644 index 00000000..37a33069 --- /dev/null +++ b/tests/std/array/array_all_basic.phpt @@ -0,0 +1,59 @@ +--TEST-- +Test array_all() function : basic functionality +--SKIPIF-- +--FILE-- + 1, + "b" => 2, + "c" => 3, + "d" => 4, + "e" => 5, +]; + +$array2 = [ + 1, 2, 3, 4, 5 +]; + +var_dump(array_all($array1, fn($value, $key) => $value > 0)); +var_dump(array_all($array2, fn($value, $key) => $value > 0)); +var_dump(array_all($array2, fn($value, $key) => $value > 1)); +var_dump(array_all([], fn($value, $key) => true)); + +var_dump(array_all($array1, 'even')); + +var_dump(array_all($array1, 'return_nothing')); + +var_dump(array_all($array1, [ + 'SmallerTenClass', + 'smallerTen' +])); + +var_dump(array_all($array1, "SmallerTenClass::smallerTen")); +} +?> +--EXPECT-- +bool(true) +bool(true) +bool(false) +bool(true) +bool(false) +bool(false) +bool(true) +bool(true) diff --git a/tests/std/array/array_any_basic.phpt b/tests/std/array/array_any_basic.phpt new file mode 100644 index 00000000..47606623 --- /dev/null +++ b/tests/std/array/array_any_basic.phpt @@ -0,0 +1,51 @@ +--TEST-- +Test array_any() function : basic functionality +--SKIPIF-- + + +--FILE-- + 1, "b" => 2, "c" => 3, "d" => 4, "e" => 5]; + $array2 = [1, 2, 3, 4, 5]; + var_dump(array_any($array1, fn($value, $key) => $value > 3)); + var_dump(array_any($array2, fn($value, $key) => $value > 3)); + var_dump(array_any($array2, fn($value, $key) => $value > 5)); + var_dump(array_any([], fn($value, $key) => true)); + var_dump(array_any($array1, fn($value, $key) => $key === "c")); + var_dump(array_any($array1, fn($value, $key) => false)); + var_dump(array_any($array1, 'even')); + var_dump(array_any($array1, 'return_nothing')); + var_dump(array_any($array1, ['EvenClass', 'even'])); + var_dump(array_any($array1, "EvenClass::even")); +} +?> +--EXPECT-- +bool(true) +bool(true) +bool(false) +bool(false) +bool(true) +bool(false) +bool(true) +bool(false) +bool(true) +bool(true) diff --git a/tests/std/array/array_change_key_case.phpt b/tests/std/array/array_change_key_case.phpt new file mode 100644 index 00000000..92c45640 --- /dev/null +++ b/tests/std/array/array_change_key_case.phpt @@ -0,0 +1,811 @@ +--TEST-- +Test array_change_key_case() function +--FILE-- + 1), + array ("a" => 1), + array ("Z" => 1), + array ("one" => 1), + array ("ONE" => 1), + array ("OnE" => 1), + array ("oNe" => 1), + array ("one" => 1, "two" => 2), + array ("ONE" => 1, "two" => 2), + array ("OnE" => 1, "two" => 2), + array ("oNe" => 1, "two" => 2), + array ("one" => 1, "TWO" => 2), + array ("ONE" => 1, "TWO" => 2), + array ("OnE" => 1, "TWO" => 2), + array ("oNe" => 1, "TWO" => 2), + array ("one" => 1, "TwO" => 2), + array ("ONE" => 1, "TwO" => 2), + array ("OnE" => 1, "TwO" => 2), + array ("oNe" => 1, "TwO" => 2), + array ("one" => 1, "tWo" => 2), + array ("ONE" => 1, "tWo" => 2), + array ("OnE" => 1, "tWo" => 2), + array ("oNe" => 1, "tWo" => 2), + array ("one" => 1, 2), + array ("ONE" => 1, 2), + array ("OnE" => 1, 2), + array ("oNe" => 1, 2), + array ("ONE" => 1, "TWO" => 2, "THREE" => 3, "FOUR" => "four"), + array ("one" => 1, "two" => 2, "three" => 3, "four" => "FOUR"), + array ("ONE" => 1, "TWO" => 2, "three" => 3, "four" => "FOUR"), + array ("one" => 1, "two" => 2, "THREE" => 3, "FOUR" => "four") +); + +echo "*** Testing basic operations ***\n"; +$loop_counter = 1; +foreach ($arrays as $item) { + echo "** Iteration $loop_counter **\n"; $loop_counter++; + var_dump(array_change_key_case($item)); + var_dump(array_change_key_case($item, CASE_UPPER)); + var_dump(array_change_key_case($item, CASE_LOWER)); + echo "\n"; +} + +echo "end\n"; +?> +--EXPECT-- +*** Testing basic operations *** +** Iteration 1 ** +array(0) { +} +array(0) { +} +array(0) { +} + +** Iteration 2 ** +array(1) { + [0]=> + int(0) +} +array(1) { + [0]=> + int(0) +} +array(1) { + [0]=> + int(0) +} + +** Iteration 3 ** +array(1) { + [0]=> + int(1) +} +array(1) { + [0]=> + int(1) +} +array(1) { + [0]=> + int(1) +} + +** Iteration 4 ** +array(1) { + [0]=> + int(-1) +} +array(1) { + [0]=> + int(-1) +} +array(1) { + [0]=> + int(-1) +} + +** Iteration 5 ** +array(5) { + [0]=> + int(0) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) +} +array(5) { + [0]=> + int(0) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) +} +array(5) { + [0]=> + int(0) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) +} + +** Iteration 6 ** +array(5) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) +} +array(5) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) +} +array(5) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) +} + +** Iteration 7 ** +array(1) { + [""]=> + int(1) +} +array(1) { + [""]=> + int(1) +} +array(1) { + [""]=> + int(1) +} + +** Iteration 8 ** +array(1) { + ["a"]=> + int(1) +} +array(1) { + ["A"]=> + int(1) +} +array(1) { + ["a"]=> + int(1) +} + +** Iteration 9 ** +array(1) { + ["z"]=> + int(1) +} +array(1) { + ["Z"]=> + int(1) +} +array(1) { + ["z"]=> + int(1) +} + +** Iteration 10 ** +array(1) { + ["one"]=> + int(1) +} +array(1) { + ["ONE"]=> + int(1) +} +array(1) { + ["one"]=> + int(1) +} + +** Iteration 11 ** +array(1) { + ["one"]=> + int(1) +} +array(1) { + ["ONE"]=> + int(1) +} +array(1) { + ["one"]=> + int(1) +} + +** Iteration 12 ** +array(1) { + ["one"]=> + int(1) +} +array(1) { + ["ONE"]=> + int(1) +} +array(1) { + ["one"]=> + int(1) +} + +** Iteration 13 ** +array(1) { + ["one"]=> + int(1) +} +array(1) { + ["ONE"]=> + int(1) +} +array(1) { + ["one"]=> + int(1) +} + +** Iteration 14 ** +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(2) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} + +** Iteration 15 ** +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(2) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} + +** Iteration 16 ** +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(2) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} + +** Iteration 17 ** +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(2) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} + +** Iteration 18 ** +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(2) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} + +** Iteration 19 ** +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(2) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} + +** Iteration 20 ** +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(2) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} + +** Iteration 21 ** +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(2) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} + +** Iteration 22 ** +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(2) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} + +** Iteration 23 ** +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(2) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} + +** Iteration 24 ** +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(2) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} + +** Iteration 25 ** +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(2) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} + +** Iteration 26 ** +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(2) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} + +** Iteration 27 ** +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(2) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} + +** Iteration 28 ** +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(2) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} + +** Iteration 29 ** +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(2) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} + +** Iteration 30 ** +array(2) { + ["one"]=> + int(1) + [0]=> + int(2) +} +array(2) { + ["ONE"]=> + int(1) + [0]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + [0]=> + int(2) +} + +** Iteration 31 ** +array(2) { + ["one"]=> + int(1) + [0]=> + int(2) +} +array(2) { + ["ONE"]=> + int(1) + [0]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + [0]=> + int(2) +} + +** Iteration 32 ** +array(2) { + ["one"]=> + int(1) + [0]=> + int(2) +} +array(2) { + ["ONE"]=> + int(1) + [0]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + [0]=> + int(2) +} + +** Iteration 33 ** +array(2) { + ["one"]=> + int(1) + [0]=> + int(2) +} +array(2) { + ["ONE"]=> + int(1) + [0]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + [0]=> + int(2) +} + +** Iteration 34 ** +array(4) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) + ["four"]=> + string(4) "four" +} +array(4) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) + ["THREE"]=> + int(3) + ["FOUR"]=> + string(4) "four" +} +array(4) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) + ["four"]=> + string(4) "four" +} + +** Iteration 35 ** +array(4) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) + ["four"]=> + string(4) "FOUR" +} +array(4) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) + ["THREE"]=> + int(3) + ["FOUR"]=> + string(4) "FOUR" +} +array(4) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) + ["four"]=> + string(4) "FOUR" +} + +** Iteration 36 ** +array(4) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) + ["four"]=> + string(4) "FOUR" +} +array(4) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) + ["THREE"]=> + int(3) + ["FOUR"]=> + string(4) "FOUR" +} +array(4) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) + ["four"]=> + string(4) "FOUR" +} + +** Iteration 37 ** +array(4) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) + ["four"]=> + string(4) "four" +} +array(4) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) + ["THREE"]=> + int(3) + ["FOUR"]=> + string(4) "four" +} +array(4) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) + ["four"]=> + string(4) "four" +} + +end diff --git a/tests/std/array/array_change_key_case_variation.phpt b/tests/std/array/array_change_key_case_variation.phpt new file mode 100644 index 00000000..c221a3f3 --- /dev/null +++ b/tests/std/array/array_change_key_case_variation.phpt @@ -0,0 +1,50 @@ +--TEST-- +Test array_change_key_case() function - 2 +--FILE-- + 1, "two" => 2, "THREE" => 3, "FOUR" => "four"); + +/* use 'case' argument other than CASE_LOWER & CASE_UPPER */ +try { + var_dump(array_change_key_case($item, "CASE_UPPER")); +} catch (TypeError $e) { + echo $e->getMessage(), "\n"; +} +var_dump(array_change_key_case($item, 5)); + +/* when keys are different in terms of only case */ +/* should return one value key pair with key being in lowercase */ +var_dump( array_change_key_case( array("ONE" => 1, "one" => 3, "One" => 4) ) ); + +/* should return one value key pair with key being in uppercase */ +var_dump( array_change_key_case( array("ONE" => 1, "one" => 2, "One" => 3), CASE_UPPER ) ); +var_dump( array_change_key_case( array("ONE" => 1, "one" => 1, "One" => 2), 5 ) ); + +echo "end\n"; +?> +--EXPECT-- +array_change_key_case(): Argument #2 ($case) must be of type int, string given +array(4) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) + ["THREE"]=> + int(3) + ["FOUR"]=> + string(4) "four" +} +array(1) { + ["one"]=> + int(4) +} +array(1) { + ["ONE"]=> + int(3) +} +array(1) { + ["ONE"]=> + int(2) +} +end diff --git a/tests/std/array/array_change_key_case_variation3.phpt b/tests/std/array/array_change_key_case_variation3.phpt new file mode 100644 index 00000000..8edec6ef --- /dev/null +++ b/tests/std/array/array_change_key_case_variation3.phpt @@ -0,0 +1,167 @@ +--TEST-- +Test array_change_key_case() function : usage variations - different data types as keys +--SKIPIF-- + + +--FILE-- + array( + 0 => 'zero', + 1 => 'one', + 12345 => 'positive', + -2345 => 'negative', + ), + + // null data +/*3*/ 'null uppercase' => array( + NULL => 'null 1', + ), + 'null lowercase' => array( + null => 'null 2', + ), + + // boolean data +/*4*/ 'bool lowercase' => array( + true => 'lowert', + false => 'lowerf', + ), + 'bool uppercase' => array( + TRUE => 'uppert', + FALSE => 'upperf', + ), + + // empty data +/*5*/ 'empty double quotes' => array( + "" => 'emptyd', + ), + 'empty single quotes' => array( + '' => 'emptys', + ), + + // string data +/*6*/ 'string' => array( + "stringd" => 'stringd', + 'strings' => 'strings', + $heredoc => 'stringh', + ), + + // undefined data +/*8*/ 'undefined' => array( + @$undefined_var => 'undefined', + ), + + // unset data +/*9*/ 'unset' => array( + @$unset_var => 'unset', + ), +); + +// loop through each sub-array of $inputs to check the behavior of array_change_key_case() +$iterator = 1; +foreach($inputs as $key => $input) { + echo "\n-- Iteration $iterator : $key data --\n"; + var_dump( array_change_key_case($input, CASE_UPPER) ); + $iterator++; +}; + +echo "Done"; +?> +--EXPECT-- +*** Testing array_change_key_case() : usage variations *** + +-- Iteration 1 : int data -- +array(4) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [12345]=> + string(8) "positive" + [-2345]=> + string(8) "negative" +} + +-- Iteration 2 : null uppercase data -- +array(1) { + [""]=> + string(6) "null 1" +} + +-- Iteration 3 : null lowercase data -- +array(1) { + [""]=> + string(6) "null 2" +} + +-- Iteration 4 : bool lowercase data -- +array(2) { + [1]=> + string(6) "lowert" + [0]=> + string(6) "lowerf" +} + +-- Iteration 5 : bool uppercase data -- +array(2) { + [1]=> + string(6) "uppert" + [0]=> + string(6) "upperf" +} + +-- Iteration 6 : empty double quotes data -- +array(1) { + [""]=> + string(6) "emptyd" +} + +-- Iteration 7 : empty single quotes data -- +array(1) { + [""]=> + string(6) "emptys" +} + +-- Iteration 8 : string data -- +array(3) { + ["STRINGD"]=> + string(7) "stringd" + ["STRINGS"]=> + string(7) "strings" + ["HELLO WORLD"]=> + string(7) "stringh" +} + +-- Iteration 9 : undefined data -- +array(1) { + [""]=> + string(9) "undefined" +} + +-- Iteration 10 : unset data -- +array(1) { + [""]=> + string(5) "unset" +} +Done diff --git a/tests/std/array/array_change_key_case_variation4.phpt b/tests/std/array/array_change_key_case_variation4.phpt new file mode 100644 index 00000000..82d21145 --- /dev/null +++ b/tests/std/array/array_change_key_case_variation4.phpt @@ -0,0 +1,132 @@ +--TEST-- +Test array_change_key_case() function : usage variations - different int values for $case +--FILE-- + 'un', 'TWO' => 'deux', 'three' => 'trois'); +for ($i = -5; $i <=5; $i += 1){ + echo "\n-- \$sort argument is $i --\n"; + $temp = $input; + var_dump(array_change_key_case($temp, $i)); +} + +echo "Done"; +?> +--EXPECT-- +*** Testing array_change_key_case() : usage variations *** + +-- $sort argument is -5 -- +array(3) { + ["ONE"]=> + string(2) "un" + ["TWO"]=> + string(4) "deux" + ["THREE"]=> + string(5) "trois" +} + +-- $sort argument is -4 -- +array(3) { + ["ONE"]=> + string(2) "un" + ["TWO"]=> + string(4) "deux" + ["THREE"]=> + string(5) "trois" +} + +-- $sort argument is -3 -- +array(3) { + ["ONE"]=> + string(2) "un" + ["TWO"]=> + string(4) "deux" + ["THREE"]=> + string(5) "trois" +} + +-- $sort argument is -2 -- +array(3) { + ["ONE"]=> + string(2) "un" + ["TWO"]=> + string(4) "deux" + ["THREE"]=> + string(5) "trois" +} + +-- $sort argument is -1 -- +array(3) { + ["ONE"]=> + string(2) "un" + ["TWO"]=> + string(4) "deux" + ["THREE"]=> + string(5) "trois" +} + +-- $sort argument is 0 -- +array(3) { + ["one"]=> + string(2) "un" + ["two"]=> + string(4) "deux" + ["three"]=> + string(5) "trois" +} + +-- $sort argument is 1 -- +array(3) { + ["ONE"]=> + string(2) "un" + ["TWO"]=> + string(4) "deux" + ["THREE"]=> + string(5) "trois" +} + +-- $sort argument is 2 -- +array(3) { + ["ONE"]=> + string(2) "un" + ["TWO"]=> + string(4) "deux" + ["THREE"]=> + string(5) "trois" +} + +-- $sort argument is 3 -- +array(3) { + ["ONE"]=> + string(2) "un" + ["TWO"]=> + string(4) "deux" + ["THREE"]=> + string(5) "trois" +} + +-- $sort argument is 4 -- +array(3) { + ["ONE"]=> + string(2) "un" + ["TWO"]=> + string(4) "deux" + ["THREE"]=> + string(5) "trois" +} + +-- $sort argument is 5 -- +array(3) { + ["ONE"]=> + string(2) "un" + ["TWO"]=> + string(4) "deux" + ["THREE"]=> + string(5) "trois" +} +Done diff --git a/tests/std/array/array_change_key_case_variation5.phpt b/tests/std/array/array_change_key_case_variation5.phpt new file mode 100644 index 00000000..7fe48e87 --- /dev/null +++ b/tests/std/array/array_change_key_case_variation5.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test array_change_key_case() function : usage variations - position of internal pointer +--FILE-- + 'un', 'two' => 'deux', 'three' => 'trois'); + +echo "\n-- Call array_change_key_case() --\n"; +var_dump($result = array_change_key_case($input, CASE_UPPER)); + +echo "-- Position of Internal Pointer in Result: --\n"; +echo key($result) . " => " . current($result) . "\n"; +echo "\n-- Position of Internal Pointer in Original Array: --\n"; +echo key($input) . " => " . current ($input) . "\n"; + +echo "Done"; +?> +--EXPECT-- +*** Testing array_change_key_case() : usage variations *** + +-- Call array_change_key_case() -- +array(3) { + ["ONE"]=> + string(2) "un" + ["TWO"]=> + string(4) "deux" + ["THREE"]=> + string(5) "trois" +} +-- Position of Internal Pointer in Result: -- +ONE => un + +-- Position of Internal Pointer in Original Array: -- +one => un +Done diff --git a/tests/std/array/array_change_key_case_variation6.phpt b/tests/std/array/array_change_key_case_variation6.phpt new file mode 100644 index 00000000..1357650e --- /dev/null +++ b/tests/std/array/array_change_key_case_variation6.phpt @@ -0,0 +1,66 @@ +--TEST-- +Test array_change_key_case() function : usage variations - multidimensional arrays +--FILE-- + array('one' => 1, 'two' => 2, 'three' => 3), + 'French' => array('un' => 1, 'deux' => 2, 'trois' => 3), + 'German' => array('eins' => 1, 'zwei' => 2, 'drei' => 3)); + +echo "\n-- Pass a two-dimensional array as \$input argument --\n"; +var_dump(array_change_key_case($input, CASE_UPPER)); + +echo "\n-- Pass a sub-array as \$input argument --\n"; +var_dump(array_change_key_case($input['English'], CASE_UPPER)); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_change_key_case() : usage variations *** + +-- Pass a two-dimensional array as $input argument -- +array(3) { + ["ENGLISH"]=> + array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) + } + ["FRENCH"]=> + array(3) { + ["un"]=> + int(1) + ["deux"]=> + int(2) + ["trois"]=> + int(3) + } + ["GERMAN"]=> + array(3) { + ["eins"]=> + int(1) + ["zwei"]=> + int(2) + ["drei"]=> + int(3) + } +} + +-- Pass a sub-array as $input argument -- +array(3) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) + ["THREE"]=> + int(3) +} +Done diff --git a/tests/std/array/array_change_key_case_variation7.phpt b/tests/std/array/array_change_key_case_variation7.phpt new file mode 100644 index 00000000..44fd6adb --- /dev/null +++ b/tests/std/array/array_change_key_case_variation7.phpt @@ -0,0 +1,57 @@ +--TEST-- +Test array_change_key_case() function : usage variations - referenced variables +--FILE-- + 1, 'two' => 2, 'ABC' => 'xyz'); + +echo "\n-- \$input argument is a reference to array --\n"; +$new_input = &$input; +echo "Result:\n"; +var_dump(array_change_key_case($new_input, CASE_UPPER)); +echo "Original:\n"; +var_dump($input); +echo "Referenced:\n"; +var_dump($new_input); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_change_key_case() : usage variations *** + +-- $input argument is a reference to array -- +Result: +array(3) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) + ["ABC"]=> + string(3) "xyz" +} +Original: +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["ABC"]=> + string(3) "xyz" +} +Referenced: +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["ABC"]=> + string(3) "xyz" +} +Done diff --git a/tests/std/array/array_change_key_case_variation8.phpt b/tests/std/array/array_change_key_case_variation8.phpt new file mode 100644 index 00000000..bb81d939 --- /dev/null +++ b/tests/std/array/array_change_key_case_variation8.phpt @@ -0,0 +1,124 @@ +--TEST-- +Test array_change_key_case() function : usage variations - Different strings as keys +--SKIPIF-- + +--FILE-- + 1, NULL => 2, "\a" => 3, "\cx" => 4, "\e" => 5, "\f" => 6, "\n" => 7, "\t" => 8, "\xhh" => 9, "\ddd" => 10, "\v" => 11), + + // array contains combination of capital/small letters + array("lemoN" => 1, "Orange" => 2, "banana" => 3, "apple" => 4, "Test" => 5, "TTTT" => 6, "ttt" => 7, "ww" => 8, "x" => 9, "X" => 10, "oraNGe" => 11, "BANANA" => 12) +); + +foreach($inputs as $input) { + echo "\n-- \$case = default --\n"; + var_dump(array_change_key_case($input)); + echo "-- \$case = upper --\n"; + var_dump(array_change_key_case($input, CASE_UPPER)); +} + +echo "Done"; +?> +--EXPECT-- +*** Testing array_change_key_case() : usage variations *** + +-- $case = default -- +array(10) { + [""]=> + int(2) + ["\a"]=> + int(3) + ["\cx"]=> + int(4) + [""]=> + int(5) + [" "]=> + int(6) + [" +"]=> + int(7) + [" "]=> + int(8) + ["\xhh"]=> + int(9) + ["\ddd"]=> + int(10) + [" "]=> + int(11) +} +-- $case = upper -- +array(10) { + [""]=> + int(2) + ["\A"]=> + int(3) + ["\CX"]=> + int(4) + [""]=> + int(5) + [" "]=> + int(6) + [" +"]=> + int(7) + [" "]=> + int(8) + ["\XHH"]=> + int(9) + ["\DDD"]=> + int(10) + [" "]=> + int(11) +} + +-- $case = default -- +array(9) { + ["lemon"]=> + int(1) + ["orange"]=> + int(11) + ["banana"]=> + int(12) + ["apple"]=> + int(4) + ["test"]=> + int(5) + ["tttt"]=> + int(6) + ["ttt"]=> + int(7) + ["ww"]=> + int(8) + ["x"]=> + int(10) +} +-- $case = upper -- +array(9) { + ["LEMON"]=> + int(1) + ["ORANGE"]=> + int(11) + ["BANANA"]=> + int(12) + ["APPLE"]=> + int(4) + ["TEST"]=> + int(5) + ["TTTT"]=> + int(6) + ["TTT"]=> + int(7) + ["WW"]=> + int(8) + ["X"]=> + int(10) +} +Done diff --git a/tests/std/array/array_chunk2.phpt b/tests/std/array/array_chunk2.phpt new file mode 100644 index 00000000..c83f051a --- /dev/null +++ b/tests/std/array/array_chunk2.phpt @@ -0,0 +1,154 @@ +--TEST-- +basic array_chunk test +--FILE-- +getMessage() . "\n"; +} + +try { + var_dump(array_chunk($input_array, 0, true)); +} catch (\ValueError $e) { + echo $e->getMessage() . "\n"; +} + +var_dump(array_chunk($input_array, 1)); +var_dump(array_chunk($input_array, 1, true)); +var_dump(array_chunk($input_array, 2)); +var_dump(array_chunk($input_array, 2, true)); +var_dump(array_chunk($input_array, 10)); +var_dump(array_chunk($input_array, 10, true)); +?> +--EXPECT-- +array_chunk(): Argument #2 ($length) must be greater than 0 +array_chunk(): Argument #2 ($length) must be greater than 0 +array(5) { + [0]=> + array(1) { + [0]=> + string(1) "a" + } + [1]=> + array(1) { + [0]=> + string(1) "b" + } + [2]=> + array(1) { + [0]=> + string(1) "c" + } + [3]=> + array(1) { + [0]=> + string(1) "d" + } + [4]=> + array(1) { + [0]=> + string(1) "e" + } +} +array(5) { + [0]=> + array(1) { + [0]=> + string(1) "a" + } + [1]=> + array(1) { + [1]=> + string(1) "b" + } + [2]=> + array(1) { + [2]=> + string(1) "c" + } + [3]=> + array(1) { + [3]=> + string(1) "d" + } + [4]=> + array(1) { + [4]=> + string(1) "e" + } +} +array(3) { + [0]=> + array(2) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + } + [1]=> + array(2) { + [0]=> + string(1) "c" + [1]=> + string(1) "d" + } + [2]=> + array(1) { + [0]=> + string(1) "e" + } +} +array(3) { + [0]=> + array(2) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + } + [1]=> + array(2) { + [2]=> + string(1) "c" + [3]=> + string(1) "d" + } + [2]=> + array(1) { + [4]=> + string(1) "e" + } +} +array(1) { + [0]=> + array(5) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + [3]=> + string(1) "d" + [4]=> + string(1) "e" + } +} +array(1) { + [0]=> + array(5) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + [3]=> + string(1) "d" + [4]=> + string(1) "e" + } +} diff --git a/tests/std/array/array_chunk_basic1.phpt b/tests/std/array/array_chunk_basic1.phpt new file mode 100644 index 00000000..e03749ec --- /dev/null +++ b/tests/std/array/array_chunk_basic1.phpt @@ -0,0 +1,132 @@ +--TEST-- +Test array_chunk() function : basic functionality - default 'preserve_keys' +--FILE-- + 1, "key2" => 2, "key3" => 3), + + // associative arrays - key as numeric + array(1 => 'one', 2 => "two", 3 => "three"), + + // array containing elements with/without keys + array(1 => 'one','two', 3 => 'three', 4, "five" => 5) + +); + +$count = 1; +// loop through each element of the array for input +foreach ($input_arrays as $input_array){ + echo "\n-- Iteration $count --\n"; + var_dump( array_chunk($input_array, $size) ); + $count++; +} + +echo "Done"; +?> +--EXPECT-- +*** Testing array_chunk() : basic functionality *** + +-- Iteration 1 -- +array(3) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(2) { + [0]=> + int(3) + [1]=> + int(4) + } + [2]=> + array(1) { + [0]=> + int(5) + } +} + +-- Iteration 2 -- +array(2) { + [0]=> + array(2) { + [0]=> + string(6) "value1" + [1]=> + string(6) "value2" + } + [1]=> + array(1) { + [0]=> + string(6) "value3" + } +} + +-- Iteration 3 -- +array(2) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(1) { + [0]=> + int(3) + } +} + +-- Iteration 4 -- +array(2) { + [0]=> + array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + } + [1]=> + array(1) { + [0]=> + string(5) "three" + } +} + +-- Iteration 5 -- +array(3) { + [0]=> + array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + } + [1]=> + array(2) { + [0]=> + string(5) "three" + [1]=> + int(4) + } + [2]=> + array(1) { + [0]=> + int(5) + } +} +Done diff --git a/tests/std/array/array_chunk_basic2.phpt b/tests/std/array/array_chunk_basic2.phpt new file mode 100644 index 00000000..472df0fe --- /dev/null +++ b/tests/std/array/array_chunk_basic2.phpt @@ -0,0 +1,216 @@ +--TEST-- +Test array_chunk() function : basic functionality - 'preserve_keys' as true/false +--FILE-- + 1, "key2" => 2, "key3" => 3), + + // associative arrays - key as numeric + array(1 => 'one', 2 => "two", 3 => "three"), + + // array containing elements with/without keys + array(1 => 'one','two', 3 => 'three', 4, "five" => 5) +); + +$count = 1; +// loop through each element of the array for input +foreach ($input_arrays as $input_array){ + echo "\n-- Iteration $count --\n"; + var_dump( array_chunk($input_array, $size, true) ); + var_dump( array_chunk($input_array, $size, false) ); + $count++; +} + +echo "Done"; +?> +--EXPECT-- +*** Testing array_chunk() : basic functionality *** + +-- Iteration 1 -- +array(3) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(2) { + [2]=> + int(3) + [3]=> + int(4) + } + [2]=> + array(1) { + [4]=> + int(5) + } +} +array(3) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(2) { + [0]=> + int(3) + [1]=> + int(4) + } + [2]=> + array(1) { + [0]=> + int(5) + } +} + +-- Iteration 2 -- +array(2) { + [0]=> + array(2) { + [0]=> + string(6) "value1" + [1]=> + string(6) "value2" + } + [1]=> + array(1) { + [2]=> + string(6) "value3" + } +} +array(2) { + [0]=> + array(2) { + [0]=> + string(6) "value1" + [1]=> + string(6) "value2" + } + [1]=> + array(1) { + [0]=> + string(6) "value3" + } +} + +-- Iteration 3 -- +array(2) { + [0]=> + array(2) { + ["key1"]=> + int(1) + ["key2"]=> + int(2) + } + [1]=> + array(1) { + ["key3"]=> + int(3) + } +} +array(2) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(1) { + [0]=> + int(3) + } +} + +-- Iteration 4 -- +array(2) { + [0]=> + array(2) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + } + [1]=> + array(1) { + [3]=> + string(5) "three" + } +} +array(2) { + [0]=> + array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + } + [1]=> + array(1) { + [0]=> + string(5) "three" + } +} + +-- Iteration 5 -- +array(3) { + [0]=> + array(2) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + } + [1]=> + array(2) { + [3]=> + string(5) "three" + [4]=> + int(4) + } + [2]=> + array(1) { + ["five"]=> + int(5) + } +} +array(3) { + [0]=> + array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + } + [1]=> + array(2) { + [0]=> + string(5) "three" + [1]=> + int(4) + } + [2]=> + array(1) { + [0]=> + int(5) + } +} +Done diff --git a/tests/std/array/array_chunk_variation10.phpt b/tests/std/array/array_chunk_variation10.phpt new file mode 100644 index 00000000..326d7de9 --- /dev/null +++ b/tests/std/array/array_chunk_variation10.phpt @@ -0,0 +1,154 @@ +--TEST-- +array_chunk() - variation 10 +--FILE-- + 1, 2 => 2, 3 => 3); +var_dump ($array); +for ($i = 1; $i < (sizeof($array) + 1); $i++) { + echo "[$i]\n"; + var_dump (array_chunk ($array, $i)); + var_dump (array_chunk ($array, $i, TRUE)); + var_dump (array_chunk ($array, $i, FALSE)); + echo "\n"; +} +?> +--EXPECT-- +array(3) { + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) +} +[1] +array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } + [2]=> + array(1) { + [0]=> + int(3) + } +} +array(3) { + [0]=> + array(1) { + [1]=> + int(1) + } + [1]=> + array(1) { + [2]=> + int(2) + } + [2]=> + array(1) { + [3]=> + int(3) + } +} +array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } + [2]=> + array(1) { + [0]=> + int(3) + } +} + +[2] +array(2) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(1) { + [0]=> + int(3) + } +} +array(2) { + [0]=> + array(2) { + [1]=> + int(1) + [2]=> + int(2) + } + [1]=> + array(1) { + [3]=> + int(3) + } +} +array(2) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(1) { + [0]=> + int(3) + } +} + +[3] +array(1) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} +array(1) { + [0]=> + array(3) { + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + } +} +array(1) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} diff --git a/tests/std/array/array_chunk_variation11.phpt b/tests/std/array/array_chunk_variation11.phpt new file mode 100644 index 00000000..e3ce4453 --- /dev/null +++ b/tests/std/array/array_chunk_variation11.phpt @@ -0,0 +1,88 @@ +--TEST-- +array_chunk() - variation 11 +--FILE-- + 0, 3 => 2); + +var_dump ($array); +for ($i = 1; $i < (sizeof($array) + 1); $i++) { + echo "[$i]\n"; + var_dump (array_chunk ($array, $i)); + var_dump (array_chunk ($array, $i, TRUE)); + var_dump (array_chunk ($array, $i, FALSE)); + echo "\n"; +} +?> +--EXPECT-- +array(2) { + [0]=> + int(0) + [3]=> + int(2) +} +[1] +array(2) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [0]=> + int(2) + } +} +array(2) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [3]=> + int(2) + } +} +array(2) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [0]=> + int(2) + } +} + +[2] +array(1) { + [0]=> + array(2) { + [0]=> + int(0) + [1]=> + int(2) + } +} +array(1) { + [0]=> + array(2) { + [0]=> + int(0) + [3]=> + int(2) + } +} +array(1) { + [0]=> + array(2) { + [0]=> + int(0) + [1]=> + int(2) + } +} diff --git a/tests/std/array/array_chunk_variation12.phpt b/tests/std/array/array_chunk_variation12.phpt new file mode 100644 index 00000000..3b0cb79b --- /dev/null +++ b/tests/std/array/array_chunk_variation12.phpt @@ -0,0 +1,154 @@ +--TEST-- +array_chunk() - variation 12 +--FILE-- + 1, 5 => 2, 8 => 3); +var_dump ($array); +for ($i = 1; $i < (sizeof($array) + 1); $i++) { + echo "[$i]\n"; + var_dump (array_chunk ($array, $i)); + var_dump (array_chunk ($array, $i, TRUE)); + var_dump (array_chunk ($array, $i, FALSE)); + echo "\n"; +} +?> +--EXPECT-- +array(3) { + [1]=> + int(1) + [5]=> + int(2) + [8]=> + int(3) +} +[1] +array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } + [2]=> + array(1) { + [0]=> + int(3) + } +} +array(3) { + [0]=> + array(1) { + [1]=> + int(1) + } + [1]=> + array(1) { + [5]=> + int(2) + } + [2]=> + array(1) { + [8]=> + int(3) + } +} +array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } + [2]=> + array(1) { + [0]=> + int(3) + } +} + +[2] +array(2) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(1) { + [0]=> + int(3) + } +} +array(2) { + [0]=> + array(2) { + [1]=> + int(1) + [5]=> + int(2) + } + [1]=> + array(1) { + [8]=> + int(3) + } +} +array(2) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(1) { + [0]=> + int(3) + } +} + +[3] +array(1) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} +array(1) { + [0]=> + array(3) { + [1]=> + int(1) + [5]=> + int(2) + [8]=> + int(3) + } +} +array(1) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} diff --git a/tests/std/array/array_chunk_variation13.phpt b/tests/std/array/array_chunk_variation13.phpt new file mode 100644 index 00000000..f62d309c --- /dev/null +++ b/tests/std/array/array_chunk_variation13.phpt @@ -0,0 +1,87 @@ +--TEST-- +array_chunk() - variation 13 +--FILE-- + +--EXPECT-- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +[1] +array(2) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } +} +array(2) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [1]=> + int(2) + } +} +array(2) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } +} + +[2] +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} diff --git a/tests/std/array/array_chunk_variation14.phpt b/tests/std/array/array_chunk_variation14.phpt new file mode 100644 index 00000000..64746bf6 --- /dev/null +++ b/tests/std/array/array_chunk_variation14.phpt @@ -0,0 +1,154 @@ +--TEST-- +array_chunk() - variation 14 +--FILE-- + +--EXPECT-- +array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) +} +[1] +array(3) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [0]=> + int(1) + } + [2]=> + array(1) { + [0]=> + int(2) + } +} +array(3) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [1]=> + int(1) + } + [2]=> + array(1) { + [2]=> + int(2) + } +} +array(3) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [0]=> + int(1) + } + [2]=> + array(1) { + [0]=> + int(2) + } +} + +[2] +array(2) { + [0]=> + array(2) { + [0]=> + int(0) + [1]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } +} +array(2) { + [0]=> + array(2) { + [0]=> + int(0) + [1]=> + int(1) + } + [1]=> + array(1) { + [2]=> + int(2) + } +} +array(2) { + [0]=> + array(2) { + [0]=> + int(0) + [1]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } +} + +[3] +array(1) { + [0]=> + array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + } +} +array(1) { + [0]=> + array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + } +} +array(1) { + [0]=> + array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + } +} diff --git a/tests/std/array/array_chunk_variation15.phpt b/tests/std/array/array_chunk_variation15.phpt new file mode 100644 index 00000000..294dd9f8 --- /dev/null +++ b/tests/std/array/array_chunk_variation15.phpt @@ -0,0 +1,154 @@ +--TEST-- +array_chunk() - variation 15 +--FILE-- + +--EXPECT-- +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +[1] +array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } + [2]=> + array(1) { + [0]=> + int(3) + } +} +array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [1]=> + int(2) + } + [2]=> + array(1) { + [2]=> + int(3) + } +} +array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } + [2]=> + array(1) { + [0]=> + int(3) + } +} + +[2] +array(2) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(1) { + [0]=> + int(3) + } +} +array(2) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(1) { + [2]=> + int(3) + } +} +array(2) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(1) { + [0]=> + int(3) + } +} + +[3] +array(1) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} +array(1) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} +array(1) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} diff --git a/tests/std/array/array_chunk_variation16.phpt b/tests/std/array/array_chunk_variation16.phpt new file mode 100644 index 00000000..b7159cba --- /dev/null +++ b/tests/std/array/array_chunk_variation16.phpt @@ -0,0 +1,233 @@ +--TEST-- +array_chunk() - variation 16 +--FILE-- + +--EXPECT-- +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) +} +[1] +array(4) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [0]=> + int(1) + } + [2]=> + array(1) { + [0]=> + int(2) + } + [3]=> + array(1) { + [0]=> + int(3) + } +} +array(4) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [1]=> + int(1) + } + [2]=> + array(1) { + [2]=> + int(2) + } + [3]=> + array(1) { + [3]=> + int(3) + } +} +array(4) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [0]=> + int(1) + } + [2]=> + array(1) { + [0]=> + int(2) + } + [3]=> + array(1) { + [0]=> + int(3) + } +} + +[2] +array(2) { + [0]=> + array(2) { + [0]=> + int(0) + [1]=> + int(1) + } + [1]=> + array(2) { + [0]=> + int(2) + [1]=> + int(3) + } +} +array(2) { + [0]=> + array(2) { + [0]=> + int(0) + [1]=> + int(1) + } + [1]=> + array(2) { + [2]=> + int(2) + [3]=> + int(3) + } +} +array(2) { + [0]=> + array(2) { + [0]=> + int(0) + [1]=> + int(1) + } + [1]=> + array(2) { + [0]=> + int(2) + [1]=> + int(3) + } +} + +[3] +array(2) { + [0]=> + array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + } + [1]=> + array(1) { + [0]=> + int(3) + } +} +array(2) { + [0]=> + array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + } + [1]=> + array(1) { + [3]=> + int(3) + } +} +array(2) { + [0]=> + array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + } + [1]=> + array(1) { + [0]=> + int(3) + } +} + +[4] +array(1) { + [0]=> + array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + } +} +array(1) { + [0]=> + array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + } +} +array(1) { + [0]=> + array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + } +} diff --git a/tests/std/array/array_chunk_variation17.phpt b/tests/std/array/array_chunk_variation17.phpt new file mode 100644 index 00000000..07826d06 --- /dev/null +++ b/tests/std/array/array_chunk_variation17.phpt @@ -0,0 +1,233 @@ +--TEST-- +array_chunk() - variation 17 +--FILE-- + +--EXPECT-- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) +} +[1] +array(4) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } + [2]=> + array(1) { + [0]=> + int(3) + } + [3]=> + array(1) { + [0]=> + int(4) + } +} +array(4) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [1]=> + int(2) + } + [2]=> + array(1) { + [2]=> + int(3) + } + [3]=> + array(1) { + [3]=> + int(4) + } +} +array(4) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } + [2]=> + array(1) { + [0]=> + int(3) + } + [3]=> + array(1) { + [0]=> + int(4) + } +} + +[2] +array(2) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(2) { + [0]=> + int(3) + [1]=> + int(4) + } +} +array(2) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(2) { + [2]=> + int(3) + [3]=> + int(4) + } +} +array(2) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(2) { + [0]=> + int(3) + [1]=> + int(4) + } +} + +[3] +array(2) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + [1]=> + array(1) { + [0]=> + int(4) + } +} +array(2) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + [1]=> + array(1) { + [3]=> + int(4) + } +} +array(2) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + [1]=> + array(1) { + [0]=> + int(4) + } +} + +[4] +array(1) { + [0]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + } +} +array(1) { + [0]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + } +} +array(1) { + [0]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + } +} diff --git a/tests/std/array/array_chunk_variation18.phpt b/tests/std/array/array_chunk_variation18.phpt new file mode 100644 index 00000000..1fa9ca6e --- /dev/null +++ b/tests/std/array/array_chunk_variation18.phpt @@ -0,0 +1,333 @@ +--TEST-- +array_chunk() - variation 18 +--FILE-- + +--EXPECT-- +array(5) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) +} +[1] +array(5) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [0]=> + int(1) + } + [2]=> + array(1) { + [0]=> + int(2) + } + [3]=> + array(1) { + [0]=> + int(3) + } + [4]=> + array(1) { + [0]=> + int(4) + } +} +array(5) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [1]=> + int(1) + } + [2]=> + array(1) { + [2]=> + int(2) + } + [3]=> + array(1) { + [3]=> + int(3) + } + [4]=> + array(1) { + [4]=> + int(4) + } +} +array(5) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [0]=> + int(1) + } + [2]=> + array(1) { + [0]=> + int(2) + } + [3]=> + array(1) { + [0]=> + int(3) + } + [4]=> + array(1) { + [0]=> + int(4) + } +} + +[2] +array(3) { + [0]=> + array(2) { + [0]=> + int(0) + [1]=> + int(1) + } + [1]=> + array(2) { + [0]=> + int(2) + [1]=> + int(3) + } + [2]=> + array(1) { + [0]=> + int(4) + } +} +array(3) { + [0]=> + array(2) { + [0]=> + int(0) + [1]=> + int(1) + } + [1]=> + array(2) { + [2]=> + int(2) + [3]=> + int(3) + } + [2]=> + array(1) { + [4]=> + int(4) + } +} +array(3) { + [0]=> + array(2) { + [0]=> + int(0) + [1]=> + int(1) + } + [1]=> + array(2) { + [0]=> + int(2) + [1]=> + int(3) + } + [2]=> + array(1) { + [0]=> + int(4) + } +} + +[3] +array(2) { + [0]=> + array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + } + [1]=> + array(2) { + [0]=> + int(3) + [1]=> + int(4) + } +} +array(2) { + [0]=> + array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + } + [1]=> + array(2) { + [3]=> + int(3) + [4]=> + int(4) + } +} +array(2) { + [0]=> + array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + } + [1]=> + array(2) { + [0]=> + int(3) + [1]=> + int(4) + } +} + +[4] +array(2) { + [0]=> + array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + } + [1]=> + array(1) { + [0]=> + int(4) + } +} +array(2) { + [0]=> + array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + } + [1]=> + array(1) { + [4]=> + int(4) + } +} +array(2) { + [0]=> + array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + } + [1]=> + array(1) { + [0]=> + int(4) + } +} + +[5] +array(1) { + [0]=> + array(5) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + } +} +array(1) { + [0]=> + array(5) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + } +} +array(1) { + [0]=> + array(5) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + } +} diff --git a/tests/std/array/array_chunk_variation19.phpt b/tests/std/array/array_chunk_variation19.phpt new file mode 100644 index 00000000..2591db89 --- /dev/null +++ b/tests/std/array/array_chunk_variation19.phpt @@ -0,0 +1,1013 @@ +--TEST-- +array_chunk() - variation 19 +--FILE-- + +--EXPECT-- +array(10) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + [6]=> + int(7) + [7]=> + int(8) + [8]=> + int(9) + [9]=> + int(10) +} +[1] +array(10) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } + [2]=> + array(1) { + [0]=> + int(3) + } + [3]=> + array(1) { + [0]=> + int(4) + } + [4]=> + array(1) { + [0]=> + int(5) + } + [5]=> + array(1) { + [0]=> + int(6) + } + [6]=> + array(1) { + [0]=> + int(7) + } + [7]=> + array(1) { + [0]=> + int(8) + } + [8]=> + array(1) { + [0]=> + int(9) + } + [9]=> + array(1) { + [0]=> + int(10) + } +} +array(10) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [1]=> + int(2) + } + [2]=> + array(1) { + [2]=> + int(3) + } + [3]=> + array(1) { + [3]=> + int(4) + } + [4]=> + array(1) { + [4]=> + int(5) + } + [5]=> + array(1) { + [5]=> + int(6) + } + [6]=> + array(1) { + [6]=> + int(7) + } + [7]=> + array(1) { + [7]=> + int(8) + } + [8]=> + array(1) { + [8]=> + int(9) + } + [9]=> + array(1) { + [9]=> + int(10) + } +} +array(10) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } + [2]=> + array(1) { + [0]=> + int(3) + } + [3]=> + array(1) { + [0]=> + int(4) + } + [4]=> + array(1) { + [0]=> + int(5) + } + [5]=> + array(1) { + [0]=> + int(6) + } + [6]=> + array(1) { + [0]=> + int(7) + } + [7]=> + array(1) { + [0]=> + int(8) + } + [8]=> + array(1) { + [0]=> + int(9) + } + [9]=> + array(1) { + [0]=> + int(10) + } +} + +[2] +array(5) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(2) { + [0]=> + int(3) + [1]=> + int(4) + } + [2]=> + array(2) { + [0]=> + int(5) + [1]=> + int(6) + } + [3]=> + array(2) { + [0]=> + int(7) + [1]=> + int(8) + } + [4]=> + array(2) { + [0]=> + int(9) + [1]=> + int(10) + } +} +array(5) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(2) { + [2]=> + int(3) + [3]=> + int(4) + } + [2]=> + array(2) { + [4]=> + int(5) + [5]=> + int(6) + } + [3]=> + array(2) { + [6]=> + int(7) + [7]=> + int(8) + } + [4]=> + array(2) { + [8]=> + int(9) + [9]=> + int(10) + } +} +array(5) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(2) { + [0]=> + int(3) + [1]=> + int(4) + } + [2]=> + array(2) { + [0]=> + int(5) + [1]=> + int(6) + } + [3]=> + array(2) { + [0]=> + int(7) + [1]=> + int(8) + } + [4]=> + array(2) { + [0]=> + int(9) + [1]=> + int(10) + } +} + +[3] +array(4) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + [1]=> + array(3) { + [0]=> + int(4) + [1]=> + int(5) + [2]=> + int(6) + } + [2]=> + array(3) { + [0]=> + int(7) + [1]=> + int(8) + [2]=> + int(9) + } + [3]=> + array(1) { + [0]=> + int(10) + } +} +array(4) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + [1]=> + array(3) { + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + } + [2]=> + array(3) { + [6]=> + int(7) + [7]=> + int(8) + [8]=> + int(9) + } + [3]=> + array(1) { + [9]=> + int(10) + } +} +array(4) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + [1]=> + array(3) { + [0]=> + int(4) + [1]=> + int(5) + [2]=> + int(6) + } + [2]=> + array(3) { + [0]=> + int(7) + [1]=> + int(8) + [2]=> + int(9) + } + [3]=> + array(1) { + [0]=> + int(10) + } +} + +[4] +array(3) { + [0]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + } + [1]=> + array(4) { + [0]=> + int(5) + [1]=> + int(6) + [2]=> + int(7) + [3]=> + int(8) + } + [2]=> + array(2) { + [0]=> + int(9) + [1]=> + int(10) + } +} +array(3) { + [0]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + } + [1]=> + array(4) { + [4]=> + int(5) + [5]=> + int(6) + [6]=> + int(7) + [7]=> + int(8) + } + [2]=> + array(2) { + [8]=> + int(9) + [9]=> + int(10) + } +} +array(3) { + [0]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + } + [1]=> + array(4) { + [0]=> + int(5) + [1]=> + int(6) + [2]=> + int(7) + [3]=> + int(8) + } + [2]=> + array(2) { + [0]=> + int(9) + [1]=> + int(10) + } +} + +[5] +array(2) { + [0]=> + array(5) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + } + [1]=> + array(5) { + [0]=> + int(6) + [1]=> + int(7) + [2]=> + int(8) + [3]=> + int(9) + [4]=> + int(10) + } +} +array(2) { + [0]=> + array(5) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + } + [1]=> + array(5) { + [5]=> + int(6) + [6]=> + int(7) + [7]=> + int(8) + [8]=> + int(9) + [9]=> + int(10) + } +} +array(2) { + [0]=> + array(5) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + } + [1]=> + array(5) { + [0]=> + int(6) + [1]=> + int(7) + [2]=> + int(8) + [3]=> + int(9) + [4]=> + int(10) + } +} + +[6] +array(2) { + [0]=> + array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + } + [1]=> + array(4) { + [0]=> + int(7) + [1]=> + int(8) + [2]=> + int(9) + [3]=> + int(10) + } +} +array(2) { + [0]=> + array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + } + [1]=> + array(4) { + [6]=> + int(7) + [7]=> + int(8) + [8]=> + int(9) + [9]=> + int(10) + } +} +array(2) { + [0]=> + array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + } + [1]=> + array(4) { + [0]=> + int(7) + [1]=> + int(8) + [2]=> + int(9) + [3]=> + int(10) + } +} + +[7] +array(2) { + [0]=> + array(7) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + [6]=> + int(7) + } + [1]=> + array(3) { + [0]=> + int(8) + [1]=> + int(9) + [2]=> + int(10) + } +} +array(2) { + [0]=> + array(7) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + [6]=> + int(7) + } + [1]=> + array(3) { + [7]=> + int(8) + [8]=> + int(9) + [9]=> + int(10) + } +} +array(2) { + [0]=> + array(7) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + [6]=> + int(7) + } + [1]=> + array(3) { + [0]=> + int(8) + [1]=> + int(9) + [2]=> + int(10) + } +} + +[8] +array(2) { + [0]=> + array(8) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + [6]=> + int(7) + [7]=> + int(8) + } + [1]=> + array(2) { + [0]=> + int(9) + [1]=> + int(10) + } +} +array(2) { + [0]=> + array(8) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + [6]=> + int(7) + [7]=> + int(8) + } + [1]=> + array(2) { + [8]=> + int(9) + [9]=> + int(10) + } +} +array(2) { + [0]=> + array(8) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + [6]=> + int(7) + [7]=> + int(8) + } + [1]=> + array(2) { + [0]=> + int(9) + [1]=> + int(10) + } +} + +[9] +array(2) { + [0]=> + array(9) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + [6]=> + int(7) + [7]=> + int(8) + [8]=> + int(9) + } + [1]=> + array(1) { + [0]=> + int(10) + } +} +array(2) { + [0]=> + array(9) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + [6]=> + int(7) + [7]=> + int(8) + [8]=> + int(9) + } + [1]=> + array(1) { + [9]=> + int(10) + } +} +array(2) { + [0]=> + array(9) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + [6]=> + int(7) + [7]=> + int(8) + [8]=> + int(9) + } + [1]=> + array(1) { + [0]=> + int(10) + } +} + +[10] +array(1) { + [0]=> + array(10) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + [6]=> + int(7) + [7]=> + int(8) + [8]=> + int(9) + [9]=> + int(10) + } +} +array(1) { + [0]=> + array(10) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + [6]=> + int(7) + [7]=> + int(8) + [8]=> + int(9) + [9]=> + int(10) + } +} +array(1) { + [0]=> + array(10) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + [6]=> + int(7) + [7]=> + int(8) + [8]=> + int(9) + [9]=> + int(10) + } +} diff --git a/tests/std/array/array_chunk_variation20.phpt b/tests/std/array/array_chunk_variation20.phpt new file mode 100644 index 00000000..ec2e45b1 --- /dev/null +++ b/tests/std/array/array_chunk_variation20.phpt @@ -0,0 +1,1194 @@ +--TEST-- +array_chunk() - variation 20 +--FILE-- + +--EXPECT-- +array(11) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) + [6]=> + int(6) + [7]=> + int(7) + [8]=> + int(8) + [9]=> + int(9) + [10]=> + int(10) +} +[1] +array(11) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [0]=> + int(1) + } + [2]=> + array(1) { + [0]=> + int(2) + } + [3]=> + array(1) { + [0]=> + int(3) + } + [4]=> + array(1) { + [0]=> + int(4) + } + [5]=> + array(1) { + [0]=> + int(5) + } + [6]=> + array(1) { + [0]=> + int(6) + } + [7]=> + array(1) { + [0]=> + int(7) + } + [8]=> + array(1) { + [0]=> + int(8) + } + [9]=> + array(1) { + [0]=> + int(9) + } + [10]=> + array(1) { + [0]=> + int(10) + } +} +array(11) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [1]=> + int(1) + } + [2]=> + array(1) { + [2]=> + int(2) + } + [3]=> + array(1) { + [3]=> + int(3) + } + [4]=> + array(1) { + [4]=> + int(4) + } + [5]=> + array(1) { + [5]=> + int(5) + } + [6]=> + array(1) { + [6]=> + int(6) + } + [7]=> + array(1) { + [7]=> + int(7) + } + [8]=> + array(1) { + [8]=> + int(8) + } + [9]=> + array(1) { + [9]=> + int(9) + } + [10]=> + array(1) { + [10]=> + int(10) + } +} +array(11) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [0]=> + int(1) + } + [2]=> + array(1) { + [0]=> + int(2) + } + [3]=> + array(1) { + [0]=> + int(3) + } + [4]=> + array(1) { + [0]=> + int(4) + } + [5]=> + array(1) { + [0]=> + int(5) + } + [6]=> + array(1) { + [0]=> + int(6) + } + [7]=> + array(1) { + [0]=> + int(7) + } + [8]=> + array(1) { + [0]=> + int(8) + } + [9]=> + array(1) { + [0]=> + int(9) + } + [10]=> + array(1) { + [0]=> + int(10) + } +} + +[2] +array(6) { + [0]=> + array(2) { + [0]=> + int(0) + [1]=> + int(1) + } + [1]=> + array(2) { + [0]=> + int(2) + [1]=> + int(3) + } + [2]=> + array(2) { + [0]=> + int(4) + [1]=> + int(5) + } + [3]=> + array(2) { + [0]=> + int(6) + [1]=> + int(7) + } + [4]=> + array(2) { + [0]=> + int(8) + [1]=> + int(9) + } + [5]=> + array(1) { + [0]=> + int(10) + } +} +array(6) { + [0]=> + array(2) { + [0]=> + int(0) + [1]=> + int(1) + } + [1]=> + array(2) { + [2]=> + int(2) + [3]=> + int(3) + } + [2]=> + array(2) { + [4]=> + int(4) + [5]=> + int(5) + } + [3]=> + array(2) { + [6]=> + int(6) + [7]=> + int(7) + } + [4]=> + array(2) { + [8]=> + int(8) + [9]=> + int(9) + } + [5]=> + array(1) { + [10]=> + int(10) + } +} +array(6) { + [0]=> + array(2) { + [0]=> + int(0) + [1]=> + int(1) + } + [1]=> + array(2) { + [0]=> + int(2) + [1]=> + int(3) + } + [2]=> + array(2) { + [0]=> + int(4) + [1]=> + int(5) + } + [3]=> + array(2) { + [0]=> + int(6) + [1]=> + int(7) + } + [4]=> + array(2) { + [0]=> + int(8) + [1]=> + int(9) + } + [5]=> + array(1) { + [0]=> + int(10) + } +} + +[3] +array(4) { + [0]=> + array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + } + [1]=> + array(3) { + [0]=> + int(3) + [1]=> + int(4) + [2]=> + int(5) + } + [2]=> + array(3) { + [0]=> + int(6) + [1]=> + int(7) + [2]=> + int(8) + } + [3]=> + array(2) { + [0]=> + int(9) + [1]=> + int(10) + } +} +array(4) { + [0]=> + array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + } + [1]=> + array(3) { + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) + } + [2]=> + array(3) { + [6]=> + int(6) + [7]=> + int(7) + [8]=> + int(8) + } + [3]=> + array(2) { + [9]=> + int(9) + [10]=> + int(10) + } +} +array(4) { + [0]=> + array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + } + [1]=> + array(3) { + [0]=> + int(3) + [1]=> + int(4) + [2]=> + int(5) + } + [2]=> + array(3) { + [0]=> + int(6) + [1]=> + int(7) + [2]=> + int(8) + } + [3]=> + array(2) { + [0]=> + int(9) + [1]=> + int(10) + } +} + +[4] +array(3) { + [0]=> + array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + } + [1]=> + array(4) { + [0]=> + int(4) + [1]=> + int(5) + [2]=> + int(6) + [3]=> + int(7) + } + [2]=> + array(3) { + [0]=> + int(8) + [1]=> + int(9) + [2]=> + int(10) + } +} +array(3) { + [0]=> + array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + } + [1]=> + array(4) { + [4]=> + int(4) + [5]=> + int(5) + [6]=> + int(6) + [7]=> + int(7) + } + [2]=> + array(3) { + [8]=> + int(8) + [9]=> + int(9) + [10]=> + int(10) + } +} +array(3) { + [0]=> + array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + } + [1]=> + array(4) { + [0]=> + int(4) + [1]=> + int(5) + [2]=> + int(6) + [3]=> + int(7) + } + [2]=> + array(3) { + [0]=> + int(8) + [1]=> + int(9) + [2]=> + int(10) + } +} + +[5] +array(3) { + [0]=> + array(5) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + } + [1]=> + array(5) { + [0]=> + int(5) + [1]=> + int(6) + [2]=> + int(7) + [3]=> + int(8) + [4]=> + int(9) + } + [2]=> + array(1) { + [0]=> + int(10) + } +} +array(3) { + [0]=> + array(5) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + } + [1]=> + array(5) { + [5]=> + int(5) + [6]=> + int(6) + [7]=> + int(7) + [8]=> + int(8) + [9]=> + int(9) + } + [2]=> + array(1) { + [10]=> + int(10) + } +} +array(3) { + [0]=> + array(5) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + } + [1]=> + array(5) { + [0]=> + int(5) + [1]=> + int(6) + [2]=> + int(7) + [3]=> + int(8) + [4]=> + int(9) + } + [2]=> + array(1) { + [0]=> + int(10) + } +} + +[6] +array(2) { + [0]=> + array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) + } + [1]=> + array(5) { + [0]=> + int(6) + [1]=> + int(7) + [2]=> + int(8) + [3]=> + int(9) + [4]=> + int(10) + } +} +array(2) { + [0]=> + array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) + } + [1]=> + array(5) { + [6]=> + int(6) + [7]=> + int(7) + [8]=> + int(8) + [9]=> + int(9) + [10]=> + int(10) + } +} +array(2) { + [0]=> + array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) + } + [1]=> + array(5) { + [0]=> + int(6) + [1]=> + int(7) + [2]=> + int(8) + [3]=> + int(9) + [4]=> + int(10) + } +} + +[7] +array(2) { + [0]=> + array(7) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) + [6]=> + int(6) + } + [1]=> + array(4) { + [0]=> + int(7) + [1]=> + int(8) + [2]=> + int(9) + [3]=> + int(10) + } +} +array(2) { + [0]=> + array(7) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) + [6]=> + int(6) + } + [1]=> + array(4) { + [7]=> + int(7) + [8]=> + int(8) + [9]=> + int(9) + [10]=> + int(10) + } +} +array(2) { + [0]=> + array(7) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) + [6]=> + int(6) + } + [1]=> + array(4) { + [0]=> + int(7) + [1]=> + int(8) + [2]=> + int(9) + [3]=> + int(10) + } +} + +[8] +array(2) { + [0]=> + array(8) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) + [6]=> + int(6) + [7]=> + int(7) + } + [1]=> + array(3) { + [0]=> + int(8) + [1]=> + int(9) + [2]=> + int(10) + } +} +array(2) { + [0]=> + array(8) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) + [6]=> + int(6) + [7]=> + int(7) + } + [1]=> + array(3) { + [8]=> + int(8) + [9]=> + int(9) + [10]=> + int(10) + } +} +array(2) { + [0]=> + array(8) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) + [6]=> + int(6) + [7]=> + int(7) + } + [1]=> + array(3) { + [0]=> + int(8) + [1]=> + int(9) + [2]=> + int(10) + } +} + +[9] +array(2) { + [0]=> + array(9) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) + [6]=> + int(6) + [7]=> + int(7) + [8]=> + int(8) + } + [1]=> + array(2) { + [0]=> + int(9) + [1]=> + int(10) + } +} +array(2) { + [0]=> + array(9) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) + [6]=> + int(6) + [7]=> + int(7) + [8]=> + int(8) + } + [1]=> + array(2) { + [9]=> + int(9) + [10]=> + int(10) + } +} +array(2) { + [0]=> + array(9) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) + [6]=> + int(6) + [7]=> + int(7) + [8]=> + int(8) + } + [1]=> + array(2) { + [0]=> + int(9) + [1]=> + int(10) + } +} + +[10] +array(2) { + [0]=> + array(10) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) + [6]=> + int(6) + [7]=> + int(7) + [8]=> + int(8) + [9]=> + int(9) + } + [1]=> + array(1) { + [0]=> + int(10) + } +} +array(2) { + [0]=> + array(10) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) + [6]=> + int(6) + [7]=> + int(7) + [8]=> + int(8) + [9]=> + int(9) + } + [1]=> + array(1) { + [10]=> + int(10) + } +} +array(2) { + [0]=> + array(10) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) + [6]=> + int(6) + [7]=> + int(7) + [8]=> + int(8) + [9]=> + int(9) + } + [1]=> + array(1) { + [0]=> + int(10) + } +} + +[11] +array(1) { + [0]=> + array(11) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) + [6]=> + int(6) + [7]=> + int(7) + [8]=> + int(8) + [9]=> + int(9) + [10]=> + int(10) + } +} +array(1) { + [0]=> + array(11) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) + [6]=> + int(6) + [7]=> + int(7) + [8]=> + int(8) + [9]=> + int(9) + [10]=> + int(10) + } +} +array(1) { + [0]=> + array(11) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) + [6]=> + int(6) + [7]=> + int(7) + [8]=> + int(8) + [9]=> + int(9) + [10]=> + int(10) + } +} diff --git a/tests/std/array/array_chunk_variation21.phpt b/tests/std/array/array_chunk_variation21.phpt new file mode 100644 index 00000000..ce672a92 --- /dev/null +++ b/tests/std/array/array_chunk_variation21.phpt @@ -0,0 +1,41 @@ +--TEST-- +array_chunk() - variation 21 +--FILE-- + 1); +var_dump ($array); +for ($i = 1; $i < (sizeof($array) + 1); $i++) { + echo "[$i]\n"; + var_dump (array_chunk ($array, $i)); + var_dump (array_chunk ($array, $i, TRUE)); + var_dump (array_chunk ($array, $i, FALSE)); + echo "\n"; +} +?> +--EXPECT-- +array(1) { + ["a"]=> + int(1) +} +[1] +array(1) { + [0]=> + array(1) { + [0]=> + int(1) + } +} +array(1) { + [0]=> + array(1) { + ["a"]=> + int(1) + } +} +array(1) { + [0]=> + array(1) { + [0]=> + int(1) + } +} diff --git a/tests/std/array/array_chunk_variation22.phpt b/tests/std/array/array_chunk_variation22.phpt new file mode 100644 index 00000000..d67269f4 --- /dev/null +++ b/tests/std/array/array_chunk_variation22.phpt @@ -0,0 +1,87 @@ +--TEST-- +array_chunk() - variation 22 +--FILE-- + 1, "c" => 2); +var_dump ($array); +for ($i = 1; $i < (sizeof($array) + 1); $i++) { + echo "[$i]\n"; + var_dump (array_chunk ($array, $i)); + var_dump (array_chunk ($array, $i, TRUE)); + var_dump (array_chunk ($array, $i, FALSE)); + echo "\n"; +} +?> +--EXPECT-- +array(2) { + ["b"]=> + int(1) + ["c"]=> + int(2) +} +[1] +array(2) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } +} +array(2) { + [0]=> + array(1) { + ["b"]=> + int(1) + } + [1]=> + array(1) { + ["c"]=> + int(2) + } +} +array(2) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } +} + +[2] +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} +array(1) { + [0]=> + array(2) { + ["b"]=> + int(1) + ["c"]=> + int(2) + } +} +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} diff --git a/tests/std/array/array_chunk_variation23.phpt b/tests/std/array/array_chunk_variation23.phpt new file mode 100644 index 00000000..99138eae --- /dev/null +++ b/tests/std/array/array_chunk_variation23.phpt @@ -0,0 +1,436 @@ +--TEST-- +array_chunk() - variation 23 +--FILE-- + 1, "q" => 2, "r" => 3, "s" => 4, "u" => 5, "v" => 6); +var_dump ($array); +for ($i = 1; $i < (sizeof($array) + 1); $i++) { + echo "[$i]\n"; + var_dump (array_chunk ($array, $i)); + var_dump (array_chunk ($array, $i, TRUE)); + var_dump (array_chunk ($array, $i, FALSE)); + echo "\n"; +} +?> +--EXPECT-- +array(6) { + ["p"]=> + int(1) + ["q"]=> + int(2) + ["r"]=> + int(3) + ["s"]=> + int(4) + ["u"]=> + int(5) + ["v"]=> + int(6) +} +[1] +array(6) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } + [2]=> + array(1) { + [0]=> + int(3) + } + [3]=> + array(1) { + [0]=> + int(4) + } + [4]=> + array(1) { + [0]=> + int(5) + } + [5]=> + array(1) { + [0]=> + int(6) + } +} +array(6) { + [0]=> + array(1) { + ["p"]=> + int(1) + } + [1]=> + array(1) { + ["q"]=> + int(2) + } + [2]=> + array(1) { + ["r"]=> + int(3) + } + [3]=> + array(1) { + ["s"]=> + int(4) + } + [4]=> + array(1) { + ["u"]=> + int(5) + } + [5]=> + array(1) { + ["v"]=> + int(6) + } +} +array(6) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } + [2]=> + array(1) { + [0]=> + int(3) + } + [3]=> + array(1) { + [0]=> + int(4) + } + [4]=> + array(1) { + [0]=> + int(5) + } + [5]=> + array(1) { + [0]=> + int(6) + } +} + +[2] +array(3) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(2) { + [0]=> + int(3) + [1]=> + int(4) + } + [2]=> + array(2) { + [0]=> + int(5) + [1]=> + int(6) + } +} +array(3) { + [0]=> + array(2) { + ["p"]=> + int(1) + ["q"]=> + int(2) + } + [1]=> + array(2) { + ["r"]=> + int(3) + ["s"]=> + int(4) + } + [2]=> + array(2) { + ["u"]=> + int(5) + ["v"]=> + int(6) + } +} +array(3) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(2) { + [0]=> + int(3) + [1]=> + int(4) + } + [2]=> + array(2) { + [0]=> + int(5) + [1]=> + int(6) + } +} + +[3] +array(2) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + [1]=> + array(3) { + [0]=> + int(4) + [1]=> + int(5) + [2]=> + int(6) + } +} +array(2) { + [0]=> + array(3) { + ["p"]=> + int(1) + ["q"]=> + int(2) + ["r"]=> + int(3) + } + [1]=> + array(3) { + ["s"]=> + int(4) + ["u"]=> + int(5) + ["v"]=> + int(6) + } +} +array(2) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + [1]=> + array(3) { + [0]=> + int(4) + [1]=> + int(5) + [2]=> + int(6) + } +} + +[4] +array(2) { + [0]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + } + [1]=> + array(2) { + [0]=> + int(5) + [1]=> + int(6) + } +} +array(2) { + [0]=> + array(4) { + ["p"]=> + int(1) + ["q"]=> + int(2) + ["r"]=> + int(3) + ["s"]=> + int(4) + } + [1]=> + array(2) { + ["u"]=> + int(5) + ["v"]=> + int(6) + } +} +array(2) { + [0]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + } + [1]=> + array(2) { + [0]=> + int(5) + [1]=> + int(6) + } +} + +[5] +array(2) { + [0]=> + array(5) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + } + [1]=> + array(1) { + [0]=> + int(6) + } +} +array(2) { + [0]=> + array(5) { + ["p"]=> + int(1) + ["q"]=> + int(2) + ["r"]=> + int(3) + ["s"]=> + int(4) + ["u"]=> + int(5) + } + [1]=> + array(1) { + ["v"]=> + int(6) + } +} +array(2) { + [0]=> + array(5) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + } + [1]=> + array(1) { + [0]=> + int(6) + } +} + +[6] +array(1) { + [0]=> + array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + } +} +array(1) { + [0]=> + array(6) { + ["p"]=> + int(1) + ["q"]=> + int(2) + ["r"]=> + int(3) + ["s"]=> + int(4) + ["u"]=> + int(5) + ["v"]=> + int(6) + } +} +array(1) { + [0]=> + array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + } +} diff --git a/tests/std/array/array_chunk_variation24.phpt b/tests/std/array/array_chunk_variation24.phpt new file mode 100644 index 00000000..c96d59d8 --- /dev/null +++ b/tests/std/array/array_chunk_variation24.phpt @@ -0,0 +1,41 @@ +--TEST-- +array_chunk() - variation 24 +--FILE-- + "A"); +var_dump ($array); +for ($i = 1; $i < (sizeof($array) + 1); $i++) { + echo "[$i]\n"; + var_dump (array_chunk ($array, $i)); + var_dump (array_chunk ($array, $i, TRUE)); + var_dump (array_chunk ($array, $i, FALSE)); + echo "\n"; +} +?> +--EXPECT-- +array(1) { + ["a"]=> + string(1) "A" +} +[1] +array(1) { + [0]=> + array(1) { + [0]=> + string(1) "A" + } +} +array(1) { + [0]=> + array(1) { + ["a"]=> + string(1) "A" + } +} +array(1) { + [0]=> + array(1) { + [0]=> + string(1) "A" + } +} diff --git a/tests/std/array/array_chunk_variation25.phpt b/tests/std/array/array_chunk_variation25.phpt new file mode 100644 index 00000000..978588e0 --- /dev/null +++ b/tests/std/array/array_chunk_variation25.phpt @@ -0,0 +1,436 @@ +--TEST-- +array_chunk() - variation 25 +--FILE-- + "A", "q" => "B", "r" => "C", "s" => "D", "u" => "E", "v" => "F"); +var_dump ($array); +for ($i = 1; $i < (sizeof($array) + 1); $i++) { + echo "[$i]\n"; + var_dump (array_chunk ($array, $i)); + var_dump (array_chunk ($array, $i, TRUE)); + var_dump (array_chunk ($array, $i, FALSE)); + echo "\n"; +} +?> +--EXPECT-- +array(6) { + ["p"]=> + string(1) "A" + ["q"]=> + string(1) "B" + ["r"]=> + string(1) "C" + ["s"]=> + string(1) "D" + ["u"]=> + string(1) "E" + ["v"]=> + string(1) "F" +} +[1] +array(6) { + [0]=> + array(1) { + [0]=> + string(1) "A" + } + [1]=> + array(1) { + [0]=> + string(1) "B" + } + [2]=> + array(1) { + [0]=> + string(1) "C" + } + [3]=> + array(1) { + [0]=> + string(1) "D" + } + [4]=> + array(1) { + [0]=> + string(1) "E" + } + [5]=> + array(1) { + [0]=> + string(1) "F" + } +} +array(6) { + [0]=> + array(1) { + ["p"]=> + string(1) "A" + } + [1]=> + array(1) { + ["q"]=> + string(1) "B" + } + [2]=> + array(1) { + ["r"]=> + string(1) "C" + } + [3]=> + array(1) { + ["s"]=> + string(1) "D" + } + [4]=> + array(1) { + ["u"]=> + string(1) "E" + } + [5]=> + array(1) { + ["v"]=> + string(1) "F" + } +} +array(6) { + [0]=> + array(1) { + [0]=> + string(1) "A" + } + [1]=> + array(1) { + [0]=> + string(1) "B" + } + [2]=> + array(1) { + [0]=> + string(1) "C" + } + [3]=> + array(1) { + [0]=> + string(1) "D" + } + [4]=> + array(1) { + [0]=> + string(1) "E" + } + [5]=> + array(1) { + [0]=> + string(1) "F" + } +} + +[2] +array(3) { + [0]=> + array(2) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + } + [1]=> + array(2) { + [0]=> + string(1) "C" + [1]=> + string(1) "D" + } + [2]=> + array(2) { + [0]=> + string(1) "E" + [1]=> + string(1) "F" + } +} +array(3) { + [0]=> + array(2) { + ["p"]=> + string(1) "A" + ["q"]=> + string(1) "B" + } + [1]=> + array(2) { + ["r"]=> + string(1) "C" + ["s"]=> + string(1) "D" + } + [2]=> + array(2) { + ["u"]=> + string(1) "E" + ["v"]=> + string(1) "F" + } +} +array(3) { + [0]=> + array(2) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + } + [1]=> + array(2) { + [0]=> + string(1) "C" + [1]=> + string(1) "D" + } + [2]=> + array(2) { + [0]=> + string(1) "E" + [1]=> + string(1) "F" + } +} + +[3] +array(2) { + [0]=> + array(3) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + [2]=> + string(1) "C" + } + [1]=> + array(3) { + [0]=> + string(1) "D" + [1]=> + string(1) "E" + [2]=> + string(1) "F" + } +} +array(2) { + [0]=> + array(3) { + ["p"]=> + string(1) "A" + ["q"]=> + string(1) "B" + ["r"]=> + string(1) "C" + } + [1]=> + array(3) { + ["s"]=> + string(1) "D" + ["u"]=> + string(1) "E" + ["v"]=> + string(1) "F" + } +} +array(2) { + [0]=> + array(3) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + [2]=> + string(1) "C" + } + [1]=> + array(3) { + [0]=> + string(1) "D" + [1]=> + string(1) "E" + [2]=> + string(1) "F" + } +} + +[4] +array(2) { + [0]=> + array(4) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + [2]=> + string(1) "C" + [3]=> + string(1) "D" + } + [1]=> + array(2) { + [0]=> + string(1) "E" + [1]=> + string(1) "F" + } +} +array(2) { + [0]=> + array(4) { + ["p"]=> + string(1) "A" + ["q"]=> + string(1) "B" + ["r"]=> + string(1) "C" + ["s"]=> + string(1) "D" + } + [1]=> + array(2) { + ["u"]=> + string(1) "E" + ["v"]=> + string(1) "F" + } +} +array(2) { + [0]=> + array(4) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + [2]=> + string(1) "C" + [3]=> + string(1) "D" + } + [1]=> + array(2) { + [0]=> + string(1) "E" + [1]=> + string(1) "F" + } +} + +[5] +array(2) { + [0]=> + array(5) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + [2]=> + string(1) "C" + [3]=> + string(1) "D" + [4]=> + string(1) "E" + } + [1]=> + array(1) { + [0]=> + string(1) "F" + } +} +array(2) { + [0]=> + array(5) { + ["p"]=> + string(1) "A" + ["q"]=> + string(1) "B" + ["r"]=> + string(1) "C" + ["s"]=> + string(1) "D" + ["u"]=> + string(1) "E" + } + [1]=> + array(1) { + ["v"]=> + string(1) "F" + } +} +array(2) { + [0]=> + array(5) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + [2]=> + string(1) "C" + [3]=> + string(1) "D" + [4]=> + string(1) "E" + } + [1]=> + array(1) { + [0]=> + string(1) "F" + } +} + +[6] +array(1) { + [0]=> + array(6) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + [2]=> + string(1) "C" + [3]=> + string(1) "D" + [4]=> + string(1) "E" + [5]=> + string(1) "F" + } +} +array(1) { + [0]=> + array(6) { + ["p"]=> + string(1) "A" + ["q"]=> + string(1) "B" + ["r"]=> + string(1) "C" + ["s"]=> + string(1) "D" + ["u"]=> + string(1) "E" + ["v"]=> + string(1) "F" + } +} +array(1) { + [0]=> + array(6) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + [2]=> + string(1) "C" + [3]=> + string(1) "D" + [4]=> + string(1) "E" + [5]=> + string(1) "F" + } +} diff --git a/tests/std/array/array_chunk_variation26.phpt b/tests/std/array/array_chunk_variation26.phpt new file mode 100644 index 00000000..7b46215f --- /dev/null +++ b/tests/std/array/array_chunk_variation26.phpt @@ -0,0 +1,41 @@ +--TEST-- +array_chunk() - variation 26 +--FILE-- + +--EXPECT-- +array(1) { + [0]=> + int(0) +} +[1] +array(1) { + [0]=> + array(1) { + [0]=> + int(0) + } +} +array(1) { + [0]=> + array(1) { + [0]=> + int(0) + } +} +array(1) { + [0]=> + array(1) { + [0]=> + int(0) + } +} diff --git a/tests/std/array/array_chunk_variation27.phpt b/tests/std/array/array_chunk_variation27.phpt new file mode 100644 index 00000000..a91a8b91 --- /dev/null +++ b/tests/std/array/array_chunk_variation27.phpt @@ -0,0 +1,41 @@ +--TEST-- +array_chunk() - variation 27 +--FILE-- + +--EXPECT-- +array(1) { + [0]=> + int(1) +} +[1] +array(1) { + [0]=> + array(1) { + [0]=> + int(1) + } +} +array(1) { + [0]=> + array(1) { + [0]=> + int(1) + } +} +array(1) { + [0]=> + array(1) { + [0]=> + int(1) + } +} diff --git a/tests/std/array/array_chunk_variation28.phpt b/tests/std/array/array_chunk_variation28.phpt new file mode 100644 index 00000000..707b0cde --- /dev/null +++ b/tests/std/array/array_chunk_variation28.phpt @@ -0,0 +1,41 @@ +--TEST-- +array_chunk() - variation 28 +--FILE-- + +--EXPECT-- +array(1) { + [0]=> + int(-1) +} +[1] +array(1) { + [0]=> + array(1) { + [0]=> + int(-1) + } +} +array(1) { + [0]=> + array(1) { + [0]=> + int(-1) + } +} +array(1) { + [0]=> + array(1) { + [0]=> + int(-1) + } +} diff --git a/tests/std/array/array_chunk_variation29.phpt b/tests/std/array/array_chunk_variation29.phpt new file mode 100644 index 00000000..07187135 --- /dev/null +++ b/tests/std/array/array_chunk_variation29.phpt @@ -0,0 +1,87 @@ +--TEST-- +array_chunk() - variation 29 +--FILE-- + +--EXPECT-- +array(2) { + [0]=> + int(0) + [1]=> + int(2) +} +[1] +array(2) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [0]=> + int(2) + } +} +array(2) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [1]=> + int(2) + } +} +array(2) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [0]=> + int(2) + } +} + +[2] +array(1) { + [0]=> + array(2) { + [0]=> + int(0) + [1]=> + int(2) + } +} +array(1) { + [0]=> + array(2) { + [0]=> + int(0) + [1]=> + int(2) + } +} +array(1) { + [0]=> + array(2) { + [0]=> + int(0) + [1]=> + int(2) + } +} diff --git a/tests/std/array/array_chunk_variation30.phpt b/tests/std/array/array_chunk_variation30.phpt new file mode 100644 index 00000000..5400b595 --- /dev/null +++ b/tests/std/array/array_chunk_variation30.phpt @@ -0,0 +1,154 @@ +--TEST-- +array_chunk() - variation 30 +--FILE-- + +--EXPECT-- +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +[1] +array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } + [2]=> + array(1) { + [0]=> + int(3) + } +} +array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [1]=> + int(2) + } + [2]=> + array(1) { + [2]=> + int(3) + } +} +array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } + [2]=> + array(1) { + [0]=> + int(3) + } +} + +[2] +array(2) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(1) { + [0]=> + int(3) + } +} +array(2) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(1) { + [2]=> + int(3) + } +} +array(2) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(1) { + [0]=> + int(3) + } +} + +[3] +array(1) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} +array(1) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} +array(1) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} diff --git a/tests/std/array/array_chunk_variation31.phpt b/tests/std/array/array_chunk_variation31.phpt new file mode 100644 index 00000000..ffdfa2bc --- /dev/null +++ b/tests/std/array/array_chunk_variation31.phpt @@ -0,0 +1,41 @@ +--TEST-- +array_chunk() - variation 31 +--FILE-- + 0); +var_dump ($array); +for ($i = 1; $i < (sizeof($array) + 1); $i++) { + echo "[$i]\n"; + var_dump (array_chunk ($array, $i)); + var_dump (array_chunk ($array, $i, TRUE)); + var_dump (array_chunk ($array, $i, FALSE)); + echo "\n"; +} +?> +--EXPECT-- +array(1) { + [1]=> + int(0) +} +[1] +array(1) { + [0]=> + array(1) { + [0]=> + int(0) + } +} +array(1) { + [0]=> + array(1) { + [1]=> + int(0) + } +} +array(1) { + [0]=> + array(1) { + [0]=> + int(0) + } +} diff --git a/tests/std/array/array_chunk_variation32.phpt b/tests/std/array/array_chunk_variation32.phpt new file mode 100644 index 00000000..b0a01f20 --- /dev/null +++ b/tests/std/array/array_chunk_variation32.phpt @@ -0,0 +1,41 @@ +--TEST-- +array_chunk() - variation 32 +--FILE-- + 1); +var_dump ($array); +for ($i = 1; $i < (sizeof($array) + 1); $i++) { + echo "[$i]\n"; + var_dump (array_chunk ($array, $i)); + var_dump (array_chunk ($array, $i, TRUE)); + var_dump (array_chunk ($array, $i, FALSE)); + echo "\n"; +} +?> +--EXPECT-- +array(1) { + [2]=> + int(1) +} +[1] +array(1) { + [0]=> + array(1) { + [0]=> + int(1) + } +} +array(1) { + [0]=> + array(1) { + [2]=> + int(1) + } +} +array(1) { + [0]=> + array(1) { + [0]=> + int(1) + } +} diff --git a/tests/std/array/array_chunk_variation4.phpt b/tests/std/array/array_chunk_variation4.phpt new file mode 100644 index 00000000..265fc390 --- /dev/null +++ b/tests/std/array/array_chunk_variation4.phpt @@ -0,0 +1,114 @@ +--TEST-- +Test array_chunk() function : usage variations - array with diff. sub arrays +--FILE-- + array(), + "array2" => array(1, 2, 3), + "array3" => array(1) +); + +echo "\n-- Testing array_chunk() by supplying an array containing different sub arrays & 'preserve_key' as default --\n"; +var_dump( array_chunk($input_array, $size) ); + +echo "\n-- Testing array_chunk() by supplying an array containing different sub arrays & 'preserve_key' = true --\n"; +var_dump( array_chunk($input_array, $size, true) ); + +echo "\n-- Testing array_chunk() by supplying an array containing different sub arrays & 'preserve_key' = false --\n"; +var_dump( array_chunk($input_array, $size, false) ); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_chunk() : usage variations *** + +-- Testing array_chunk() by supplying an array containing different sub arrays & 'preserve_key' as default -- +array(2) { + [0]=> + array(2) { + [0]=> + array(0) { + } + [1]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + } + [1]=> + array(1) { + [0]=> + array(1) { + [0]=> + int(1) + } + } +} + +-- Testing array_chunk() by supplying an array containing different sub arrays & 'preserve_key' = true -- +array(2) { + [0]=> + array(2) { + ["array1"]=> + array(0) { + } + ["array2"]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + } + [1]=> + array(1) { + ["array3"]=> + array(1) { + [0]=> + int(1) + } + } +} + +-- Testing array_chunk() by supplying an array containing different sub arrays & 'preserve_key' = false -- +array(2) { + [0]=> + array(2) { + [0]=> + array(0) { + } + [1]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + } + [1]=> + array(1) { + [0]=> + array(1) { + [0]=> + int(1) + } + } +} +Done diff --git a/tests/std/array/array_chunk_variation5.phpt b/tests/std/array/array_chunk_variation5.phpt new file mode 100644 index 00000000..dfae4897 --- /dev/null +++ b/tests/std/array/array_chunk_variation5.phpt @@ -0,0 +1,140 @@ +--TEST-- +Test array_chunk() function : usage variations - different 'size' values +--FILE-- +getMessage() . "\n"; + } + try { + var_dump( array_chunk($input_array, $size, true) ); + } catch (\ValueError $e) { + echo $e->getMessage() . "\n"; + } + try { + var_dump( array_chunk($input_array, $size, false) ); + } catch (\ValueError $e) { + echo $e->getMessage() . "\n"; + } +} +?> +--EXPECT-- +*** Testing array_chunk() : usage variations *** + +-- Testing array_chunk() when size = -1 -- +array_chunk(): Argument #2 ($length) must be greater than 0 +array_chunk(): Argument #2 ($length) must be greater than 0 +array_chunk(): Argument #2 ($length) must be greater than 0 + +-- Testing array_chunk() when size = 4 -- +array(1) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} +array(1) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} +array(1) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} + +-- Testing array_chunk() when size = 0 -- +array_chunk(): Argument #2 ($length) must be greater than 0 +array_chunk(): Argument #2 ($length) must be greater than 0 +array_chunk(): Argument #2 ($length) must be greater than 0 + +-- Testing array_chunk() when size = 1 -- +array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } + [2]=> + array(1) { + [0]=> + int(3) + } +} +array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [1]=> + int(2) + } + [2]=> + array(1) { + [2]=> + int(3) + } +} +array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } + [2]=> + array(1) { + [0]=> + int(3) + } +} diff --git a/tests/std/array/array_chunk_variation6.phpt b/tests/std/array/array_chunk_variation6.phpt new file mode 100644 index 00000000..c9c34e51 --- /dev/null +++ b/tests/std/array/array_chunk_variation6.phpt @@ -0,0 +1,129 @@ +--TEST-- +Test array_chunk() function : usage variations - different arrays +--FILE-- + array(), + + // array with one element + "array2" => array(1), + + // associative array with duplicate keys + "array3" => array("a" => 1, "b" => 2, "c" => 3, "a" => 4, "d" => 5) + +); + +$size = 2; +$count = 1; + +echo "\n-- Testing array_chunk() by supplying various arrays --\n"; + +// loop through the array for 'array' argument +foreach ($input_arrays as $input_array){ + echo "\n-- Iteration $count --\n"; + var_dump( array_chunk($input_array, $size) ); + var_dump( array_chunk($input_array, $size, true) ); + var_dump( array_chunk($input_array, $size, false) ); + $count++; +} + +echo "Done"; +?> +--EXPECT-- +*** Testing array_chunk() : usage variations *** + +-- Testing array_chunk() by supplying various arrays -- + +-- Iteration 1 -- +array(0) { +} +array(0) { +} +array(0) { +} + +-- Iteration 2 -- +array(1) { + [0]=> + array(1) { + [0]=> + int(1) + } +} +array(1) { + [0]=> + array(1) { + [0]=> + int(1) + } +} +array(1) { + [0]=> + array(1) { + [0]=> + int(1) + } +} + +-- Iteration 3 -- +array(2) { + [0]=> + array(2) { + [0]=> + int(4) + [1]=> + int(2) + } + [1]=> + array(2) { + [0]=> + int(3) + [1]=> + int(5) + } +} +array(2) { + [0]=> + array(2) { + ["a"]=> + int(4) + ["b"]=> + int(2) + } + [1]=> + array(2) { + ["c"]=> + int(3) + ["d"]=> + int(5) + } +} +array(2) { + [0]=> + array(2) { + [0]=> + int(4) + [1]=> + int(2) + } + [1]=> + array(2) { + [0]=> + int(3) + [1]=> + int(5) + } +} +Done diff --git a/tests/std/array/array_chunk_variation7.phpt b/tests/std/array/array_chunk_variation7.phpt new file mode 100644 index 00000000..8deb9a32 --- /dev/null +++ b/tests/std/array/array_chunk_variation7.phpt @@ -0,0 +1,85 @@ +--TEST-- +Test array_chunk() function : usage variations - references +--SKIPIF-- + +--FILE-- + &$numbers[0], + "two" => &$numbers[1], + "three" => &$numbers[2], + "four" => &$numbers[3] +); + +var_dump( array_chunk($input_array, $size) ); +var_dump( array_chunk($input_array, $size, true) ); +var_dump( array_chunk($input_array, $size, false) ); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_chunk() : usage variations *** + +-- Testing array_chunk(), input array containing references +array(2) { + [0]=> + array(2) { + [0]=> + &int(1) + [1]=> + &int(2) + } + [1]=> + array(2) { + [0]=> + &int(3) + [1]=> + &int(4) + } +} +array(2) { + [0]=> + array(2) { + ["one"]=> + &int(1) + ["two"]=> + &int(2) + } + [1]=> + array(2) { + ["three"]=> + &int(3) + ["four"]=> + &int(4) + } +} +array(2) { + [0]=> + array(2) { + [0]=> + &int(1) + [1]=> + &int(2) + } + [1]=> + array(2) { + [0]=> + &int(3) + [1]=> + &int(4) + } +} +Done diff --git a/tests/std/array/array_chunk_variation8.phpt b/tests/std/array/array_chunk_variation8.phpt new file mode 100644 index 00000000..2d8fa07c --- /dev/null +++ b/tests/std/array/array_chunk_variation8.phpt @@ -0,0 +1,41 @@ +--TEST-- +array_chunk() - variation 8 +--FILE-- + -1); +var_dump ($array); +for ($i = 1; $i < (sizeof($array) + 1); $i++) { + echo "[$i]\n"; + var_dump (array_chunk ($array, $i)); + var_dump (array_chunk ($array, $i, TRUE)); + var_dump (array_chunk ($array, $i, FALSE)); + echo "\n"; +} +?> +--EXPECT-- +array(1) { + [3]=> + int(-1) +} +[1] +array(1) { + [0]=> + array(1) { + [0]=> + int(-1) + } +} +array(1) { + [0]=> + array(1) { + [3]=> + int(-1) + } +} +array(1) { + [0]=> + array(1) { + [0]=> + int(-1) + } +} diff --git a/tests/std/array/array_chunk_variation9.phpt b/tests/std/array/array_chunk_variation9.phpt new file mode 100644 index 00000000..2be7b81e --- /dev/null +++ b/tests/std/array/array_chunk_variation9.phpt @@ -0,0 +1,87 @@ +--TEST-- +array_chunk() - variation 9 +--FILE-- + 0, 2 => 2); +var_dump ($array); +for ($i = 1; $i < (sizeof($array) + 1); $i++) { + echo "[$i]\n"; + var_dump (array_chunk ($array, $i)); + var_dump (array_chunk ($array, $i, TRUE)); + var_dump (array_chunk ($array, $i, FALSE)); + echo "\n"; +} +?> +--EXPECT-- +array(2) { + [1]=> + int(0) + [2]=> + int(2) +} +[1] +array(2) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [0]=> + int(2) + } +} +array(2) { + [0]=> + array(1) { + [1]=> + int(0) + } + [1]=> + array(1) { + [2]=> + int(2) + } +} +array(2) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [0]=> + int(2) + } +} + +[2] +array(1) { + [0]=> + array(2) { + [0]=> + int(0) + [1]=> + int(2) + } +} +array(1) { + [0]=> + array(2) { + [1]=> + int(0) + [2]=> + int(2) + } +} +array(1) { + [0]=> + array(2) { + [0]=> + int(0) + [1]=> + int(2) + } +} diff --git a/tests/std/array/array_column_basic.phpt b/tests/std/array/array_column_basic.phpt new file mode 100644 index 00000000..a7d0ec70 --- /dev/null +++ b/tests/std/array/array_column_basic.phpt @@ -0,0 +1,259 @@ +--TEST-- +Test array_column() function: basic functionality +--SKIPIF-- + +--FILE-- + 1, 'first_name' => 'John', 'last_name' => 'Doe'), array('id' => 2, 'first_name' => 'Sally', 'last_name' => 'Smith'), array('id' => 3, 'first_name' => 'Jane', 'last_name' => 'Jones')); + echo "-- first_name column from recordset --\n"; + var_dump(array_column($records, 'first_name')); + echo "-- id column from recordset --\n"; + var_dump(array_column($records, 'id')); + echo "-- last_name column from recordset, keyed by value from id column --\n"; + var_dump(array_column($records, 'last_name', 'id')); + echo "-- last_name column from recordset, keyed by value from first_name column --\n"; + var_dump(array_column($records, 'last_name', 'first_name')); + echo "\n*** Testing multiple data types ***\n"; + $fh = fopen(__FILE__, 'r', true); + $values = array(array('id' => 1, 'value' => new stdClass()), array('id' => 2, 'value' => 34.2345), array('id' => 3, 'value' => true), array('id' => 4, 'value' => false), array('id' => 5, 'value' => null), array('id' => 6, 'value' => 1234), array('id' => 7, 'value' => 'Foo'), array('id' => 8, 'value' => $fh)); + var_dump(array_column($values, 'value')); + var_dump(array_column($values, 'value', 'id')); + echo "\n*** Testing numeric column keys ***\n"; + $numericCols = array(array('aaa', '111'), array('bbb', '222'), array('ccc', '333', -1 => 'ddd')); + var_dump(array_column($numericCols, 1)); + var_dump(array_column($numericCols, 1, 0)); + var_dump(array_column($numericCols, 1, 0.123)); + var_dump(array_column($numericCols, 1, -1)); + echo "\n*** Testing failure to find specified column ***\n"; + var_dump(array_column($numericCols, 2)); + var_dump(array_column($numericCols, 'foo')); + var_dump(array_column($numericCols, 0, 'foo')); + var_dump(array_column($numericCols, 3.14)); + echo "\n*** Testing single dimensional array ***\n"; + $singleDimension = array('foo', 'bar', 'baz'); + var_dump(array_column($singleDimension, 1)); + echo "\n*** Testing columns not present in all rows ***\n"; + $mismatchedColumns = array(array('a' => 'foo', 'b' => 'bar', 'e' => 'bbb'), array('a' => 'baz', 'c' => 'qux', 'd' => 'aaa'), array('a' => 'eee', 'b' => 'fff', 'e' => 'ggg')); + var_dump(array_column($mismatchedColumns, 'c')); + var_dump(array_column($mismatchedColumns, 'c', 'a')); + var_dump(array_column($mismatchedColumns, 'a', 'd')); + var_dump(array_column($mismatchedColumns, 'a', 'e')); + var_dump(array_column($mismatchedColumns, 'b')); + var_dump(array_column($mismatchedColumns, 'b', 'a')); + echo "\n*** Testing use of object converted to string ***\n"; + $f = new Foo(); + $b = new Bar(); + var_dump(array_column($records, $f)); + var_dump(array_column($records, $f, $b)); + echo "Done\n"; +} +?> +--EXPECTF-- +*** Testing array_column() : basic functionality *** +-- first_name column from recordset -- +array(3) { + [0]=> + string(4) "John" + [1]=> + string(5) "Sally" + [2]=> + string(4) "Jane" +} +-- id column from recordset -- +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +-- last_name column from recordset, keyed by value from id column -- +array(3) { + [1]=> + string(3) "Doe" + [2]=> + string(5) "Smith" + [3]=> + string(5) "Jones" +} +-- last_name column from recordset, keyed by value from first_name column -- +array(3) { + ["John"]=> + string(3) "Doe" + ["Sally"]=> + string(5) "Smith" + ["Jane"]=> + string(5) "Jones" +} + +*** Testing multiple data types *** +array(8) { + [0]=> + object(stdClass)#%d (0) { + } + [1]=> + float(34.2345) + [2]=> + bool(true) + [3]=> + bool(false) + [4]=> + NULL + [5]=> + int(1234) + [6]=> + string(3) "Foo" + [7]=> + resource(%d) of type (stream) +} +array(8) { + [1]=> + object(stdClass)#%d (0) { + } + [2]=> + float(34.2345) + [3]=> + bool(true) + [4]=> + bool(false) + [5]=> + NULL + [6]=> + int(1234) + [7]=> + string(3) "Foo" + [8]=> + resource(%d) of type (stream) +} + +*** Testing numeric column keys *** +array(3) { + [0]=> + string(3) "111" + [1]=> + string(3) "222" + [2]=> + string(3) "333" +} +array(3) { + ["aaa"]=> + string(3) "111" + ["bbb"]=> + string(3) "222" + ["ccc"]=> + string(3) "333" +} + +Deprecated: Implicit conversion from float 0.123 to int loses precision in %s on line %d +array(3) { + ["aaa"]=> + string(3) "111" + ["bbb"]=> + string(3) "222" + ["ccc"]=> + string(3) "333" +} +array(3) { + [0]=> + string(3) "111" + [1]=> + string(3) "222" + ["ddd"]=> + string(3) "333" +} + +*** Testing failure to find specified column *** +array(0) { +} +array(0) { +} +array(3) { + [0]=> + string(3) "aaa" + [1]=> + string(3) "bbb" + [2]=> + string(3) "ccc" +} + +Deprecated: Implicit conversion from float 3.14 to int loses precision in %s on line %d +array(0) { +} + +*** Testing single dimensional array *** +array(0) { +} + +*** Testing columns not present in all rows *** +array(1) { + [0]=> + string(3) "qux" +} +array(1) { + ["baz"]=> + string(3) "qux" +} +array(3) { + [0]=> + string(3) "foo" + ["aaa"]=> + string(3) "baz" + [1]=> + string(3) "eee" +} +array(3) { + ["bbb"]=> + string(3) "foo" + [0]=> + string(3) "baz" + ["ggg"]=> + string(3) "eee" +} +array(2) { + [0]=> + string(3) "bar" + [1]=> + string(3) "fff" +} +array(2) { + ["foo"]=> + string(3) "bar" + ["eee"]=> + string(3) "fff" +} + +*** Testing use of object converted to string *** +array(3) { + [0]=> + string(3) "Doe" + [1]=> + string(5) "Smith" + [2]=> + string(5) "Jones" +} +array(3) { + ["John"]=> + string(3) "Doe" + ["Sally"]=> + string(5) "Smith" + ["Jane"]=> + string(5) "Jones" +} +Done diff --git a/tests/std/array/array_column_numeric_string_key.phpt b/tests/std/array/array_column_numeric_string_key.phpt new file mode 100644 index 00000000..aed3c35e --- /dev/null +++ b/tests/std/array/array_column_numeric_string_key.phpt @@ -0,0 +1,23 @@ +--TEST-- +array_column() treats numeric string keys as usual +--FILE-- + 'a'], [42 => 'b']]; +var_dump(array_column($array, 42)); +var_dump(array_column($array, "42")); + +?> +--EXPECT-- +array(2) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" +} +array(2) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" +} diff --git a/tests/std/array/array_column_object_cast.phpt b/tests/std/array/array_column_object_cast.phpt new file mode 100644 index 00000000..eee58528 --- /dev/null +++ b/tests/std/array/array_column_object_cast.phpt @@ -0,0 +1,38 @@ +--TEST-- +Test array_column() function: basic functionality +--FILE-- + 2135, 'first_name' => 'John', 'last_name' => 'XXX'), array('id' => 3245, 'first_name' => 'Sally', 'last_name' => 'Smith')); + $firstNames = array_column($records, $column_key, $index_key); + print_r($firstNames); + var_dump($column_key); + var_dump($index_key); +} +?> +--EXPECT-- +Array +( + [2135] => John + [3245] => Sally +) +object(ColumnKeyClass)#1 (0) { +} +object(IndexKeyClass)#2 (0) { +} diff --git a/tests/std/array/array_column_property_visibility.phpt b/tests/std/array/array_column_property_visibility.phpt new file mode 100644 index 00000000..3595596c --- /dev/null +++ b/tests/std/array/array_column_property_visibility.phpt @@ -0,0 +1,31 @@ +--TEST-- +array_column() respects property visibility +--FILE-- +prop = $value; + } + public function __isset($name): bool + { + return true; + } + public function __get($name) + { + return "__get({$this->prop})"; + } +} +function main() +{ + $arr = [new Test("foobar")]; + var_dump(array_column($arr, "prop")); +} +?> +--EXPECT-- +array(1) { + [0]=> + string(13) "__get(foobar)" +} diff --git a/tests/std/array/array_column_scalar_index_strict_types.phpt b/tests/std/array/array_column_scalar_index_strict_types.phpt new file mode 100644 index 00000000..fbb4a641 --- /dev/null +++ b/tests/std/array/array_column_scalar_index_strict_types.phpt @@ -0,0 +1,66 @@ +--TEST-- +Test array_column(): Index argument with various types in strict type mode +--SKIPIF-- + +--FILE-- +getMessage() . "\n"; + } + try { + var_dump(array_column([['php7', 'foo'], ['php8', 'bar']], true)); + } catch (\TypeError $e) { + echo $e->getMessage() . "\n"; + } + + echo "\n-- Testing array_column() column key parameter should be a string or integer (testing array) --\n"; + try { + var_dump(array_column([['php7', 'foo'], ['php8', 'bar']], array())); + } catch (\TypeError $e) { + echo $e->getMessage() . "\n"; + } + + echo "\n-- Testing array_column() index key parameter should be a string or an integer (testing bool) --\n"; + try { + var_dump(array_column([['php' => 7, 'foo'], ['php' => 8, 'bar']], 'php', false)); + } catch (\TypeError $e) { + echo $e->getMessage() . "\n"; + } + try { + var_dump(array_column([['php' => 7, 'foo'], ['php' => 8, 'bar']], 'php', true)); + } catch (\TypeError $e) { + echo $e->getMessage() . "\n"; + } + + echo "\n-- Testing array_column() index key parameter should be a string or integer (testing array) --\n"; + try { + var_dump(array_column([['php' => 7, 'foo'], ['php' => 8, 'bar']], 'php', array())); + } catch (\TypeError $e) { + echo $e->getMessage() . "\n"; + } + + echo "DONE\n"; +} +?> +--EXPECT-- +-- Testing array_column() column key parameter should be a string or an integer (testing bool) -- +array_column(): Argument #2 ($column_key) must be of type string|int|null, false given +array_column(): Argument #2 ($column_key) must be of type string|int|null, true given + +-- Testing array_column() column key parameter should be a string or integer (testing array) -- +array_column(): Argument #2 ($column_key) must be of type string|int|null, array given + +-- Testing array_column() index key parameter should be a string or an integer (testing bool) -- +array_column(): Argument #3 ($index_key) must be of type string|int|null, false given +array_column(): Argument #3 ($index_key) must be of type string|int|null, true given + +-- Testing array_column() index key parameter should be a string or integer (testing array) -- +array_column(): Argument #3 ($index_key) must be of type string|int|null, array given + +DONE diff --git a/tests/std/array/array_column_scalar_index_weak_types.phpt b/tests/std/array/array_column_scalar_index_weak_types.phpt new file mode 100644 index 00000000..4cba6919 --- /dev/null +++ b/tests/std/array/array_column_scalar_index_weak_types.phpt @@ -0,0 +1,83 @@ +--TEST-- +Test array_column(): Index argument with various types in weak type mode +--SKIPIF-- +--FILE-- +getMessage() . "\n"; + } + try { + var_dump(array_column([['php7', 'foo'], ['php8', 'bar']], true)); + } catch (\TypeError $e) { + echo $e->getMessage() . "\n"; + } + + echo "\n-- Testing array_column() column key parameter should be a string or integer (testing array) --\n"; + try { + var_dump(array_column([['php7', 'foo'], ['php8', 'bar']], array())); + } catch (\TypeError $e) { + echo $e->getMessage() . "\n"; + } + + echo "\n-- Testing array_column() index key parameter should be a string or an integer (testing bool) --\n"; + try { + var_dump(array_column([['php' => 7, 'foo'], ['php' => 8, 'bar']], 'php', false)); + } catch (\TypeError $e) { + echo $e->getMessage() . "\n"; + } + try { + var_dump(array_column([['php' => 7, 'foo'], ['php' => 8, 'bar']], 'php', true)); + } catch (\TypeError $e) { + echo $e->getMessage() . "\n"; + } + + echo "\n-- Testing array_column() index key parameter should be a string or integer (testing array) --\n"; + try { + var_dump(array_column([['php' => 7, 'foo'], ['php' => 8, 'bar']], 'php', array())); + } catch (\TypeError $e) { + echo $e->getMessage() . "\n"; + } + + echo "DONE\n"; +} +?> +--EXPECT-- +-- Testing array_column() column key parameter should be a string or an integer (testing bool) -- +array(2) { + [0]=> + string(4) "php7" + [1]=> + string(4) "php8" +} +array(2) { + [0]=> + string(3) "foo" + [1]=> + string(3) "bar" +} + +-- Testing array_column() column key parameter should be a string or integer (testing array) -- +array_column(): Argument #2 ($column_key) must be of type string|int|null, array given + +-- Testing array_column() index key parameter should be a string or an integer (testing bool) -- +array(2) { + ["foo"]=> + int(7) + ["bar"]=> + int(8) +} +array(2) { + [0]=> + int(7) + [1]=> + int(8) +} + +-- Testing array_column() index key parameter should be a string or integer (testing array) -- +array_column(): Argument #3 ($index_key) must be of type string|int|null, array given +DONE \ No newline at end of file diff --git a/tests/std/array/array_column_variant.phpt b/tests/std/array/array_column_variant.phpt new file mode 100644 index 00000000..9673ff17 --- /dev/null +++ b/tests/std/array/array_column_variant.phpt @@ -0,0 +1,86 @@ +--TEST-- +Test array_column() function: variant functionality +--FILE-- + array('id' => '3', 'title' => 'Foo', 'date' => '2013-03-25'), + 457 => array('id' => '5', 'title' => 'Bar', 'date' => '2012-05-20'), +); + +echo "-- pass null as second parameter to get back all columns indexed by third parameter --\n"; +var_dump(array_column($rows, null, 'id')); + +echo "-- pass null as second parameter and bogus third param to get back zero-indexed array of all columns --\n"; +var_dump(array_column($rows, null, 'foo')); + +echo "-- pass null as second parameter and no third param to get back array_values(input) --\n"; +var_dump(array_column($rows, null)); + +echo "Done\n"; +?> +--EXPECT-- +-- pass null as second parameter to get back all columns indexed by third parameter -- +array(2) { + [3]=> + array(3) { + ["id"]=> + string(1) "3" + ["title"]=> + string(3) "Foo" + ["date"]=> + string(10) "2013-03-25" + } + [5]=> + array(3) { + ["id"]=> + string(1) "5" + ["title"]=> + string(3) "Bar" + ["date"]=> + string(10) "2012-05-20" + } +} +-- pass null as second parameter and bogus third param to get back zero-indexed array of all columns -- +array(2) { + [0]=> + array(3) { + ["id"]=> + string(1) "3" + ["title"]=> + string(3) "Foo" + ["date"]=> + string(10) "2013-03-25" + } + [1]=> + array(3) { + ["id"]=> + string(1) "5" + ["title"]=> + string(3) "Bar" + ["date"]=> + string(10) "2012-05-20" + } +} +-- pass null as second parameter and no third param to get back array_values(input) -- +array(2) { + [0]=> + array(3) { + ["id"]=> + string(1) "3" + ["title"]=> + string(3) "Foo" + ["date"]=> + string(10) "2013-03-25" + } + [1]=> + array(3) { + ["id"]=> + string(1) "5" + ["title"]=> + string(3) "Bar" + ["date"]=> + string(10) "2012-05-20" + } +} +Done diff --git a/tests/std/array/array_column_variant_objects.phpt b/tests/std/array/array_column_variant_objects.phpt new file mode 100644 index 00000000..79174490 --- /dev/null +++ b/tests/std/array/array_column_variant_objects.phpt @@ -0,0 +1,142 @@ +--TEST-- +Test array_column() function: testing with objects +--FILE-- +id = $id; + $this->first_name = $first_name; + $this->last_name = $last_name; + } +} +function newUser($id, $first_name, $last_name) +{ + $o = new stdClass(); + $o->{0} = $id; + $o->{1} = $first_name; + $o->{2} = $last_name; + return $o; +} +class Something +{ + public function __isset($name): bool + { + return $name == 'first_name'; + } + public function __get($name) + { + return new User(4, 'Jack', 'Sparrow'); + } +} +function main() +{ + $records = array(newUser(1, 'John', 'Doe'), newUser(2, 'Sally', 'Smith'), newUser(3, 'Jane', 'Jones'), new User(1, 'John', 'Doe'), new User(2, 'Sally', 'Smith'), new User(3, 'Jane', 'Jones'), new Something()); + echo "*** Testing array_column() : object property fetching (numeric property names) ***\n"; + echo "-- first_name column from recordset --\n"; + var_dump(array_column($records, 1)); + echo "-- id column from recordset --\n"; + var_dump(array_column($records, 0)); + echo "-- last_name column from recordset, keyed by value from id column --\n"; + var_dump(array_column($records, 2, 0)); + echo "-- last_name column from recordset, keyed by value from first_name column --\n"; + var_dump(array_column($records, 2, 1)); + echo "*** Testing array_column() : object property fetching (string property names) ***\n"; + echo "-- first_name column from recordset --\n"; + var_dump(array_column($records, 'first_name')); + echo "-- id column from recordset --\n"; + var_dump(array_column($records, 'id')); + echo "-- last_name column from recordset, keyed by value from id column --\n"; + var_dump(array_column($records, 'last_name', 'id')); + echo "-- last_name column from recordset, keyed by value from first_name column --\n"; + var_dump(array_column($records, 'last_name', 'first_name')); + echo "Done\n"; +} +?> +--EXPECT-- +*** Testing array_column() : object property fetching (numeric property names) *** +-- first_name column from recordset -- +array(3) { + [0]=> + string(4) "John" + [1]=> + string(5) "Sally" + [2]=> + string(4) "Jane" +} +-- id column from recordset -- +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +-- last_name column from recordset, keyed by value from id column -- +array(3) { + [1]=> + string(3) "Doe" + [2]=> + string(5) "Smith" + [3]=> + string(5) "Jones" +} +-- last_name column from recordset, keyed by value from first_name column -- +array(3) { + ["John"]=> + string(3) "Doe" + ["Sally"]=> + string(5) "Smith" + ["Jane"]=> + string(5) "Jones" +} +*** Testing array_column() : object property fetching (string property names) *** +-- first_name column from recordset -- +array(4) { + [0]=> + string(4) "John" + [1]=> + string(5) "Sally" + [2]=> + string(4) "Jane" + [3]=> + object(User)#8 (3) { + ["id"]=> + int(4) + ["first_name"]=> + string(4) "Jack" + ["last_name"]=> + string(7) "Sparrow" + } +} +-- id column from recordset -- +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +-- last_name column from recordset, keyed by value from id column -- +array(3) { + [1]=> + string(3) "Doe" + [2]=> + string(5) "Smith" + [3]=> + string(5) "Jones" +} +-- last_name column from recordset, keyed by value from first_name column -- +array(3) { + ["John"]=> + string(3) "Doe" + ["Sally"]=> + string(5) "Smith" + ["Jane"]=> + string(5) "Jones" +} +Done diff --git a/tests/std/array/array_combine.phpt b/tests/std/array/array_combine.phpt new file mode 100644 index 00000000..d6ec31b0 --- /dev/null +++ b/tests/std/array/array_combine.phpt @@ -0,0 +1,155 @@ +--TEST-- +basic array_combine test +--SKIPIF-- + +--FILE-- + +--EXPECT-- +array(3) { + ["green"]=> + string(5) "green" + ["red"]=> + string(3) "red" + ["yellow"]=> + string(6) "yellow" +} +array(3) { + ["green"]=> + string(1) "1" + ["red"]=> + string(1) "2" + ["yellow"]=> + string(1) "3" +} +array(3) { + ["green"]=> + int(0) + ["red"]=> + int(1) + ["yellow"]=> + int(2) +} +array(3) { + ["green"]=> + bool(true) + ["red"]=> + bool(false) + ["yellow"]=> + NULL +} +array(3) { + [1]=> + string(5) "green" + [2]=> + string(3) "red" + [3]=> + string(6) "yellow" +} +array(3) { + [1]=> + string(1) "1" + [2]=> + string(1) "2" + [3]=> + string(1) "3" +} +array(3) { + [1]=> + int(0) + [2]=> + int(1) + [3]=> + int(2) +} +array(3) { + [1]=> + bool(true) + [2]=> + bool(false) + [3]=> + NULL +} +array(3) { + [0]=> + string(5) "green" + [1]=> + string(3) "red" + [2]=> + string(6) "yellow" +} +array(3) { + [0]=> + string(1) "1" + [1]=> + string(1) "2" + [2]=> + string(1) "3" +} +array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) +} +array(3) { + [0]=> + bool(true) + [1]=> + bool(false) + [2]=> + NULL +} +array(2) { + [1]=> + string(5) "green" + [""]=> + string(6) "yellow" +} +array(2) { + [1]=> + string(1) "1" + [""]=> + string(1) "3" +} +array(2) { + [1]=> + int(0) + [""]=> + int(2) +} +array(2) { + [1]=> + bool(true) + [""]=> + NULL +} diff --git a/tests/std/array/array_combine_basic.phpt b/tests/std/array/array_combine_basic.phpt new file mode 100644 index 00000000..ccf1bbf4 --- /dev/null +++ b/tests/std/array/array_combine_basic.phpt @@ -0,0 +1,46 @@ +--TEST-- +Test array_combine() function : basic functionality +--FILE-- + "a", 2 => 'b'); +$values_array = array(3 => 'c', 4 => "d"); +var_dump( array_combine($keys_array, $values_array) ); + +// mixed array for $keys and $values arguments +$keys_array = array(1, 2 => "b"); +$values_array = array(3 => 'c', 4); +var_dump( array_combine($keys_array, $values_array) ); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_combine() : basic functionality *** +array(2) { + [1]=> + int(3) + [2]=> + int(4) +} +array(2) { + ["a"]=> + string(1) "c" + ["b"]=> + string(1) "d" +} +array(2) { + [1]=> + string(1) "c" + ["b"]=> + int(4) +} +Done diff --git a/tests/std/array/array_combine_error2.phpt b/tests/std/array/array_combine_error2.phpt new file mode 100644 index 00000000..8d3440ea --- /dev/null +++ b/tests/std/array/array_combine_error2.phpt @@ -0,0 +1,48 @@ +--TEST-- +Test array_combine() function : error conditions - empty array +--FILE-- +getMessage(); +} + +// Testing array_combine by passing empty array to $values +echo "\n-- Testing array_combine() function with empty array for \$values argument --\n"; +try { + var_dump( array_combine(array(1, 2), array()) ); +} catch (\ValueError $e) { + echo $e->getMessage(); +} + +// Testing array_combine with arrays having unequal number of elements +echo "\n-- Testing array_combine() function by passing array with unequal number of elements --\n"; +try { + var_dump( array_combine(array(1, 2), array(1, 2, 3)) ); +} catch (\ValueError $e) { + echo $e->getMessage(); +} + +?> +--EXPECT-- +*** Testing array_combine() : error conditions specific to array_combine() *** + +-- Testing array_combine() function with empty arrays -- +array(0) { +} + +-- Testing array_combine() function with empty array for $keys argument -- +array_combine(): Argument #1 ($keys) and argument #2 ($values) must have the same number of elements +-- Testing array_combine() function with empty array for $values argument -- +array_combine(): Argument #1 ($keys) and argument #2 ($values) must have the same number of elements +-- Testing array_combine() function by passing array with unequal number of elements -- +array_combine(): Argument #1 ($keys) and argument #2 ($values) must have the same number of elements diff --git a/tests/std/array/array_combine_variation3.phpt b/tests/std/array/array_combine_variation3.phpt new file mode 100644 index 00000000..a04c67e7 --- /dev/null +++ b/tests/std/array/array_combine_variation3.phpt @@ -0,0 +1,275 @@ +--TEST-- +Test array_combine() function : usage variations - different arrays(Bug#43424) +--SKIPIF-- + +--FILE-- +22 +'single quoted string' +"double quoted string" +2222 != 1111.\t 0000 = 0000\n +EOT; + +// arrays passed to $keys argument +$arrays = array ( +/*1*/ array(1, 2), // with default keys and numeric values + array(1.1, 2.2), // with default keys & float values + array(false,true), // with default keys and boolean values + array(), // empty array +/*5*/ array(NULL), // with NULL + array("a\v\f","aaaa\r","b","b\tbbb","c","\[\]\!\@\#\$\%\^\&\*\(\)\{\}"), // with double quoted strings + array('a\v\f','aaaa\r','b','b\tbbb','c','\[\]\!\@\#\$\%\^\&\*\(\)\{\}'), // with single quoted strings + array("h1" => $blank_line, "h2" => $multiline_string, "h3" => $diff_whitespaces, $numeric_string), // with heredocs + + // associative arrays +/*9*/ array(1 => "one", 2 => "two", 3 => "three"), // explicit numeric keys, string values + array("one" => 1, "two" => 2, "three" => 3 ), // string keys & numeric values + array( 1 => 10, 2 => 20, 4 => 40, 3 => 30), // explicit numeric keys and numeric values + array( "one" => "ten", "two" => "twenty", "three" => "thirty"), // string key/value + array("one" => 1, 2 => "two", 4 => "four"), //mixed + + // associative array, containing null/empty/boolean values as key/value +/*14*/ array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null), + array(true => "true", false => "false", "false" => false, "true" => true), + array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''), + array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true), + array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6), + + // array with repetitive keys +/*19*/ array("One" => 1, "two" => 2, "One" => 10, "two" => 20, "three" => 3) +); + +// loop through each sub-array within $arrays to check the behavior of array_combine() +// same arrays are passed to both $keys and $values +$iterator = 1; +foreach($arrays as $array) { + echo "-- Iteration $iterator --\n"; + var_dump( array_combine($array, $array) ); + $iterator++; +} + +echo "Done"; +?> +--EXPECT-- +*** Testing array_combine() : Passing different types of arrays to both $keys and $values argument *** +-- Iteration 1 -- +array(2) { + [1]=> + int(1) + [2]=> + int(2) +} +-- Iteration 2 -- +array(2) { + ["1.1"]=> + float(1.1) + ["2.2"]=> + float(2.2) +} +-- Iteration 3 -- +array(2) { + [""]=> + bool(false) + [1]=> + bool(true) +} +-- Iteration 4 -- +array(0) { +} +-- Iteration 5 -- +array(1) { + [""]=> + NULL +} +-- Iteration 6 -- +array(6) { + ["a "]=> + string(3) "a " + ["aaaa "]=> + string(5) "aaaa " + ["b"]=> + string(1) "b" + ["b bbb"]=> + string(5) "b bbb" + ["c"]=> + string(1) "c" + ["\[\]\!\@\#$\%\^\&\*\(\)\{\}"]=> + string(27) "\[\]\!\@\#$\%\^\&\*\(\)\{\}" +} +-- Iteration 7 -- +array(6) { + ["a\v\f"]=> + string(5) "a\v\f" + ["aaaa\r"]=> + string(6) "aaaa\r" + ["b"]=> + string(1) "b" + ["b\tbbb"]=> + string(6) "b\tbbb" + ["c"]=> + string(1) "c" + ["\[\]\!\@\#\$\%\^\&\*\(\)\{\}"]=> + string(28) "\[\]\!\@\#\$\%\^\&\*\(\)\{\}" +} +-- Iteration 8 -- +array(4) { + [" +"]=> + string(1) " +" + ["hello world +The quick brown fox jumped over; +the lazy dog +This is a double quoted string"]=> + string(88) "hello world +The quick brown fox jumped over; +the lazy dog +This is a double quoted string" + ["hello world +1111 != 2222 +heredoc +double quoted string. with different white spaces"]=> + string(88) "hello world +1111 != 2222 +heredoc +double quoted string. with different white spaces" + ["11 < 12. 123 >22 +'single quoted string' +"double quoted string" +2222 != 1111. 0000 = 0000 +"]=> + string(90) "11 < 12. 123 >22 +'single quoted string' +"double quoted string" +2222 != 1111. 0000 = 0000 +" +} +-- Iteration 9 -- +array(3) { + ["one"]=> + string(3) "one" + ["two"]=> + string(3) "two" + ["three"]=> + string(5) "three" +} +-- Iteration 10 -- +array(3) { + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) +} +-- Iteration 11 -- +array(4) { + [10]=> + int(10) + [20]=> + int(20) + [40]=> + int(40) + [30]=> + int(30) +} +-- Iteration 12 -- +array(3) { + ["ten"]=> + string(3) "ten" + ["twenty"]=> + string(6) "twenty" + ["thirty"]=> + string(6) "thirty" +} +-- Iteration 13 -- +array(3) { + [1]=> + int(1) + ["two"]=> + string(3) "two" + ["four"]=> + string(4) "four" +} +-- Iteration 14 -- +array(2) { + ["null"]=> + string(4) "null" + [""]=> + NULL +} +-- Iteration 15 -- +array(4) { + ["true"]=> + string(4) "true" + ["false"]=> + string(5) "false" + [""]=> + bool(false) + [1]=> + bool(true) +} +-- Iteration 16 -- +array(2) { + ["emptys"]=> + string(6) "emptys" + [""]=> + string(0) "" +} +-- Iteration 17 -- +array(2) { + [""]=> + bool(false) + [1]=> + bool(true) +} +-- Iteration 18 -- +array(3) { + [4]=> + int(4) + [5]=> + int(5) + [6]=> + int(6) +} +-- Iteration 19 -- +array(3) { + [10]=> + int(10) + [20]=> + int(20) + [3]=> + int(3) +} +Done diff --git a/tests/std/array/array_combine_variation4.phpt b/tests/std/array/array_combine_variation4.phpt new file mode 100644 index 00000000..c8fca16a --- /dev/null +++ b/tests/std/array/array_combine_variation4.phpt @@ -0,0 +1,150 @@ +--TEST-- +Test array_combine() function : usage variations - associative array with different keys(Bug#43424) +--SKIPIF-- + +--FILE-- + "0"), + array(1 => "1"), + array(1 => "1", 2 => "2", 3 => "3", 4 => "4"), + // arrays with string keys + /*7*/ + array('\tHello' => 111, 're\td' => "color", '\v\fworld' => 2.2, 'pen\n' => 33), + array("\tHello" => 111, "re\td" => "color", "\v\fworld" => 2.2, "pen\n" => 33), + array("hello", $heredoc => "string"), + // heredoc + // array with object, unset variable and resource variable + /*10*/ + array(@$unset_var => "hello", $fp => 'resource'), + // array with mixed keys + /*11*/ + array('hello' => 1, "fruit" => 2.2, $fp => 'resource', 133 => "int", @$unset_var => "unset", $heredoc => "heredoc"), + ); + // array to be passsed to $arr2 argument + $arr2 = array(0 => 0, 2 => "float", 4 => "f3", 33333333 => "f4", "\tHello" => 111, 2.2, 'color', "Hello world" => "string", "pen\n" => 33, 133 => "int"); + // loop through each sub-array within $arrays to check the behavior of array_combine() + // same arrays are passed to both $keys and $values + $iterator = 1; + foreach ($arrays as $array) { + echo "-- Iteration {$iterator} --\n"; + var_dump(array_combine($array, $array)); + $iterator++; + } + // close the file resource used + fclose($fp); + echo "Done"; +} +?> +--EXPECTF-- +*** Testing array_combine() : assoc array with diff keys to both $keys and $values argument *** + +Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d + +Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d +-- Iteration 1 -- +array(0) { +} +-- Iteration 2 -- +array(1) { + [0]=> + string(1) "0" +} +-- Iteration 3 -- +array(1) { + [1]=> + string(1) "1" +} +-- Iteration 4 -- +array(4) { + [1]=> + string(1) "1" + [2]=> + string(1) "2" + [3]=> + string(1) "3" + [4]=> + string(1) "4" +} +-- Iteration 5 -- +array(4) { + [111]=> + int(111) + ["color"]=> + string(5) "color" + ["2.2"]=> + float(2.2) + [33]=> + int(33) +} +-- Iteration 6 -- +array(4) { + [111]=> + int(111) + ["color"]=> + string(5) "color" + ["2.2"]=> + float(2.2) + [33]=> + int(33) +} +-- Iteration 7 -- +array(2) { + ["hello"]=> + string(5) "hello" + ["string"]=> + string(6) "string" +} +-- Iteration 8 -- +array(2) { + ["hello"]=> + string(5) "hello" + ["resource"]=> + string(8) "resource" +} +-- Iteration 9 -- +array(6) { + [1]=> + int(1) + ["2.2"]=> + float(2.2) + ["resource"]=> + string(8) "resource" + ["int"]=> + string(3) "int" + ["unset"]=> + string(5) "unset" + ["heredoc"]=> + string(7) "heredoc" +} +Done diff --git a/tests/std/array/array_combine_variation5.phpt b/tests/std/array/array_combine_variation5.phpt new file mode 100644 index 00000000..2d80ac57 --- /dev/null +++ b/tests/std/array/array_combine_variation5.phpt @@ -0,0 +1,172 @@ +--TEST-- +Test array_combine() function : usage variations - associative array with different values(Bug#43424) +--SKIPIF-- + +--FILE-- + 0), + array("1" => 1), + array("one" => 1, 'two' => 2, "three" => 3, 4 => 4), + // arrays with float values + /*5*/ + array("float" => 2.3333), + array("f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => 33333333.333), + // arrays with string values + /*7*/ + array(111 => "\tHello", "red" => "col\tor", 2 => "\v\fworld", 3 => "pen\n"), + array(111 => '\tHello', "red" => 'col\tor', 2 => '\v\fworld', 3 => 'pen\n'), + array(1 => "hello", "heredoc" => $heredoc), + // array with object, unset variable and resource variable + /*10*/ + array(11 => new classA(), "unset" => @$unset_var, "resource" => $fp), + // array with mixed values + /*11*/ + array(1 => 'hello', 2 => new classA(), 222 => "fruit", 'resource' => $fp, "int" => 133, "float" => 444.432, "unset" => @$unset_var, "heredoc" => $heredoc), + ); + // loop through each sub-array within $arrays to check the behavior of array_combine() + $iterator = 1; + foreach ($arrays as $array) { + echo "-- Iteration {$iterator} --\n"; + var_dump(array_combine($array, $array)); + $iterator++; + } + // close the file resource used + fclose($fp); + echo "Done"; +} +?> +--EXPECTF-- +*** Testing array_combine() : assoc array with diff values to both $keys and $values argument *** +-- Iteration 1 -- +array(0) { +} +-- Iteration 2 -- +array(1) { + [0]=> + int(0) +} +-- Iteration 3 -- +array(1) { + [1]=> + int(1) +} +-- Iteration 4 -- +array(4) { + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) +} +-- Iteration 5 -- +array(1) { + ["2.3333"]=> + float(2.3333) +} +-- Iteration 6 -- +array(4) { + ["1.2"]=> + float(1.2) + ["3.33"]=> + float(3.33) + ["4.8999992284"]=> + float(4.89999922839999) + ["33333333.333"]=> + float(33333333.333) +} +-- Iteration 7 -- +array(4) { + [" Hello"]=> + string(6) " Hello" + ["col or"]=> + string(6) "col or" + [" world"]=> + string(7) " world" + ["pen +"]=> + string(4) "pen +" +} +-- Iteration 8 -- +array(4) { + ["\tHello"]=> + string(7) "\tHello" + ["col\tor"]=> + string(7) "col\tor" + ["\v\fworld"]=> + string(9) "\v\fworld" + ["pen\n"]=> + string(5) "pen\n" +} +-- Iteration 9 -- +array(2) { + ["hello"]=> + string(5) "hello" + ["Hello world"]=> + string(11) "Hello world" +} +-- Iteration 10 -- +array(3) { + ["Class A object"]=> + object(classA)#%d (0) { + } + [""]=> + NULL + ["Resource id #%d"]=> + resource(%d) of type (stream) +} +-- Iteration 11 -- +array(8) { + ["hello"]=> + string(5) "hello" + ["Class A object"]=> + object(classA)#%d (0) { + } + ["fruit"]=> + string(5) "fruit" + ["Resource id #%d"]=> + resource(%d) of type (stream) + [133]=> + int(133) + ["444.432"]=> + float(444.432) + [""]=> + NULL + ["Hello world"]=> + string(11) "Hello world" +} +Done diff --git a/tests/std/array/array_combine_variation6.phpt b/tests/std/array/array_combine_variation6.phpt new file mode 100644 index 00000000..b9985a0a --- /dev/null +++ b/tests/std/array/array_combine_variation6.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test array_combine() function : usage variations - binary safe checking +--FILE-- + +--EXPECT-- +*** Testing array_combine() : binary safe checking *** +array(2) { + ["hello"]=> + string(5) "hello" + ["world"]=> + string(5) "world" +} +array(2) { + ["hello"]=> + string(5) "hello" + ["world"]=> + string(5) "world" +} +array(2) { + ["hello"]=> + string(5) "hello" + ["world"]=> + string(5) "world" +} +Done diff --git a/tests/std/array/array_count_values.phpt b/tests/std/array/array_count_values.phpt new file mode 100644 index 00000000..eb515124 --- /dev/null +++ b/tests/std/array/array_count_values.phpt @@ -0,0 +1,94 @@ +--TEST-- +array_count_values() +--FILE-- + +--EXPECT-- +array(0) { +} + +array(1) { + [0]=> + int(1) +} + +array(1) { + [1]=> + int(1) +} + +array(1) { + [-1]=> + int(1) +} + +array(1) { + [0]=> + int(2) +} + +array(2) { + [0]=> + int(1) + [1]=> + int(1) +} + +array(1) { + [1]=> + int(2) +} + +array(3) { + [1]=> + int(2) + ["hello"]=> + int(2) + ["world"]=> + int(1) +} + +array(2) { + ["hello"]=> + int(2) + ["world"]=> + int(1) +} + +array(3) { + [""]=> + int(2) + ["world"]=> + int(3) + ["hello"]=> + int(4) +} + +array(1) { + [0]=> + int(1) +} + +array(1) { + [1]=> + int(1) +} diff --git a/tests/std/array/array_count_values2.phpt b/tests/std/array/array_count_values2.phpt new file mode 100644 index 00000000..1b7d8442 --- /dev/null +++ b/tests/std/array/array_count_values2.phpt @@ -0,0 +1,43 @@ +--TEST-- +basic array_count_values test +--FILE-- + +--EXPECTF-- +Warning:%S Can only count string and integer values, entry skipped in %s on line %d + +Warning:%S Can only count string and integer values, entry skipped in %s on line %d + +Warning:%S Can only count string and integer values, entry skipped in %s on line %d +array(8) { + [1]=> + int(2) + ["hello"]=> + int(2) + ["world"]=> + int(1) + [""]=> + int(1) + ["rabbit"]=> + int(1) + ["foo"]=> + int(1) + ["Foo"]=> + int(1) + [0]=> + int(1) +} diff --git a/tests/std/array/array_count_values_variation.phpt b/tests/std/array/array_count_values_variation.phpt new file mode 100644 index 00000000..9d895a33 --- /dev/null +++ b/tests/std/array/array_count_values_variation.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test array_count_values() function : Test all normal parameter variations +--FILE-- + "bobv", "val", 6 => "val6", $fp, $ob); + var_dump(@array_count_values($arrays)); + echo "\n"; + echo "Done"; +} +?> +--CLEAN-- + +--EXPECT-- +*** Testing array_count_values() : parameter variations *** +array(3) { + ["bobv"]=> + int(1) + ["val"]=> + int(1) + ["val6"]=> + int(1) +} + +Done diff --git a/tests/std/array/array_diff_1.phpt b/tests/std/array/array_diff_1.phpt new file mode 100644 index 00000000..7b58077e --- /dev/null +++ b/tests/std/array/array_diff_1.phpt @@ -0,0 +1,19 @@ +--TEST-- +Test array_diff when non-array is passed +--FILE-- +getMessage(), "\n"; +} +//-=-=-=-=-=- +echo "OK!"; +?> +--EXPECT-- +array_diff(): Argument #2 must be of type array, int given +OK! diff --git a/tests/std/array/array_diff_assoc.phpt b/tests/std/array/array_diff_assoc.phpt new file mode 100644 index 00000000..ef659f50 --- /dev/null +++ b/tests/std/array/array_diff_assoc.phpt @@ -0,0 +1,46 @@ +--TEST-- +basic array_diff_assoc test +--FILE-- + "green", "b" => "brown", "c" => "blue", "red", ""); +$array2 = array("a" => "green", "yellow", "red", TRUE); +$array3 = array("red", "a"=>"brown", ""); +$result[] = array_diff_assoc($array1, $array2); +$result[] = array_diff_assoc($array1, $array3); +$result[] = array_diff_assoc($array2, $array3); +$result[] = array_diff_assoc($array1, $array2, $array3); +print_r($result); +?> +--EXPECT-- +Array +( + [0] => Array + ( + [b] => brown + [c] => blue + [0] => red + [1] => + ) + + [1] => Array + ( + [a] => green + [b] => brown + [c] => blue + ) + + [2] => Array + ( + [a] => green + [0] => yellow + [1] => red + [2] => 1 + ) + + [3] => Array + ( + [b] => brown + [c] => blue + ) + +) diff --git a/tests/std/array/array_diff_assoc_basic.phpt b/tests/std/array/array_diff_assoc_basic.phpt new file mode 100644 index 00000000..3a9ec872 --- /dev/null +++ b/tests/std/array/array_diff_assoc_basic.phpt @@ -0,0 +1,84 @@ +--TEST-- +Test array_diff_assoc() function : basic functionality +--FILE-- + 'one', 2=> 'two', 3 => 4); +$array_string_key = array('one' => 1, 'two' => '2', '3' => 'three'); + + + +echo "-- Compare Default keys to numeric keys --\n"; +var_dump(array_diff_assoc($array_default_key, $array_numeric_key)); +var_dump(array_diff_assoc($array_numeric_key, $array_default_key)); + + +echo "\n-- Compare Default keys to string keys --\n"; +var_dump(array_diff_assoc($array_default_key, $array_numeric_key)); +var_dump(array_diff_assoc($array_numeric_key, $array_default_key)); + + +echo "\n-- Compare numeric keys to string keys --\n"; +var_dump(array_diff_assoc($array_numeric_key, $array_string_key)); +var_dump(array_diff_assoc($array_string_key, $array_numeric_key)); + + +echo "Done"; +?> +--EXPECT-- +*** Testing array_diff_assoc() : basic functionality *** +-- Compare Default keys to numeric keys -- +array(3) { + [0]=> + string(3) "one" + [1]=> + int(2) + [2]=> + string(5) "three" +} +array(2) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" +} + +-- Compare Default keys to string keys -- +array(3) { + [0]=> + string(3) "one" + [1]=> + int(2) + [2]=> + string(5) "three" +} +array(2) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" +} + +-- Compare numeric keys to string keys -- +array(3) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + int(4) +} +array(3) { + ["one"]=> + int(1) + ["two"]=> + string(1) "2" + [3]=> + string(5) "three" +} +Done diff --git a/tests/std/array/array_diff_assoc_variation1.phpt b/tests/std/array/array_diff_assoc_variation1.phpt new file mode 100644 index 00000000..82618d0f --- /dev/null +++ b/tests/std/array/array_diff_assoc_variation1.phpt @@ -0,0 +1,179 @@ +--TEST-- +Test array_diff_assoc() function : usage variations - unexpected values for 'array1' argument +--SKIPIF-- + + +--FILE-- +getMessage(), "\n"; + } + $iterator++; + } + fclose($fp); + echo "Done"; +} +?> +--EXPECT-- +*** Testing array_diff_assoc() : usage variations *** + +-- Iteration 1 -- +array_diff_assoc(): Argument #1 ($array) must be of type array, int given + +-- Iteration 2 -- +array_diff_assoc(): Argument #1 ($array) must be of type array, int given + +-- Iteration 3 -- +array_diff_assoc(): Argument #1 ($array) must be of type array, int given + +-- Iteration 4 -- +array_diff_assoc(): Argument #1 ($array) must be of type array, int given + +-- Iteration 5 -- +array_diff_assoc(): Argument #1 ($array) must be of type array, float given + +-- Iteration 6 -- +array_diff_assoc(): Argument #1 ($array) must be of type array, float given + +-- Iteration 7 -- +array_diff_assoc(): Argument #1 ($array) must be of type array, float given + +-- Iteration 8 -- +array_diff_assoc(): Argument #1 ($array) must be of type array, float given + +-- Iteration 9 -- +array_diff_assoc(): Argument #1 ($array) must be of type array, float given + +-- Iteration 10 -- +array_diff_assoc(): Argument #1 ($array) must be of type array, null given + +-- Iteration 11 -- +array_diff_assoc(): Argument #1 ($array) must be of type array, null given + +-- Iteration 12 -- +array_diff_assoc(): Argument #1 ($array) must be of type array, true given + +-- Iteration 13 -- +array_diff_assoc(): Argument #1 ($array) must be of type array, false given + +-- Iteration 14 -- +array_diff_assoc(): Argument #1 ($array) must be of type array, true given + +-- Iteration 15 -- +array_diff_assoc(): Argument #1 ($array) must be of type array, false given + +-- Iteration 16 -- +array_diff_assoc(): Argument #1 ($array) must be of type array, string given + +-- Iteration 17 -- +array_diff_assoc(): Argument #1 ($array) must be of type array, string given + +-- Iteration 18 -- +array_diff_assoc(): Argument #1 ($array) must be of type array, string given + +-- Iteration 19 -- +array_diff_assoc(): Argument #1 ($array) must be of type array, string given + +-- Iteration 20 -- +array_diff_assoc(): Argument #1 ($array) must be of type array, string given + +-- Iteration 21 -- +array_diff_assoc(): Argument #1 ($array) must be of type array, string given + +-- Iteration 22 -- +array_diff_assoc(): Argument #1 ($array) must be of type array, string given + +-- Iteration 23 -- +array_diff_assoc(): Argument #1 ($array) must be of type array, classA given + +-- Iteration 24 -- +array_diff_assoc(): Argument #1 ($array) must be of type array, null given + +-- Iteration 25 -- +array_diff_assoc(): Argument #1 ($array) must be of type array, null given + +-- Iteration 26 -- +array_diff_assoc(): Argument #1 ($array) must be of type array, resource given +Done diff --git a/tests/std/array/array_diff_assoc_variation10.phpt b/tests/std/array/array_diff_assoc_variation10.phpt new file mode 100644 index 00000000..edaaec73 --- /dev/null +++ b/tests/std/array/array_diff_assoc_variation10.phpt @@ -0,0 +1,43 @@ +--TEST-- +Test array_diff_assoc() function : usage variations - binary safe check +--FILE-- + "hello", + "str2" => "world"); + +$array2 = array( b"1" => 'hello', + b"world", + "hello", + 'test'); + +var_dump(array_diff_assoc($array1, $array2)); +var_dump(array_diff_assoc($array2, $array1)); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_diff_assoc() : usage variations *** +array(3) { + [0]=> + string(1) "1" + ["str1"]=> + string(5) "hello" + ["str2"]=> + string(5) "world" +} +array(2) { + [3]=> + string(5) "hello" + [4]=> + string(4) "test" +} +Done diff --git a/tests/std/array/array_diff_assoc_variation2.phpt b/tests/std/array/array_diff_assoc_variation2.phpt new file mode 100644 index 00000000..ff1c0ff8 --- /dev/null +++ b/tests/std/array/array_diff_assoc_variation2.phpt @@ -0,0 +1,179 @@ +--TEST-- +Test array_diff_assoc() function : usage variations - unexpected values for 'array1' argument +--SKIPIF-- + + +--FILE-- +getMessage(), "\n"; + } + $iterator++; + } + fclose($fp); + echo "Done"; +} +?> +--EXPECT-- +*** Testing array_diff_assoc() : usage variations *** + +-- Iteration 1 -- +array_diff_assoc(): Argument #2 must be of type array, int given + +-- Iteration 2 -- +array_diff_assoc(): Argument #2 must be of type array, int given + +-- Iteration 3 -- +array_diff_assoc(): Argument #2 must be of type array, int given + +-- Iteration 4 -- +array_diff_assoc(): Argument #2 must be of type array, int given + +-- Iteration 5 -- +array_diff_assoc(): Argument #2 must be of type array, float given + +-- Iteration 6 -- +array_diff_assoc(): Argument #2 must be of type array, float given + +-- Iteration 7 -- +array_diff_assoc(): Argument #2 must be of type array, float given + +-- Iteration 8 -- +array_diff_assoc(): Argument #2 must be of type array, float given + +-- Iteration 9 -- +array_diff_assoc(): Argument #2 must be of type array, float given + +-- Iteration 10 -- +array_diff_assoc(): Argument #2 must be of type array, null given + +-- Iteration 11 -- +array_diff_assoc(): Argument #2 must be of type array, null given + +-- Iteration 12 -- +array_diff_assoc(): Argument #2 must be of type array, true given + +-- Iteration 13 -- +array_diff_assoc(): Argument #2 must be of type array, false given + +-- Iteration 14 -- +array_diff_assoc(): Argument #2 must be of type array, true given + +-- Iteration 15 -- +array_diff_assoc(): Argument #2 must be of type array, false given + +-- Iteration 16 -- +array_diff_assoc(): Argument #2 must be of type array, string given + +-- Iteration 17 -- +array_diff_assoc(): Argument #2 must be of type array, string given + +-- Iteration 18 -- +array_diff_assoc(): Argument #2 must be of type array, string given + +-- Iteration 19 -- +array_diff_assoc(): Argument #2 must be of type array, string given + +-- Iteration 20 -- +array_diff_assoc(): Argument #2 must be of type array, string given + +-- Iteration 21 -- +array_diff_assoc(): Argument #2 must be of type array, string given + +-- Iteration 22 -- +array_diff_assoc(): Argument #2 must be of type array, string given + +-- Iteration 23 -- +array_diff_assoc(): Argument #2 must be of type array, classA given + +-- Iteration 24 -- +array_diff_assoc(): Argument #2 must be of type array, null given + +-- Iteration 25 -- +array_diff_assoc(): Argument #2 must be of type array, null given + +-- Iteration 26 -- +array_diff_assoc(): Argument #2 must be of type array, resource given +Done diff --git a/tests/std/array/array_diff_assoc_variation3.phpt b/tests/std/array/array_diff_assoc_variation3.phpt new file mode 100644 index 00000000..3826a907 --- /dev/null +++ b/tests/std/array/array_diff_assoc_variation3.phpt @@ -0,0 +1,165 @@ +--TEST-- +Test array_diff_assoc() function : variation - array containing different data types +--SKIPIF-- + + +--FILE-- + array(0, 1, 12345, -2345), + // float data + /*2*/ + 'float' => array(10.5, -10.5, 123456789000.0, 1.23456789E-9, 0.5), + // null data + /*3*/ + 'null' => array(NULL, null), + // boolean data + /*4*/ + 'bool' => array(true, false, TRUE, FALSE), + // empty data + /*5*/ + 'empty' => array("", ''), + // string data + /*6*/ + 'string' => array("string", 'string', $heredoc), + // binary data + /*7*/ + 'binary' => array("binary", (string) "binary"), + // object data + /*8*/ + 'object' => array(new classA()), + // undefined data + /*9*/ + 'undefined' => array(@$undefined_var), + // unset data + /*10*/ + 'unset' => array(@$unset_var), + ); + // loop through each element of $inputs to check the behavior of array_diff_assoc + $iterator = 1; + foreach ($inputs as $key => $input) { + echo "\n-- Iteration {$iterator} --\n"; + var_dump(array_diff_assoc($input, $array)); + $iterator++; + } + echo "Done"; +} +?> +--EXPECTF-- +*** Testing array_diff_assoc() : usage variations *** + +-- Iteration 1 -- +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(12345) + [3]=> + int(-2345) +} + +-- Iteration 2 -- +array(5) { + [0]=> + float(10.5) + [1]=> + float(-10.5) + [2]=> + float(123456789000) + [3]=> + float(1.23456789E-9) + [4]=> + float(0.5) +} + +-- Iteration 3 -- +array(2) { + [0]=> + NULL + [1]=> + NULL +} + +-- Iteration 4 -- +array(3) { + [1]=> + bool(false) + [2]=> + bool(true) + [3]=> + bool(false) +} + +-- Iteration 5 -- +array(2) { + [0]=> + string(0) "" + [1]=> + string(0) "" +} + +-- Iteration 6 -- +array(3) { + [0]=> + string(6) "string" + [1]=> + string(6) "string" + [2]=> + string(11) "hello world" +} + +-- Iteration 7 -- +array(2) { + [0]=> + string(6) "binary" + [1]=> + string(6) "binary" +} + +-- Iteration 8 -- +array(1) { + [0]=> + object(classA)#%d (0) { + } +} + +-- Iteration 9 -- +array(1) { + [0]=> + NULL +} + +-- Iteration 10 -- +array(1) { + [0]=> + NULL +} +Done diff --git a/tests/std/array/array_diff_assoc_variation4.phpt b/tests/std/array/array_diff_assoc_variation4.phpt new file mode 100644 index 00000000..f18143fe --- /dev/null +++ b/tests/std/array/array_diff_assoc_variation4.phpt @@ -0,0 +1,156 @@ +--TEST-- +Test array_diff_assoc() function : usage variations - arrays with different data types as keys +--SKIPIF-- + + +--FILE-- + array( + 0 => 'zero', + 1 => 'one', + 12345 => 'positive', + -2345 => 'negative'), + + // null data +/*3*/ +'null' => array( + NULL => 'null 1', + null => 'null 2'), + + // boolean data +/*4*/ +'bool' => array( + true => 'boolt', + false => 'boolf', + TRUE => 'boolT', + FALSE => 'boolF'), + + // empty data +/*5*/ +'empty' => array( + "" => 'emptyd', + '' => 'emptys'), + + // string data +/*6*/ +'string' => array( + "string" => 'stringd', + 'string' => 'strings', + $heredoc => 'stringh'), + + // binary data +/*7*/ +'binary' => array( + b"binary1" => 'binary 1', + (binary)"binary2" => 'binary 2'), + + // undefined data +/*8*/ +'undefined' => array( + @$undefined_var => 'undefined'), + + // unset data +/*9*/ +'unset' => array( + @$unset_var => 'unset'), + +); + +// loop through each element of $inputs to check the behavior of array_diff_assoc +$iterator = 1; +foreach($inputs as $key => $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( array_diff_assoc($input, $array)); + $iterator++; +}; + +echo "Done"; +?> +--EXPECT-- +*** Testing array_diff_assoc() : usage variations *** + +-- Iteration 1 -- +array(4) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [12345]=> + string(8) "positive" + [-2345]=> + string(8) "negative" +} + +-- Iteration 2 -- +array(1) { + [""]=> + string(6) "null 2" +} + +-- Iteration 3 -- +array(2) { + [1]=> + string(5) "boolT" + [0]=> + string(5) "boolF" +} + +-- Iteration 4 -- +array(1) { + [""]=> + string(6) "emptys" +} + +-- Iteration 5 -- +array(2) { + ["string"]=> + string(7) "strings" + ["hello world"]=> + string(7) "stringh" +} + +-- Iteration 6 -- +array(2) { + ["binary1"]=> + string(8) "binary 1" + ["binary2"]=> + string(8) "binary 2" +} + +-- Iteration 7 -- +array(1) { + [""]=> + string(9) "undefined" +} + +-- Iteration 8 -- +array(1) { + [""]=> + string(5) "unset" +} +Done diff --git a/tests/std/array/array_diff_assoc_variation5.phpt b/tests/std/array/array_diff_assoc_variation5.phpt new file mode 100644 index 00000000..09af9cb4 --- /dev/null +++ b/tests/std/array/array_diff_assoc_variation5.phpt @@ -0,0 +1,141 @@ +--TEST-- +Test array_diff_assoc() function : usage variations - compare integers, floats and strings +--FILE-- + 1.00, 1 => 2.00, 2 => 3.00, 'b'); +$arr_string = array('1', '2', '3', 'c'); +$arr_string_float = array('0' => '1.00', '1.00' => '2.00', '2.00' => '3.00', 'd'); + +echo "-- Result of comparing integers and floating point numbers: --\n"; +var_dump(array_diff_assoc($arr_default_int, $arr_float)); +var_dump(array_diff_assoc($arr_float, $arr_default_int)); + +echo "-- Result of comparing integers and strings containing an integers : --\n"; +var_dump(array_diff_assoc($arr_default_int, $arr_string)); +var_dump(array_diff_assoc($arr_string, $arr_default_int)); + +echo "-- Result of comparing integers and strings containing floating points : --\n"; +var_dump(array_diff_assoc($arr_default_int, $arr_string_float)); +var_dump(array_diff_assoc($arr_string_float, $arr_default_int)); + +echo "-- Result of comparing floating points and strings containing integers : --\n"; +var_dump(array_diff_assoc($arr_float, $arr_string)); +var_dump(array_diff_assoc($arr_string, $arr_float)); + +echo "-- Result of comparing floating points and strings containing floating point: --\n"; +var_dump(array_diff_assoc($arr_float, $arr_string_float)); +var_dump(array_diff_assoc($arr_string_float, $arr_float)); + +echo "-- Result of comparing strings containing integers and strings containing floating points : --\n"; +var_dump(array_diff_assoc($arr_string, $arr_string_float)); +var_dump(array_diff_assoc($arr_string_float, $arr_string)); + +echo "-- Result of comparing more than two arrays: --\n"; +var_dump(array_diff_assoc($arr_default_int, $arr_float, $arr_string, $arr_string_float)); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_diff_assoc() : usage variations *** +-- Result of comparing integers and floating point numbers: -- +array(1) { + [3]=> + string(1) "a" +} +array(1) { + [3]=> + string(1) "b" +} +-- Result of comparing integers and strings containing an integers : -- +array(1) { + [3]=> + string(1) "a" +} +array(1) { + [3]=> + string(1) "c" +} +-- Result of comparing integers and strings containing floating points : -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + string(1) "a" +} +array(4) { + [0]=> + string(4) "1.00" + ["1.00"]=> + string(4) "2.00" + ["2.00"]=> + string(4) "3.00" + [1]=> + string(1) "d" +} +-- Result of comparing floating points and strings containing integers : -- +array(1) { + [3]=> + string(1) "b" +} +array(1) { + [3]=> + string(1) "c" +} +-- Result of comparing floating points and strings containing floating point: -- +array(4) { + [0]=> + float(1) + [1]=> + float(2) + [2]=> + float(3) + [3]=> + string(1) "b" +} +array(4) { + [0]=> + string(4) "1.00" + ["1.00"]=> + string(4) "2.00" + ["2.00"]=> + string(4) "3.00" + [1]=> + string(1) "d" +} +-- Result of comparing strings containing integers and strings containing floating points : -- +array(4) { + [0]=> + string(1) "1" + [1]=> + string(1) "2" + [2]=> + string(1) "3" + [3]=> + string(1) "c" +} +array(4) { + [0]=> + string(4) "1.00" + ["1.00"]=> + string(4) "2.00" + ["2.00"]=> + string(4) "3.00" + [1]=> + string(1) "d" +} +-- Result of comparing more than two arrays: -- +array(1) { + [3]=> + string(1) "a" +} +Done diff --git a/tests/std/array/array_diff_assoc_variation6.phpt b/tests/std/array/array_diff_assoc_variation6.phpt new file mode 100644 index 00000000..bee55152 --- /dev/null +++ b/tests/std/array/array_diff_assoc_variation6.phpt @@ -0,0 +1,192 @@ +--TEST-- +Test array_diff_assoc() function : usage variations - strict string comparison check +--SKIPIF-- + +--FILE-- + 1, + 'two' => 2.00000000000001); + +$inputs = array ( + +//default keys => string values +/*1*/ array('2.00000000000001', '1', 'zero', 'a'), + +//numeric keys => string values +/*2*/ array(2 => '2.00000000000001', + 1 => '1', + 0 => 'zero', + 3 => 'a'), + +//string keys => string values +/*3*/ array('2' => '2.00000000000001', + '1' => '1', + '0' => 'zero', + '3' => 'a') , + +//default keys => numeric values +/*4*/ array(2, 1, 0), + +//numeric keys => numeric values +/*5*/ array(2 => 2, + 1 => 1, + 0 => 0), + +//string keys => numeric values +/*6*/ array('two' => 2, + '1' => 1, + '0' => 0), + +//default keys => float values +/*7*/ array(2.00000000000001, 1.00, 0.01E-9), + +//numeric keys => float values +/*8*/ array(2 => 2.00000000000001, + 1 => 1.00, + 0 => 0.01E-9), + +//string keys => float values +/*9*/ array ('two' => 2.00000000000001, + '1' => 1.00, + '0' =>0.01E-9) +); + +// loop through each element of $inputs to check the behavior of array_diff_assoc +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump(array_diff_assoc($array, $input)); + var_dump(array_diff_assoc($input, $array)); + $iterator++; +}; +echo "Done"; +?> +--EXPECT-- +*** Testing array_diff_assoc() : usage variations *** + +-- Iteration 1 -- +array(2) { + [0]=> + string(4) "zero" + ["two"]=> + float(2.00000000000001) +} +array(3) { + [0]=> + string(16) "2.00000000000001" + [2]=> + string(4) "zero" + [3]=> + string(1) "a" +} + +-- Iteration 2 -- +array(1) { + ["two"]=> + float(2.00000000000001) +} +array(2) { + [2]=> + string(16) "2.00000000000001" + [3]=> + string(1) "a" +} + +-- Iteration 3 -- +array(1) { + ["two"]=> + float(2.00000000000001) +} +array(2) { + [2]=> + string(16) "2.00000000000001" + [3]=> + string(1) "a" +} + +-- Iteration 4 -- +array(2) { + [0]=> + string(4) "zero" + ["two"]=> + float(2.00000000000001) +} +array(2) { + [0]=> + int(2) + [2]=> + int(0) +} + +-- Iteration 5 -- +array(2) { + [0]=> + string(4) "zero" + ["two"]=> + float(2.00000000000001) +} +array(2) { + [2]=> + int(2) + [0]=> + int(0) +} + +-- Iteration 6 -- +array(1) { + [0]=> + string(4) "zero" +} +array(1) { + [0]=> + int(0) +} + +-- Iteration 7 -- +array(2) { + [0]=> + string(4) "zero" + ["two"]=> + float(2.00000000000001) +} +array(2) { + [0]=> + float(2.00000000000001) + [2]=> + float(1.0E-11) +} + +-- Iteration 8 -- +array(2) { + [0]=> + string(4) "zero" + ["two"]=> + float(2.00000000000001) +} +array(2) { + [2]=> + float(2.00000000000001) + [0]=> + float(1.0E-11) +} + +-- Iteration 9 -- +array(1) { + [0]=> + string(4) "zero" +} +array(1) { + [0]=> + float(1.0E-11) +} +Done diff --git a/tests/std/array/array_diff_assoc_variation7.phpt b/tests/std/array/array_diff_assoc_variation7.phpt new file mode 100644 index 00000000..ee791247 --- /dev/null +++ b/tests/std/array/array_diff_assoc_variation7.phpt @@ -0,0 +1,97 @@ +--TEST-- +Test array_diff_assoc() function : usage variations - arrays containing referenced variables +--SKIPIF-- + + +--FILE-- + 1, 'b' => 2, 'c' => 3, &$a); + +echo "-- Results when \$a = $a: --\n"; +var_dump(array_diff_assoc($arr1, $arr2)); +var_dump(array_diff_assoc($arr2, $arr1)); + +$a = 4; + +echo "-- Results when \$a has been changed to $a: --\n"; +var_dump(array_diff_assoc($arr1, $arr2)); +var_dump(array_diff_assoc($arr2, $arr1)); + +$arr2 = &$arr1; + +echo "-- Results when \$arr2 is referenced to \$arr1 --\n"; +var_dump(array_diff_assoc($arr1, $arr2)); +var_dump(array_diff_assoc($arr2, $arr1)); + +$arr1 = array('zero' => 'x', 'one' => 'y', 'two' => 'z'); + +echo "-- Results when \$arr1 is changed --\n"; +var_dump(array_diff_assoc($arr1, $arr2)); +var_dump(array_diff_assoc($arr2, $arr1)); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_diff_assoc() : usage variations *** +-- Results when $a = a: -- +array(3) { + [1]=> + string(1) "b" + [2]=> + string(1) "c" + [3]=> + string(1) "a" +} +array(3) { + ["a"]=> + int(1) + ["b"]=> + int(2) + ["c"]=> + int(3) +} +-- Results when $a has been changed to 4: -- +array(4) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + [3]=> + string(1) "a" +} +array(4) { + ["a"]=> + int(1) + ["b"]=> + int(2) + ["c"]=> + int(3) + [0]=> + &int(4) +} +-- Results when $arr2 is referenced to $arr1 -- +array(0) { +} +array(0) { +} +-- Results when $arr1 is changed -- +array(0) { +} +array(0) { +} +Done diff --git a/tests/std/array/array_diff_assoc_variation8.phpt b/tests/std/array/array_diff_assoc_variation8.phpt new file mode 100644 index 00000000..0ca368f9 --- /dev/null +++ b/tests/std/array/array_diff_assoc_variation8.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test array_diff_assoc() function : usage variations - array containing duplicate keys and values +--FILE-- + 'd', 'b'); //duplicate key (0), duplicate value (b) +$array_assoc = array ('2' => 'c', //same key=>value pair, different order + '1' => 'b', + '0' => 'a', + 'b' => '3', //key and value from array_index swapped + 'c' => 2); //same as above, using integer + +var_dump(array_diff_assoc($array_index, $array_assoc)); +var_dump(array_diff_assoc($array_assoc, $array_index)); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_diff_assoc() : variation *** +array(2) { + [0]=> + string(1) "d" + [3]=> + string(1) "b" +} +array(3) { + [0]=> + string(1) "a" + ["b"]=> + string(1) "3" + ["c"]=> + int(2) +} +Done diff --git a/tests/std/array/array_diff_assoc_variation9.phpt b/tests/std/array/array_diff_assoc_variation9.phpt new file mode 100644 index 00000000..e6d8ce06 --- /dev/null +++ b/tests/std/array/array_diff_assoc_variation9.phpt @@ -0,0 +1,134 @@ +--TEST-- +Test array_diff_assoc() function : usage variations - compare multidimensional arrays +--FILE-- + array (1, 2, 3), + 'sub_array2' => array ('a', 'b', 'c')); +$array2 = array('sub_arraya' => array (1, 3, 5), + 'sub_arrayb' => array ('a', 'z', 'y')); + +echo "-- Compare two 2-D arrays --\n"; +var_dump(array_diff_assoc($array1, $array2)); +var_dump(array_diff_assoc($array2, $array1)); + +echo "\n-- Compare subarrays from two 2-D arrays --\n"; +var_dump(array_diff_assoc($array1['sub_array1'], $array2['sub_arraya'])); +var_dump(array_diff_assoc($array2['sub_arraya'], $array1['sub_array1'])); +var_dump(array_diff_assoc($array1['sub_array2'], $array2['sub_arrayb'])); +var_dump(array_diff_assoc($array2['sub_arrayb'], $array1['sub_array1'])); + +echo "\n-- Compare a subarray from one 2-D array and one 2-D array --\n"; +var_dump(array_diff_assoc($array1['sub_array1'], $array2)); +var_dump(array_diff_assoc($array1, $array2['sub_arraya'])); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_diff_assoc() : usage variations *** +-- Compare two 2-D arrays -- +array(2) { + ["sub_array1"]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["sub_array2"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +array(2) { + ["sub_arraya"]=> + array(3) { + [0]=> + int(1) + [1]=> + int(3) + [2]=> + int(5) + } + ["sub_arrayb"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "z" + [2]=> + string(1) "y" + } +} + +-- Compare subarrays from two 2-D arrays -- +array(2) { + [1]=> + int(2) + [2]=> + int(3) +} +array(2) { + [1]=> + int(3) + [2]=> + int(5) +} +array(2) { + [1]=> + string(1) "b" + [2]=> + string(1) "c" +} +array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "z" + [2]=> + string(1) "y" +} + +-- Compare a subarray from one 2-D array and one 2-D array -- +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +array(2) { + ["sub_array1"]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["sub_array2"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +Done diff --git a/tests/std/array/array_diff_basic.phpt b/tests/std/array/array_diff_basic.phpt new file mode 100644 index 00000000..aa9f1cbf --- /dev/null +++ b/tests/std/array/array_diff_basic.phpt @@ -0,0 +1,110 @@ +--TEST-- +Test array_diff() function : basic functionality +--FILE-- + 1, 'two' => 2, 'three' => 3, 'four' => 4); +$array_assoc_int2 = array ('three' => 3, 'four' => 4, 'five' => 5, 'six' => 6); + +echo "-- Test associative array with strings as keys and integers as elements --\n"; +var_dump(array_diff($array_assoc_int1, $array_assoc_int2)); +var_dump(array_diff($array_assoc_int2, $array_assoc_int1)); + +//Test associative array with strings as keys and elements +$array_assoc_str1 = array ('one' => 'un', 'two' => 'deux', 'three' => 'trois', 'four' => 'quatre'); +$array_assoc_str2 = array ('three' => 'trois', 'four' => 'quatre', 'five' => 'cinq', 'six' => 'six'); + +echo "-- Test associative array with strings as keys and integers as elements --\n"; +var_dump(array_diff($array_assoc_str1, $array_assoc_str2)); +var_dump(array_diff($array_assoc_str2, $array_assoc_str1)); + +echo "-- Test array_diff with more than 2 arguments --\n"; +var_dump(array_diff($array_int1, $array_int2, $array_string1, $array_string2)); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_diff() : basic functionality *** +-- Test indexed array with integers as elements -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +array(2) { + [2]=> + int(5) + [3]=> + int(6) +} +-- Test indexed array with strings as elements -- +array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" +} +array(2) { + [2]=> + string(4) "five" + [3]=> + string(3) "six" +} +-- Test associative array with strings as keys and integers as elements -- +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(2) { + ["five"]=> + int(5) + ["six"]=> + int(6) +} +-- Test associative array with strings as keys and integers as elements -- +array(2) { + ["one"]=> + string(2) "un" + ["two"]=> + string(4) "deux" +} +array(2) { + ["five"]=> + string(4) "cinq" + ["six"]=> + string(3) "six" +} +-- Test array_diff with more than 2 arguments -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +Done diff --git a/tests/std/array/array_diff_key.phpt b/tests/std/array/array_diff_key.phpt new file mode 100644 index 00000000..bb3db1a1 --- /dev/null +++ b/tests/std/array/array_diff_key.phpt @@ -0,0 +1,286 @@ +--TEST-- +Test of the array_diff_key() and array_diff_ukey() +--FILE-- + $b ? 1 : -1; +} +function main() +{ + $a = array(1, 6, 2, -20, 15, 1200, -2500); + $b = array(0, 7, 2, -20, 11, 1100, -2500); + $c = array(0, 6, 2, -20, 19, 1000, -2500); + $d = array(3, 8, -2, -20, 14, 900, -2600); + $a_f = array_flip($a); + $b_f = array_flip($b); + $c_f = array_flip($c); + $d_f = array_flip($d); + $i = 1; + /* give nicer values */ + foreach ($a_f as $k => &$a_f_el) { + $a_f_el = $k * 2; + } + foreach ($b_f as $k => &$b_f_el) { + $b_f_el = $k * 2; + } + foreach ($c_f as $k => &$c_f_el) { + $c_f_el = $k * 2; + } + foreach ($d_f as $k => &$d_f_el) { + $d_f_el = $k * 2; + } + echo "------ Test {$i} --------\n"; + $i++; + // 1 + var_dump(array_diff_key($a_f, $b_f)); + // keys -> 1, 6, 15, 1200 + var_dump(array_diff_ukey($a_f, $b_f, "comp_func")); + // 1, 6, 15, 1200 + echo "------ Test {$i} --------\n"; + $i++; + // 2 + var_dump(array_diff_key($a_f, $c_f)); + // keys -> 1, 15, 1200 + var_dump(array_diff_ukey($a_f, $c_f, "comp_func")); + // 1, 15, 1200 + echo "------ Test {$i} --------\n"; + $i++; + // 3 + var_dump(array_diff_key($a_f, $d_f)); + // 1, 6, 2, 15, 1200, -2500 + var_dump(array_diff_ukey($a_f, $d_f, "comp_func")); + // 1, 6, 2, 15, 1200, -2500 + echo "------ Test {$i} --------\n"; + $i++; + // 4 + var_dump(array_diff_key($a_f, $b_f, $c_f)); + // 1, 15, 1200 + var_dump(array_diff_ukey($a_f, $b_f, $c_f, "comp_func")); + // 1, 15, 1200 + echo "------ Test {$i} --------\n"; + $i++; + // 5 + var_dump(array_diff_key($a_f, $b_f, $d_f)); + // 1, 6, 15, 1200 + var_dump(array_diff_ukey($a_f, $b_f, $d_f, "comp_func")); + // 1, 6, 15, 1200 + echo "------ Test {$i} --------\n"; + $i++; + // 6 + var_dump(array_diff_key($a_f, $b_f, $c_f, $d_f)); + // 1, 15, 1200 + var_dump(array_diff_ukey($a_f, $b_f, $c_f, $d_f, "comp_func")); + //1, 15, 1200 + echo "------ Test {$i} --------\n"; + $i++; + // 7 + var_dump(array_diff_key($b_f, $c_f)); + // 7, 11, 1100 + var_dump(array_diff_ukey($b_f, $c_f, "comp_func")); + //7, 11, 1100 + echo "------ Test {$i} --------\n"; + $i++; + // 8 + var_dump(array_diff_key($b_f, $d_f)); + //0, 7, 2, 11, 1100, -2500 + var_dump(array_diff_ukey($b_f, $d_f, "comp_func")); + //0, 7, 2, 11, 1100, -2500 + echo "------ Test {$i} --------\n"; + $i++; + // 9 + var_dump(array_diff_key($b_f, $c_f, $d_f)); + // 7, 11, 1100 + var_dump(array_diff_ukey($b_f, $c_f, $d_f, "comp_func")); +} +?> +--EXPECT-- +------ Test 1 -------- +array(4) { + [1]=> + int(2) + [6]=> + int(12) + [15]=> + int(30) + [1200]=> + int(2400) +} +array(4) { + [1]=> + int(2) + [6]=> + int(12) + [15]=> + int(30) + [1200]=> + int(2400) +} +------ Test 2 -------- +array(3) { + [1]=> + int(2) + [15]=> + int(30) + [1200]=> + int(2400) +} +array(3) { + [1]=> + int(2) + [15]=> + int(30) + [1200]=> + int(2400) +} +------ Test 3 -------- +array(6) { + [1]=> + int(2) + [6]=> + int(12) + [2]=> + int(4) + [15]=> + int(30) + [1200]=> + int(2400) + [-2500]=> + &int(-5000) +} +array(6) { + [1]=> + int(2) + [6]=> + int(12) + [2]=> + int(4) + [15]=> + int(30) + [1200]=> + int(2400) + [-2500]=> + &int(-5000) +} +------ Test 4 -------- +array(3) { + [1]=> + int(2) + [15]=> + int(30) + [1200]=> + int(2400) +} +array(3) { + [1]=> + int(2) + [15]=> + int(30) + [1200]=> + int(2400) +} +------ Test 5 -------- +array(4) { + [1]=> + int(2) + [6]=> + int(12) + [15]=> + int(30) + [1200]=> + int(2400) +} +array(4) { + [1]=> + int(2) + [6]=> + int(12) + [15]=> + int(30) + [1200]=> + int(2400) +} +------ Test 6 -------- +array(3) { + [1]=> + int(2) + [15]=> + int(30) + [1200]=> + int(2400) +} +array(3) { + [1]=> + int(2) + [15]=> + int(30) + [1200]=> + int(2400) +} +------ Test 7 -------- +array(3) { + [7]=> + int(14) + [11]=> + int(22) + [1100]=> + int(2200) +} +array(3) { + [7]=> + int(14) + [11]=> + int(22) + [1100]=> + int(2200) +} +------ Test 8 -------- +array(6) { + [0]=> + int(0) + [7]=> + int(14) + [2]=> + int(4) + [11]=> + int(22) + [1100]=> + int(2200) + [-2500]=> + &int(-5000) +} +array(6) { + [0]=> + int(0) + [7]=> + int(14) + [2]=> + int(4) + [11]=> + int(22) + [1100]=> + int(2200) + [-2500]=> + &int(-5000) +} +------ Test 9 -------- +array(3) { + [7]=> + int(14) + [11]=> + int(22) + [1100]=> + int(2200) +} +array(3) { + [7]=> + int(14) + [11]=> + int(22) + [1100]=> + int(2200) +} diff --git a/tests/std/array/array_diff_key2.phpt b/tests/std/array/array_diff_key2.phpt new file mode 100644 index 00000000..b7ef7f31 --- /dev/null +++ b/tests/std/array/array_diff_key2.phpt @@ -0,0 +1,44 @@ +--TEST-- +basic array_diff_key test +--FILE-- + "green", "b" => "brown", "c" => "blue", "red", ""); +$array2 = array("a" => "green", "yellow", "red", TRUE); +$array3 = array("red", "a"=>"brown", ""); +$result[] = array_diff_key($array1, $array2); +$result[] = array_diff_key($array1, $array3); +$result[] = array_diff_key($array2, $array3); +$result[] = array_diff_key($array1, $array2, $array3); + +var_dump($result); + +?> +--EXPECT-- +array(4) { + [0]=> + array(2) { + ["b"]=> + string(5) "brown" + ["c"]=> + string(4) "blue" + } + [1]=> + array(2) { + ["b"]=> + string(5) "brown" + ["c"]=> + string(4) "blue" + } + [2]=> + array(1) { + [2]=> + bool(true) + } + [3]=> + array(2) { + ["b"]=> + string(5) "brown" + ["c"]=> + string(4) "blue" + } +} diff --git a/tests/std/array/array_diff_key_basic.phpt b/tests/std/array/array_diff_key_basic.phpt new file mode 100644 index 00000000..1ce70c6a --- /dev/null +++ b/tests/std/array/array_diff_key_basic.phpt @@ -0,0 +1,18 @@ +--TEST-- +Test array_diff_key() : basic functionality +--FILE-- + 1, 'red' => 2, 'green' => 3, 'purple' => 4); +$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); +var_dump(array_diff_key($array1, $array2)); +?> +--EXPECT-- +array(2) { + ["red"]=> + int(2) + ["purple"]=> + int(4) +} diff --git a/tests/std/array/array_diff_key_variation1.phpt b/tests/std/array/array_diff_key_variation1.phpt new file mode 100644 index 00000000..b9d38dde --- /dev/null +++ b/tests/std/array/array_diff_key_variation1.phpt @@ -0,0 +1,196 @@ +--TEST-- +Test array_diff_key() function : usage variation - Passing unexpected values to first argument +--SKIPIF-- + + +--FILE-- + 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); + $array3 = array(1, 2, 3, 4, 5); + //get an unset variable + $unset_var = 10; + unset($unset_var); + //resource variable + $fp = fopen(__FILE__, "r"); + // heredoc string + $heredoc = << 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -12345, + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 123456789000.0, + 'float -12.3456789000e10' => -123456789000.0, + 'float .5' => 0.5, + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + // boolean data + 'lowercase true' => true, + 'lowercase false' => false, + 'uppercase TRUE' => TRUE, + 'uppercase FALSE' => FALSE, + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + // undefined data + 'undefined var' => @$undefined_var, + // unset data + 'unset var' => @$unset_var, + // resource data + 'resource' => $fp, + ); + // loop through each element of the array for array1 + foreach ($inputs as $key => $value) { + echo "\n--{$key}--\n"; + try { + var_dump(array_diff_key($value, $array2)); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + try { + var_dump(array_diff_key($value, $array2, $array3)); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + } + fclose($fp); +} +?> +--EXPECT-- +*** Testing array_diff_key() : usage variation *** + +--int 0-- +array_diff_key(): Argument #1 ($array) must be of type array, int given +array_diff_key(): Argument #1 ($array) must be of type array, int given + +--int 1-- +array_diff_key(): Argument #1 ($array) must be of type array, int given +array_diff_key(): Argument #1 ($array) must be of type array, int given + +--int 12345-- +array_diff_key(): Argument #1 ($array) must be of type array, int given +array_diff_key(): Argument #1 ($array) must be of type array, int given + +--int -12345-- +array_diff_key(): Argument #1 ($array) must be of type array, int given +array_diff_key(): Argument #1 ($array) must be of type array, int given + +--float 10.5-- +array_diff_key(): Argument #1 ($array) must be of type array, float given +array_diff_key(): Argument #1 ($array) must be of type array, float given + +--float -10.5-- +array_diff_key(): Argument #1 ($array) must be of type array, float given +array_diff_key(): Argument #1 ($array) must be of type array, float given + +--float 12.3456789000e10-- +array_diff_key(): Argument #1 ($array) must be of type array, float given +array_diff_key(): Argument #1 ($array) must be of type array, float given + +--float -12.3456789000e10-- +array_diff_key(): Argument #1 ($array) must be of type array, float given +array_diff_key(): Argument #1 ($array) must be of type array, float given + +--float .5-- +array_diff_key(): Argument #1 ($array) must be of type array, float given +array_diff_key(): Argument #1 ($array) must be of type array, float given + +--uppercase NULL-- +array_diff_key(): Argument #1 ($array) must be of type array, null given +array_diff_key(): Argument #1 ($array) must be of type array, null given + +--lowercase null-- +array_diff_key(): Argument #1 ($array) must be of type array, null given +array_diff_key(): Argument #1 ($array) must be of type array, null given + +--lowercase true-- +array_diff_key(): Argument #1 ($array) must be of type array, true given +array_diff_key(): Argument #1 ($array) must be of type array, true given + +--lowercase false-- +array_diff_key(): Argument #1 ($array) must be of type array, false given +array_diff_key(): Argument #1 ($array) must be of type array, false given + +--uppercase TRUE-- +array_diff_key(): Argument #1 ($array) must be of type array, true given +array_diff_key(): Argument #1 ($array) must be of type array, true given + +--uppercase FALSE-- +array_diff_key(): Argument #1 ($array) must be of type array, false given +array_diff_key(): Argument #1 ($array) must be of type array, false given + +--empty string DQ-- +array_diff_key(): Argument #1 ($array) must be of type array, string given +array_diff_key(): Argument #1 ($array) must be of type array, string given + +--empty string SQ-- +array_diff_key(): Argument #1 ($array) must be of type array, string given +array_diff_key(): Argument #1 ($array) must be of type array, string given + +--string DQ-- +array_diff_key(): Argument #1 ($array) must be of type array, string given +array_diff_key(): Argument #1 ($array) must be of type array, string given + +--string SQ-- +array_diff_key(): Argument #1 ($array) must be of type array, string given +array_diff_key(): Argument #1 ($array) must be of type array, string given + +--mixed case string-- +array_diff_key(): Argument #1 ($array) must be of type array, string given +array_diff_key(): Argument #1 ($array) must be of type array, string given + +--heredoc-- +array_diff_key(): Argument #1 ($array) must be of type array, string given +array_diff_key(): Argument #1 ($array) must be of type array, string given + +--instance of classWithToString-- +array_diff_key(): Argument #1 ($array) must be of type array, classWithToString given +array_diff_key(): Argument #1 ($array) must be of type array, classWithToString given + +--instance of classWithoutToString-- +array_diff_key(): Argument #1 ($array) must be of type array, classWithoutToString given +array_diff_key(): Argument #1 ($array) must be of type array, classWithoutToString given + +--undefined var-- +array_diff_key(): Argument #1 ($array) must be of type array, null given +array_diff_key(): Argument #1 ($array) must be of type array, null given + +--unset var-- +array_diff_key(): Argument #1 ($array) must be of type array, null given +array_diff_key(): Argument #1 ($array) must be of type array, null given + +--resource-- +array_diff_key(): Argument #1 ($array) must be of type array, resource given +array_diff_key(): Argument #1 ($array) must be of type array, resource given diff --git a/tests/std/array/array_diff_key_variation2.phpt b/tests/std/array/array_diff_key_variation2.phpt new file mode 100644 index 00000000..f18661a4 --- /dev/null +++ b/tests/std/array/array_diff_key_variation2.phpt @@ -0,0 +1,196 @@ +--TEST-- +Test array_diff_key() function : usage variation - Passing unexpected values to second argument +--SKIPIF-- + + +--FILE-- + 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); + $array3 = array(1, 2, 3, 4, 5); + //get an unset variable + $unset_var = 10; + unset($unset_var); + //resource variable + $fp = fopen(__FILE__, "r"); + // heredoc string + $heredoc = << 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -12345, + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 123456789000.0, + 'float -12.3456789000e10' => -123456789000.0, + 'float .5' => 0.5, + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + // boolean data + 'lowercase true' => true, + 'lowercase false' => false, + 'uppercase TRUE' => TRUE, + 'uppercase FALSE' => FALSE, + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + // undefined data + 'undefined var' => @$undefined_var, + // unset data + 'unset var' => @$unset_var, + // resource data + 'resource' => $fp, + ); + // loop through each element of the array for array1 + foreach ($inputs as $key => $value) { + echo "\n--{$key}--\n"; + try { + var_dump(array_diff_key($array1, $value)); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + try { + var_dump(array_diff_key($array1, $value, $array3)); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + } + fclose($fp); +} +?> +--EXPECT-- +*** Testing array_diff_key() : usage variation *** + +--int 0-- +array_diff_key(): Argument #2 must be of type array, int given +array_diff_key(): Argument #2 must be of type array, int given + +--int 1-- +array_diff_key(): Argument #2 must be of type array, int given +array_diff_key(): Argument #2 must be of type array, int given + +--int 12345-- +array_diff_key(): Argument #2 must be of type array, int given +array_diff_key(): Argument #2 must be of type array, int given + +--int -12345-- +array_diff_key(): Argument #2 must be of type array, int given +array_diff_key(): Argument #2 must be of type array, int given + +--float 10.5-- +array_diff_key(): Argument #2 must be of type array, float given +array_diff_key(): Argument #2 must be of type array, float given + +--float -10.5-- +array_diff_key(): Argument #2 must be of type array, float given +array_diff_key(): Argument #2 must be of type array, float given + +--float 12.3456789000e10-- +array_diff_key(): Argument #2 must be of type array, float given +array_diff_key(): Argument #2 must be of type array, float given + +--float -12.3456789000e10-- +array_diff_key(): Argument #2 must be of type array, float given +array_diff_key(): Argument #2 must be of type array, float given + +--float .5-- +array_diff_key(): Argument #2 must be of type array, float given +array_diff_key(): Argument #2 must be of type array, float given + +--uppercase NULL-- +array_diff_key(): Argument #2 must be of type array, null given +array_diff_key(): Argument #2 must be of type array, null given + +--lowercase null-- +array_diff_key(): Argument #2 must be of type array, null given +array_diff_key(): Argument #2 must be of type array, null given + +--lowercase true-- +array_diff_key(): Argument #2 must be of type array, true given +array_diff_key(): Argument #2 must be of type array, true given + +--lowercase false-- +array_diff_key(): Argument #2 must be of type array, false given +array_diff_key(): Argument #2 must be of type array, false given + +--uppercase TRUE-- +array_diff_key(): Argument #2 must be of type array, true given +array_diff_key(): Argument #2 must be of type array, true given + +--uppercase FALSE-- +array_diff_key(): Argument #2 must be of type array, false given +array_diff_key(): Argument #2 must be of type array, false given + +--empty string DQ-- +array_diff_key(): Argument #2 must be of type array, string given +array_diff_key(): Argument #2 must be of type array, string given + +--empty string SQ-- +array_diff_key(): Argument #2 must be of type array, string given +array_diff_key(): Argument #2 must be of type array, string given + +--string DQ-- +array_diff_key(): Argument #2 must be of type array, string given +array_diff_key(): Argument #2 must be of type array, string given + +--string SQ-- +array_diff_key(): Argument #2 must be of type array, string given +array_diff_key(): Argument #2 must be of type array, string given + +--mixed case string-- +array_diff_key(): Argument #2 must be of type array, string given +array_diff_key(): Argument #2 must be of type array, string given + +--heredoc-- +array_diff_key(): Argument #2 must be of type array, string given +array_diff_key(): Argument #2 must be of type array, string given + +--instance of classWithToString-- +array_diff_key(): Argument #2 must be of type array, classWithToString given +array_diff_key(): Argument #2 must be of type array, classWithToString given + +--instance of classWithoutToString-- +array_diff_key(): Argument #2 must be of type array, classWithoutToString given +array_diff_key(): Argument #2 must be of type array, classWithoutToString given + +--undefined var-- +array_diff_key(): Argument #2 must be of type array, null given +array_diff_key(): Argument #2 must be of type array, null given + +--unset var-- +array_diff_key(): Argument #2 must be of type array, null given +array_diff_key(): Argument #2 must be of type array, null given + +--resource-- +array_diff_key(): Argument #2 must be of type array, resource given +array_diff_key(): Argument #2 must be of type array, resource given diff --git a/tests/std/array/array_diff_key_variation4.phpt b/tests/std/array/array_diff_key_variation4.phpt new file mode 100644 index 00000000..eb358af0 --- /dev/null +++ b/tests/std/array/array_diff_key_variation4.phpt @@ -0,0 +1,54 @@ +--TEST-- +Test array_diff_key() function : usage variation - Passing integer indexed array +--FILE-- + '-07', 0xA => '0xA'); + +$input_arrays = array( + 'decimal indexed' => array(10 => '10', '-17' => '-17'), + 'octal indexed' => array(-011 => '-011', 012 => '012'), + 'hexa indexed' => array(0x12 => '0x12', -0x7 => '-0x7', ), +); + +// loop through each element of the array for arr1 +foreach($input_arrays as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_diff_key($input_array, $value) ); + var_dump( array_diff_key($value, $input_array) ); +} +?> +--EXPECT-- +*** Testing array_diff_key() : usage variation *** + +--decimal indexed-- +array(1) { + [-7]=> + string(3) "-07" +} +array(1) { + [-17]=> + string(3) "-17" +} + +--octal indexed-- +array(1) { + [-7]=> + string(3) "-07" +} +array(1) { + [-9]=> + string(4) "-011" +} + +--hexa indexed-- +array(1) { + [10]=> + string(3) "0xA" +} +array(1) { + [18]=> + string(4) "0x12" +} diff --git a/tests/std/array/array_diff_key_variation6.phpt b/tests/std/array/array_diff_key_variation6.phpt new file mode 100644 index 00000000..b3b19db8 --- /dev/null +++ b/tests/std/array/array_diff_key_variation6.phpt @@ -0,0 +1,30 @@ +--TEST-- +Test array_diff_key() function : usage variation - Passing boolean indexed array +--SKIPIF-- +--FILE-- + '0', 1 => '1', -10 => '-10', 'true' => 1, 'false' => 0); +$boolean_indx_array = array(true => 'boolt', false => 'boolf', TRUE => 'boolT', FALSE => 'boolF'); + +echo "\n-- Testing array_diff_key() function with boolean indexed array --\n"; +// loop through each element of the array for arr1 +var_dump( array_diff_key($input_array, $boolean_indx_array) ); +var_dump( array_diff_key($boolean_indx_array, $input_array) ); +?> +--EXPECT-- +*** Testing array_diff_key() : usage variation *** + +-- Testing array_diff_key() function with boolean indexed array -- +array(3) { + [-10]=> + string(3) "-10" + ["true"]=> + int(1) + ["false"]=> + int(0) +} +array(0) { +} diff --git a/tests/std/array/array_diff_key_variation7.phpt b/tests/std/array/array_diff_key_variation7.phpt new file mode 100644 index 00000000..f8821cb9 --- /dev/null +++ b/tests/std/array/array_diff_key_variation7.phpt @@ -0,0 +1,57 @@ +--TEST-- +Test array_diff_key() function : usage variation - Passing null,unset and undefined variable indexed array +--SKIPIF-- + + +--FILE-- + '10', "" => 'empty'); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +$input_arrays = array( + 'null indexed' => array(NULL => 'null 1', null => 'null 2'), + 'undefined indexed' => array(@$undefined_var => 'undefined'), + 'unset indexed' => array(@$unset_var => 'unset'), +); + +foreach($input_arrays as $key =>$value) { + echo "\n--$key--\n"; + // loop through each element of the array for arr1 + var_dump( array_diff_key($input_array, $value) ); + var_dump( array_diff_key($value, $input_array) ); +} +?> +--EXPECT-- +*** Testing array_diff_key() : usage variation *** + +--null indexed-- +array(1) { + [10]=> + string(2) "10" +} +array(0) { +} + +--undefined indexed-- +array(1) { + [10]=> + string(2) "10" +} +array(0) { +} + +--unset indexed-- +array(1) { + [10]=> + string(2) "10" +} +array(0) { +} diff --git a/tests/std/array/array_diff_key_variation8.phpt b/tests/std/array/array_diff_key_variation8.phpt new file mode 100644 index 00000000..dc54a976 --- /dev/null +++ b/tests/std/array/array_diff_key_variation8.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test array_diff_key() function : usage variation - Passing multi-dimensional array +--FILE-- + array('blue' => 1, 'red' => 2), + + 'second' => array('yellow' => 7), + + 'third' => array(0 => 'zero'), +); + +$array2 = array ( + + 'first' => array('blue' => 1, 'red' => 2,), + + 'second' => array('cyan' => 8), + + 'fourth' => array(2 => 'two'), +); + +echo "\n-- Testing array_diff_key() function with multi dimensional array --\n"; +var_dump( array_diff_key($array1, $array2) ); +var_dump( array_diff_key($array2, $array1) ); +?> +--EXPECT-- +*** Testing array_diff_key() : usage variation *** + +-- Testing array_diff_key() function with multi dimensional array -- +array(1) { + ["third"]=> + array(1) { + [0]=> + string(4) "zero" + } +} +array(1) { + ["fourth"]=> + array(1) { + [2]=> + string(3) "two" + } +} diff --git a/tests/std/array/array_diff_single_array.phpt b/tests/std/array/array_diff_single_array.phpt new file mode 100644 index 00000000..83355b08 --- /dev/null +++ b/tests/std/array/array_diff_single_array.phpt @@ -0,0 +1,50 @@ +--TEST-- +array_diff() with single array argument +--FILE-- + 42]; +$cmp = function($a, $b) { return $a <=> $b; }; +var_dump(array_diff($array)); +var_dump(array_diff_key($array)); +var_dump(array_diff_ukey($array, $cmp)); +var_dump(array_diff_assoc($array)); +var_dump(array_diff_uassoc($array, $cmp)); +var_dump(array_udiff($array, $cmp)); +var_dump(array_udiff_assoc($array, $cmp)); +var_dump(array_udiff_uassoc($array, $cmp, $cmp)); + +?> +--EXPECT-- +array(1) { + ["a"]=> + int(42) +} +array(1) { + ["a"]=> + int(42) +} +array(1) { + ["a"]=> + int(42) +} +array(1) { + ["a"]=> + int(42) +} +array(1) { + ["a"]=> + int(42) +} +array(1) { + ["a"]=> + int(42) +} +array(1) { + ["a"]=> + int(42) +} +array(1) { + ["a"]=> + int(42) +} diff --git a/tests/std/array/array_diff_uassoc_basic.phpt b/tests/std/array/array_diff_uassoc_basic.phpt new file mode 100644 index 00000000..3a9296e5 --- /dev/null +++ b/tests/std/array/array_diff_uassoc_basic.phpt @@ -0,0 +1,32 @@ +--TEST-- +array_diff_uassoc(): Basic test +--FILE-- + $b ? 1 : -1; +} +function main() +{ + $array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red"); + $array2 = array("a" => "green", "yellow", "red"); + $result = array_diff_uassoc($array1, $array2, "key_compare_func"); + var_dump($result); +} +?> +--EXPECT-- +array(3) { + ["b"]=> + string(5) "brown" + ["c"]=> + string(4) "blue" + [0]=> + string(3) "red" +} diff --git a/tests/std/array/array_diff_uassoc_error.phpt b/tests/std/array/array_diff_uassoc_error.phpt new file mode 100644 index 00000000..8f166d50 --- /dev/null +++ b/tests/std/array/array_diff_uassoc_error.phpt @@ -0,0 +1,50 @@ +--TEST-- +Test array_diff_uassoc() function : error conditions +--FILE-- + $b ? 1 : -1; +} +function main() +{ + echo "*** Testing array_diff_uassoc() : error conditions ***\n"; + //Initialize array + $array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red"); + $array2 = array("a" => "green", "yellow", "red"); + $array3 = array("a" => "green", "red"); + $array4 = array(); + $extra_arg = array(1, 2, 3, 4); + //Test array_diff_uassoc with one more than the expected number of arguments + echo "\n-- Testing array_diff_uassoc() function with more than expected no. of arguments --\n"; + try { + var_dump(array_diff_uassoc($array1, $array2, "key_compare_func", $extra_arg)); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + try { + var_dump(array_diff_uassoc($array1, $array2, $array3, $array4, "key_compare_func", $extra_arg)); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + // Testing array_diff_uassoc with one less than the expected number of arguments + echo "\n-- Testing array_diff_uassoc() function with less than expected no. of arguments --\n"; + try { + var_dump(array_diff_uassoc($array1, $array2)); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } +} +?> +--EXPECT-- +*** Testing array_diff_uassoc() : error conditions *** + +-- Testing array_diff_uassoc() function with more than expected no. of arguments -- +array_diff_uassoc(): Argument #4 must be a valid callback, array callback must have exactly two members +array_diff_uassoc(): Argument #6 must be a valid callback, array callback must have exactly two members + +-- Testing array_diff_uassoc() function with less than expected no. of arguments -- +array_diff_uassoc(): Argument #2 must be a valid callback, array callback must have exactly two members diff --git a/tests/std/array/array_diff_uassoc_variation1.phpt b/tests/std/array/array_diff_uassoc_variation1.phpt new file mode 100644 index 00000000..c7a737f6 --- /dev/null +++ b/tests/std/array/array_diff_uassoc_variation1.phpt @@ -0,0 +1,174 @@ +--TEST-- +Test array_diff_uassoc() function : usage variation - Passing unexpected values to first argument +--SKIPIF-- + + +--FILE-- + $b ? 1 : -1; +} +// define some classes +class classWithToString +{ + public function __toString(): string { + return "Class A object"; + } +} +class classWithoutToString +{ +} +function main() +{ + echo "*** Testing array_diff_uassoc() : usage variation ***\n"; + //Initialize variables + $array2 = array("a" => "green", "yellow", "red"); + //get an unset variable + $unset_var = 10; + unset($unset_var); + //resource variable + $fp = fopen(__FILE__, "r"); + // heredoc string + $heredoc = << 1, 'two' => 2); + //array of values to iterate over + $inputs = array( + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 123456789000.0, + 'float -12.3456789000e10' => -123456789000.0, + 'float .5' => 0.5, + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + // boolean data + 'lowercase true' => true, + 'lowercase false' => false, + 'uppercase TRUE' => TRUE, + 'uppercase FALSE' => FALSE, + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + // undefined data + 'undefined var' => @$undefined_var, + // unset data + 'unset var' => @$unset_var, + // resource data + 'resource' => $fp, + ); + // loop through each element of the array for array1 + foreach ($inputs as $key => $value) { + echo "\n--{$key}--\n"; + try { + var_dump(array_diff_uassoc($value, $array2, "key_compare_func")); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + } + fclose($fp); +} +?> +--EXPECT-- +*** Testing array_diff_uassoc() : usage variation *** + +--int 0-- +array_diff_uassoc(): Argument #1 ($array) must be of type array, int given + +--int 1-- +array_diff_uassoc(): Argument #1 ($array) must be of type array, int given + +--int 12345-- +array_diff_uassoc(): Argument #1 ($array) must be of type array, int given + +--int -12345-- +array_diff_uassoc(): Argument #1 ($array) must be of type array, int given + +--float 10.5-- +array_diff_uassoc(): Argument #1 ($array) must be of type array, float given + +--float -10.5-- +array_diff_uassoc(): Argument #1 ($array) must be of type array, float given + +--float 12.3456789000e10-- +array_diff_uassoc(): Argument #1 ($array) must be of type array, float given + +--float -12.3456789000e10-- +array_diff_uassoc(): Argument #1 ($array) must be of type array, float given + +--float .5-- +array_diff_uassoc(): Argument #1 ($array) must be of type array, float given + +--uppercase NULL-- +array_diff_uassoc(): Argument #1 ($array) must be of type array, null given + +--lowercase null-- +array_diff_uassoc(): Argument #1 ($array) must be of type array, null given + +--lowercase true-- +array_diff_uassoc(): Argument #1 ($array) must be of type array, true given + +--lowercase false-- +array_diff_uassoc(): Argument #1 ($array) must be of type array, false given + +--uppercase TRUE-- +array_diff_uassoc(): Argument #1 ($array) must be of type array, true given + +--uppercase FALSE-- +array_diff_uassoc(): Argument #1 ($array) must be of type array, false given + +--empty string DQ-- +array_diff_uassoc(): Argument #1 ($array) must be of type array, string given + +--empty string SQ-- +array_diff_uassoc(): Argument #1 ($array) must be of type array, string given + +--string DQ-- +array_diff_uassoc(): Argument #1 ($array) must be of type array, string given + +--string SQ-- +array_diff_uassoc(): Argument #1 ($array) must be of type array, string given + +--mixed case string-- +array_diff_uassoc(): Argument #1 ($array) must be of type array, string given + +--heredoc-- +array_diff_uassoc(): Argument #1 ($array) must be of type array, string given + +--instance of classWithToString-- +array_diff_uassoc(): Argument #1 ($array) must be of type array, classWithToString given + +--instance of classWithoutToString-- +array_diff_uassoc(): Argument #1 ($array) must be of type array, classWithoutToString given + +--undefined var-- +array_diff_uassoc(): Argument #1 ($array) must be of type array, null given + +--unset var-- +array_diff_uassoc(): Argument #1 ($array) must be of type array, null given + +--resource-- +array_diff_uassoc(): Argument #1 ($array) must be of type array, resource given diff --git a/tests/std/array/array_diff_uassoc_variation11.phpt b/tests/std/array/array_diff_uassoc_variation11.phpt new file mode 100644 index 00000000..ac9544b1 --- /dev/null +++ b/tests/std/array/array_diff_uassoc_variation11.phpt @@ -0,0 +1,38 @@ +--TEST-- +Test array_diff_uassoc() function : usage variation - Passing boolean indexed array +--SKIPIF-- +--FILE-- + '0', 1 => '1', -10 => '-10', 'true' => 1, 'false' => 0); +$boolean_indx_array = array(true => 'boolt', false => 'boolf', TRUE => 'boolT', FALSE => 'boolF'); + +echo "\n-- Testing array_diff_key() function with float indexed array --\n"; +var_dump( array_diff_uassoc($input_array, $boolean_indx_array, "strcasecmp") ); +var_dump( array_diff_uassoc($boolean_indx_array, $input_array, "strcasecmp") ); + +?> +--EXPECT-- +*** Testing array_diff_uassoc() : usage variation *** + +-- Testing array_diff_key() function with float indexed array -- +array(5) { + [0]=> + string(1) "0" + [1]=> + string(1) "1" + [-10]=> + string(3) "-10" + ["true"]=> + int(1) + ["false"]=> + int(0) +} +array(2) { + [1]=> + string(5) "boolT" + [0]=> + string(5) "boolF" +} diff --git a/tests/std/array/array_diff_uassoc_variation12.phpt b/tests/std/array/array_diff_uassoc_variation12.phpt new file mode 100644 index 00000000..4ab1cf0e --- /dev/null +++ b/tests/std/array/array_diff_uassoc_variation12.phpt @@ -0,0 +1,57 @@ +--TEST-- +Test array_diff_uassoc() function : usage variation - Passing null,unset and undefined variable indexed array +--SKIPIF-- + + +--FILE-- + '10', "" => ''); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +$input_arrays = array( + 'null indexed' => array(NULL => NULL, null => null), + 'undefined indexed' => array(@$undefined_var => @$undefined_var), + 'unset indexed' => array(@$unset_var => @$unset_var), +); + +foreach($input_arrays as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_diff_uassoc($input_array, $value, "strcasecmp") ); + var_dump( array_diff_uassoc($value, $input_array, "strcasecmp") ); +} + +?> +--EXPECT-- +*** Testing array_diff_uassoc() : usage variation *** + +--null indexed-- +array(1) { + [10]=> + string(2) "10" +} +array(0) { +} + +--undefined indexed-- +array(1) { + [10]=> + string(2) "10" +} +array(0) { +} + +--unset indexed-- +array(1) { + [10]=> + string(2) "10" +} +array(0) { +} diff --git a/tests/std/array/array_diff_uassoc_variation13.phpt b/tests/std/array/array_diff_uassoc_variation13.phpt new file mode 100644 index 00000000..7ff8e49b --- /dev/null +++ b/tests/std/array/array_diff_uassoc_variation13.phpt @@ -0,0 +1,65 @@ +--TEST-- +Test array_diff_uassoc() function : usage variations - arrays containing referenced variables +--SKIPIF-- + + +--FILE-- + 1, &$ref_var); + +echo "\n-- Testing array_diff_uassoc() function with referenced variable \$ref_var has value '$ref_var' --\n"; +var_dump( array_diff_uassoc($array1, $array2, "strcasecmp") ); +var_dump( array_diff_uassoc($array2, $array1, "strcasecmp") ); + +// re-assign reference variable to different value +$ref_var = 10.00; +echo "\n-- Testing array_diff_uassoc() function with referenced variable \$ref_var value changed to $ref_var --\n"; +var_dump( array_diff_uassoc($array1, $array2, "strcasecmp") ); +var_dump( array_diff_uassoc($array2, $array1, "strcasecmp") ); + +//When array are refenced +$array2 = &$array1; +echo "\n-- Testing array_diff_uassoc() function when \$array2 is referenced to \$array1 --\n"; +var_dump( array_diff_uassoc($array1, $array2, "strcasecmp") ); +var_dump( array_diff_uassoc($array2, $array1, "strcasecmp") ); + +?> +--EXPECT-- +*** Testing array_diff_uassoc() : usage variation *** + +-- Testing array_diff_uassoc() function with referenced variable $ref_var has value 'a' -- +array(1) { + [1]=> + string(1) "a" +} +array(1) { + ["a"]=> + int(1) +} + +-- Testing array_diff_uassoc() function with referenced variable $ref_var value changed to 10 -- +array(2) { + [0]=> + string(1) "a" + [1]=> + string(1) "a" +} +array(2) { + ["a"]=> + int(1) + [0]=> + &float(10) +} + +-- Testing array_diff_uassoc() function when $array2 is referenced to $array1 -- +array(0) { +} +array(0) { +} diff --git a/tests/std/array/array_diff_uassoc_variation2.phpt b/tests/std/array/array_diff_uassoc_variation2.phpt new file mode 100644 index 00000000..9f85ed89 --- /dev/null +++ b/tests/std/array/array_diff_uassoc_variation2.phpt @@ -0,0 +1,174 @@ +--TEST-- +Test array_diff_uassoc() function : usage variation -Passing unexpected values to second argument +--SKIPIF-- + + +--FILE-- + $b ? 1 : -1; +} +// define some classes +class classWithToString +{ + public function __toString(): string { + return "Class A object"; + } +} +class classWithoutToString +{ +} +function main() +{ + echo "*** Testing array_diff_uassoc() : usage variation ***\n"; + //Initialize variables + $array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red"); + //get an unset variable + $unset_var = 10; + unset($unset_var); + //resource variable + $fp = fopen(__FILE__, "r"); + // heredoc string + $heredoc = << 1, 'two' => 2); + //array of values to iterate over + $inputs = array( + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 123456789000.0, + 'float -12.3456789000e10' => -123456789000.0, + 'float .5' => 0.5, + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + // boolean data + 'lowercase true' => true, + 'lowercase false' => false, + 'uppercase TRUE' => TRUE, + 'uppercase FALSE' => FALSE, + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + // undefined data + 'undefined var' => @$undefined_var, + // unset data + 'unset var' => @$unset_var, + // resource data + 'resource' => $fp, + ); + // loop through each element of the array for array2 + foreach ($inputs as $key => $value) { + echo "\n--{$key}--\n"; + try { + var_dump(array_diff_uassoc($array1, $value, "key_compare_func")); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + } + fclose($fp); +} +?> +--EXPECT-- +*** Testing array_diff_uassoc() : usage variation *** + +--int 0-- +array_diff_uassoc(): Argument #2 must be of type array, int given + +--int 1-- +array_diff_uassoc(): Argument #2 must be of type array, int given + +--int 12345-- +array_diff_uassoc(): Argument #2 must be of type array, int given + +--int -12345-- +array_diff_uassoc(): Argument #2 must be of type array, int given + +--float 10.5-- +array_diff_uassoc(): Argument #2 must be of type array, float given + +--float -10.5-- +array_diff_uassoc(): Argument #2 must be of type array, float given + +--float 12.3456789000e10-- +array_diff_uassoc(): Argument #2 must be of type array, float given + +--float -12.3456789000e10-- +array_diff_uassoc(): Argument #2 must be of type array, float given + +--float .5-- +array_diff_uassoc(): Argument #2 must be of type array, float given + +--uppercase NULL-- +array_diff_uassoc(): Argument #2 must be of type array, null given + +--lowercase null-- +array_diff_uassoc(): Argument #2 must be of type array, null given + +--lowercase true-- +array_diff_uassoc(): Argument #2 must be of type array, true given + +--lowercase false-- +array_diff_uassoc(): Argument #2 must be of type array, false given + +--uppercase TRUE-- +array_diff_uassoc(): Argument #2 must be of type array, true given + +--uppercase FALSE-- +array_diff_uassoc(): Argument #2 must be of type array, false given + +--empty string DQ-- +array_diff_uassoc(): Argument #2 must be of type array, string given + +--empty string SQ-- +array_diff_uassoc(): Argument #2 must be of type array, string given + +--string DQ-- +array_diff_uassoc(): Argument #2 must be of type array, string given + +--string SQ-- +array_diff_uassoc(): Argument #2 must be of type array, string given + +--mixed case string-- +array_diff_uassoc(): Argument #2 must be of type array, string given + +--heredoc-- +array_diff_uassoc(): Argument #2 must be of type array, string given + +--instance of classWithToString-- +array_diff_uassoc(): Argument #2 must be of type array, classWithToString given + +--instance of classWithoutToString-- +array_diff_uassoc(): Argument #2 must be of type array, classWithoutToString given + +--undefined var-- +array_diff_uassoc(): Argument #2 must be of type array, null given + +--unset var-- +array_diff_uassoc(): Argument #2 must be of type array, null given + +--resource-- +array_diff_uassoc(): Argument #2 must be of type array, resource given diff --git a/tests/std/array/array_diff_uassoc_variation5.phpt b/tests/std/array/array_diff_uassoc_variation5.phpt new file mode 100644 index 00000000..384c9774 --- /dev/null +++ b/tests/std/array/array_diff_uassoc_variation5.phpt @@ -0,0 +1,30 @@ +--TEST-- +Test array_diff_uassoc() function : usage variation - Comparing integers and floating point numbers +--FILE-- + $key2 ? 1 : -1; +} +function main() +{ + echo "*** Testing array_diff_uassoc() : usage variation ***\n"; + //Initialize variables + $arr_default_int = array(1, 2, 3, 4); + $arr_float = array(0 => 1.0, 1 => 2.0, 2 => 3.0, 3 => 4.0); + echo "\n-- Result of comparing integers and floating point numbers --\n"; + var_dump(array_diff_uassoc($arr_default_int, $arr_float, "key_compare_func")); + var_dump(array_diff_uassoc($arr_float, $arr_default_int, "key_compare_func")); +} +?> +--EXPECT-- +*** Testing array_diff_uassoc() : usage variation *** + +-- Result of comparing integers and floating point numbers -- +array(0) { +} +array(0) { +} diff --git a/tests/std/array/array_diff_uassoc_variation6.phpt b/tests/std/array/array_diff_uassoc_variation6.phpt new file mode 100644 index 00000000..56c65590 --- /dev/null +++ b/tests/std/array/array_diff_uassoc_variation6.phpt @@ -0,0 +1,48 @@ +--TEST-- +Test array_diff_uassoc() function : usage variation - Comparing floating points with strings having integers and float +--FILE-- + $key2 ? 1 : -1; +} +function main() +{ + echo "*** Testing array_diff_uassoc() : usage variation ***\n"; + //Initialize variables + $arr_float = array(0 => 1.0, 1 => 2.0); + $arr_string_int = array('1', '2'); + $arr_string_float = array('0' => '1.00', '1.00' => '2.00'); + echo "\n-- Result of comparing floating points and strings containing integers --\n"; + var_dump(array_diff_uassoc($arr_float, $arr_string_int, "key_compare_func")); + var_dump(array_diff_uassoc($arr_string_int, $arr_float, "key_compare_func")); + echo "\n-- Result of comparing floating points and strings containing floating point --\n"; + var_dump(array_diff_uassoc($arr_float, $arr_string_float, "key_compare_func")); + var_dump(array_diff_uassoc($arr_string_float, $arr_float, "key_compare_func")); +} +?> +--EXPECT-- +*** Testing array_diff_uassoc() : usage variation *** + +-- Result of comparing floating points and strings containing integers -- +array(0) { +} +array(0) { +} + +-- Result of comparing floating points and strings containing floating point -- +array(2) { + [0]=> + float(1) + [1]=> + float(2) +} +array(2) { + [0]=> + string(4) "1.00" + ["1.00"]=> + string(4) "2.00" +} diff --git a/tests/std/array/array_diff_uassoc_variation7.phpt b/tests/std/array/array_diff_uassoc_variation7.phpt new file mode 100644 index 00000000..63bdbdcb --- /dev/null +++ b/tests/std/array/array_diff_uassoc_variation7.phpt @@ -0,0 +1,38 @@ +--TEST-- +Test array_diff_uassoc() function : usage variation - Comparing strings containing integers and float +--FILE-- + $key2 ? 1 : -1; +} +function main() +{ + echo "*** Testing array_diff_uassoc() : usage variation ***\n"; + //Initialize variables + $arr_string_int = array('1', '2'); + $arr_string_float = array('0' => '1.00', '1.00' => '2.00'); + echo "\n-- Result of comparing strings containing integers and strings containing floating points --\n"; + var_dump(array_diff_uassoc($arr_string_int, $arr_string_float, "key_compare_func")); + var_dump(array_diff_uassoc($arr_string_float, $arr_string_int, "key_compare_func")); +} +?> +--EXPECT-- +*** Testing array_diff_uassoc() : usage variation *** + +-- Result of comparing strings containing integers and strings containing floating points -- +array(2) { + [0]=> + string(1) "1" + [1]=> + string(1) "2" +} +array(2) { + [0]=> + string(4) "1.00" + ["1.00"]=> + string(4) "2.00" +} diff --git a/tests/std/array/array_diff_uassoc_variation8.phpt b/tests/std/array/array_diff_uassoc_variation8.phpt new file mode 100644 index 00000000..1746f112 --- /dev/null +++ b/tests/std/array/array_diff_uassoc_variation8.phpt @@ -0,0 +1,52 @@ +--TEST-- +Test array_diff_uassoc() function : usage variation - Comparing integers with strings containing integers and float +--FILE-- + $key2 ? 1 : -1; +} +function main() +{ + echo "*** Testing array_diff_uassoc() : usage variation ***\n"; + //Initialize variables + $arr_default_int = array(1, 2, 3); + $arr_string_int = array('1', '2'); + $arr_string_float = array('0' => '1.00', '1.00' => '2.00'); + echo "\n-- Result of comparing integers and strings containing an integers --\n"; + var_dump(array_diff_uassoc($arr_default_int, $arr_string_int, "key_compare_func")); + var_dump(array_diff_uassoc($arr_string_int, $arr_default_int, "key_compare_func")); + echo "\n-- Result of comparing integers and strings containing floating points --\n"; + var_dump(array_diff_uassoc($arr_default_int, $arr_string_float, "key_compare_func")); + var_dump(array_diff_uassoc($arr_string_float, $arr_default_int, "key_compare_func")); +} +?> +--EXPECT-- +*** Testing array_diff_uassoc() : usage variation *** + +-- Result of comparing integers and strings containing an integers -- +array(1) { + [2]=> + int(3) +} +array(0) { +} + +-- Result of comparing integers and strings containing floating points -- +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +array(2) { + [0]=> + string(4) "1.00" + ["1.00"]=> + string(4) "2.00" +} diff --git a/tests/std/array/array_diff_uassoc_variation9.phpt b/tests/std/array/array_diff_uassoc_variation9.phpt new file mode 100644 index 00000000..a8033ba3 --- /dev/null +++ b/tests/std/array/array_diff_uassoc_variation9.phpt @@ -0,0 +1,54 @@ +--TEST-- +Test array_diff_uassoc() function : usage variation - Passing integer indexed array +--FILE-- + 10, 12 => 12); + +$input_arrays = array( + 'decimal indexed' => array(10 => 10, -17 => -17), + 'octal indexed' => array( 012 => 10, -011 => -011,), + 'hexa indexed' => array(0xA => 10, -0x7 => -0x7 ), +); + +foreach($input_arrays as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_diff_uassoc($input_array, $value, "strcasecmp") ); + var_dump( array_diff_uassoc($value, $input_array, "strcasecmp") ); +} + +?> +--EXPECT-- +*** Testing array_diff_uassoc() : usage variation *** + +--decimal indexed-- +array(1) { + [12]=> + int(12) +} +array(1) { + [-17]=> + int(-17) +} + +--octal indexed-- +array(1) { + [12]=> + int(12) +} +array(1) { + [-9]=> + int(-9) +} + +--hexa indexed-- +array(1) { + [12]=> + int(12) +} +array(1) { + [-7]=> + int(-7) +} diff --git a/tests/std/array/array_diff_ukey_basic.phpt b/tests/std/array/array_diff_ukey_basic.phpt new file mode 100644 index 00000000..3a925120 --- /dev/null +++ b/tests/std/array/array_diff_ukey_basic.phpt @@ -0,0 +1,31 @@ +--TEST-- +array_diff_ukey() : Basic test. +--FILE-- + $key2) { + return 1; + } else { + return -1; + } +} +function main() +{ + $array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); + $array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); + var_dump(array_diff_ukey($array1, $array2, 'key_compare_func')); +} +?> +--EXPECT-- +array(2) { + ["red"]=> + int(2) + ["purple"]=> + int(4) +} diff --git a/tests/std/array/array_diff_ukey_variation1.phpt b/tests/std/array/array_diff_ukey_variation1.phpt new file mode 100644 index 00000000..1ac2b870 --- /dev/null +++ b/tests/std/array/array_diff_ukey_variation1.phpt @@ -0,0 +1,203 @@ +--TEST-- +Test array_diff_ukey() function : usage variation - Passing unexpected values to first argument +--SKIPIF-- + + +--FILE-- + $key2 ? 1 : -1; +} +// define some classes +class classWithToString +{ + public function __toString(): string { + return "Class A object"; + } +} +class classWithoutToString +{ +} +function main() +{ + echo "*** Testing array_diff_ukey() : usage variation ***\n"; + // Initialise function arguments not being substituted (if any) + $array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); + $array3 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); + //get an unset variable + $unset_var = 10; + unset($unset_var); + //resource variable + $fp = fopen(__FILE__, "r"); + // heredoc string + $heredoc = << 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 123456789000.0, + 'float -12.3456789000e10' => -123456789000.0, + 'float .5' => 0.5, + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + // boolean data + 'lowercase true' => true, + 'lowercase false' => false, + 'uppercase TRUE' => TRUE, + 'uppercase FALSE' => FALSE, + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + // undefined data + 'undefined var' => @$undefined_var, + // unset data + 'unset var' => @$unset_var, + // resource data + 'resource' => $fp, + ); + // loop through each element of the array for array1 + foreach ($inputs as $key => $value) { + echo "\n--{$key}--\n"; + try { + var_dump(array_diff_ukey($value, $array2, 'key_compare_func')); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + try { + var_dump(array_diff_ukey($value, $array2, $array3, 'key_compare_func')); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + } + fclose($fp); +} +?> +--EXPECT-- +*** Testing array_diff_ukey() : usage variation *** + +--int 0-- +array_diff_ukey(): Argument #1 ($array) must be of type array, int given +array_diff_ukey(): Argument #1 ($array) must be of type array, int given + +--int 1-- +array_diff_ukey(): Argument #1 ($array) must be of type array, int given +array_diff_ukey(): Argument #1 ($array) must be of type array, int given + +--int 12345-- +array_diff_ukey(): Argument #1 ($array) must be of type array, int given +array_diff_ukey(): Argument #1 ($array) must be of type array, int given + +--int -12345-- +array_diff_ukey(): Argument #1 ($array) must be of type array, int given +array_diff_ukey(): Argument #1 ($array) must be of type array, int given + +--float 10.5-- +array_diff_ukey(): Argument #1 ($array) must be of type array, float given +array_diff_ukey(): Argument #1 ($array) must be of type array, float given + +--float -10.5-- +array_diff_ukey(): Argument #1 ($array) must be of type array, float given +array_diff_ukey(): Argument #1 ($array) must be of type array, float given + +--float 12.3456789000e10-- +array_diff_ukey(): Argument #1 ($array) must be of type array, float given +array_diff_ukey(): Argument #1 ($array) must be of type array, float given + +--float -12.3456789000e10-- +array_diff_ukey(): Argument #1 ($array) must be of type array, float given +array_diff_ukey(): Argument #1 ($array) must be of type array, float given + +--float .5-- +array_diff_ukey(): Argument #1 ($array) must be of type array, float given +array_diff_ukey(): Argument #1 ($array) must be of type array, float given + +--uppercase NULL-- +array_diff_ukey(): Argument #1 ($array) must be of type array, null given +array_diff_ukey(): Argument #1 ($array) must be of type array, null given + +--lowercase null-- +array_diff_ukey(): Argument #1 ($array) must be of type array, null given +array_diff_ukey(): Argument #1 ($array) must be of type array, null given + +--lowercase true-- +array_diff_ukey(): Argument #1 ($array) must be of type array, true given +array_diff_ukey(): Argument #1 ($array) must be of type array, true given + +--lowercase false-- +array_diff_ukey(): Argument #1 ($array) must be of type array, false given +array_diff_ukey(): Argument #1 ($array) must be of type array, false given + +--uppercase TRUE-- +array_diff_ukey(): Argument #1 ($array) must be of type array, true given +array_diff_ukey(): Argument #1 ($array) must be of type array, true given + +--uppercase FALSE-- +array_diff_ukey(): Argument #1 ($array) must be of type array, false given +array_diff_ukey(): Argument #1 ($array) must be of type array, false given + +--empty string DQ-- +array_diff_ukey(): Argument #1 ($array) must be of type array, string given +array_diff_ukey(): Argument #1 ($array) must be of type array, string given + +--empty string SQ-- +array_diff_ukey(): Argument #1 ($array) must be of type array, string given +array_diff_ukey(): Argument #1 ($array) must be of type array, string given + +--string DQ-- +array_diff_ukey(): Argument #1 ($array) must be of type array, string given +array_diff_ukey(): Argument #1 ($array) must be of type array, string given + +--string SQ-- +array_diff_ukey(): Argument #1 ($array) must be of type array, string given +array_diff_ukey(): Argument #1 ($array) must be of type array, string given + +--mixed case string-- +array_diff_ukey(): Argument #1 ($array) must be of type array, string given +array_diff_ukey(): Argument #1 ($array) must be of type array, string given + +--heredoc-- +array_diff_ukey(): Argument #1 ($array) must be of type array, string given +array_diff_ukey(): Argument #1 ($array) must be of type array, string given + +--instance of classWithToString-- +array_diff_ukey(): Argument #1 ($array) must be of type array, classWithToString given +array_diff_ukey(): Argument #1 ($array) must be of type array, classWithToString given + +--instance of classWithoutToString-- +array_diff_ukey(): Argument #1 ($array) must be of type array, classWithoutToString given +array_diff_ukey(): Argument #1 ($array) must be of type array, classWithoutToString given + +--undefined var-- +array_diff_ukey(): Argument #1 ($array) must be of type array, null given +array_diff_ukey(): Argument #1 ($array) must be of type array, null given + +--unset var-- +array_diff_ukey(): Argument #1 ($array) must be of type array, null given +array_diff_ukey(): Argument #1 ($array) must be of type array, null given + +--resource-- +array_diff_ukey(): Argument #1 ($array) must be of type array, resource given +array_diff_ukey(): Argument #1 ($array) must be of type array, resource given diff --git a/tests/std/array/array_diff_ukey_variation10.phpt b/tests/std/array/array_diff_ukey_variation10.phpt new file mode 100644 index 00000000..b8dfb738 --- /dev/null +++ b/tests/std/array/array_diff_ukey_variation10.phpt @@ -0,0 +1,29 @@ +--TEST-- +Test array_diff_ukey() function : usage variation - Passing non-existing function name to callback +--FILE-- + "green", "b" => "brown", "c" => "blue", "red"); +$array2 = array("a" => "green", "yellow", "red"); + +//function name within double quotes +try { + var_dump( array_diff_ukey($array1, $array1, "unknown_function") ); +} catch (TypeError $e) { + echo $e->getMessage(), "\n"; +} + +//function name within single quotes +try { + var_dump( array_diff_ukey($array1, $array1, 'unknown_function') ); +} catch (TypeError $e) { + echo $e->getMessage(), "\n"; +} + +?> +--EXPECT-- +*** Testing array_diff_ukey() : usage variation *** +array_diff_ukey(): Argument #3 must be a valid callback, function "unknown_function" not found or invalid function name +array_diff_ukey(): Argument #3 must be a valid callback, function "unknown_function" not found or invalid function name diff --git a/tests/std/array/array_diff_ukey_variation2.phpt b/tests/std/array/array_diff_ukey_variation2.phpt new file mode 100644 index 00000000..0955b566 --- /dev/null +++ b/tests/std/array/array_diff_ukey_variation2.phpt @@ -0,0 +1,204 @@ +--TEST-- +Test array_diff_ukey() function : usage variation - Passing unexpected values to second argument +--SKIPIF-- + + +--FILE-- + $key2 ? 1 : -1; +} +// define some classes +class classWithToString +{ + public function __toString(): string { + return "Class A object"; + } +} +class classWithoutToString +{ +} +function main() +{ + echo "*** Testing array_diff_ukey() : usage variation ***\n"; + // Initialize function arguments not being substituted (if any) + $array1 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); + $array3 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); + //get an unset variable + $unset_var = 10; + unset($unset_var); + //resource variable + $fp = fopen(__FILE__, "r"); + // heredoc string + $heredoc = << 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 123456789000.0, + 'float -12.3456789000e10' => -123456789000.0, + 'float .5' => 0.5, + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + // boolean data + 'lowercase true' => true, + 'lowercase false' => false, + 'uppercase TRUE' => TRUE, + 'uppercase FALSE' => FALSE, + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + // undefined data + 'undefined var' => @$undefined_var, + // unset data + 'unset var' => @$unset_var, + // resource data + 'resource' => $fp, + ); + // loop through each element of the array for array2 + foreach ($inputs as $key => $value) { + echo "\n--{$key}--\n"; + try { + var_dump(array_diff_ukey($array1, $value, 'key_compare_func')); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + try { + var_dump(array_diff_ukey($array1, $value, $array3, 'key_compare_func')); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + } + fclose($fp); +} +?> +--EXPECT-- +*** Testing array_diff_ukey() : usage variation *** + +--int 0-- +array_diff_ukey(): Argument #2 must be of type array, int given +array_diff_ukey(): Argument #2 must be of type array, int given + +--int 1-- +array_diff_ukey(): Argument #2 must be of type array, int given +array_diff_ukey(): Argument #2 must be of type array, int given + +--int 12345-- +array_diff_ukey(): Argument #2 must be of type array, int given +array_diff_ukey(): Argument #2 must be of type array, int given + +--int -12345-- +array_diff_ukey(): Argument #2 must be of type array, int given +array_diff_ukey(): Argument #2 must be of type array, int given + +--float 10.5-- +array_diff_ukey(): Argument #2 must be of type array, float given +array_diff_ukey(): Argument #2 must be of type array, float given + +--float -10.5-- +array_diff_ukey(): Argument #2 must be of type array, float given +array_diff_ukey(): Argument #2 must be of type array, float given + +--float 12.3456789000e10-- +array_diff_ukey(): Argument #2 must be of type array, float given +array_diff_ukey(): Argument #2 must be of type array, float given + +--float -12.3456789000e10-- +array_diff_ukey(): Argument #2 must be of type array, float given +array_diff_ukey(): Argument #2 must be of type array, float given + +--float .5-- +array_diff_ukey(): Argument #2 must be of type array, float given +array_diff_ukey(): Argument #2 must be of type array, float given + +--uppercase NULL-- +array_diff_ukey(): Argument #2 must be of type array, null given +array_diff_ukey(): Argument #2 must be of type array, null given + +--lowercase null-- +array_diff_ukey(): Argument #2 must be of type array, null given +array_diff_ukey(): Argument #2 must be of type array, null given + +--lowercase true-- +array_diff_ukey(): Argument #2 must be of type array, true given +array_diff_ukey(): Argument #2 must be of type array, true given + +--lowercase false-- +array_diff_ukey(): Argument #2 must be of type array, false given +array_diff_ukey(): Argument #2 must be of type array, false given + +--uppercase TRUE-- +array_diff_ukey(): Argument #2 must be of type array, true given +array_diff_ukey(): Argument #2 must be of type array, true given + +--uppercase FALSE-- +array_diff_ukey(): Argument #2 must be of type array, false given +array_diff_ukey(): Argument #2 must be of type array, false given + +--empty string DQ-- +array_diff_ukey(): Argument #2 must be of type array, string given +array_diff_ukey(): Argument #2 must be of type array, string given + +--empty string SQ-- +array_diff_ukey(): Argument #2 must be of type array, string given +array_diff_ukey(): Argument #2 must be of type array, string given + +--string DQ-- +array_diff_ukey(): Argument #2 must be of type array, string given +array_diff_ukey(): Argument #2 must be of type array, string given + +--string SQ-- +array_diff_ukey(): Argument #2 must be of type array, string given +array_diff_ukey(): Argument #2 must be of type array, string given + +--mixed case string-- +array_diff_ukey(): Argument #2 must be of type array, string given +array_diff_ukey(): Argument #2 must be of type array, string given + +--heredoc-- +array_diff_ukey(): Argument #2 must be of type array, string given +array_diff_ukey(): Argument #2 must be of type array, string given + +--instance of classWithToString-- +array_diff_ukey(): Argument #2 must be of type array, classWithToString given +array_diff_ukey(): Argument #2 must be of type array, classWithToString given + +--instance of classWithoutToString-- +array_diff_ukey(): Argument #2 must be of type array, classWithoutToString given +array_diff_ukey(): Argument #2 must be of type array, classWithoutToString given + +--undefined var-- +array_diff_ukey(): Argument #2 must be of type array, null given +array_diff_ukey(): Argument #2 must be of type array, null given + +--unset var-- +array_diff_ukey(): Argument #2 must be of type array, null given +array_diff_ukey(): Argument #2 must be of type array, null given + +--resource-- +array_diff_ukey(): Argument #2 must be of type array, resource given +array_diff_ukey(): Argument #2 must be of type array, resource given diff --git a/tests/std/array/array_diff_ukey_variation5.phpt b/tests/std/array/array_diff_ukey_variation5.phpt new file mode 100644 index 00000000..c41147d8 --- /dev/null +++ b/tests/std/array/array_diff_ukey_variation5.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test array_diff_ukey() function : usage variation - Passing multi-dimensional array +--FILE-- + array('blue' => 1, 'red' => 2), + + 'second' => array('yellow' => 7), + + 'third' => array(0 => 'zero'), +); + +$array2 = array ( + + 'first' => array('blue' => 1, 'red' => 2,), + + 'second' => array('cyan' => 8), + + 'fourth' => array(2 => 'two'), +); + +echo "\n-- Testing array_diff_ukey() function with multi dimensional array --\n"; +var_dump( array_diff_ukey($array1, $array2, 'strcasecmp') ); +var_dump( array_diff_ukey($array2, $array1, 'strcasecmp') ); +?> +--EXPECT-- +*** Testing array_diff_ukey() : usage variation *** + +-- Testing array_diff_ukey() function with multi dimensional array -- +array(1) { + ["third"]=> + array(1) { + [0]=> + string(4) "zero" + } +} +array(1) { + ["fourth"]=> + array(1) { + [2]=> + string(3) "two" + } +} diff --git a/tests/std/array/array_diff_ukey_variation6.phpt b/tests/std/array/array_diff_ukey_variation6.phpt new file mode 100644 index 00000000..fdc6dd65 --- /dev/null +++ b/tests/std/array/array_diff_ukey_variation6.phpt @@ -0,0 +1,53 @@ +--TEST-- +Test array_diff_ukey() function : usage variation - Passing integer indexed array +--FILE-- + '-07', 0xa => '0xA'); + $input_arrays = array('decimal indexed' => array(10 => '10', '-17' => '-17'), 'octal indexed' => array(-011 => '-011', 012 => '012'), 'hexa indexed' => array(0x12 => '0x12', -0x7 => '-0x7')); + foreach ($input_arrays as $key => $value) { + echo "\n--{$key}--\n"; + var_dump(array_diff_ukey($value, $input_array, 'key_compare_func')); + var_dump(array_diff_ukey($input_array, $value, 'key_compare_func')); + } +} +?> +--EXPECT-- +*** Testing array_diff_ukey() : usage variation *** + +--decimal indexed-- +array(1) { + [-17]=> + string(3) "-17" +} +array(1) { + [-7]=> + string(3) "-07" +} + +--octal indexed-- +array(1) { + [-9]=> + string(4) "-011" +} +array(1) { + [-7]=> + string(3) "-07" +} + +--hexa indexed-- +array(1) { + [18]=> + string(4) "0x12" +} +array(1) { + [10]=> + string(3) "0xA" +} diff --git a/tests/std/array/array_diff_ukey_variation8.phpt b/tests/std/array/array_diff_ukey_variation8.phpt new file mode 100644 index 00000000..24298a66 --- /dev/null +++ b/tests/std/array/array_diff_ukey_variation8.phpt @@ -0,0 +1,34 @@ +--TEST-- +Test array_diff_ukey() function : usage variation - Passing boolean indexed array +--SKIPIF-- +--FILE-- + '0', 1 => '1', -10 => '-10', 'true' => 1, 'false' => 0); + $boolean_indx_array = array(true => 'boolt', false => 'boolf', TRUE => 'boolT', FALSE => 'boolF'); + echo "\n-- Testing array_diff_ukey() function with boolean indexed array --\n"; + var_dump(array_diff_ukey($boolean_indx_array, $input_array, 'key_compare_func')); + var_dump(array_diff_ukey($input_array, $boolean_indx_array, 'key_compare_func')); +} +?> +--EXPECT-- +*** Testing array_diff_ukey() : usage variation *** + +-- Testing array_diff_ukey() function with boolean indexed array -- +array(0) { +} +array(3) { + [-10]=> + string(3) "-10" + ["true"]=> + int(1) + ["false"]=> + int(0) +} diff --git a/tests/std/array/array_diff_ukey_variation9.phpt b/tests/std/array/array_diff_ukey_variation9.phpt new file mode 100644 index 00000000..f2ca3a66 --- /dev/null +++ b/tests/std/array/array_diff_ukey_variation9.phpt @@ -0,0 +1,57 @@ +--TEST-- +Test array_diff_ukey() function : usage variation - Passing null,unset and undefined variable indexed array +--SKIPIF-- + + +--FILE-- + '10', "" => 'empty'); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +$input_arrays = array( + 'null indexed' => array(NULL => 'null 1', null => 'null 2'), + 'undefined indexed' => array(@$undefined_var => 'undefined'), + 'unset indexed' => array(@$unset_var => 'unset'), +); + +foreach($input_arrays as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_diff_ukey($value, $input_array, 'strcasecmp') ); + var_dump( array_diff_ukey($input_array, $value, 'strcasecmp') ); +} + +?> +--EXPECT-- +*** Testing array_diff_ukey() : usage variation *** + +--null indexed-- +array(0) { +} +array(1) { + [10]=> + string(2) "10" +} + +--undefined indexed-- +array(0) { +} +array(1) { + [10]=> + string(2) "10" +} + +--unset indexed-- +array(0) { +} +array(1) { + [10]=> + string(2) "10" +} diff --git a/tests/std/array/array_diff_variation1.phpt b/tests/std/array/array_diff_variation1.phpt new file mode 100644 index 00000000..e9cbad88 --- /dev/null +++ b/tests/std/array/array_diff_variation1.phpt @@ -0,0 +1,153 @@ +--TEST-- +Test array_diff() function : usage variations - unexpected values for 'array1' argument +--SKIPIF-- + + +--FILE-- +getMessage(), "\n"; + } + $iterator++; + } + fclose($fp); + echo "Done"; +} +?> +--EXPECT-- +*** Testing array_diff() : usage variations *** + +-- Iteration 1 --array_diff(): Argument #1 ($array) must be of type array, int given + +-- Iteration 2 --array_diff(): Argument #1 ($array) must be of type array, int given + +-- Iteration 3 --array_diff(): Argument #1 ($array) must be of type array, int given + +-- Iteration 4 --array_diff(): Argument #1 ($array) must be of type array, int given + +-- Iteration 5 --array_diff(): Argument #1 ($array) must be of type array, float given + +-- Iteration 6 --array_diff(): Argument #1 ($array) must be of type array, float given + +-- Iteration 7 --array_diff(): Argument #1 ($array) must be of type array, float given + +-- Iteration 8 --array_diff(): Argument #1 ($array) must be of type array, float given + +-- Iteration 9 --array_diff(): Argument #1 ($array) must be of type array, float given + +-- Iteration 10 --array_diff(): Argument #1 ($array) must be of type array, null given + +-- Iteration 11 --array_diff(): Argument #1 ($array) must be of type array, null given + +-- Iteration 12 --array_diff(): Argument #1 ($array) must be of type array, true given + +-- Iteration 13 --array_diff(): Argument #1 ($array) must be of type array, false given + +-- Iteration 14 --array_diff(): Argument #1 ($array) must be of type array, true given + +-- Iteration 15 --array_diff(): Argument #1 ($array) must be of type array, false given + +-- Iteration 16 --array_diff(): Argument #1 ($array) must be of type array, string given + +-- Iteration 17 --array_diff(): Argument #1 ($array) must be of type array, string given + +-- Iteration 18 --array_diff(): Argument #1 ($array) must be of type array, string given + +-- Iteration 19 --array_diff(): Argument #1 ($array) must be of type array, string given + +-- Iteration 20 --array_diff(): Argument #1 ($array) must be of type array, string given + +-- Iteration 21 --array_diff(): Argument #1 ($array) must be of type array, string given + +-- Iteration 22 --array_diff(): Argument #1 ($array) must be of type array, string given + +-- Iteration 23 --array_diff(): Argument #1 ($array) must be of type array, classA given + +-- Iteration 24 --array_diff(): Argument #1 ($array) must be of type array, null given + +-- Iteration 25 --array_diff(): Argument #1 ($array) must be of type array, null given + +-- Iteration 26 --array_diff(): Argument #1 ($array) must be of type array, resource given +Done diff --git a/tests/std/array/array_diff_variation10.phpt b/tests/std/array/array_diff_variation10.phpt new file mode 100644 index 00000000..01e849f2 --- /dev/null +++ b/tests/std/array/array_diff_variation10.phpt @@ -0,0 +1,38 @@ +--TEST-- +Test array_diff() function : usage variations - binary safe checking +--FILE-- + "hello", + "str2" => "world"); + +$array2 = array( b"1" => 'hello', + b"world", + "hello", + 'test'); + +var_dump(array_diff($array1, $array2)); +var_dump(array_diff($array2, $array1)); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_diff() : usage variations *** +array(1) { + [0]=> + string(1) "1" +} +array(1) { + [4]=> + string(4) "test" +} +Done diff --git a/tests/std/array/array_diff_variation2.phpt b/tests/std/array/array_diff_variation2.phpt new file mode 100644 index 00000000..bdc41144 --- /dev/null +++ b/tests/std/array/array_diff_variation2.phpt @@ -0,0 +1,153 @@ +--TEST-- +Test array_diff() function : usage variations - unexpected values for 'array2' argument +--SKIPIF-- + + +--FILE-- +getMessage(), "\n"; + } + $iterator++; + } + fclose($fp); + echo "Done"; +} +?> +--EXPECT-- +*** Testing array_diff() : usage variations *** + +-- Iteration 1 --array_diff(): Argument #2 must be of type array, int given + +-- Iteration 2 --array_diff(): Argument #2 must be of type array, int given + +-- Iteration 3 --array_diff(): Argument #2 must be of type array, int given + +-- Iteration 4 --array_diff(): Argument #2 must be of type array, int given + +-- Iteration 5 --array_diff(): Argument #2 must be of type array, float given + +-- Iteration 6 --array_diff(): Argument #2 must be of type array, float given + +-- Iteration 7 --array_diff(): Argument #2 must be of type array, float given + +-- Iteration 8 --array_diff(): Argument #2 must be of type array, float given + +-- Iteration 9 --array_diff(): Argument #2 must be of type array, float given + +-- Iteration 10 --array_diff(): Argument #2 must be of type array, null given + +-- Iteration 11 --array_diff(): Argument #2 must be of type array, null given + +-- Iteration 12 --array_diff(): Argument #2 must be of type array, true given + +-- Iteration 13 --array_diff(): Argument #2 must be of type array, false given + +-- Iteration 14 --array_diff(): Argument #2 must be of type array, true given + +-- Iteration 15 --array_diff(): Argument #2 must be of type array, false given + +-- Iteration 16 --array_diff(): Argument #2 must be of type array, string given + +-- Iteration 17 --array_diff(): Argument #2 must be of type array, string given + +-- Iteration 18 --array_diff(): Argument #2 must be of type array, string given + +-- Iteration 19 --array_diff(): Argument #2 must be of type array, string given + +-- Iteration 20 --array_diff(): Argument #2 must be of type array, string given + +-- Iteration 21 --array_diff(): Argument #2 must be of type array, string given + +-- Iteration 22 --array_diff(): Argument #2 must be of type array, string given + +-- Iteration 23 --array_diff(): Argument #2 must be of type array, classA given + +-- Iteration 24 --array_diff(): Argument #2 must be of type array, null given + +-- Iteration 25 --array_diff(): Argument #2 must be of type array, null given + +-- Iteration 26 --array_diff(): Argument #2 must be of type array, resource given +Done diff --git a/tests/std/array/array_diff_variation3.phpt b/tests/std/array/array_diff_variation3.phpt new file mode 100644 index 00000000..557b9166 --- /dev/null +++ b/tests/std/array/array_diff_variation3.phpt @@ -0,0 +1,189 @@ +--TEST-- +Test array_diff() function : usage variations - array with different data types as values +--SKIPIF-- + + +--FILE-- + array(), + +/*2*/ +"int" => array( + // int data + 0, + 1, + 12345, + -2345), + +/*3*/ +"float" => array( + // float data + 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5), + +/*4*/ +"null" => array( + // null data + NULL, + null), + +/*5*/ +"boolean" => array( + // boolean data + true, + false, + TRUE, + FALSE), + +/*6*/ +"empty" => array( + // empty data + "", + ''), + +/*7*/ +"string" => array( + // string data + "string", + 'string', + $heredoc), + +/*8*/ +"binary" => array( + // binary data + b"binary", + (binary)"binary"), + +/*9*/ +"undefined" => array( + // undefined data + @$undefined_var), + +/*10*/ +"unset" => array( + // unset data + @$unset_var) +); + +// loop through each element of the array for arr1 +$iterator = 1; +foreach($values as $value) { + echo "\n Iteration: $iterator \n"; + var_dump( array_diff($value, $array) ); + $iterator++; +}; + +echo "Done"; +?> +--EXPECT-- +*** Testing array_diff() : usage variations *** + + Iteration: 1 +array(0) { +} + + Iteration: 2 +array(3) { + [0]=> + int(0) + [2]=> + int(12345) + [3]=> + int(-2345) +} + + Iteration: 3 +array(5) { + [0]=> + float(10.5) + [1]=> + float(-10.5) + [2]=> + float(123456789000) + [3]=> + float(1.23456789E-9) + [4]=> + float(0.5) +} + + Iteration: 4 +array(2) { + [0]=> + NULL + [1]=> + NULL +} + + Iteration: 5 +array(2) { + [1]=> + bool(false) + [3]=> + bool(false) +} + + Iteration: 6 +array(2) { + [0]=> + string(0) "" + [1]=> + string(0) "" +} + + Iteration: 7 +array(3) { + [0]=> + string(6) "string" + [1]=> + string(6) "string" + [2]=> + string(17) "This is a heredoc" +} + + Iteration: 8 +array(2) { + [0]=> + string(6) "binary" + [1]=> + string(6) "binary" +} + + Iteration: 9 +array(1) { + [0]=> + NULL +} + + Iteration: 10 +array(1) { + [0]=> + NULL +} +Done diff --git a/tests/std/array/array_diff_variation4.phpt b/tests/std/array/array_diff_variation4.phpt new file mode 100644 index 00000000..3ba95d96 --- /dev/null +++ b/tests/std/array/array_diff_variation4.phpt @@ -0,0 +1,183 @@ +--TEST-- +Test array_diff() function : usage variations - array with different data types as values +--SKIPIF-- + + +--FILE-- + array(), + +/*2*/ +"int" => array( + // int data + 0, + 1, + 12345, + -2345), + +/*3*/ +"float" => array( + // float data + 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5), + +/*4*/ +"null" => array( + // null data + NULL, + null), + +/*5*/ +"boolean" => array( + // boolean data + true, + false, + TRUE, + FALSE), + +/*6*/ +"empty" => array( + // empty data + "", + ''), + +/*7*/ +"string" => array( + // string data + "string", + 'string', + $heredoc), + +/*8*/ +"binary" => array( + // binary data + b"binary", + (binary)"binary"), + +/*9*/ +"undefined" => array( + // undefined data + @$undefined_var), + +/*10*/ +"unset" => array( + // unset data + @$unset_var) +); + +// loop through each element of the array for $arr2 +$iterator = 1; +foreach($values as $value) { + echo "\n Iteration: $iterator \n"; + var_dump( array_diff($array, $value) ); + $iterator++; +}; + +echo "Done"; +?> +--EXPECT-- +*** Testing array_diff() : usage variations *** + + Iteration: 1 +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + + Iteration: 2 +array(1) { + [1]=> + int(2) +} + + Iteration: 3 +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + + Iteration: 4 +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + + Iteration: 5 +array(1) { + [1]=> + int(2) +} + + Iteration: 6 +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + + Iteration: 7 +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + + Iteration: 8 +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + + Iteration: 9 +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + + Iteration: 10 +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +Done diff --git a/tests/std/array/array_diff_variation5.phpt b/tests/std/array/array_diff_variation5.phpt new file mode 100644 index 00000000..9c9369de --- /dev/null +++ b/tests/std/array/array_diff_variation5.phpt @@ -0,0 +1,113 @@ +--TEST-- +Test array_diff() function : usage variations - comparing integers, float +and string array values +--FILE-- + +--EXPECT-- +*** Testing array_diff() : usage variations *** +-- Compare integers and floats: -- +array(0) { +} +array(0) { +} +-- Compare integers and strings containing an integers: -- +array(0) { +} +array(0) { +} +-- Compare integers and strings containing floats: -- +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +array(3) { + [0]=> + string(4) "1.00" + [1]=> + string(4) "2.00" + [2]=> + string(4) "3.00" +} +-- Compare floats and strings containing integers: -- +array(0) { +} +array(0) { +} +-- Compare floats and strings containing floats: -- +array(3) { + [0]=> + float(1) + [1]=> + float(2) + [2]=> + float(3) +} +array(3) { + [0]=> + string(4) "1.00" + [1]=> + string(4) "2.00" + [2]=> + string(4) "3.00" +} +-- Compare strings containing integers and strings containing floats: -- +array(3) { + [0]=> + string(1) "1" + [1]=> + string(1) "2" + [2]=> + string(1) "3" +} +array(3) { + [0]=> + string(4) "1.00" + [1]=> + string(4) "2.00" + [2]=> + string(4) "3.00" +} +Done diff --git a/tests/std/array/array_diff_variation6.phpt b/tests/std/array/array_diff_variation6.phpt new file mode 100644 index 00000000..15cedc6c --- /dev/null +++ b/tests/std/array/array_diff_variation6.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test array_diff() function : usage variations - array containing duplicate keys and values +--FILE-- + 'd', 'b'); //duplicate key (0), duplicate value (b) +$array_assoc = array ('2' => 'c', //same key=>value pair, different order + '1' => 'b', + '0' => 'a', + 'b' => '3', //key and value from array_index swapped + 'c' => 2); //same as above, using integer + +var_dump(array_diff($array_index, $array_assoc)); +var_dump(array_diff($array_assoc, $array_index)); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_diff() : usage variations *** +array(1) { + [0]=> + string(1) "d" +} +array(3) { + [0]=> + string(1) "a" + ["b"]=> + string(1) "3" + ["c"]=> + int(2) +} +Done diff --git a/tests/std/array/array_diff_variation7.phpt b/tests/std/array/array_diff_variation7.phpt new file mode 100644 index 00000000..75374f1c --- /dev/null +++ b/tests/std/array/array_diff_variation7.phpt @@ -0,0 +1,92 @@ +--TEST-- +Test array_diff() function : usage variations - arrays containing referenced variables +--SKIPIF-- + + +--FILE-- + +--EXPECT-- +*** Testing array_diff() : usage variations *** +-- Basic Comparison -- +array(3) { + [0]=> + string(2) "&a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" +} +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +-- $a changed -- +array(3) { + [0]=> + string(2) "&a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" +} +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +-- Arrays referenced to each other -- +array(0) { +} +array(0) { +} +-- $arr1 changed -- +array(0) { +} +array(0) { +} +Done diff --git a/tests/std/array/array_diff_variation8.phpt b/tests/std/array/array_diff_variation8.phpt new file mode 100644 index 00000000..0035f580 --- /dev/null +++ b/tests/std/array/array_diff_variation8.phpt @@ -0,0 +1,198 @@ +--TEST-- +Test array_diff() function : usage variations - associative arrays containing different data types +--SKIPIF-- + +--FILE-- + '1', 'b' => '2', 'c' => '3'); + // get an unset variable + $unset_var = 10; + unset($unset_var); + // get a resource variable + $fp = fopen(__FILE__, "r"); + // get a heredoc string + $heredoc = << 0, '1' => 0), + array("one" => 1, 'two' => 2, "three" => 1, 4 => 1), + // arrays with float values + /*3*/ + array("float1" => 2.3333, "float2" => 2.3333), + array("f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => 1.2), + // arrays with string values + /*5*/ + array(111 => "\tHello", "red" => "col\tor", 2 => "\v\fworld", 3 => "\tHello"), + array(111 => '\tHello', "red" => 'col\tor', 2 => '\v\fworld', 3 => '\tHello'), + array(1 => "hello", "heredoc" => $heredoc, $heredoc), + // array with object, unset variable and resource variable + /*8*/ + array(11 => new classA(), "unset" => @$unset_var, "resource" => $fp, new classA(), $fp), + ); + // loop through each sub-array of $inputs to check the behavior of array_unique() + $iterator = 1; + foreach ($inputs as $input) { + echo "-- Iteration {$iterator} --\n"; + var_dump(array_diff($array, $input)); + var_dump(array_diff($input, $array)); + $iterator++; + } + fclose($fp); + echo "Done"; +} +?> +--EXPECTF-- +*** Testing array_diff() : usage variations *** +-- Iteration 1 -- +array(3) { + ["a"]=> + string(1) "1" + ["b"]=> + string(1) "2" + ["c"]=> + string(1) "3" +} +array(2) { + [0]=> + int(0) + [1]=> + int(0) +} +-- Iteration 2 -- +array(1) { + ["c"]=> + string(1) "3" +} +array(0) { +} +-- Iteration 3 -- +array(3) { + ["a"]=> + string(1) "1" + ["b"]=> + string(1) "2" + ["c"]=> + string(1) "3" +} +array(2) { + ["float1"]=> + float(2.3333) + ["float2"]=> + float(2.3333) +} +-- Iteration 4 -- +array(3) { + ["a"]=> + string(1) "1" + ["b"]=> + string(1) "2" + ["c"]=> + string(1) "3" +} +array(4) { + ["f1"]=> + float(1.2) + ["f2"]=> + float(3.33) + [3]=> + float(4.89999922839999) + ["f4"]=> + float(1.2) +} +-- Iteration 5 -- +array(3) { + ["a"]=> + string(1) "1" + ["b"]=> + string(1) "2" + ["c"]=> + string(1) "3" +} +array(4) { + [111]=> + string(6) " Hello" + ["red"]=> + string(6) "col or" + [2]=> + string(7) " world" + [3]=> + string(6) " Hello" +} +-- Iteration 6 -- +array(3) { + ["a"]=> + string(1) "1" + ["b"]=> + string(1) "2" + ["c"]=> + string(1) "3" +} +array(4) { + [111]=> + string(7) "\tHello" + ["red"]=> + string(7) "col\tor" + [2]=> + string(9) "\v\fworld" + [3]=> + string(7) "\tHello" +} +-- Iteration 7 -- +array(3) { + ["a"]=> + string(1) "1" + ["b"]=> + string(1) "2" + ["c"]=> + string(1) "3" +} +array(3) { + [1]=> + string(5) "hello" + ["heredoc"]=> + string(11) "Hello world" + [2]=> + string(11) "Hello world" +} +-- Iteration 8 -- +array(3) { + ["a"]=> + string(1) "1" + ["b"]=> + string(1) "2" + ["c"]=> + string(1) "3" +} +array(5) { + [11]=> + object(classA)#%d (0) { + } + ["unset"]=> + NULL + ["resource"]=> + resource(%d) of type (stream) + [12]=> + object(classA)#%d (0) { + } + [13]=> + resource(%d) of type (stream) +} +Done diff --git a/tests/std/array/array_diff_variation9.phpt b/tests/std/array/array_diff_variation9.phpt new file mode 100644 index 00000000..3a956e99 --- /dev/null +++ b/tests/std/array/array_diff_variation9.phpt @@ -0,0 +1,118 @@ +--TEST-- +Test array_diff() function : usage variations - multidimensional arrays +--FILE-- + array (1, 2, 3), + 'sub_array2' => array ('a', 'b', 'c')); +$array2 = array('sub_arraya' => array (1, 3, 5), + 'sub_arrayb' => array ('a', 'z', 'y')); + +echo "-- Compare two 2-D arrays --\n"; +var_dump(array_diff($array1, $array2)); +var_dump(array_diff($array2, $array1)); + +echo "\n-- Compare subarrays from two 2-D arrays --\n"; +var_dump(array_diff($array1['sub_array1'], $array2['sub_arraya'])); +var_dump(array_diff($array2['sub_arraya'], $array1['sub_array1'])); + +var_dump(array_diff($array1['sub_array2'], $array2['sub_arrayb'])); +var_dump(array_diff($array2['sub_arrayb'], $array1['sub_array1'])); + +echo "\n-- Compare a subarray from one 2-D array and one 2-D array --\n"; +var_dump(array_diff($array1['sub_array1'], $array2)); +var_dump(array_diff($array1, $array2['sub_arraya'])); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_diff() : usage variations *** +-- Compare two 2-D arrays -- + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d +array(0) { +} + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d +array(0) { +} + +-- Compare subarrays from two 2-D arrays -- +array(1) { + [1]=> + int(2) +} +array(1) { + [2]=> + int(5) +} +array(2) { + [1]=> + string(1) "b" + [2]=> + string(1) "c" +} +array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "z" + [2]=> + string(1) "y" +} + +-- Compare a subarray from one 2-D array and one 2-D array -- + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d +array(2) { + ["sub_array1"]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["sub_array2"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +Done diff --git a/tests/std/array/array_fill.phpt b/tests/std/array/array_fill.phpt new file mode 100644 index 00000000..cfc2126d --- /dev/null +++ b/tests/std/array/array_fill.phpt @@ -0,0 +1,345 @@ +--TEST-- +basic array_fill test +--FILE-- + +--EXPECT-- +=========================== +bool(true) +start: 0 num: 0 value: array(0) { +} +=========================== +bool(false) +start: 0 num: 0 value: array(0) { +} +=========================== +NULL +start: 0 num: 0 value: array(0) { +} +=========================== +string(1) "d" +start: 0 num: 0 value: array(0) { +} +=========================== +string(1) "e" +start: 0 num: 0 value: array(0) { +} +=========================== +string(1) "f" +start: 0 num: 0 value: array(0) { +} +=========================== +bool(true) +start: 0 num: 1 value: array(1) { + [0]=> + bool(true) +} +=========================== +bool(false) +start: 0 num: 1 value: array(1) { + [0]=> + bool(false) +} +=========================== +NULL +start: 0 num: 1 value: array(1) { + [0]=> + NULL +} +=========================== +string(1) "d" +start: 0 num: 1 value: array(1) { + [0]=> + string(1) "d" +} +=========================== +string(1) "e" +start: 0 num: 1 value: array(1) { + [0]=> + string(1) "e" +} +=========================== +string(1) "f" +start: 0 num: 1 value: array(1) { + [0]=> + string(1) "f" +} +=========================== +bool(true) +start: 0 num: 2 value: array(2) { + [0]=> + bool(true) + [1]=> + bool(true) +} +=========================== +bool(false) +start: 0 num: 2 value: array(2) { + [0]=> + bool(false) + [1]=> + bool(false) +} +=========================== +NULL +start: 0 num: 2 value: array(2) { + [0]=> + NULL + [1]=> + NULL +} +=========================== +string(1) "d" +start: 0 num: 2 value: array(2) { + [0]=> + string(1) "d" + [1]=> + string(1) "d" +} +=========================== +string(1) "e" +start: 0 num: 2 value: array(2) { + [0]=> + string(1) "e" + [1]=> + string(1) "e" +} +=========================== +string(1) "f" +start: 0 num: 2 value: array(2) { + [0]=> + string(1) "f" + [1]=> + string(1) "f" +} +=========================== +bool(true) +start: 1 num: 0 value: array(0) { +} +=========================== +bool(false) +start: 1 num: 0 value: array(0) { +} +=========================== +NULL +start: 1 num: 0 value: array(0) { +} +=========================== +string(1) "d" +start: 1 num: 0 value: array(0) { +} +=========================== +string(1) "e" +start: 1 num: 0 value: array(0) { +} +=========================== +string(1) "f" +start: 1 num: 0 value: array(0) { +} +=========================== +bool(true) +start: 1 num: 1 value: array(1) { + [1]=> + bool(true) +} +=========================== +bool(false) +start: 1 num: 1 value: array(1) { + [1]=> + bool(false) +} +=========================== +NULL +start: 1 num: 1 value: array(1) { + [1]=> + NULL +} +=========================== +string(1) "d" +start: 1 num: 1 value: array(1) { + [1]=> + string(1) "d" +} +=========================== +string(1) "e" +start: 1 num: 1 value: array(1) { + [1]=> + string(1) "e" +} +=========================== +string(1) "f" +start: 1 num: 1 value: array(1) { + [1]=> + string(1) "f" +} +=========================== +bool(true) +start: 1 num: 2 value: array(2) { + [1]=> + bool(true) + [2]=> + bool(true) +} +=========================== +bool(false) +start: 1 num: 2 value: array(2) { + [1]=> + bool(false) + [2]=> + bool(false) +} +=========================== +NULL +start: 1 num: 2 value: array(2) { + [1]=> + NULL + [2]=> + NULL +} +=========================== +string(1) "d" +start: 1 num: 2 value: array(2) { + [1]=> + string(1) "d" + [2]=> + string(1) "d" +} +=========================== +string(1) "e" +start: 1 num: 2 value: array(2) { + [1]=> + string(1) "e" + [2]=> + string(1) "e" +} +=========================== +string(1) "f" +start: 1 num: 2 value: array(2) { + [1]=> + string(1) "f" + [2]=> + string(1) "f" +} +=========================== +bool(true) +start: 2 num: 0 value: array(0) { +} +=========================== +bool(false) +start: 2 num: 0 value: array(0) { +} +=========================== +NULL +start: 2 num: 0 value: array(0) { +} +=========================== +string(1) "d" +start: 2 num: 0 value: array(0) { +} +=========================== +string(1) "e" +start: 2 num: 0 value: array(0) { +} +=========================== +string(1) "f" +start: 2 num: 0 value: array(0) { +} +=========================== +bool(true) +start: 2 num: 1 value: array(1) { + [2]=> + bool(true) +} +=========================== +bool(false) +start: 2 num: 1 value: array(1) { + [2]=> + bool(false) +} +=========================== +NULL +start: 2 num: 1 value: array(1) { + [2]=> + NULL +} +=========================== +string(1) "d" +start: 2 num: 1 value: array(1) { + [2]=> + string(1) "d" +} +=========================== +string(1) "e" +start: 2 num: 1 value: array(1) { + [2]=> + string(1) "e" +} +=========================== +string(1) "f" +start: 2 num: 1 value: array(1) { + [2]=> + string(1) "f" +} +=========================== +bool(true) +start: 2 num: 2 value: array(2) { + [2]=> + bool(true) + [3]=> + bool(true) +} +=========================== +bool(false) +start: 2 num: 2 value: array(2) { + [2]=> + bool(false) + [3]=> + bool(false) +} +=========================== +NULL +start: 2 num: 2 value: array(2) { + [2]=> + NULL + [3]=> + NULL +} +=========================== +string(1) "d" +start: 2 num: 2 value: array(2) { + [2]=> + string(1) "d" + [3]=> + string(1) "d" +} +=========================== +string(1) "e" +start: 2 num: 2 value: array(2) { + [2]=> + string(1) "e" + [3]=> + string(1) "e" +} +=========================== +string(1) "f" +start: 2 num: 2 value: array(2) { + [2]=> + string(1) "f" + [3]=> + string(1) "f" +} diff --git a/tests/std/array/array_fill_basic.phpt b/tests/std/array/array_fill_basic.phpt new file mode 100644 index 00000000..a613f5a2 --- /dev/null +++ b/tests/std/array/array_fill_basic.phpt @@ -0,0 +1,91 @@ +--TEST-- +Test array_fill() function : basic functionality +--FILE-- + +--EXPECT-- +*** Testing array_fill() : basic functionality *** +-- Iteration 1 -- +array(2) { + [0]=> + NULL + [1]=> + NULL +} +-- Iteration 2 -- +array(2) { + [0]=> + int(0) + [1]=> + int(0) +} +-- Iteration 3 -- +array(2) { + [0]=> + int(1) + [1]=> + int(1) +} +-- Iteration 4 -- +array(2) { + [0]=> + float(1.5) + [1]=> + float(1.5) +} +-- Iteration 5 -- +array(2) { + [0]=> + string(2) "hi" + [1]=> + string(2) "hi" +} +-- Iteration 6 -- +array(2) { + [0]=> + string(2) "hi" + [1]=> + string(2) "hi" +} +-- Iteration 7 -- +array(2) { + [0]=> + string(5) "Hello" + [1]=> + string(5) "Hello" +} +Done diff --git a/tests/std/array/array_fill_error.phpt b/tests/std/array/array_fill_error.phpt new file mode 100644 index 00000000..9b04f755 --- /dev/null +++ b/tests/std/array/array_fill_error.phpt @@ -0,0 +1,21 @@ +--TEST-- +Test array_fill() function : error conditions +--FILE-- +getMessage() . "\n"; +} + +?> +--EXPECT-- +*** Testing array_fill() : error conditions *** +array_fill(): Argument #2 ($count) must be greater than or equal to 0 diff --git a/tests/std/array/array_fill_error2.phpt b/tests/std/array/array_fill_error2.phpt new file mode 100644 index 00000000..054a52aa --- /dev/null +++ b/tests/std/array/array_fill_error2.phpt @@ -0,0 +1,20 @@ +--TEST-- +Test array_fill() function : error conditions - count is too large +--SKIPIF-- +--FILE-- +getMessage() . "\n"; +} + +// calling array_fill() with 'count' equals to INT_MAX +$array = array_fill(0, $intMax, 1); + +?> +--EXPECTF-- +%SFatal error: Possible integer overflow in memory allocation (%d * %d + %d) in %s diff --git a/tests/std/array/array_fill_keys.phpt b/tests/std/array/array_fill_keys.phpt new file mode 100644 index 00000000..eebfd0aa --- /dev/null +++ b/tests/std/array/array_fill_keys.phpt @@ -0,0 +1,40 @@ +--TEST-- +basic array_fill_keys test +--INI-- +precision=14 +--FILE-- + +--EXPECT-- +array(0) { +} +array(2) { + ["foo"]=> + NULL + ["bar"]=> + NULL +} +array(4) { + [5]=> + int(123) + ["foo"]=> + int(123) + [10]=> + int(123) + ["1.23"]=> + int(123) +} +array(4) { + ["test"]=> + string(0) "" + [1]=> + string(0) "" + [10]=> + string(0) "" + [100]=> + string(0) "" +} diff --git a/tests/std/array/array_fill_keys_variation1.phpt b/tests/std/array/array_fill_keys_variation1.phpt new file mode 100644 index 00000000..2f210823 --- /dev/null +++ b/tests/std/array/array_fill_keys_variation1.phpt @@ -0,0 +1,73 @@ +--TEST-- +Test array_fill_keys() function : variation of parameter +--SKIPIF-- + +--FILE-- + 2, "strk1" => "strv1", 4, $simpleStr); + var_dump(array_fill_keys($keyedArray, $simpleStr)); + echo "\n-- Testing array_fill_keys() function with mixed array --\n"; + $mixedArray = array($fp, $obj, $simpleStr, $emptyArr, 2, $bool, $float); + var_dump(array_fill_keys($mixedArray, $simpleStr)); + fclose($fp); + echo "Done"; +} +?> +--EXPECTF-- +*** Testing array_fill_keys() : parameter variations *** + +-- Testing array_fill_keys() function with empty arguments -- +array(0) { +} + +-- Testing array_fill_keys() function with keyed array -- +array(4) { + [2]=> + string(6) "simple" + ["strv1"]=> + string(6) "simple" + [4]=> + string(6) "simple" + ["simple"]=> + string(6) "simple" +} + +-- Testing array_fill_keys() function with mixed array -- + +Warning: Array to string conversion in %s on line %d +array(7) { + ["Resource id #%d"]=> + string(6) "simple" + ["Class A object"]=> + string(6) "simple" + ["simple"]=> + string(6) "simple" + ["Array"]=> + string(6) "simple" + [2]=> + string(6) "simple" + [""]=> + string(6) "simple" + ["2.4"]=> + string(6) "simple" +} +Done diff --git a/tests/std/array/array_fill_keys_variation2.phpt b/tests/std/array/array_fill_keys_variation2.phpt new file mode 100644 index 00000000..15d0bfbf --- /dev/null +++ b/tests/std/array/array_fill_keys_variation2.phpt @@ -0,0 +1,72 @@ +--TEST-- +Test array_fill_keys() function : variation of parameter +--FILE-- + +--EXPECT-- +*** Testing array_fill_keys() : parameter variations *** + +-- Testing array_fill_keys() function with reference value -- +array(2) { + ["one"]=> + string(6) "simple" + ["two"]=> + string(6) "simple" +} + +-- Testing array_fill_keys() function with reference keys -- +array(2) { + ["one"]=> + string(6) "simple" + ["simple"]=> + string(6) "simple" +} +array(2) { + ["one"]=> + string(6) "simple" + ["simple"]=> + string(6) "simple" +} + +-- Testing array_fill_keys() function with reference array input -- +array(2) { + ["one"]=> + string(3) "bob" + ["two"]=> + string(3) "bob" +} +Done diff --git a/tests/std/array/array_fill_keys_variation3.phpt b/tests/std/array/array_fill_keys_variation3.phpt new file mode 100644 index 00000000..a800965a --- /dev/null +++ b/tests/std/array/array_fill_keys_variation3.phpt @@ -0,0 +1,28 @@ +--TEST-- +Test array_fill_keys() function : variation of parameter +--FILE-- + +--EXPECTF-- +*** Testing array_fill_keys() : parameter variations *** + +-- Testing array_fill_keys() function with unusual second arguments -- +array(2) { + ["one"]=> + resource(%d) of type (stream) + ["two"]=> + resource(%d) of type (stream) +} +Done diff --git a/tests/std/array/array_fill_keys_variation4.phpt b/tests/std/array/array_fill_keys_variation4.phpt new file mode 100644 index 00000000..995a30c2 --- /dev/null +++ b/tests/std/array/array_fill_keys_variation4.phpt @@ -0,0 +1,82 @@ +--TEST-- +Test array_fill_keys() function : variation of parameter +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +*** Testing array_fill_keys() : parameter variations *** + +-- Testing array_fill_keys() function with float -- +array(1) { + ["one"]=> + float(2.4) +} + +-- Testing array_fill_keys() function with null -- +array(1) { + ["one"]=> + NULL +} + +-- Testing array_fill_keys() function with object -- +array(1) { + ["one"]=> + object(classA)#%d (0) { + } +} + +-- Testing array_fill_keys() function with boolean -- +array(1) { + ["one"]=> + bool(false) +} + +-- Testing array_fill_keys() function with resource -- +array(1) { + ["one"]=> + resource(%d) of type (stream) +} + +-- Testing array_fill_keys() function with unset var -- + +Warning: Undefined variable $unset_var in %s on line %d +array(1) { + ["one"]=> + NULL +} +Done diff --git a/tests/std/array/array_fill_object.phpt b/tests/std/array/array_fill_object.phpt new file mode 100644 index 00000000..474c17f7 --- /dev/null +++ b/tests/std/array/array_fill_object.phpt @@ -0,0 +1,403 @@ +--TEST-- +Test array_fill() function : usage variations - various object values for 'val' argument +--SKIPIF-- + +--FILE-- +member1 = $value1; + $this->var2 = $value2; + } +} +// child class which inherits parent class test1 +class Child_test1 extends Test1 +{ + public $member2; + function __construct($value1, $value2, $value3) + { + parent::__construct($value1, $value2); + $this->member2 = $value3; + } +} +//class with private member, static member, constant and constructor to initialize the private member +class Test2 +{ + const test2_constant = "test2"; + public static $test2_static = 0; + private $member1; + var $var1 = 30; + var $var2; + function __construct($value1, $value2) + { + $this->member1 = $value1; + $this->var2 = $value2; + } +} +// child class which inherits parent class test2 +class Child_test2 extends Test2 +{ + private $member1; + function __construct($value1, $value2, $value3) + { + parent::__construct($value1, $value2); + $this->member1 = $value3; + } +} +// class with protected member, static member, constant and consturctor to initialize the protected member +class Test3 +{ + const test3_constant = "test3"; + public static $test3_static = 0; + protected $member1; + var $var1 = 30; + var $var2; + function __construct($value1, $value2) + { + $this->member1 = $value1; + $this->var2 = $value2; + } +} +// child class which inherits parent class test3 +class Child_test3 extends Test3 +{ + protected $member1; + function __construct($value1, $value2, $value3) + { + parent::__construct($value1, $value2); + $this->member1 = $value3; + } +} +// class with public, private, protected members, static, constant members and constructor to initialize all the members +class Test4 +{ + const test4_constant = "test4"; + public static $test4_static = 0; + public $member1; + private $member2; + protected $member3; + function __construct($value1, $value2, $value3) + { + $this->member1 = $value1; + $this->member2 = $value2; + $this->member3 = $value3; + } +} +// child class which inherits parent class test4 +class Child_test4 extends Test4 +{ + var $var1; + function __construct($value1, $value2, $value3, $value4) + { + parent::__construct($value1, $value2, $value3); + $this->var1 = $value4; + } +} +// abstract class with public, private, protected members +abstract class AbstractClass +{ + public $member1; + private $member2; + protected $member3; + var $var1 = 30; + abstract protected function display(); +} +// implement abstract 'AbstractClass' class +class ConcreteClass1 extends AbstractClass +{ + protected function display() + { + echo "class name is ConcreteClass1 \n"; + } +} +// declarationn of the interface 'iTemplate' +interface iTemplate +{ + public function display(); +} +// implement the interface 'iTemplate' +class Template1 implements iTemplate +{ + public function display() + { + echo "class name is Template1\n"; + } +} +function main() +{ + /* + * testing array_fill() by passing various object values for 'val' argument + */ + echo "*** Testing array_fill() : usage variations ***\n"; + // Initialise function arguments not being substituted + $start_key = 0; + $num = 2; + //array of object values for 'val' argument + $objects = array( + /* 1 */ + new Test(), + new Test1(100, 101), + new Child_test1(100, 101, 102), + new Test2(100, 101), + /* 5 */ + new Child_test2(100, 101, 102), + new Test3(100, 101), + new Child_test3(100, 101, 102), + new Test4(100, 101, 102), + new Child_test4(100, 101, 102, 103), + new ConcreteClass1(), + /* 11 */ + new Template1(), + ); + // loop through each element of the array for 'val' argument + // check the working of array_fill() + echo "--- Testing array_fill() with different object values for 'val' argument ---\n"; + $counter = 1; + for ($index = 0; $index < count($objects); $index++) { + echo "-- Iteration {$counter} --\n"; + $val = $objects[$index]; + var_dump(array_fill($start_key, $num, $val)); + $counter++; + } + echo "Done"; +} +?> +--EXPECTF-- +*** Testing array_fill() : usage variations *** +--- Testing array_fill() with different object values for 'val' argument --- +-- Iteration 1 -- +array(2) { + [0]=> + object(Test)#%d (0) { + } + [1]=> + object(Test)#%d (0) { + } +} +-- Iteration 2 -- +array(2) { + [0]=> + object(Test1)#%d (3) { + ["member1"]=> + int(100) + ["var1"]=> + int(30) + ["var2"]=> + int(101) + } + [1]=> + object(Test1)#%d (3) { + ["member1"]=> + int(100) + ["var1"]=> + int(30) + ["var2"]=> + int(101) + } +} +-- Iteration 3 -- +array(2) { + [0]=> + object(Child_test1)#%d (4) { + ["member1"]=> + int(100) + ["var1"]=> + int(30) + ["var2"]=> + int(101) + ["member2"]=> + int(102) + } + [1]=> + object(Child_test1)#%d (4) { + ["member1"]=> + int(100) + ["var1"]=> + int(30) + ["var2"]=> + int(101) + ["member2"]=> + int(102) + } +} +-- Iteration 4 -- +array(2) { + [0]=> + object(Test2)#%d (3) { + ["member1":"Test2":private]=> + int(100) + ["var1"]=> + int(30) + ["var2"]=> + int(101) + } + [1]=> + object(Test2)#%d (3) { + ["member1":"Test2":private]=> + int(100) + ["var1"]=> + int(30) + ["var2"]=> + int(101) + } +} +-- Iteration 5 -- +array(2) { + [0]=> + object(Child_test2)#%d (4) { + ["member1":"Test2":private]=> + int(100) + ["var1"]=> + int(30) + ["var2"]=> + int(101) + ["member1":"Child_test2":private]=> + int(102) + } + [1]=> + object(Child_test2)#%d (4) { + ["member1":"Test2":private]=> + int(100) + ["var1"]=> + int(30) + ["var2"]=> + int(101) + ["member1":"Child_test2":private]=> + int(102) + } +} +-- Iteration 6 -- +array(2) { + [0]=> + object(Test3)#%d (3) { + ["member1":protected]=> + int(100) + ["var1"]=> + int(30) + ["var2"]=> + int(101) + } + [1]=> + object(Test3)#%d (3) { + ["member1":protected]=> + int(100) + ["var1"]=> + int(30) + ["var2"]=> + int(101) + } +} +-- Iteration 7 -- +array(2) { + [0]=> + object(Child_test3)#%d (3) { + ["member1":protected]=> + int(102) + ["var1"]=> + int(30) + ["var2"]=> + int(101) + } + [1]=> + object(Child_test3)#%d (3) { + ["member1":protected]=> + int(102) + ["var1"]=> + int(30) + ["var2"]=> + int(101) + } +} +-- Iteration 8 -- +array(2) { + [0]=> + object(Test4)#%d (3) { + ["member1"]=> + int(100) + ["member2":"Test4":private]=> + int(101) + ["member3":protected]=> + int(102) + } + [1]=> + object(Test4)#%d (3) { + ["member1"]=> + int(100) + ["member2":"Test4":private]=> + int(101) + ["member3":protected]=> + int(102) + } +} +-- Iteration 9 -- +array(2) { + [0]=> + object(Child_test4)#%d (4) { + ["member1"]=> + int(100) + ["member2":"Test4":private]=> + int(101) + ["member3":protected]=> + int(102) + ["var1"]=> + int(103) + } + [1]=> + object(Child_test4)#%d (4) { + ["member1"]=> + int(100) + ["member2":"Test4":private]=> + int(101) + ["member3":protected]=> + int(102) + ["var1"]=> + int(103) + } +} +-- Iteration 10 -- +array(2) { + [0]=> + object(ConcreteClass1)#%d (4) { + ["member1"]=> + NULL + ["member2":"AbstractClass":private]=> + NULL + ["member3":protected]=> + NULL + ["var1"]=> + int(30) + } + [1]=> + object(ConcreteClass1)#%d (4) { + ["member1"]=> + NULL + ["member2":"AbstractClass":private]=> + NULL + ["member3":protected]=> + NULL + ["var1"]=> + int(30) + } +} +-- Iteration 11 -- +array(2) { + [0]=> + object(Template1)#%d (0) { + } + [1]=> + object(Template1)#%d (0) { + } +} +Done diff --git a/tests/std/array/array_fill_variation3.phpt b/tests/std/array/array_fill_variation3.phpt new file mode 100644 index 00000000..7963ea12 --- /dev/null +++ b/tests/std/array/array_fill_variation3.phpt @@ -0,0 +1,102 @@ +--TEST-- +Test array_fill() function : usage variations - unexpected values for 'val' argument +--SKIPIF-- + + +--FILE-- + +--EXPECTF-- +*** Testing array_fill() : usage variations *** +--- Testing array_fill() with different values for 'val' argument --- +-- Iteration 1 -- +array(2) { + [0]=> + string(0) "" + [1]=> + string(0) "" +} +-- Iteration 2 -- +array(2) { + [0]=> + string(0) "" + [1]=> + string(0) "" +} +-- Iteration 3 -- +array(2) { + [0]=> + object(test)#%d (1) { + ["t"]=> + int(10) + } + [1]=> + object(test)#%d (1) { + ["t"]=> + int(10) + } +} +-- Iteration 4 -- +array(2) { + [0]=> + NULL + [1]=> + NULL +} +-- Iteration 5 -- +array(2) { + [0]=> + NULL + [1]=> + NULL +} +Done diff --git a/tests/std/array/array_fill_variation4.phpt b/tests/std/array/array_fill_variation4.phpt new file mode 100644 index 00000000..79df201e --- /dev/null +++ b/tests/std/array/array_fill_variation4.phpt @@ -0,0 +1,163 @@ +--TEST-- +Test array_fill() function : usage variations - using return value of array_fill for 'val' argument +--FILE-- + +--EXPECT-- +*** Testing array_fill() : variation *** +*** Filling 2 dimensional array with all basic valid values *** +-- Iteration 1 -- +array(2) { + [0]=> + array(2) { + [0]=> + NULL + [1]=> + NULL + } + [1]=> + array(2) { + [0]=> + NULL + [1]=> + NULL + } +} +-- Iteration 2 -- +array(2) { + [0]=> + array(2) { + [0]=> + int(0) + [1]=> + int(0) + } + [1]=> + array(2) { + [0]=> + int(0) + [1]=> + int(0) + } +} +-- Iteration 3 -- +array(2) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(1) + } + [1]=> + array(2) { + [0]=> + int(1) + [1]=> + int(1) + } +} +-- Iteration 4 -- +array(2) { + [0]=> + array(2) { + [0]=> + float(1) + [1]=> + float(1) + } + [1]=> + array(2) { + [0]=> + float(1) + [1]=> + float(1) + } +} +-- Iteration 5 -- +array(2) { + [0]=> + array(2) { + [0]=> + string(2) "hi" + [1]=> + string(2) "hi" + } + [1]=> + array(2) { + [0]=> + string(2) "hi" + [1]=> + string(2) "hi" + } +} +-- Iteration 6 -- +array(2) { + [0]=> + array(2) { + [0]=> + string(2) "hi" + [1]=> + string(2) "hi" + } + [1]=> + array(2) { + [0]=> + string(2) "hi" + [1]=> + string(2) "hi" + } +} +-- Iteration 7 -- +array(2) { + [0]=> + array(2) { + [0]=> + string(5) "Hello" + [1]=> + string(5) "Hello" + } + [1]=> + array(2) { + [0]=> + string(5) "Hello" + [1]=> + string(5) "Hello" + } +} +Done diff --git a/tests/std/array/array_fill_variation5.phpt b/tests/std/array/array_fill_variation5.phpt new file mode 100644 index 00000000..43dd5fd3 --- /dev/null +++ b/tests/std/array/array_fill_variation5.phpt @@ -0,0 +1,289 @@ +--TEST-- +Test array_fill() function : usage variations - different types of array values for 'val' argument +--SKIPIF-- + +--FILE-- + "Hi" , 2 => "Hello"), + array("Saffron" , "White" , "Green"), + /* 5 */ array('color' => 'red' , 'item' => 'pen'), + array( 'color' => 'red' , 2 => 'green ' ), + array("colour" => "red" , "item" => "pen"), + array( TRUE => "red" , FALSE => "green" ), + array( true => "red" , FALSE => "green" ), + /* 10 */ array( 1 => "Hi" , "color" => "red" , 'item' => 'pen'), + array( NULL => "Hi", '1' => "Hello" , "1" => "Green"), + array( ""=>1, "color" => "green"), + /* 13 */ array('Saffron' , 'White' , 'Green') +); + +// loop through each element of the values array for 'val' argument +// check the working of array_fill() +echo "--- Testing array_fill() with different types of array values for 'val' argument ---\n"; +$counter = 1; +for($i = 0; $i < count($values); $i++) +{ + echo "-- Iteration $counter --\n"; + $val = $values[$i]; + + var_dump( array_fill($start_key , $num , $val) ); + + $counter++; +} + +echo "Done"; +?> +--EXPECT-- +*** Testing array_fill() : usage variations *** +--- Testing array_fill() with different types of array values for 'val' argument --- +-- Iteration 1 -- +array(2) { + [0]=> + array(0) { + } + [1]=> + array(0) { + } +} +-- Iteration 2 -- +array(2) { + [0]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + } + [1]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + } +} +-- Iteration 3 -- +array(2) { + [0]=> + array(2) { + [1]=> + string(2) "Hi" + [2]=> + string(5) "Hello" + } + [1]=> + array(2) { + [1]=> + string(2) "Hi" + [2]=> + string(5) "Hello" + } +} +-- Iteration 4 -- +array(2) { + [0]=> + array(3) { + [0]=> + string(7) "Saffron" + [1]=> + string(5) "White" + [2]=> + string(5) "Green" + } + [1]=> + array(3) { + [0]=> + string(7) "Saffron" + [1]=> + string(5) "White" + [2]=> + string(5) "Green" + } +} +-- Iteration 5 -- +array(2) { + [0]=> + array(2) { + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + } + [1]=> + array(2) { + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + } +} +-- Iteration 6 -- +array(2) { + [0]=> + array(2) { + ["color"]=> + string(3) "red" + [2]=> + string(6) "green " + } + [1]=> + array(2) { + ["color"]=> + string(3) "red" + [2]=> + string(6) "green " + } +} +-- Iteration 7 -- +array(2) { + [0]=> + array(2) { + ["colour"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + } + [1]=> + array(2) { + ["colour"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + } +} +-- Iteration 8 -- +array(2) { + [0]=> + array(2) { + [1]=> + string(3) "red" + [0]=> + string(5) "green" + } + [1]=> + array(2) { + [1]=> + string(3) "red" + [0]=> + string(5) "green" + } +} +-- Iteration 9 -- +array(2) { + [0]=> + array(2) { + [1]=> + string(3) "red" + [0]=> + string(5) "green" + } + [1]=> + array(2) { + [1]=> + string(3) "red" + [0]=> + string(5) "green" + } +} +-- Iteration 10 -- +array(2) { + [0]=> + array(3) { + [1]=> + string(2) "Hi" + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + } + [1]=> + array(3) { + [1]=> + string(2) "Hi" + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + } +} +-- Iteration 11 -- +array(2) { + [0]=> + array(2) { + [""]=> + string(2) "Hi" + [1]=> + string(5) "Green" + } + [1]=> + array(2) { + [""]=> + string(2) "Hi" + [1]=> + string(5) "Green" + } +} +-- Iteration 12 -- +array(2) { + [0]=> + array(2) { + [""]=> + int(1) + ["color"]=> + string(5) "green" + } + [1]=> + array(2) { + [""]=> + int(1) + ["color"]=> + string(5) "green" + } +} +-- Iteration 13 -- +array(2) { + [0]=> + array(3) { + [0]=> + string(7) "Saffron" + [1]=> + string(5) "White" + [2]=> + string(5) "Green" + } + [1]=> + array(3) { + [0]=> + string(7) "Saffron" + [1]=> + string(5) "White" + [2]=> + string(5) "Green" + } +} +Done diff --git a/tests/std/array/array_fill_variation6.phpt b/tests/std/array/array_fill_variation6.phpt new file mode 100644 index 00000000..c9ca2616 --- /dev/null +++ b/tests/std/array/array_fill_variation6.phpt @@ -0,0 +1,21 @@ +--TEST-- +array_fill(): last element +--SKIPIF-- + +--FILE-- +getMessage(), PHP_EOL; +} +?> +--EXPECT-- +int(1) +bool(true) +Cannot add element to the array as the next element is already occupied diff --git a/tests/std/array/array_filter.phpt b/tests/std/array/array_filter.phpt new file mode 100644 index 00000000..6b7f45ad --- /dev/null +++ b/tests/std/array/array_filter.phpt @@ -0,0 +1,77 @@ +--TEST-- +basic array_filter test +--FILE-- + 1, "b" => 2, "c" => 3, "d" => 4, "e" => 5); + $array2 = array(6, 7, 8, 9, 10, 11, 12, 0); + $array3 = array(TRUE, FALSE, NULL); + echo "Odd :\n"; + var_dump(array_filter($array1, "odd")); + var_dump(array_filter($array2, "odd")); + var_dump(array_filter($array3, "odd")); + echo "Even:\n"; + var_dump(array_filter($array1, "even")); + var_dump(array_filter($array2, "even")); + var_dump(array_filter($array3, "even")); + var_dump(array_filter(array())); +} +?> +--EXPECT-- +Odd : +array(3) { + ["a"]=> + int(1) + ["c"]=> + int(3) + ["e"]=> + int(5) +} +array(3) { + [1]=> + int(7) + [3]=> + int(9) + [5]=> + int(11) +} +array(1) { + [0]=> + bool(true) +} +Even: +array(2) { + ["b"]=> + int(2) + ["d"]=> + int(4) +} +array(5) { + [0]=> + int(6) + [2]=> + int(8) + [4]=> + int(10) + [6]=> + int(12) + [7]=> + int(0) +} +array(2) { + [1]=> + bool(false) + [2]=> + NULL +} +array(0) { +} diff --git a/tests/std/array/array_filter_basic.phpt b/tests/std/array/array_filter_basic.phpt new file mode 100644 index 00000000..f13af677 --- /dev/null +++ b/tests/std/array/array_filter_basic.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test array_filter() function : basic functionality +--FILE-- + +--EXPECT-- +*** Testing array_filter() : basic functionality *** +array(2) { + [1]=> + int(2) + [3]=> + int(0) +} +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [4]=> + int(-1) +} +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [4]=> + int(-1) +} +Done diff --git a/tests/std/array/array_filter_object.phpt b/tests/std/array/array_filter_object.phpt new file mode 100644 index 00000000..3b0c4776 --- /dev/null +++ b/tests/std/array/array_filter_object.phpt @@ -0,0 +1,151 @@ +--TEST-- +Test array_filter() function : object functionality +--FILE-- +var1; + } +} + +// class without members +class EmptyClass +{ +} + +// abstract class +abstract class AbstractClass +{ + protected $var2 = 5; + abstract function emptyMethod(); +} + +// class deriving above abstract class +class ChildClass extends AbstractClass +{ + private $var3; + public function emptyMethod() { + echo "defined in child"; + } +} + +// class with final method +class FinalClass +{ + private $var4; + final function finalMethod() { + echo 'This cannot be overloaded'; + } +} + +// class with static members +class StaticClass +{ + static $var5 = 5; + public static function staticMethod() { + echo 'this is static method'; + } +} + +function always_true($input) +{ + return true; +} + +// Callback function which returns always false +function always_false($input) +{ + return false; +} + +function main() { +echo "*** Testing array_filter() : object functionality ***\n"; + +// 'input' array containing objects as elements +$input = array( + new SimpleClass(), + new EmptyClass(), + new ChildClass(), + new FinalClass(), + new StaticClass() +); + + +// with default callback +var_dump( array_filter($input) ); + +// with always_true callback function +var_dump( array_filter($input, "always_true") ); + +// with always_false callback function +var_dump( array_filter($input, "always_false") ); + +echo "Done"; +} +?> +--EXPECTF-- +*** Testing array_filter() : object functionality *** +array(5) { + [0]=> + object(SimpleClass)#%d (1) { + ["var1"]=> + int(10) + } + [1]=> + object(EmptyClass)#%d (0) { + } + [2]=> + object(ChildClass)#%d (2) { + ["var2":protected]=> + int(5) + ["var3":"ChildClass":private]=> + NULL + } + [3]=> + object(FinalClass)#%d (1) { + ["var4":"FinalClass":private]=> + NULL + } + [4]=> + object(StaticClass)#%d (0) { + } +} +array(5) { + [0]=> + object(SimpleClass)#%d (1) { + ["var1"]=> + int(10) + } + [1]=> + object(EmptyClass)#%d (0) { + } + [2]=> + object(ChildClass)#%d (2) { + ["var2":protected]=> + int(5) + ["var3":"ChildClass":private]=> + NULL + } + [3]=> + object(FinalClass)#%d (1) { + ["var4":"FinalClass":private]=> + NULL + } + [4]=> + object(StaticClass)#%d (0) { + } +} +array(0) { +} +Done diff --git a/tests/std/array/array_filter_variation10.phpt b/tests/std/array/array_filter_variation10.phpt new file mode 100644 index 00000000..4688efab --- /dev/null +++ b/tests/std/array/array_filter_variation10.phpt @@ -0,0 +1,79 @@ +--TEST-- +Test array_filter() function : usage variations - using the array keys inside 'callback' +--SKIPIF-- + +--FILE-- + 4; +} + +function main() { +echo "*** Testing array_filter() : usage variations - using array keys in 'callback' ***\n"; + +$input = array(0, 1, -1, 10, 100, 1000, 'Hello', null); + +var_dump( array_filter($input, 'dump', true) ); + +echo "*** Testing array_filter() : usage variations - 'callback' filters based on key value ***\n"; + +var_dump( array_filter($input, 'dump2', true) ); + +echo "*** Testing array_filter() with various use types ***\n"; + +$mixed = array(1 => 'a', 2 => 'b', 'a' => 1, 'b' => 2); + +var_dump(array_filter($mixed, 'is_numeric', ARRAY_FILTER_USE_KEY)); + +var_dump(array_filter($mixed, 'is_numeric', 0)); + +echo "Done"; +} +?> +--EXPECT-- +*** Testing array_filter() : usage variations - using array keys in 'callback' *** +0 = 0 +1 = 1 +2 = -1 +3 = 10 +4 = 100 +5 = 1000 +6 = Hello +7 = +array(0) { +} +*** Testing array_filter() : usage variations - 'callback' filters based on key value *** +array(3) { + [5]=> + int(1000) + [6]=> + string(5) "Hello" + [7]=> + NULL +} +*** Testing array_filter() with various use types *** +array(2) { + [1]=> + string(1) "a" + [2]=> + string(1) "b" +} +array(2) { + ["a"]=> + int(1) + ["b"]=> + int(2) +} +Done diff --git a/tests/std/array/array_filter_variation3.phpt b/tests/std/array/array_filter_variation3.phpt new file mode 100644 index 00000000..fd4b90b9 --- /dev/null +++ b/tests/std/array/array_filter_variation3.phpt @@ -0,0 +1,216 @@ +--TEST-- +Test array_filter() function : usage variations - Different types of array for 'input' argument +--SKIPIF-- + +--FILE-- + 'one', 'zero' => 0, -2 => "value"), //associative array + array("one" => 1, null => 'null', 5 => "float", true => 1, "" => 'empty'), // associative array with different keys + array(1 => 'one', 2, "key" => 'value') // combinition of associative and non-associative array + +); + +// loop through each element of 'input' with default callback +for($count = 0; $count < count($input_values); $count++) +{ + echo "-- Iteration ".($count + 1). " --\n"; + var_dump( array_filter($input_values[$count]) ); + var_dump( array_filter($input_values[$count], 'always_true') ); + var_dump( array_filter($input_values[$count], 'always_false') ); +} + +echo "Done"; +} +?> +--EXPECT-- +*** Testing array_filter() : usage variations - different types of array for 'input' argument*** +-- Iteration 1 -- +array(5) { + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(-1) + [4]=> + int(28) + [5]=> + int(74) +} +array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(-1) + [4]=> + int(28) + [5]=> + int(74) +} +array(0) { +} +-- Iteration 2 -- +array(3) { + [1]=> + float(1.2) + [2]=> + float(1200) + [3]=> + float(0.0012) +} +array(4) { + [0]=> + float(0) + [1]=> + float(1.2) + [2]=> + float(1200) + [3]=> + float(0.0012) +} +array(0) { +} +-- Iteration 3 -- +array(3) { + [0]=> + string(6) "value1" + [1]=> + string(6) "value2" + [3]=> + string(1) " " +} +array(5) { + [0]=> + string(6) "value1" + [1]=> + string(6) "value2" + [2]=> + string(0) "" + [3]=> + string(1) " " + [4]=> + string(0) "" +} +array(0) { +} +-- Iteration 4 -- +array(2) { + [0]=> + bool(true) + [2]=> + bool(true) +} +array(4) { + [0]=> + bool(true) + [1]=> + bool(false) + [2]=> + bool(true) + [3]=> + bool(false) +} +array(0) { +} +-- Iteration 5 -- +array(0) { +} +array(2) { + [0]=> + NULL + [1]=> + NULL +} +array(0) { +} +-- Iteration 6 -- +array(2) { + [1]=> + string(3) "one" + [-2]=> + string(5) "value" +} +array(3) { + [1]=> + string(3) "one" + ["zero"]=> + int(0) + [-2]=> + string(5) "value" +} +array(0) { +} +-- Iteration 7 -- +array(4) { + ["one"]=> + int(1) + [""]=> + string(5) "empty" + [5]=> + string(5) "float" + [1]=> + int(1) +} +array(4) { + ["one"]=> + int(1) + [""]=> + string(5) "empty" + [5]=> + string(5) "float" + [1]=> + int(1) +} +array(0) { +} +-- Iteration 8 -- +array(3) { + [1]=> + string(3) "one" + [2]=> + int(2) + ["key"]=> + string(5) "value" +} +array(3) { + [1]=> + string(3) "one" + [2]=> + int(2) + ["key"]=> + string(5) "value" +} +array(0) { +} +Done diff --git a/tests/std/array/array_filter_variation4.phpt b/tests/std/array/array_filter_variation4.phpt new file mode 100644 index 00000000..6db83574 --- /dev/null +++ b/tests/std/array/array_filter_variation4.phpt @@ -0,0 +1,99 @@ +--TEST-- +Test array_filter() function : usage variations - Different types of 'callback' function +--FILE-- + 0 ) { + return true; + } + else { + return false; + } +} + +function main() { +echo "*** Testing array_filter() : usage variation - different 'callback' functions***\n"; + +// Initialize variables +$input = array(0, -1, 2, 3.4E-3, 'hello', "value", "key" => 4, 'null' => NULL); + +echo "-- Callback function without parameter and with return --\n"; +var_dump( array_filter($input, "callback1") ); + +echo "-- Callback function with parameter and without return --\n"; +var_dump( array_filter($input, "callback2") ); + +echo "-- Callback function without parameter and return --\n"; +var_dump( array_filter($input, "callback3") ); + +echo "-- Callback function with parameter and return --\n"; +var_dump( array_filter($input, "callback4") ); + +echo "Done"; +} +?> +--EXPECT-- +*** Testing array_filter() : usage variation - different 'callback' functions*** +-- Callback function without parameter and with return -- +array(8) { + [0]=> + int(0) + [1]=> + int(-1) + [2]=> + int(2) + [3]=> + float(0.0034) + [4]=> + string(5) "hello" + [5]=> + string(5) "value" + ["key"]=> + int(4) + ["null"]=> + NULL +} +-- Callback function with parameter and without return -- +array(0) { +} +-- Callback function without parameter and return -- +array(0) { +} +-- Callback function with parameter and return -- +array(5) { + [2]=> + int(2) + [3]=> + float(0.0034) + [4]=> + string(5) "hello" + [5]=> + string(5) "value" + ["key"]=> + int(4) +} +Done diff --git a/tests/std/array/array_filter_variation5.phpt b/tests/std/array/array_filter_variation5.phpt new file mode 100644 index 00000000..d5dd6f91 --- /dev/null +++ b/tests/std/array/array_filter_variation5.phpt @@ -0,0 +1,109 @@ +--TEST-- +Test array_filter() function : usage variations - 'input' argument with different false entries +--SKIPIF-- + +--FILE-- + +--EXPECT-- +*** Testing array_filter() : usage variations - different false elements in 'input' *** +array(0) { +} +array(16) { + [0]=> + bool(false) + [1]=> + bool(false) + [2]=> + string(0) "" + [3]=> + string(0) "" + [4]=> + int(0) + [5]=> + float(0) + [6]=> + NULL + [7]=> + NULL + [8]=> + string(1) "0" + [9]=> + string(1) "0" + [10]=> + array(0) { + } + [11]=> + bool(false) + [12]=> + bool(false) + [13]=> + string(0) "" + [14]=> + NULL + [15]=> + NULL +} +array(0) { +} +Done diff --git a/tests/std/array/array_filter_variation6.phpt b/tests/std/array/array_filter_variation6.phpt new file mode 100644 index 00000000..adc1d4ff --- /dev/null +++ b/tests/std/array/array_filter_variation6.phpt @@ -0,0 +1,90 @@ +--TEST-- +Test array_filter() function : usage variations - 'input' array containing references +--SKIPIF-- + +--FILE-- + 5) { + return true; + } + else { + return false; + } +} + +function main() { +echo "*** Testing array_filter() : usage variations - 'input' containing references ***\n"; + +// initializing variables +$value1 = array(1, 2, 8); +$value2 = array(5, 6, 4); +$input = array(&$value1, 10, &$value2, 'value'); + +// with 'callback' argument +var_dump( array_filter($input, 'callback') ); + +// with default 'callback' argument +var_dump( array_filter($input) ); + +echo "Done"; +} +?> +--EXPECT-- +*** Testing array_filter() : usage variations - 'input' containing references *** +array(4) { + [0]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(8) + } + [1]=> + int(10) + [2]=> + &array(3) { + [0]=> + int(5) + [1]=> + int(6) + [2]=> + int(4) + } + [3]=> + string(5) "value" +} +array(4) { + [0]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(8) + } + [1]=> + int(10) + [2]=> + &array(3) { + [0]=> + int(5) + [1]=> + int(6) + [2]=> + int(4) + } + [3]=> + string(5) "value" +} +Done diff --git a/tests/std/array/array_filter_variation7.phpt b/tests/std/array/array_filter_variation7.phpt new file mode 100644 index 00000000..cea5e7ae --- /dev/null +++ b/tests/std/array/array_filter_variation7.phpt @@ -0,0 +1,62 @@ +--TEST-- +Test array_filter() function : usage variations - anonymous callback functions +--FILE-- + 1); }) ); + +// anonymous callback function with null argument +echo "Anonymous callback function with null argument\n"; +var_dump( array_filter($input, function() { return true; }) ); + +// anonymous callback function with argument and null statement +echo "Anonymous callback function with regular argument and null statement\n"; +var_dump( array_filter($input, function($input) { }) ); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_filter() : usage variations - Anonymous callback functions *** +Anonymous callback function with regular parameter and statement +array(4) { + [3]=> + int(10) + [4]=> + int(100) + [5]=> + int(1000) + [6]=> + string(5) "Hello" +} +Anonymous callback function with null argument +array(8) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(-1) + [3]=> + int(10) + [4]=> + int(100) + [5]=> + int(1000) + [6]=> + string(5) "Hello" + [7]=> + NULL +} +Anonymous callback function with regular argument and null statement +array(0) { +} +Done diff --git a/tests/std/array/array_filter_variation8.phpt b/tests/std/array/array_filter_variation8.phpt new file mode 100644 index 00000000..79978898 --- /dev/null +++ b/tests/std/array/array_filter_variation8.phpt @@ -0,0 +1,151 @@ +--TEST-- +Test array_filter() function : usage variations - Callback function with different return values +--FILE-- + +--EXPECT-- +*** Testing array_filter() : usage variations - callback function with different return values*** +callback function with int return value +array(9) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(-1) + [3]=> + int(10) + [4]=> + int(100) + [5]=> + int(1000) + [6]=> + string(5) "Hello" + [7]=> + NULL + [8]=> + bool(true) +} +callback function with float return value +array(9) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(-1) + [3]=> + int(10) + [4]=> + int(100) + [5]=> + int(1000) + [6]=> + string(5) "Hello" + [7]=> + NULL + [8]=> + bool(true) +} +callback function with string return value +array(9) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(-1) + [3]=> + int(10) + [4]=> + int(100) + [5]=> + int(1000) + [6]=> + string(5) "Hello" + [7]=> + NULL + [8]=> + bool(true) +} +callback function with null return value +array(0) { +} +callback function with array as return value +array(9) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(-1) + [3]=> + int(10) + [4]=> + int(100) + [5]=> + int(1000) + [6]=> + string(5) "Hello" + [7]=> + NULL + [8]=> + bool(true) +} +Done diff --git a/tests/std/array/array_filter_variation9.phpt b/tests/std/array/array_filter_variation9.phpt new file mode 100644 index 00000000..e0000612 --- /dev/null +++ b/tests/std/array/array_filter_variation9.phpt @@ -0,0 +1,67 @@ +--TEST-- +Test array_filter() function : usage variations - built-in functions as 'callback' argument +--FILE-- +getMessage(), "\n"; +} + +// using language construct 'isset' as 'callback' +try { + var_dump( array_filter($input, 'isset') ); +} catch (TypeError $e) { + echo $e->getMessage(), "\n"; +} + +echo "Done"; +?> +--EXPECT-- +*** Testing array_filter() : usage variations - built-in functions as 'callback' argument *** +array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(-1) + [3]=> + int(10) + [4]=> + int(100) + [5]=> + int(1000) +} +array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(-1) + [3]=> + int(10) + [4]=> + int(100) + [5]=> + int(1000) +} +array_filter(): Argument #2 ($callback) must be a valid callback or null, function "echo" not found or invalid function name +array_filter(): Argument #2 ($callback) must be a valid callback or null, function "isset" not found or invalid function name +Done diff --git a/tests/std/array/array_find_basic.phpt b/tests/std/array/array_find_basic.phpt new file mode 100644 index 00000000..b98debee --- /dev/null +++ b/tests/std/array/array_find_basic.phpt @@ -0,0 +1,51 @@ +--TEST-- +Test array_find() function : basic functionality +--SKIPIF-- + + +--FILE-- + 1, "b" => 2, "c" => 3, "d" => 4, "e" => 5]; + $array2 = [1, 2, 3, 4, 5]; + var_dump(array_find($array1, fn($value, $key) => $value > 3)); + var_dump(array_find($array2, fn($value, $key) => $value > 3)); + var_dump(array_find($array2, fn($value, $key) => $value > 5)); + var_dump(array_find([], fn($value, $key) => true)); + var_dump(array_find($array1, fn($value, $key) => $key === "c")); + var_dump(array_find($array1, fn($value, $key) => false)); + var_dump(array_find($array1, 'even')); + var_dump(array_find($array1, 'return_nothing')); + var_dump(array_find($array1, ['EvenClass', 'even'])); + var_dump(array_find($array1, "EvenClass::even")); +} +?> +--EXPECT-- +int(4) +int(4) +NULL +NULL +int(3) +NULL +int(2) +NULL +int(2) +int(2) diff --git a/tests/std/array/array_find_key_basic.phpt b/tests/std/array/array_find_key_basic.phpt new file mode 100644 index 00000000..6b972237 --- /dev/null +++ b/tests/std/array/array_find_key_basic.phpt @@ -0,0 +1,51 @@ +--TEST-- +Test array_find_key() function : basic functionality +--SKIPIF-- + + +--FILE-- + 1, "b" => 2, "c" => 3, "d" => 4, "e" => 5]; + $array2 = [1, 2, 3, 4, 5]; + var_dump(array_find_key($array1, fn($value, $key) => $value > 3)); + var_dump(array_find_key($array2, fn($value, $key) => $value > 3)); + var_dump(array_find_key($array2, fn($value, $key) => $value > 5)); + var_dump(array_find_key([], fn($value, $key) => true)); + var_dump(array_find_key($array1, fn($value, $key) => $key === "c")); + var_dump(array_find_key($array1, fn($value, $key) => false)); + var_dump(array_find_key($array1, 'even')); + var_dump(array_find_key($array1, 'return_nothing')); + var_dump(array_find_key($array1, ['EvenClass', 'even'])); + var_dump(array_find_key($array1, "EvenClass::even")); +} +?> +--EXPECT-- +string(1) "d" +int(3) +NULL +NULL +string(1) "c" +NULL +string(1) "b" +NULL +string(1) "b" +string(1) "b" diff --git a/tests/std/array/array_find_types.phpt b/tests/std/array/array_find_types.phpt new file mode 100644 index 00000000..9c6e5e96 --- /dev/null +++ b/tests/std/array/array_find_types.phpt @@ -0,0 +1,210 @@ +--TEST-- +basic array_find test +--SKIPIF-- + + +--FILE-- +a = "1"; + +$array = [ + ...[0, 1, 2, -1, 034, 0X4A], + ...[0.0, 1.2, 1.2e3, 1.2e-3], + ...['value1', "value2", '', " ", ""], + ...[true, false, TRUE, FALSE], + ...[null, NULL], + ...[1 => 'one', 'zero' => 0, -2 => "value"], + ...["one" => 1, 5 => "float", true => 1, "" => 'empty'], + ...[1 => 'one', 2, "key" => 'value'], + ...[new stdClass(), $stdClass, (object)['b' => 2]], + ...[[], [1, 2, 3], [-1 => 1, -2 => 2]], + ...[@$undefined_var] +]; + +echo "*** Dumping each key value pair. ***". PHP_EOL; +var_dump(array_find($array, function ($value, $key) { + var_dump($key, $value); + + return false; +})); + +echo "*** Dumping only first key value pair. ***". PHP_EOL; +var_dump(array_find($array, function ($value, $key) { + var_dump($key, $value); + + return true; +})); + +echo "*** Returning each value. ***". PHP_EOL; +foreach (array_keys($array) as $key) { + var_dump(array_find($array, function ($value, $arrayKey) use ($key) { + return $arrayKey === $key; + })); +} +?> +--EXPECT-- +*** Dumping each key value pair. *** +int(0) +int(0) +int(1) +int(1) +int(2) +int(2) +int(3) +int(-1) +int(4) +int(28) +int(5) +int(74) +int(6) +float(0) +int(7) +float(1.2) +int(8) +float(1200) +int(9) +float(0.0012) +int(10) +string(6) "value1" +int(11) +string(6) "value2" +int(12) +string(0) "" +int(13) +string(1) " " +int(14) +string(0) "" +int(15) +bool(true) +int(16) +bool(false) +int(17) +bool(true) +int(18) +bool(false) +int(19) +NULL +int(20) +NULL +int(21) +string(3) "one" +string(4) "zero" +int(0) +int(22) +string(5) "value" +string(3) "one" +int(1) +int(23) +string(5) "float" +int(24) +int(1) +string(0) "" +string(5) "empty" +int(25) +string(3) "one" +int(26) +int(2) +string(3) "key" +string(5) "value" +int(27) +object(stdClass)#2 (0) { +} +int(28) +object(stdClass)#1 (1) { + ["a"]=> + string(1) "1" +} +int(29) +object(stdClass)#3 (1) { + ["b"]=> + int(2) +} +int(30) +array(0) { +} +int(31) +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +int(32) +array(2) { + [-1]=> + int(1) + [-2]=> + int(2) +} +int(33) +NULL +NULL +*** Dumping only first key value pair. *** +int(0) +int(0) +int(0) +*** Returning each value. *** +int(0) +int(1) +int(2) +int(-1) +int(28) +int(74) +float(0) +float(1.2) +float(1200) +float(0.0012) +string(6) "value1" +string(6) "value2" +string(0) "" +string(1) " " +string(0) "" +bool(true) +bool(false) +bool(true) +bool(false) +NULL +NULL +string(3) "one" +int(0) +string(5) "value" +int(1) +string(5) "float" +int(1) +string(5) "empty" +string(3) "one" +int(2) +string(5) "value" +object(stdClass)#2 (0) { +} +object(stdClass)#1 (1) { + ["a"]=> + string(1) "1" +} +object(stdClass)#3 (1) { + ["b"]=> + int(2) +} +array(0) { +} +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +array(2) { + [-1]=> + int(1) + [-2]=> + int(2) +} +NULL diff --git a/tests/std/array/array_flip.phpt b/tests/std/array/array_flip.phpt new file mode 100644 index 00000000..b16063a4 --- /dev/null +++ b/tests/std/array/array_flip.phpt @@ -0,0 +1,37 @@ +--TEST-- +basic array_flip test +--FILE-- + 1, + "b" => 1, + "c" => 2, + "z" => 0, + "d" => TRUE, + "E" => FALSE, + "F" => NULL, + 0 => "G", + 1 => "h", + 2 => "i"); +$trans = array_flip($trans); +var_dump($trans); +?> +--EXPECTF-- +Warning:%S Can only flip string and integer values, entry skipped in %s on line %d + +Warning:%S Can only flip string and integer values, entry skipped in %s on line %d + +Warning:%S Can only flip string and integer values, entry skipped in %s on line %d +array(6) { + [1]=> + string(1) "b" + [2]=> + string(1) "c" + [0]=> + string(1) "z" + ["G"]=> + int(0) + ["h"]=> + int(1) + ["i"]=> + int(2) +} diff --git a/tests/std/array/array_flip_basic.phpt b/tests/std/array/array_flip_basic.phpt new file mode 100644 index 00000000..3edcd3b5 --- /dev/null +++ b/tests/std/array/array_flip_basic.phpt @@ -0,0 +1,66 @@ +--TEST-- +Test array_flip() function : basic functionality +--FILE-- + 1, "key2" => 2); +var_dump( array_flip($input) ); + +// associative arrays - key as numeric +$input = array(1 => 'one', 2 => "two"); +var_dump( array_flip($input) ); + +// combination of associative and non-associative array +$input = array(1 => 'one','two', 3 => 'three', 4, "five" => 5); +var_dump( array_flip($input) ); +echo "Done"; +?> +--EXPECT-- +*** Testing array_flip() : basic functionality *** +array(2) { + [1]=> + int(0) + [2]=> + int(1) +} +array(2) { + ["value1"]=> + int(0) + ["value2"]=> + int(1) +} +array(2) { + [1]=> + string(4) "key1" + [2]=> + string(4) "key2" +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(5) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) + [4]=> + int(4) + [5]=> + string(4) "five" +} +Done diff --git a/tests/std/array/array_flip_variation2.phpt b/tests/std/array/array_flip_variation2.phpt new file mode 100644 index 00000000..f147fa9d --- /dev/null +++ b/tests/std/array/array_flip_variation2.phpt @@ -0,0 +1,99 @@ +--TEST-- +Test array_flip() function : usage variations - 'input' array with different keys +--SKIPIF-- + +--FILE-- + 'int_key', // expected: value will be replaced by 'bool_key3' + -2 => 'negative_key', + 012 => 'octal_key', + 0x34 => 'hex_key', + + // string keys + 'key' => 'string_key1', + "two" => 'string_key2', + '' => 'string_key3', + "" => 'string_key4', + " " => 'string_key5', + + // bool keys + true => 'bool_key1', + false => 'bool_key2', + TRUE => 'bool_key3', + FALSE => 'bool_key4', + + // null keys + null => 'null_key1', // expected: value will be replaced by 'null_key2' + NULL => 'null_key2', + + // binary key + "a".chr(0)."b" => 'binary_key1', + b"binary" => 'binary_key2', + + //heredoc keys + $empty_heredoc => 'empty_heredoc', + $simple_heredoc => 'simple_heredoc', + $multiline_heredoc => 'multiline_heredoc', +); + +var_dump( array_flip($input) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_flip() : different keys for 'input' array argument *** +array(13) { + ["bool_key4"]=> + int(0) + ["bool_key3"]=> + int(1) + ["negative_key"]=> + int(-2) + ["octal_key"]=> + int(10) + ["hex_key"]=> + int(52) + ["string_key1"]=> + string(3) "key" + ["string_key2"]=> + string(3) "two" + ["empty_heredoc"]=> + string(0) "" + ["string_key5"]=> + string(1) " " + ["binary_key1"]=> + string(3) "a%0b" + ["binary_key2"]=> + string(6) "binary" + ["simple_heredoc"]=> + string(6) "simple" + ["multiline_heredoc"]=> + string(6%d) "multiline heredoc with 123 and +speci@! ch@r$...checking +and also" +} +Done diff --git a/tests/std/array/array_flip_variation3.phpt b/tests/std/array/array_flip_variation3.phpt new file mode 100644 index 00000000..32d7452d --- /dev/null +++ b/tests/std/array/array_flip_variation3.phpt @@ -0,0 +1,120 @@ +--TEST-- +Test array_flip() function : usage variations - 'input' argument with different valid values +--FILE-- + 1, + 'negative_value' => -2, + 'zero_value' => 0, + 'octal_value' => 012, + 'hex_value' => 0x23, + + // single quoted string value + 'empty_value1' => '', + 'space_value1' => ' ', + 'char_value1' => 'a', + 'string_value1' => 'string1', + 'numeric_value1' => '123', + 'special_char_value1' => '!@#$%', + 'whitespace1_value1' => '\t', + 'whitespace2_value1' => '\n', + 'null_char_value1' => '\0', + + // double quoted string value + 'empty_value2' => "", + 'space_value2' => " ", + 'char_value2' => "b", + 'string_value2' => "string2", + 'numeric_value2' => "456", + 'special_char_value2' => "^&*", + 'whitespace1_value2' => "\t", + 'whitespace2_value2' => "\n", + 'null_char_value2' => "\0", + 'binary_value' => "a".chr(0)."b", + + // heredoc string value + 'empty_heredoc' => $empty_heredoc, + 'simple_heredoc' => $simple_heredoc, + 'multiline_heredoc' => $multiline_heredoc, +); + +var_dump( array_flip($input) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_flip() : different valid values in 'input' array argument *** +array(24) { + [1]=> + string(9) "int_value" + [-2]=> + string(14) "negative_value" + [0]=> + string(10) "zero_value" + [10]=> + string(11) "octal_value" + [35]=> + string(9) "hex_value" + [""]=> + string(13) "empty_heredoc" + [" "]=> + string(12) "space_value2" + ["a"]=> + string(11) "char_value1" + ["string1"]=> + string(13) "string_value1" + [123]=> + string(14) "numeric_value1" + ["!@#$%"]=> + string(19) "special_char_value1" + ["\t"]=> + string(18) "whitespace1_value1" + ["\n"]=> + string(18) "whitespace2_value1" + ["\0"]=> + string(16) "null_char_value1" + ["b"]=> + string(11) "char_value2" + ["string2"]=> + string(13) "string_value2" + [456]=> + string(14) "numeric_value2" + ["^&*"]=> + string(19) "special_char_value2" + [" "]=> + string(18) "whitespace1_value2" + [" +"]=> + string(18) "whitespace2_value2" + ["%0"]=> + string(16) "null_char_value2" + ["a%0b"]=> + string(12) "binary_value" + ["simple"]=> + string(14) "simple_heredoc" + ["multiline heredoc with 123 and +speci@! ch@r$..checking +with also"]=> + string(17) "multiline_heredoc" +} +Done diff --git a/tests/std/array/array_flip_variation4.phpt b/tests/std/array/array_flip_variation4.phpt new file mode 100644 index 00000000..60d51ef0 --- /dev/null +++ b/tests/std/array/array_flip_variation4.phpt @@ -0,0 +1,88 @@ +--TEST-- +Test array_flip() function : usage variations - 'input' argument with different invalid values for keys +--SKIPIF-- +--FILE-- + 1.2, + 'float_value2' => 0.5, + 'flaot_value3' => 3.4E3, + 'flaot_value4' => 5.6E-6, + + // bool values + 'bool_value1' => true, + 'bool_value2' => false, + 'bool_value3' => TRUE, + 'bool_value4' => FALSE, + + // null values + 'null_value1' => null, + + // array value + 'array_value' => array(1), + + // object value + 'obj_value' => $obj, + + // resource value + 'resource_value' => $fp, +); + +var_dump( array_flip($input) ); + +// closing resource +fclose($fp); + +echo "Done"; +} +?> +--EXPECTF-- +*** Testing array_flip() : different invalid values in 'input' array argument *** + +Warning:%S Can only flip string and integer values, entry skipped in %s + +Warning:%S Can only flip string and integer values, entry skipped in %s + +Warning:%S Can only flip string and integer values, entry skipped in %s + +Warning:%S Can only flip string and integer values, entry skipped in %s + +Warning:%S Can only flip string and integer values, entry skipped in %s + +Warning:%S Can only flip string and integer values, entry skipped in %s + +Warning:%S Can only flip string and integer values, entry skipped in %s + +Warning:%S Can only flip string and integer values, entry skipped in %s + +Warning:%S Can only flip string and integer values, entry skipped in %s + +Warning:%S Can only flip string and integer values, entry skipped in %s + +Warning:%S Can only flip string and integer values, entry skipped in %s + +Warning:%S Can only flip string and integer values, entry skipped in %s +array(0) { +} +Done diff --git a/tests/std/array/array_flip_variation5.phpt b/tests/std/array/array_flip_variation5.phpt new file mode 100644 index 00000000..6e75648f --- /dev/null +++ b/tests/std/array/array_flip_variation5.phpt @@ -0,0 +1,79 @@ +--TEST-- +Test array_flip() function : usage variations - 'input' argument with repeatitive keys and values +--SKIPIF-- + +--FILE-- + 'value', 2 => 'VALUE', 1 => "VaLuE", 3 => 4, 3 => 5); +var_dump( array_flip($input) ); + +// array with string key repeatition +$input = array("key" => 1, "two" => 'TWO', 'three' => 3, 'key' => "FOUR"); +var_dump( array_flip($input) ); + +// array with bool key repeatition +$input = array(true => 1, false => 0, TRUE => -1); +var_dump( array_flip($input) ); + +// array with null key repeatition +$input = array(null => "Hello", NULL => 0); +var_dump( array_flip($input) ); + +// array with numeric value repeatition +$input = array('one' => 1, 'two' => 2, 3 => 1, "index" => 1); +var_dump( array_flip($input) ); + +//array with string value repeatition +$input = array('key1' => "value1", "key2" => '2', 'key3' => 'value1'); +var_dump( array_flip($input) ); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_flip() : 'input' array with repeatitive keys/values *** +array(3) { + ["VaLuE"]=> + int(1) + ["VALUE"]=> + int(2) + [5]=> + int(3) +} +array(3) { + ["FOUR"]=> + string(3) "key" + ["TWO"]=> + string(3) "two" + [3]=> + string(5) "three" +} +array(2) { + [-1]=> + int(1) + [0]=> + int(0) +} +array(1) { + [0]=> + string(0) "" +} +array(2) { + [1]=> + string(5) "index" + [2]=> + string(3) "two" +} +array(2) { + ["value1"]=> + string(4) "key3" + [2]=> + string(4) "key2" +} +Done diff --git a/tests/std/array/array_intersect_1.phpt b/tests/std/array/array_intersect_1.phpt new file mode 100644 index 00000000..72a9fa56 --- /dev/null +++ b/tests/std/array/array_intersect_1.phpt @@ -0,0 +1,370 @@ +--TEST-- +Test of the *intersect* bunch of functions (both assoc and non-assoc) +--FILE-- +priv_member = $val; + $this->public_member = $val; + } + static function comp_func_cr($a, $b) + { + if ($a->priv_member === $b->priv_member) { + return 0; + } + return $a->priv_member > $b->priv_member ? 1 : -1; + } +} +function comp_func($a, $b) +{ + if ($a === $b) { + return 0; + } + return $a > $b ? 1 : -1; +} +function comp_func_cr($a, $b) +{ + if ($a->public_member === $b->public_member) { + return 0; + } + return $a->public_member > $b->public_member ? 1 : -1; +} +function main() +{ + error_reporting(E_ALL); + $a = array("0.1" => new cr(9), "0.5" => new cr(12), 0 => new cr(23), 1 => new cr(4), 2 => new cr(-15)); + $b = array("0.2" => new cr(9), "0.5" => new cr(22), 0 => new cr(3), 1 => new cr(4), 2 => new cr(-15)); + /* array_uintersect() */ + echo "begin ------------ array_uintersect() ---------------------------\n"; + echo '$a=' . var_export($a, TRUE) . ";\n"; + echo '$b=' . var_export($b, TRUE) . ";\n"; + echo 'var_dump(array_uintersect($a, $b, "comp_func_cr"));' . "\n"; + var_dump(array_uintersect($a, $b, "comp_func_cr")); + echo "end ------------ array_uintersect() ---------------------------\n"; + /* array_uintersect_assoc() */ + echo "begin ------------ array_uintersect_assoc() ---------------------\n"; + echo '$a=' . var_export($a, TRUE) . ";\n"; + echo '$b=' . var_export($b, TRUE) . ";\n"; + echo 'var_dump(array_uintersect_assoc($a, $b, "comp_func_cr"));' . "\n"; + var_dump(array_uintersect_assoc($a, $b, "comp_func_cr")); + echo "end ------------ array_uintersect_assoc() ---------------------\n"; + /* array_uintersect_uassoc() - with ordinary function */ + echo "begin ------------ array_uintersect_uassoc() with ordinary func -\n"; + echo '$a=' . var_export($a, TRUE) . ";\n"; + echo '$b=' . var_export($b, TRUE) . ";\n"; + echo 'var_dump(array_uintersect_uassoc($a, $b, "comp_func_cr", "comp_func"));' . "\n"; + var_dump(array_uintersect_uassoc($a, $b, "comp_func_cr", "comp_func")); + echo "end ------------ array_uintersect_uassoc() with ordinary func -\n"; + /* array_uintersect_uassoc() - by method call */ + echo "begin ------------ array_uintersect_uassoc() with method --------\n"; + echo '$a=' . var_export($a, TRUE) . ";\n"; + echo '$b=' . var_export($b, TRUE) . ";\n"; + echo 'var_dump(array_uintersect_uassoc($a, $b, array("cr", "comp_func_cr"), "comp_func"));' . "\n"; + var_dump(array_uintersect_uassoc($a, $b, array("cr", "comp_func_cr"), "comp_func")); + echo "end ------------ array_uintersect_uassoc() with method --------\n"; +} +?> +--EXPECTF-- +begin ------------ array_uintersect() --------------------------- +$a=array ( + '0.1' => + \cr::__set_state(array( + 'priv_member' => 9, + 'public_member' => 9, + )), + '0.5' => + \cr::__set_state(array( + 'priv_member' => 12, + 'public_member' => 12, + )), + 0 => + \cr::__set_state(array( + 'priv_member' => 23, + 'public_member' => 23, + )), + 1 => + \cr::__set_state(array( + 'priv_member' => 4, + 'public_member' => 4, + )), + 2 => + \cr::__set_state(array( + 'priv_member' => -15, + 'public_member' => -15, + )), +); +$b=array ( + '0.2' => + \cr::__set_state(array( + 'priv_member' => 9, + 'public_member' => 9, + )), + '0.5' => + \cr::__set_state(array( + 'priv_member' => 22, + 'public_member' => 22, + )), + 0 => + \cr::__set_state(array( + 'priv_member' => 3, + 'public_member' => 3, + )), + 1 => + \cr::__set_state(array( + 'priv_member' => 4, + 'public_member' => 4, + )), + 2 => + \cr::__set_state(array( + 'priv_member' => -15, + 'public_member' => -15, + )), +); +var_dump(array_uintersect($a, $b, "comp_func_cr")); +array(3) { + ["0.1"]=> + object(cr)#%d (2) { + ["priv_member":"cr":private]=> + int(9) + ["public_member"]=> + int(9) + } + [1]=> + object(cr)#%d (2) { + ["priv_member":"cr":private]=> + int(4) + ["public_member"]=> + int(4) + } + [2]=> + object(cr)#%d (2) { + ["priv_member":"cr":private]=> + int(-15) + ["public_member"]=> + int(-15) + } +} +end ------------ array_uintersect() --------------------------- +begin ------------ array_uintersect_assoc() --------------------- +$a=array ( + '0.1' => + \cr::__set_state(array( + 'priv_member' => 9, + 'public_member' => 9, + )), + '0.5' => + \cr::__set_state(array( + 'priv_member' => 12, + 'public_member' => 12, + )), + 0 => + \cr::__set_state(array( + 'priv_member' => 23, + 'public_member' => 23, + )), + 1 => + \cr::__set_state(array( + 'priv_member' => 4, + 'public_member' => 4, + )), + 2 => + \cr::__set_state(array( + 'priv_member' => -15, + 'public_member' => -15, + )), +); +$b=array ( + '0.2' => + \cr::__set_state(array( + 'priv_member' => 9, + 'public_member' => 9, + )), + '0.5' => + \cr::__set_state(array( + 'priv_member' => 22, + 'public_member' => 22, + )), + 0 => + \cr::__set_state(array( + 'priv_member' => 3, + 'public_member' => 3, + )), + 1 => + \cr::__set_state(array( + 'priv_member' => 4, + 'public_member' => 4, + )), + 2 => + \cr::__set_state(array( + 'priv_member' => -15, + 'public_member' => -15, + )), +); +var_dump(array_uintersect_assoc($a, $b, "comp_func_cr")); +array(2) { + [1]=> + object(cr)#%d (2) { + ["priv_member":"cr":private]=> + int(4) + ["public_member"]=> + int(4) + } + [2]=> + object(cr)#%d (2) { + ["priv_member":"cr":private]=> + int(-15) + ["public_member"]=> + int(-15) + } +} +end ------------ array_uintersect_assoc() --------------------- +begin ------------ array_uintersect_uassoc() with ordinary func - +$a=array ( + '0.1' => + \cr::__set_state(array( + 'priv_member' => 9, + 'public_member' => 9, + )), + '0.5' => + \cr::__set_state(array( + 'priv_member' => 12, + 'public_member' => 12, + )), + 0 => + \cr::__set_state(array( + 'priv_member' => 23, + 'public_member' => 23, + )), + 1 => + \cr::__set_state(array( + 'priv_member' => 4, + 'public_member' => 4, + )), + 2 => + \cr::__set_state(array( + 'priv_member' => -15, + 'public_member' => -15, + )), +); +$b=array ( + '0.2' => + \cr::__set_state(array( + 'priv_member' => 9, + 'public_member' => 9, + )), + '0.5' => + \cr::__set_state(array( + 'priv_member' => 22, + 'public_member' => 22, + )), + 0 => + \cr::__set_state(array( + 'priv_member' => 3, + 'public_member' => 3, + )), + 1 => + \cr::__set_state(array( + 'priv_member' => 4, + 'public_member' => 4, + )), + 2 => + \cr::__set_state(array( + 'priv_member' => -15, + 'public_member' => -15, + )), +); +var_dump(array_uintersect_uassoc($a, $b, "comp_func_cr", "comp_func")); +array(2) { + [1]=> + object(cr)#%d (2) { + ["priv_member":"cr":private]=> + int(4) + ["public_member"]=> + int(4) + } + [2]=> + object(cr)#%d (2) { + ["priv_member":"cr":private]=> + int(-15) + ["public_member"]=> + int(-15) + } +} +end ------------ array_uintersect_uassoc() with ordinary func - +begin ------------ array_uintersect_uassoc() with method -------- +$a=array ( + '0.1' => + \cr::__set_state(array( + 'priv_member' => 9, + 'public_member' => 9, + )), + '0.5' => + \cr::__set_state(array( + 'priv_member' => 12, + 'public_member' => 12, + )), + 0 => + \cr::__set_state(array( + 'priv_member' => 23, + 'public_member' => 23, + )), + 1 => + \cr::__set_state(array( + 'priv_member' => 4, + 'public_member' => 4, + )), + 2 => + \cr::__set_state(array( + 'priv_member' => -15, + 'public_member' => -15, + )), +); +$b=array ( + '0.2' => + \cr::__set_state(array( + 'priv_member' => 9, + 'public_member' => 9, + )), + '0.5' => + \cr::__set_state(array( + 'priv_member' => 22, + 'public_member' => 22, + )), + 0 => + \cr::__set_state(array( + 'priv_member' => 3, + 'public_member' => 3, + )), + 1 => + \cr::__set_state(array( + 'priv_member' => 4, + 'public_member' => 4, + )), + 2 => + \cr::__set_state(array( + 'priv_member' => -15, + 'public_member' => -15, + )), +); +var_dump(array_uintersect_uassoc($a, $b, array("cr", "comp_func_cr"), "comp_func")); +array(2) { + [1]=> + object(cr)#%d (2) { + ["priv_member":"cr":private]=> + int(4) + ["public_member"]=> + int(4) + } + [2]=> + object(cr)#%d (2) { + ["priv_member":"cr":private]=> + int(-15) + ["public_member"]=> + int(-15) + } +} +end ------------ array_uintersect_uassoc() with method -------- diff --git a/tests/std/array/array_intersect_assoc_basic.phpt b/tests/std/array/array_intersect_assoc_basic.phpt new file mode 100644 index 00000000..d20cef75 --- /dev/null +++ b/tests/std/array/array_intersect_assoc_basic.phpt @@ -0,0 +1,63 @@ +--TEST-- +Test array_intersect_assoc() function : basic functionality +--FILE-- + 1, "two" => 2); + +// default key array for both $arr1 and $arr2 argument +var_dump( array_intersect_assoc($arr_default_keys, $arr_default_keys) ); + +// default key array for $arr1 and associative array for $arr2 argument +var_dump( array_intersect_assoc($arr_default_keys, $arr_associative) ); + +// associative array for $arr1 and default key array for $arr2 +var_dump( array_intersect_assoc($arr_associative, $arr_default_keys) ); + +// associative array for both $arr1 and $arr2 argument +var_dump( array_intersect_assoc($arr_associative, $arr_associative) ); + +// more arrays to be intersected +$arr3 = array(2, 3, 4); +var_dump( array_intersect_assoc($arr_default_keys, $arr_associative, $arr3) ); +var_dump( array_intersect_assoc($arr_associative, $arr_default_keys, $arr3, $arr_associative) ); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_intersect_assoc() : basic functionality *** +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(5) "hello" + [3]=> + string(5) "world" +} +array(0) { +} +array(0) { +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(0) { +} +array(0) { +} +Done diff --git a/tests/std/array/array_intersect_assoc_variation1.phpt b/tests/std/array/array_intersect_assoc_variation1.phpt new file mode 100644 index 00000000..245b9792 --- /dev/null +++ b/tests/std/array/array_intersect_assoc_variation1.phpt @@ -0,0 +1,183 @@ +--TEST-- +Test array_intersect_assoc() function : usage variations - unexpected values for 'array1' argument(Bug#43196) +--SKIPIF-- + + +--FILE-- + 1, "two" => 2); + // get an unset variable + $unset_var = null; + // already null + $undefined_var = null; + // heredoc string + $heredoc = <<getMessage(), "\n"; + } + // Calling array_intersect_assoc() with more arguments + try { + var_dump(array_intersect_assoc($unexpected_value, $array2, $arr3)); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + $iterator++; + } + // close the file resource used + fclose($fp); + echo "Done"; +} +?> +--EXPECT-- +*** Testing array_intersect_assoc() : Passing non-array values to $array1 argument *** + +-- Iteration 1 --array_intersect_assoc(): Argument #1 ($array) must be of type array, int given +array_intersect_assoc(): Argument #1 ($array) must be of type array, int given + +-- Iteration 2 --array_intersect_assoc(): Argument #1 ($array) must be of type array, int given +array_intersect_assoc(): Argument #1 ($array) must be of type array, int given + +-- Iteration 3 --array_intersect_assoc(): Argument #1 ($array) must be of type array, int given +array_intersect_assoc(): Argument #1 ($array) must be of type array, int given + +-- Iteration 4 --array_intersect_assoc(): Argument #1 ($array) must be of type array, int given +array_intersect_assoc(): Argument #1 ($array) must be of type array, int given + +-- Iteration 5 --array_intersect_assoc(): Argument #1 ($array) must be of type array, float given +array_intersect_assoc(): Argument #1 ($array) must be of type array, float given + +-- Iteration 6 --array_intersect_assoc(): Argument #1 ($array) must be of type array, float given +array_intersect_assoc(): Argument #1 ($array) must be of type array, float given + +-- Iteration 7 --array_intersect_assoc(): Argument #1 ($array) must be of type array, float given +array_intersect_assoc(): Argument #1 ($array) must be of type array, float given + +-- Iteration 8 --array_intersect_assoc(): Argument #1 ($array) must be of type array, float given +array_intersect_assoc(): Argument #1 ($array) must be of type array, float given + +-- Iteration 9 --array_intersect_assoc(): Argument #1 ($array) must be of type array, float given +array_intersect_assoc(): Argument #1 ($array) must be of type array, float given + +-- Iteration 10 --array_intersect_assoc(): Argument #1 ($array) must be of type array, null given +array_intersect_assoc(): Argument #1 ($array) must be of type array, null given + +-- Iteration 11 --array_intersect_assoc(): Argument #1 ($array) must be of type array, null given +array_intersect_assoc(): Argument #1 ($array) must be of type array, null given + +-- Iteration 12 --array_intersect_assoc(): Argument #1 ($array) must be of type array, true given +array_intersect_assoc(): Argument #1 ($array) must be of type array, true given + +-- Iteration 13 --array_intersect_assoc(): Argument #1 ($array) must be of type array, false given +array_intersect_assoc(): Argument #1 ($array) must be of type array, false given + +-- Iteration 14 --array_intersect_assoc(): Argument #1 ($array) must be of type array, true given +array_intersect_assoc(): Argument #1 ($array) must be of type array, true given + +-- Iteration 15 --array_intersect_assoc(): Argument #1 ($array) must be of type array, false given +array_intersect_assoc(): Argument #1 ($array) must be of type array, false given + +-- Iteration 16 --array_intersect_assoc(): Argument #1 ($array) must be of type array, string given +array_intersect_assoc(): Argument #1 ($array) must be of type array, string given + +-- Iteration 17 --array_intersect_assoc(): Argument #1 ($array) must be of type array, string given +array_intersect_assoc(): Argument #1 ($array) must be of type array, string given + +-- Iteration 18 --array_intersect_assoc(): Argument #1 ($array) must be of type array, string given +array_intersect_assoc(): Argument #1 ($array) must be of type array, string given + +-- Iteration 19 --array_intersect_assoc(): Argument #1 ($array) must be of type array, string given +array_intersect_assoc(): Argument #1 ($array) must be of type array, string given + +-- Iteration 20 --array_intersect_assoc(): Argument #1 ($array) must be of type array, string given +array_intersect_assoc(): Argument #1 ($array) must be of type array, string given + +-- Iteration 21 --array_intersect_assoc(): Argument #1 ($array) must be of type array, classA given +array_intersect_assoc(): Argument #1 ($array) must be of type array, classA given + +-- Iteration 22 --array_intersect_assoc(): Argument #1 ($array) must be of type array, null given +array_intersect_assoc(): Argument #1 ($array) must be of type array, null given + +-- Iteration 23 --array_intersect_assoc(): Argument #1 ($array) must be of type array, null given +array_intersect_assoc(): Argument #1 ($array) must be of type array, null given + +-- Iteration 24 --array_intersect_assoc(): Argument #1 ($array) must be of type array, resource given +array_intersect_assoc(): Argument #1 ($array) must be of type array, resource given +Done diff --git a/tests/std/array/array_intersect_assoc_variation10.phpt b/tests/std/array/array_intersect_assoc_variation10.phpt new file mode 100644 index 00000000..8e5c1adc --- /dev/null +++ b/tests/std/array/array_intersect_assoc_variation10.phpt @@ -0,0 +1,48 @@ +--TEST-- +Test array_intersect_assoc() function : usage variations - binary safe checking +--FILE-- + +--EXPECT-- +*** Testing array_intersect_assoc() : binary safe checking *** +array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" +} +array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" +} +array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" +} +Done diff --git a/tests/std/array/array_intersect_assoc_variation2.phpt b/tests/std/array/array_intersect_assoc_variation2.phpt new file mode 100644 index 00000000..73645489 --- /dev/null +++ b/tests/std/array/array_intersect_assoc_variation2.phpt @@ -0,0 +1,182 @@ +--TEST-- +Test array_intersect_assoc() function : usage variations - unexpected values for 'array2' argument(Bug#43196) +--SKIPIF-- + + +--FILE-- + 1, "two" => 2); + // get an unset variable + $unset_var = 10; + unset($unset_var); + // heredoc string + $heredoc = <<getMessage(), "\n"; + } + // Calling array_intersect_assoc() with more arguments + try { + var_dump(array_intersect_assoc($array1, $unexpected_value, $arr3)); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + $iterator++; + } + // close the file resource used + fclose($fp); + echo "Done"; +} +?> +--EXPECT-- +*** Testing array_intersect_assoc() : Passing non-array values to $array2 argument *** + +-- Iteration 1 --array_intersect_assoc(): Argument #2 must be of type array, int given +array_intersect_assoc(): Argument #2 must be of type array, int given + +-- Iteration 2 --array_intersect_assoc(): Argument #2 must be of type array, int given +array_intersect_assoc(): Argument #2 must be of type array, int given + +-- Iteration 3 --array_intersect_assoc(): Argument #2 must be of type array, int given +array_intersect_assoc(): Argument #2 must be of type array, int given + +-- Iteration 4 --array_intersect_assoc(): Argument #2 must be of type array, int given +array_intersect_assoc(): Argument #2 must be of type array, int given + +-- Iteration 5 --array_intersect_assoc(): Argument #2 must be of type array, float given +array_intersect_assoc(): Argument #2 must be of type array, float given + +-- Iteration 6 --array_intersect_assoc(): Argument #2 must be of type array, float given +array_intersect_assoc(): Argument #2 must be of type array, float given + +-- Iteration 7 --array_intersect_assoc(): Argument #2 must be of type array, float given +array_intersect_assoc(): Argument #2 must be of type array, float given + +-- Iteration 8 --array_intersect_assoc(): Argument #2 must be of type array, float given +array_intersect_assoc(): Argument #2 must be of type array, float given + +-- Iteration 9 --array_intersect_assoc(): Argument #2 must be of type array, float given +array_intersect_assoc(): Argument #2 must be of type array, float given + +-- Iteration 10 --array_intersect_assoc(): Argument #2 must be of type array, null given +array_intersect_assoc(): Argument #2 must be of type array, null given + +-- Iteration 11 --array_intersect_assoc(): Argument #2 must be of type array, null given +array_intersect_assoc(): Argument #2 must be of type array, null given + +-- Iteration 12 --array_intersect_assoc(): Argument #2 must be of type array, true given +array_intersect_assoc(): Argument #2 must be of type array, true given + +-- Iteration 13 --array_intersect_assoc(): Argument #2 must be of type array, false given +array_intersect_assoc(): Argument #2 must be of type array, false given + +-- Iteration 14 --array_intersect_assoc(): Argument #2 must be of type array, true given +array_intersect_assoc(): Argument #2 must be of type array, true given + +-- Iteration 15 --array_intersect_assoc(): Argument #2 must be of type array, false given +array_intersect_assoc(): Argument #2 must be of type array, false given + +-- Iteration 16 --array_intersect_assoc(): Argument #2 must be of type array, string given +array_intersect_assoc(): Argument #2 must be of type array, string given + +-- Iteration 17 --array_intersect_assoc(): Argument #2 must be of type array, string given +array_intersect_assoc(): Argument #2 must be of type array, string given + +-- Iteration 18 --array_intersect_assoc(): Argument #2 must be of type array, string given +array_intersect_assoc(): Argument #2 must be of type array, string given + +-- Iteration 19 --array_intersect_assoc(): Argument #2 must be of type array, string given +array_intersect_assoc(): Argument #2 must be of type array, string given + +-- Iteration 20 --array_intersect_assoc(): Argument #2 must be of type array, string given +array_intersect_assoc(): Argument #2 must be of type array, string given + +-- Iteration 21 --array_intersect_assoc(): Argument #2 must be of type array, classA given +array_intersect_assoc(): Argument #2 must be of type array, classA given + +-- Iteration 22 --array_intersect_assoc(): Argument #2 must be of type array, null given +array_intersect_assoc(): Argument #2 must be of type array, null given + +-- Iteration 23 --array_intersect_assoc(): Argument #2 must be of type array, null given +array_intersect_assoc(): Argument #2 must be of type array, null given + +-- Iteration 24 --array_intersect_assoc(): Argument #2 must be of type array, resource given +array_intersect_assoc(): Argument #2 must be of type array, resource given +Done diff --git a/tests/std/array/array_intersect_assoc_variation3.phpt b/tests/std/array/array_intersect_assoc_variation3.phpt new file mode 100644 index 00000000..bb439a05 --- /dev/null +++ b/tests/std/array/array_intersect_assoc_variation3.phpt @@ -0,0 +1,237 @@ +--TEST-- +Test array_intersect_assoc() function : usage variations - different arrays for 'arr1' argument +--FILE-- +22 +'single quoted string' +"double quoted string" +2222 != 1111.\t 0000 = 0000\n +EOT; + +// arrays to be passed to $arr1 argument +$arrays = array ( +/*1*/ array(1, 2), // with default keys and numeric values + array(1.1, 2.2), // with default keys & float values + array(false,true), // with default keys and boolean values + array(), // empty array +/*5*/ array(NULL), // with NULL + array("a\v\f","aaaa\r","b","b\tbbb","c","\[\]\!\@\#\$\%\^\&\*\(\)\{\}"), // with double quoted strings + array('a\v\f','aaaa\r','b','b\tbbb','c','\[\]\!\@\#\$\%\^\&\*\(\)\{\}'), // with single quoted strings + array("h1" => $blank_line, "h2" => $multiline_string, "h3" => $diff_whitespaces, $numeric_string), // with heredocs + + // associative arrays +/*9*/ array(1 => "one", 2 => "two", 3 => "three"), // explicit numeric keys, string values + array("one" => 1, "two" => 2, "three" => 3 ), // string keys & numeric values + array( 1 => 10, 2 => 20, 4 => 40, 3 => 30), // explicit numeric keys and numeric values + array( "one" => "ten", "two" => "twenty", "three" => "thirty"), // string key/value + array("one" => 1, 2 => "two", 4 => "four"), //mixed + + // associative array, containing null/empty/boolean values as key/value +/*14*/ array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null), + array(true => "true", false => "false", "false" => false, "true" => true), + array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''), + array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true), + array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6), + + // array with repetitive keys +/*19*/ array("One" => 1, "two" => 2, "One" => 10, "two" => 20, "three" => 3) +); + + +// array to be passsed to $arr2 argument +$arr2 = array ( + 1, 1.1, 2.2, "hello", "one", NULL, 2, + 'world', true,5 => false, 1 => 'aaaa\r', "aaaa\r", + 'h3' => $diff_whitespaces, $numeric_string, + "one" => "ten", 4 => "four", "two" => 2, + '', null => "null", '' => 'emptys', "emptyd" => "", +); + +// loop through each sub-array within $arrays to check the behavior of array_intersect_assoc() +$iterator = 1; +foreach($arrays as $arr1) { + echo "-- Iteration $iterator --\n"; + + // Calling array_intersect_assoc() with default arguments + var_dump( array_intersect_assoc($arr1, $arr2) ); + + // Calling array_intersect_assoc() with more arguments. + // additional argument passed is the same as $arr1 argument + var_dump( array_intersect_assoc($arr1, $arr2, $arr1) ); + $iterator++; +} + +echo "Done"; +?> +--EXPECT-- +*** Testing array_intersect_assoc() : Passing different types of arrays to $arr1 argument *** +-- Iteration 1 -- +array(1) { + [0]=> + int(1) +} +array(1) { + [0]=> + int(1) +} +-- Iteration 2 -- +array(0) { +} +array(0) { +} +-- Iteration 3 -- +array(0) { +} +array(0) { +} +-- Iteration 4 -- +array(0) { +} +array(0) { +} +-- Iteration 5 -- +array(0) { +} +array(0) { +} +-- Iteration 6 -- +array(0) { +} +array(0) { +} +-- Iteration 7 -- +array(1) { + [1]=> + string(6) "aaaa\r" +} +array(1) { + [1]=> + string(6) "aaaa\r" +} +-- Iteration 8 -- +array(1) { + ["h3"]=> + string(88) "hello world +1111 != 2222 +heredoc +double quoted string. with different white spaces" +} +array(1) { + ["h3"]=> + string(88) "hello world +1111 != 2222 +heredoc +double quoted string. with different white spaces" +} +-- Iteration 9 -- +array(0) { +} +array(0) { +} +-- Iteration 10 -- +array(1) { + ["two"]=> + int(2) +} +array(1) { + ["two"]=> + int(2) +} +-- Iteration 11 -- +array(0) { +} +array(0) { +} +-- Iteration 12 -- +array(1) { + ["one"]=> + string(3) "ten" +} +array(1) { + ["one"]=> + string(3) "ten" +} +-- Iteration 13 -- +array(1) { + [4]=> + string(4) "four" +} +array(1) { + [4]=> + string(4) "four" +} +-- Iteration 14 -- +array(0) { +} +array(0) { +} +-- Iteration 15 -- +array(0) { +} +array(0) { +} +-- Iteration 16 -- +array(2) { + [""]=> + string(6) "emptys" + ["emptyd"]=> + string(0) "" +} +array(2) { + [""]=> + string(6) "emptys" + ["emptyd"]=> + string(0) "" +} +-- Iteration 17 -- +array(1) { + [5]=> + bool(false) +} +array(1) { + [5]=> + bool(false) +} +-- Iteration 18 -- +array(0) { +} +array(0) { +} +-- Iteration 19 -- +array(0) { +} +array(0) { +} +Done diff --git a/tests/std/array/array_intersect_assoc_variation4.phpt b/tests/std/array/array_intersect_assoc_variation4.phpt new file mode 100644 index 00000000..859b7280 --- /dev/null +++ b/tests/std/array/array_intersect_assoc_variation4.phpt @@ -0,0 +1,248 @@ +--TEST-- +Test array_intersect_assoc() function : usage variations - different arrays for 'arr2' argument +--FILE-- +22 +'single quoted string' +"double quoted string" +2222 != 1111.\t 0000 = 0000\n +EOT; + +// array to be passsed to $arr1 argument +$arr1 = array ( + 1, 1.1, 1.3, 1 => true, "hello", "one", NULL, 2, + 'world', true, false, 3 => "b\tbbb", "aaaa\r", + $numeric_string, "h3" => $diff_whitespaces, "true" => true, + "one" => "ten", 4 => "four", "two" => 2, 6 => "six", + '', null => "null", '' => 'emptys' +); + +// arrays to be passed to $arr2 argument +$arrays = array ( +/*1*/ array(1, 2), // array with default keys and numeric values + array(1.1, 1.2, 1.3), // array with default keys & float values + array(false,true), // array with default keys and boolean values + array(), // empty array +/*5*/ array(NULL), // array with NULL + array("a\v\f","aaaa\r","b","b\tbbb","c","\[\]\!\@\#\$\%\^\&\*\(\)\{\}"), // array with double quoted strings + array('a\v\f','aaaa\r','b','b\tbbb','c','\[\]\!\@\#\$\%\^\&\*\(\)\{\}'), // array with single quoted strings + array($blank_line, "h2" => $multiline_string, "h3" => $diff_whitespaces, $numeric_string), // array with heredocs + + // associative arrays +/*9*/ array(1 => "one", 2 => "two", 6 => "six"), // explicit numeric keys, string values + array("one" => 1, "two" => 2, "three" => 3 ), // string keys & numeric values + array( 1 => 10, 2 => 20, 4 => 40, 3 => 30), // explicit numeric keys and numeric values + array( "one" => "ten", "two" => "twenty", "three" => "thirty"), // string key/value + array("one" => 1, 2 => "two", 4 => "four"), //mixed + + // associative array, containing null/empty/boolean values as key/value +/*14*/ array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null), + array(true => "true", false => "false", "false" => false, "true" => true), + array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''), + array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true), + array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6), + + // array with repetitive keys +/*19*/ array("One" => 1, "two" => 2, "One" => 10, "two" => 20, "three" => 3) +); + +// loop through each sub-array within $arrays to check the behavior of array_intersect_assoc() +$iterator = 1; +foreach($arrays as $arr2) { + echo "-- Iteration $iterator --\n"; + + // Calling array_intersect_assoc() with default arguments + var_dump( array_intersect_assoc($arr1, $arr2) ); + + // Calling array_intersect_assoc() with more arguments + // additional argument passed is the same as $arr1 argument + var_dump( array_intersect_assoc($arr1, $arr2, $arr1) ); + $iterator++; +} + +echo "Done"; +?> +--EXPECT-- +*** Testing array_intersect_assoc() : Passing different types of arrays to $arr2 argument *** +-- Iteration 1 -- +array(1) { + [0]=> + int(1) +} +array(1) { + [0]=> + int(1) +} +-- Iteration 2 -- +array(1) { + [2]=> + float(1.3) +} +array(1) { + [2]=> + float(1.3) +} +-- Iteration 3 -- +array(1) { + [1]=> + bool(true) +} +array(1) { + [1]=> + bool(true) +} +-- Iteration 4 -- +array(0) { +} +array(0) { +} +-- Iteration 5 -- +array(0) { +} +array(0) { +} +-- Iteration 6 -- +array(1) { + [3]=> + string(5) "b bbb" +} +array(1) { + [3]=> + string(5) "b bbb" +} +-- Iteration 7 -- +array(0) { +} +array(0) { +} +-- Iteration 8 -- +array(1) { + ["h3"]=> + string(88) "hello world +1111 != 2222 +heredoc +double quoted string. with different white spaces" +} +array(1) { + ["h3"]=> + string(88) "hello world +1111 != 2222 +heredoc +double quoted string. with different white spaces" +} +-- Iteration 9 -- +array(1) { + [6]=> + string(3) "six" +} +array(1) { + [6]=> + string(3) "six" +} +-- Iteration 10 -- +array(1) { + ["two"]=> + int(2) +} +array(1) { + ["two"]=> + int(2) +} +-- Iteration 11 -- +array(0) { +} +array(0) { +} +-- Iteration 12 -- +array(1) { + ["one"]=> + string(3) "ten" +} +array(1) { + ["one"]=> + string(3) "ten" +} +-- Iteration 13 -- +array(1) { + [4]=> + string(4) "four" +} +array(1) { + [4]=> + string(4) "four" +} +-- Iteration 14 -- +array(0) { +} +array(0) { +} +-- Iteration 15 -- +array(1) { + ["true"]=> + bool(true) +} +array(1) { + ["true"]=> + bool(true) +} +-- Iteration 16 -- +array(1) { + [""]=> + string(6) "emptys" +} +array(1) { + [""]=> + string(6) "emptys" +} +-- Iteration 17 -- +array(1) { + [5]=> + NULL +} +array(1) { + [5]=> + NULL +} +-- Iteration 18 -- +array(0) { +} +array(0) { +} +-- Iteration 19 -- +array(0) { +} +array(0) { +} +Done diff --git a/tests/std/array/array_intersect_assoc_variation5.phpt b/tests/std/array/array_intersect_assoc_variation5.phpt new file mode 100644 index 00000000..65ce1dae --- /dev/null +++ b/tests/std/array/array_intersect_assoc_variation5.phpt @@ -0,0 +1,139 @@ +--TEST-- +Test array_intersect_assoc() function : usage variations - assoc array with diff keys for 'arr1' argument +--FILE-- + "0"), + array(1 => "1"), + array(1 => "1", 2 => "2", 3 => "3", 4 => "4"), + + // arrays with string keys +/*7*/ array('\tHello' => 111, 're\td' => "color", + '\v\fworld' => 2.2, 'pen\n' => 33), + array("\tHello" => 111, "re\td" => "color", + "\v\fworld" => 2.2, "pen\n" => 33), + array("hello", $heredoc => "string"), // heredoc + + // array with object, unset variable and resource variable +/*10*/ array(@$unset_var => "hello"), + + // array with mixed keys +/*11*/ array('hello' => 1, "fruit" => 2.2, + 133 => "int", + @$unset_var => "unset", $heredoc => "heredoc") +); + +// array to be passed to $arr2 argument +$arr2 = array(0 => 0, 2 => "float", 4 => "f3", 33333333 => "f4", + "\tHello" => 111, 2.2, 'color', "Hello world" => "string", + "pen\n" => 33, 133 => "int"); + +// loop through each sub-array within $arrays to check the behavior of array_intersect_assoc() +$iterator = 1; +foreach($arrays as $arr1) { + echo "-- Iteration $iterator --\n"; + + // Calling array_intersect_assoc() with default arguments + var_dump( array_intersect_assoc($arr1, $arr2) ); + + // Calling array_intersect_assoc() with more arguments. + // additional argument passed is the same as $arr1 argument + var_dump( array_intersect_assoc($arr1, $arr2, $arr1) ); + $iterator++; +} + +echo "Done"; +?> +--EXPECT-- +*** Testing array_intersect_assoc() : assoc array with diff keys to $arr1 argument *** +-- Iteration 1 -- +array(0) { +} +array(0) { +} +-- Iteration 2 -- +array(1) { + [0]=> + string(1) "0" +} +array(1) { + [0]=> + string(1) "0" +} +-- Iteration 3 -- +array(0) { +} +array(0) { +} +-- Iteration 4 -- +array(0) { +} +array(0) { +} +-- Iteration 5 -- +array(0) { +} +array(0) { +} +-- Iteration 6 -- +array(2) { + [" Hello"]=> + int(111) + ["pen +"]=> + int(33) +} +array(2) { + [" Hello"]=> + int(111) + ["pen +"]=> + int(33) +} +-- Iteration 7 -- +array(1) { + ["Hello world"]=> + string(6) "string" +} +array(1) { + ["Hello world"]=> + string(6) "string" +} +-- Iteration 8 -- +array(0) { +} +array(0) { +} +-- Iteration 9 -- +array(1) { + [133]=> + string(3) "int" +} +array(1) { + [133]=> + string(3) "int" +} +Done diff --git a/tests/std/array/array_intersect_assoc_variation6.phpt b/tests/std/array/array_intersect_assoc_variation6.phpt new file mode 100644 index 00000000..f446c687 --- /dev/null +++ b/tests/std/array/array_intersect_assoc_variation6.phpt @@ -0,0 +1,139 @@ +--TEST-- +Test array_intersect_assoc() function : usage variations - assoc array with diff keys for 'arr2' argument +--FILE-- + "0"), + array(1 => "1"), + array(1 => "1", 2 => "2", 3 => "3", 4 => "4"), + + // arrays with string keys +/*7*/ array('\tHello' => 111, 're\td' => "color", + '\v\fworld' => 2.2, 'pen\n' => 33), + array("\tHello" => 111, "re\td" => "color", + "\v\fworld" => 2.2, "pen\n" => 33), + array("hello", $heredoc => "string"), // heredoc + + // array with unset variable +/*10*/ array( @$unset_var => "hello"), + + // array with mixed keys +/*11*/ array('hello' => 1, "fruit" => 2.2, + 133 => "int", + @$unset_var => "unset", $heredoc => "heredoc") +); + +// array to be passed to $arr1 argument +$arr1 = array(0 => 0, 2 => "float", 4 => "f3", 33333333 => "f4", + "\tHello" => 111, 2.2, 'color', "Hello world" => "string", + "pen\n" => 33, 133 => "int"); + +// loop through each sub-array within $arrays to check the behavior of array_intersect_assoc() +$iterator = 1; +foreach($arrays as $arr2) { + echo "-- Iteration $iterator --\n"; + + // Calling array_intersect_assoc() with default arguments + var_dump( array_intersect_assoc($arr1, $arr2) ); + + // Calling array_intersect_assoc() with more arguments. + // additional argument passed is the same as $arr1 argument + var_dump( array_intersect_assoc($arr1, $arr2, $arr1) ); + $iterator++; +} + +echo "Done"; +?> +--EXPECT-- +*** Testing array_intersect_assoc() : assoc array with diff keys to $arr2 argument *** +-- Iteration 1 -- +array(0) { +} +array(0) { +} +-- Iteration 2 -- +array(1) { + [0]=> + int(0) +} +array(1) { + [0]=> + int(0) +} +-- Iteration 3 -- +array(0) { +} +array(0) { +} +-- Iteration 4 -- +array(0) { +} +array(0) { +} +-- Iteration 5 -- +array(0) { +} +array(0) { +} +-- Iteration 6 -- +array(2) { + [" Hello"]=> + int(111) + ["pen +"]=> + int(33) +} +array(2) { + [" Hello"]=> + int(111) + ["pen +"]=> + int(33) +} +-- Iteration 7 -- +array(1) { + ["Hello world"]=> + string(6) "string" +} +array(1) { + ["Hello world"]=> + string(6) "string" +} +-- Iteration 8 -- +array(0) { +} +array(0) { +} +-- Iteration 9 -- +array(1) { + [133]=> + string(3) "int" +} +array(1) { + [133]=> + string(3) "int" +} +Done diff --git a/tests/std/array/array_intersect_assoc_variation7.phpt b/tests/std/array/array_intersect_assoc_variation7.phpt new file mode 100644 index 00000000..a1171fb9 --- /dev/null +++ b/tests/std/array/array_intersect_assoc_variation7.phpt @@ -0,0 +1,191 @@ +--TEST-- +Test array_intersect_assoc() function : usage variations - assoc array with diff values for 'arr1' argument +--FILE-- + 0), + array("1" => 1), + array("one" => 1, 'two' => 2, "three" => 3, 4 => 4), + // arrays with float values + /*5*/ + array("float" => 2.3333), + array("f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => 33333333.333), + // arrays with string values + /*7*/ + array(111 => "\tHello", "red" => "col\tor", 2 => "\v\fworld", 3 => "pen\n"), + array(111 => '\tHello', "red" => 'col\tor', 2 => '\v\fworld', 3 => 'pen\n'), + array(1 => "hello", "heredoc" => $heredoc), + // array with object, unset variable and resource variable + /*10*/ + array(11 => new classA(), "unset" => @$unset_var, "resource" => $fp), + // array with mixed values + /*11*/ + array(1 => 'hello', 2 => new classA(), 222 => "fruit", 'resource' => $fp, "int" => 133, "float" => 444.432, "unset" => @$unset_var, "heredoc" => $heredoc), + ); + // array to be passsed to $arr2 argument + $arr2 = array(0 => "0", 1, "two" => 2, "float" => 2.3333, "f1" => 1.2, "f4" => 33333333.333, 111 => "\tHello", 3 => 'pen\n', '\v\fworld', "heredoc" => "Hello world", 11 => new classA(), "resource" => $fp, "int" => 133, 222 => "fruit"); + // loop through each sub-array within $arrays to check the behavior of array_intersect_assoc() + $iterator = 1; + foreach ($arrays as $arr1) { + echo "-- Iteration {$iterator} --\n"; + // Calling array_intersect_assoc() with default arguments + var_dump(array_intersect_assoc($arr1, $arr2)); + // Calling array_intersect_assoc() with more arguments. + // additional argument passed is the same as $arr1 argument + var_dump(array_intersect_assoc($arr1, $arr2, $arr1)); + $iterator++; + } + // close the file resource used + fclose($fp); + echo "Done"; +} +?> +--EXPECTF-- +*** Testing array_intersect_assoc() : assoc array with diff values to $arr1 argument *** +-- Iteration 1 -- +array(0) { +} +array(0) { +} +-- Iteration 2 -- +array(1) { + [0]=> + int(0) +} +array(1) { + [0]=> + int(0) +} +-- Iteration 3 -- +array(1) { + [1]=> + int(1) +} +array(1) { + [1]=> + int(1) +} +-- Iteration 4 -- +array(1) { + ["two"]=> + int(2) +} +array(1) { + ["two"]=> + int(2) +} +-- Iteration 5 -- +array(1) { + ["float"]=> + float(2.3333) +} +array(1) { + ["float"]=> + float(2.3333) +} +-- Iteration 6 -- +array(2) { + ["f1"]=> + float(1.2) + ["f4"]=> + float(33333333.333) +} +array(2) { + ["f1"]=> + float(1.2) + ["f4"]=> + float(33333333.333) +} +-- Iteration 7 -- +array(1) { + [111]=> + string(6) " Hello" +} +array(1) { + [111]=> + string(6) " Hello" +} +-- Iteration 8 -- +array(1) { + [3]=> + string(5) "pen\n" +} +array(1) { + [3]=> + string(5) "pen\n" +} +-- Iteration 9 -- +array(1) { + ["heredoc"]=> + string(11) "Hello world" +} +array(1) { + ["heredoc"]=> + string(11) "Hello world" +} +-- Iteration 10 -- +array(2) { + [11]=> + object(classA)#%d (0) { + } + ["resource"]=> + resource(%d) of type (stream) +} +array(2) { + [11]=> + object(classA)#%d (0) { + } + ["resource"]=> + resource(%d) of type (stream) +} +-- Iteration 11 -- +array(4) { + [222]=> + string(5) "fruit" + ["resource"]=> + resource(%d) of type (stream) + ["int"]=> + int(133) + ["heredoc"]=> + string(11) "Hello world" +} +array(4) { + [222]=> + string(5) "fruit" + ["resource"]=> + resource(%d) of type (stream) + ["int"]=> + int(133) + ["heredoc"]=> + string(11) "Hello world" +} +Done diff --git a/tests/std/array/array_intersect_assoc_variation8.phpt b/tests/std/array/array_intersect_assoc_variation8.phpt new file mode 100644 index 00000000..4d252349 --- /dev/null +++ b/tests/std/array/array_intersect_assoc_variation8.phpt @@ -0,0 +1,191 @@ +--TEST-- +Test array_intersect_assoc() function : usage variations - assoc array with diff values for 'arr2' argument +--FILE-- + 0), + array("1" => 1), + array("one" => 1, 'two' => 2, "three" => 3, 4 => 4), + // arrays with float values + /*5*/ + array("float" => 2.3333), + array("f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => 33333333.333), + // arrays with string values + /*7*/ + array(111 => "\tHello", "red" => "col\tor", 2 => "\v\fworld", 3 => "pen\n"), + array(111 => '\tHello', "red" => 'col\tor', 2 => '\v\fworld', 3 => 'pen\n'), + array(1 => "hello", "heredoc" => $heredoc), + // array with object, unset variable and resource variable + /*10*/ + array(11 => new classA(), "unset" => @$unset_var, "resource" => $fp), + // array with mixed values + /*11*/ + array(1 => 'hello', 2 => new classA(), 222 => "fruit", 'resource' => $fp, "int" => 133, "float" => 444.432, "unset" => @$unset_var, "heredoc" => $heredoc), + ); + // array to be passsed to $arr1 argument + $arr1 = array(0 => "0", 1, "two" => 2, "float" => 2.3333, "f1" => 1.2, "f4" => 33333333.333, 111 => "\tHello", 3 => 'pen\n', '\v\fworld', "heredoc" => "Hello world", 11 => new classA(), "resource" => $fp, "int" => 133, 222 => "fruit"); + // loop through each sub-array within $arrays to check the behavior of array_intersect_assoc() + $iterator = 1; + foreach ($arrays as $arr2) { + echo "-- Iteration {$iterator} --\n"; + // Calling array_intersect_assoc() with default arguments + var_dump(array_intersect_assoc($arr1, $arr2)); + // Calling array_intersect_assoc() with more arguments. + // additional argument passed is the same as $arr1 argument + var_dump(array_intersect_assoc($arr1, $arr2, $arr1)); + $iterator++; + } + // close the file resource used + fclose($fp); + echo "Done"; +} +?> +--EXPECTF-- +*** Testing array_intersect_assoc() : assoc array with diff values to $arr2 argument *** +-- Iteration 1 -- +array(0) { +} +array(0) { +} +-- Iteration 2 -- +array(1) { + [0]=> + string(1) "0" +} +array(1) { + [0]=> + string(1) "0" +} +-- Iteration 3 -- +array(1) { + [1]=> + int(1) +} +array(1) { + [1]=> + int(1) +} +-- Iteration 4 -- +array(1) { + ["two"]=> + int(2) +} +array(1) { + ["two"]=> + int(2) +} +-- Iteration 5 -- +array(1) { + ["float"]=> + float(2.3333) +} +array(1) { + ["float"]=> + float(2.3333) +} +-- Iteration 6 -- +array(2) { + ["f1"]=> + float(1.2) + ["f4"]=> + float(33333333.333) +} +array(2) { + ["f1"]=> + float(1.2) + ["f4"]=> + float(33333333.333) +} +-- Iteration 7 -- +array(1) { + [111]=> + string(6) " Hello" +} +array(1) { + [111]=> + string(6) " Hello" +} +-- Iteration 8 -- +array(1) { + [3]=> + string(5) "pen\n" +} +array(1) { + [3]=> + string(5) "pen\n" +} +-- Iteration 9 -- +array(1) { + ["heredoc"]=> + string(11) "Hello world" +} +array(1) { + ["heredoc"]=> + string(11) "Hello world" +} +-- Iteration 10 -- +array(2) { + [11]=> + object(classA)#%d (0) { + } + ["resource"]=> + resource(%d) of type (stream) +} +array(2) { + [11]=> + object(classA)#%d (0) { + } + ["resource"]=> + resource(%d) of type (stream) +} +-- Iteration 11 -- +array(4) { + ["heredoc"]=> + string(11) "Hello world" + ["resource"]=> + resource(%d) of type (stream) + ["int"]=> + int(133) + [222]=> + string(5) "fruit" +} +array(4) { + ["heredoc"]=> + string(11) "Hello world" + ["resource"]=> + resource(%d) of type (stream) + ["int"]=> + int(133) + [222]=> + string(5) "fruit" +} +Done diff --git a/tests/std/array/array_intersect_assoc_variation9.phpt b/tests/std/array/array_intersect_assoc_variation9.phpt new file mode 100644 index 00000000..86d0e8e7 --- /dev/null +++ b/tests/std/array/array_intersect_assoc_variation9.phpt @@ -0,0 +1,146 @@ +--TEST-- +Test array_intersect_assoc() function : usage variations - two dimensional arrays for $arr1 and $arr2 arguments +--FILE-- + "one", 2 => "two", 3 => "three"), + array("ten" => 10, "twenty" => 20.00, "thirty" => 30) +); + +$arr2 = array ( + array(1, 2, 3, 4), + array(1 => "one", 2 => "two", 3 => "three") +); + +/* Passing the entire array as argument to $arr1 and $arr2 */ +// Calling array_intersect_assoc() with default arguments +echo "-- Passing the entire 2-D array to \$arr1 and \$arr2 --\n"; +echo "- With default arguments -\n"; +var_dump( array_intersect_assoc($arr1, $arr2) ); + +// Calling array_intersect_assoc() with more arguments +// additional argument passed is the same as $arr1 +echo "- With more arguments -\n"; +var_dump( array_intersect_assoc($arr1, $arr2, $arr1) ); + +/* Passing the sub-array as argument to $arr1 and $arr2 */ +// Calling array_intersect_assoc() with default arguments +echo "-- Passing the sub-array to \$arr1 and \$arr2 --\n"; +echo "- With default arguments -\n"; +var_dump( array_intersect_assoc($arr1[0], $arr2[0]) ); + +// Calling array_intersect_assoc() with more arguments +// additional argument passed is the same as $arr1 +echo "- With more arguments -\n"; +var_dump( array_intersect_assoc($arr1[0], $arr2[0], $arr1[0]) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_intersect_assoc() : passing two dimensional array to both $arr1 and $arr2 arguments *** +-- Passing the entire 2-D array to $arr1 and $arr2 -- +- With default arguments - + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d +array(2) { + [0]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(5) "hello" + [3]=> + string(5) "world" + } + [1]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + } +} +- With more arguments - + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d +array(2) { + [0]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(5) "hello" + [3]=> + string(5) "world" + } + [1]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + } +} +-- Passing the sub-array to $arr1 and $arr2 -- +- With default arguments - +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +- With more arguments - +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +Done diff --git a/tests/std/array/array_intersect_basic.phpt b/tests/std/array/array_intersect_basic.phpt new file mode 100644 index 00000000..86ef64e1 --- /dev/null +++ b/tests/std/array/array_intersect_basic.phpt @@ -0,0 +1,75 @@ +--TEST-- +Test array_intersect() function : basic functionality +--FILE-- + 1, "two" => 2); + +// default key array for both $arr1 and $arr2 argument +var_dump( array_intersect($arr_default_keys, $arr_default_keys) ); + +// default key array for $arr1 and associative array for $arr2 argument +var_dump( array_intersect($arr_default_keys, $arr_associative) ); + +// associative array for $arr1 and default key array for $arr2 +var_dump( array_intersect($arr_associative, $arr_default_keys) ); + +// associative array for both $arr1 and $arr2 argument +var_dump( array_intersect($arr_associative, $arr_associative) ); + +// more arrays to be intersected +$arr3 = array(2, 3, 4); +var_dump( array_intersect($arr_default_keys, $arr_associative, $arr3) ); +var_dump( array_intersect($arr_associative, $arr_default_keys, $arr3, $arr_associative) ); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_intersect() : basic functionality *** +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(5) "hello" + [3]=> + string(5) "world" +} +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(1) { + [1]=> + int(2) +} +array(1) { + ["two"]=> + int(2) +} +Done diff --git a/tests/std/array/array_intersect_key.phpt b/tests/std/array/array_intersect_key.phpt new file mode 100644 index 00000000..a8b55156 --- /dev/null +++ b/tests/std/array/array_intersect_key.phpt @@ -0,0 +1,228 @@ +--TEST-- +Test of the array_intersect_key() and array_intersect_ukey() +--FILE-- + $b ? 1 : -1; +} +function main() +{ + $a = array(1, 6, 2, -20, 15, 1200, -2500); + $b = array(0, 7, 2, -20, 11, 1100, -2500); + $c = array(0, 6, 2, -20, 19, 1000, -2500); + $d = array(3, 8, -2, -20, 14, 900, -2600); + $a_f = array_flip($a); + $b_f = array_flip($b); + $c_f = array_flip($c); + $d_f = array_flip($d); + /* give nicer values */ + foreach ($a_f as $k => &$a_f_el) { + $a_f_el = $k * 2; + } + foreach ($b_f as $k => &$b_f_el) { + $b_f_el = $k * 2; + } + foreach ($c_f as $k => &$c_f_el) { + $c_f_el = $k * 2; + } + foreach ($d_f as $k => &$d_f_el) { + $d_f_el = $k * 2; + } + var_dump(array_intersect_key($a_f, $b_f)); + // keys -> 2, -20, -2500 + var_dump(array_intersect_ukey($a_f, $b_f, "comp_func")); + // 2, 20, -2500 + var_dump(array_intersect_key($a_f, $c_f)); + // keys -> 6, 2, -20, -2500 + var_dump(array_intersect_ukey($a_f, $c_f, "comp_func")); + // 6, 2, -20, -2500 + var_dump(array_intersect_key($a_f, $d_f)); + // -20 + var_dump(array_intersect_ukey($a_f, $d_f, "comp_func")); + // -20 + var_dump(array_intersect_key($a_f, $b_f, $c_f)); + // 2, -20, -2500 + var_dump(array_intersect_ukey($a_f, $b_f, $c_f, "comp_func")); + // 2, -20, -2500 + var_dump(array_intersect_key($a_f, $b_f, $d_f)); + // -20 + var_dump(array_intersect_ukey($a_f, $b_f, $d_f, "comp_func")); + // -20 + var_dump(array_intersect_key($a_f, $b_f, $c_f, $d_f)); + // -20 + var_dump(array_intersect_ukey($a_f, $b_f, $c_f, $d_f, "comp_func")); + //-20 + var_dump(array_intersect_key($b_f, $c_f)); + // 0, 2, -20, -2500 + var_dump(array_intersect_ukey($b_f, $c_f, "comp_func")); + //0, 2, -20, 2500 + var_dump(array_intersect_key($b_f, $d_f)); + // -20 + var_dump(array_intersect_ukey($b_f, $d_f, "comp_func")); + // -20 + var_dump(array_intersect_key($b_f, $c_f, $d_f)); + // -20 + var_dump(array_intersect_ukey($b_f, $c_f, $d_f, "comp_func")); + // -20 + echo "----- Now testing array_intersect() ------- \n"; + var_dump(array_intersect($a, $b_f)); + var_dump(array_uintersect($a, $b, "comp_func")); + var_dump(array_intersect($a, $b, $c)); + var_dump(array_uintersect($a, $b, $c, "comp_func")); + var_dump(array_intersect($a, $b, $c, $d)); + var_dump(array_uintersect($a, $b, $c, $d, "comp_func")); +} +?> +--EXPECT-- +array(3) { + [2]=> + int(4) + [-20]=> + int(-40) + [-2500]=> + &int(-5000) +} +array(3) { + [2]=> + int(4) + [-20]=> + int(-40) + [-2500]=> + &int(-5000) +} +array(4) { + [6]=> + int(12) + [2]=> + int(4) + [-20]=> + int(-40) + [-2500]=> + &int(-5000) +} +array(4) { + [6]=> + int(12) + [2]=> + int(4) + [-20]=> + int(-40) + [-2500]=> + &int(-5000) +} +array(1) { + [-20]=> + int(-40) +} +array(1) { + [-20]=> + int(-40) +} +array(3) { + [2]=> + int(4) + [-20]=> + int(-40) + [-2500]=> + &int(-5000) +} +array(3) { + [2]=> + int(4) + [-20]=> + int(-40) + [-2500]=> + &int(-5000) +} +array(1) { + [-20]=> + int(-40) +} +array(1) { + [-20]=> + int(-40) +} +array(1) { + [-20]=> + int(-40) +} +array(1) { + [-20]=> + int(-40) +} +array(4) { + [0]=> + int(0) + [2]=> + int(4) + [-20]=> + int(-40) + [-2500]=> + &int(-5000) +} +array(4) { + [0]=> + int(0) + [2]=> + int(4) + [-20]=> + int(-40) + [-2500]=> + &int(-5000) +} +array(1) { + [-20]=> + int(-40) +} +array(1) { + [-20]=> + int(-40) +} +array(1) { + [-20]=> + int(-40) +} +array(1) { + [-20]=> + int(-40) +} +----- Now testing array_intersect() ------- +array(0) { +} +array(3) { + [2]=> + int(2) + [3]=> + int(-20) + [6]=> + int(-2500) +} +array(3) { + [2]=> + int(2) + [3]=> + int(-20) + [6]=> + int(-2500) +} +array(3) { + [2]=> + int(2) + [3]=> + int(-20) + [6]=> + int(-2500) +} +array(1) { + [3]=> + int(-20) +} +array(1) { + [3]=> + int(-20) +} diff --git a/tests/std/array/array_intersect_key_basic.phpt b/tests/std/array/array_intersect_key_basic.phpt new file mode 100644 index 00000000..4c650441 --- /dev/null +++ b/tests/std/array/array_intersect_key_basic.phpt @@ -0,0 +1,18 @@ +--TEST-- +array_intersect_key(): Basic Test +--FILE-- + 1, 'red' => 2, 'green' => 3, 'purple' => 4); +$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); +var_dump(array_intersect_key($array1, $array2)); +?> +--EXPECT-- +array(2) { + ["blue"]=> + int(1) + ["green"]=> + int(3) +} diff --git a/tests/std/array/array_intersect_key_variation1.phpt b/tests/std/array/array_intersect_key_variation1.phpt new file mode 100644 index 00000000..8e28a3b6 --- /dev/null +++ b/tests/std/array/array_intersect_key_variation1.phpt @@ -0,0 +1,199 @@ +--TEST-- +Test array_intersect_key() function : usage variation - Passing unexpected values to first argument +--SKIPIF-- + + +--FILE-- + 1, 'red' => 2, 'green' => 3, 'purple' => 4); + $array3 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); + //get an unset variable + $unset_var = 10; + unset($unset_var); + //resource variable + $fp = fopen(__FILE__, "r"); + // heredoc string + $heredoc = << 1, 'two' => 2); + //array of values to iterate over + $inputs = array( + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -12345, + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 123456789000.0, + 'float -12.3456789000e10' => -123456789000.0, + 'float .5' => 0.5, + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + // boolean data + 'lowercase true' => true, + 'lowercase false' => false, + 'uppercase TRUE' => TRUE, + 'uppercase FALSE' => FALSE, + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + // undefined data + 'undefined var' => @$undefined_var, + // unset data + 'unset var' => @$unset_var, + // resource data + 'resource var' => $fp, + ); + // loop through each element of the array for array1 + foreach ($inputs as $key => $value) { + echo "\n--{$key}--\n"; + try { + var_dump(array_intersect_key($value, $array2)); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + try { + var_dump(array_intersect_key($value, $array2, $array3)); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + } + fclose($fp); +} +?> +--EXPECT-- +*** Testing array_intersect_key() : usage variation *** + +--int 0-- +array_intersect_key(): Argument #1 ($array) must be of type array, int given +array_intersect_key(): Argument #1 ($array) must be of type array, int given + +--int 1-- +array_intersect_key(): Argument #1 ($array) must be of type array, int given +array_intersect_key(): Argument #1 ($array) must be of type array, int given + +--int 12345-- +array_intersect_key(): Argument #1 ($array) must be of type array, int given +array_intersect_key(): Argument #1 ($array) must be of type array, int given + +--int -12345-- +array_intersect_key(): Argument #1 ($array) must be of type array, int given +array_intersect_key(): Argument #1 ($array) must be of type array, int given + +--float 10.5-- +array_intersect_key(): Argument #1 ($array) must be of type array, float given +array_intersect_key(): Argument #1 ($array) must be of type array, float given + +--float -10.5-- +array_intersect_key(): Argument #1 ($array) must be of type array, float given +array_intersect_key(): Argument #1 ($array) must be of type array, float given + +--float 12.3456789000e10-- +array_intersect_key(): Argument #1 ($array) must be of type array, float given +array_intersect_key(): Argument #1 ($array) must be of type array, float given + +--float -12.3456789000e10-- +array_intersect_key(): Argument #1 ($array) must be of type array, float given +array_intersect_key(): Argument #1 ($array) must be of type array, float given + +--float .5-- +array_intersect_key(): Argument #1 ($array) must be of type array, float given +array_intersect_key(): Argument #1 ($array) must be of type array, float given + +--uppercase NULL-- +array_intersect_key(): Argument #1 ($array) must be of type array, null given +array_intersect_key(): Argument #1 ($array) must be of type array, null given + +--lowercase null-- +array_intersect_key(): Argument #1 ($array) must be of type array, null given +array_intersect_key(): Argument #1 ($array) must be of type array, null given + +--lowercase true-- +array_intersect_key(): Argument #1 ($array) must be of type array, true given +array_intersect_key(): Argument #1 ($array) must be of type array, true given + +--lowercase false-- +array_intersect_key(): Argument #1 ($array) must be of type array, false given +array_intersect_key(): Argument #1 ($array) must be of type array, false given + +--uppercase TRUE-- +array_intersect_key(): Argument #1 ($array) must be of type array, true given +array_intersect_key(): Argument #1 ($array) must be of type array, true given + +--uppercase FALSE-- +array_intersect_key(): Argument #1 ($array) must be of type array, false given +array_intersect_key(): Argument #1 ($array) must be of type array, false given + +--empty string DQ-- +array_intersect_key(): Argument #1 ($array) must be of type array, string given +array_intersect_key(): Argument #1 ($array) must be of type array, string given + +--empty string SQ-- +array_intersect_key(): Argument #1 ($array) must be of type array, string given +array_intersect_key(): Argument #1 ($array) must be of type array, string given + +--string DQ-- +array_intersect_key(): Argument #1 ($array) must be of type array, string given +array_intersect_key(): Argument #1 ($array) must be of type array, string given + +--string SQ-- +array_intersect_key(): Argument #1 ($array) must be of type array, string given +array_intersect_key(): Argument #1 ($array) must be of type array, string given + +--mixed case string-- +array_intersect_key(): Argument #1 ($array) must be of type array, string given +array_intersect_key(): Argument #1 ($array) must be of type array, string given + +--heredoc-- +array_intersect_key(): Argument #1 ($array) must be of type array, string given +array_intersect_key(): Argument #1 ($array) must be of type array, string given + +--instance of classWithToString-- +array_intersect_key(): Argument #1 ($array) must be of type array, classWithToString given +array_intersect_key(): Argument #1 ($array) must be of type array, classWithToString given + +--instance of classWithoutToString-- +array_intersect_key(): Argument #1 ($array) must be of type array, classWithoutToString given +array_intersect_key(): Argument #1 ($array) must be of type array, classWithoutToString given + +--undefined var-- +array_intersect_key(): Argument #1 ($array) must be of type array, null given +array_intersect_key(): Argument #1 ($array) must be of type array, null given + +--unset var-- +array_intersect_key(): Argument #1 ($array) must be of type array, null given +array_intersect_key(): Argument #1 ($array) must be of type array, null given + +--resource var-- +array_intersect_key(): Argument #1 ($array) must be of type array, resource given +array_intersect_key(): Argument #1 ($array) must be of type array, resource given diff --git a/tests/std/array/array_intersect_key_variation2.phpt b/tests/std/array/array_intersect_key_variation2.phpt new file mode 100644 index 00000000..fd3acf83 --- /dev/null +++ b/tests/std/array/array_intersect_key_variation2.phpt @@ -0,0 +1,199 @@ +--TEST-- +Test array_intersect_key() function : usage variation - Passing unexpected values to second argument +--SKIPIF-- + + +--FILE-- + 1, 'red' => 2, 'green' => 3, 'purple' => 4); + $array3 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); + //get an unset variable + $unset_var = 10; + unset($unset_var); + //resource variable + $fp = fopen(__FILE__, "r"); + // heredoc string + $heredoc = << 1, 'two' => 2); + //array of values to iterate over + $inputs = array( + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -12345, + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 123456789000.0, + 'float -12.3456789000e10' => -123456789000.0, + 'float .5' => 0.5, + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + // boolean data + 'lowercase true' => true, + 'lowercase false' => false, + 'uppercase TRUE' => TRUE, + 'uppercase FALSE' => FALSE, + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + // undefined data + 'undefined var' => @$undefined_var, + // unset data + 'unset var' => @$unset_var, + // resource data + 'resource var' => $fp, + ); + // loop through each element of the array for array2 + foreach ($inputs as $key => $value) { + echo "\n--{$key}--\n"; + try { + var_dump(array_intersect_key($array1, $value)); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + try { + var_dump(array_intersect_key($array1, $value, $array3)); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + } + fclose($fp); +} +?> +--EXPECT-- +*** Testing array_intersect_key() : usage variation *** + +--int 0-- +array_intersect_key(): Argument #2 must be of type array, int given +array_intersect_key(): Argument #2 must be of type array, int given + +--int 1-- +array_intersect_key(): Argument #2 must be of type array, int given +array_intersect_key(): Argument #2 must be of type array, int given + +--int 12345-- +array_intersect_key(): Argument #2 must be of type array, int given +array_intersect_key(): Argument #2 must be of type array, int given + +--int -12345-- +array_intersect_key(): Argument #2 must be of type array, int given +array_intersect_key(): Argument #2 must be of type array, int given + +--float 10.5-- +array_intersect_key(): Argument #2 must be of type array, float given +array_intersect_key(): Argument #2 must be of type array, float given + +--float -10.5-- +array_intersect_key(): Argument #2 must be of type array, float given +array_intersect_key(): Argument #2 must be of type array, float given + +--float 12.3456789000e10-- +array_intersect_key(): Argument #2 must be of type array, float given +array_intersect_key(): Argument #2 must be of type array, float given + +--float -12.3456789000e10-- +array_intersect_key(): Argument #2 must be of type array, float given +array_intersect_key(): Argument #2 must be of type array, float given + +--float .5-- +array_intersect_key(): Argument #2 must be of type array, float given +array_intersect_key(): Argument #2 must be of type array, float given + +--uppercase NULL-- +array_intersect_key(): Argument #2 must be of type array, null given +array_intersect_key(): Argument #2 must be of type array, null given + +--lowercase null-- +array_intersect_key(): Argument #2 must be of type array, null given +array_intersect_key(): Argument #2 must be of type array, null given + +--lowercase true-- +array_intersect_key(): Argument #2 must be of type array, true given +array_intersect_key(): Argument #2 must be of type array, true given + +--lowercase false-- +array_intersect_key(): Argument #2 must be of type array, false given +array_intersect_key(): Argument #2 must be of type array, false given + +--uppercase TRUE-- +array_intersect_key(): Argument #2 must be of type array, true given +array_intersect_key(): Argument #2 must be of type array, true given + +--uppercase FALSE-- +array_intersect_key(): Argument #2 must be of type array, false given +array_intersect_key(): Argument #2 must be of type array, false given + +--empty string DQ-- +array_intersect_key(): Argument #2 must be of type array, string given +array_intersect_key(): Argument #2 must be of type array, string given + +--empty string SQ-- +array_intersect_key(): Argument #2 must be of type array, string given +array_intersect_key(): Argument #2 must be of type array, string given + +--string DQ-- +array_intersect_key(): Argument #2 must be of type array, string given +array_intersect_key(): Argument #2 must be of type array, string given + +--string SQ-- +array_intersect_key(): Argument #2 must be of type array, string given +array_intersect_key(): Argument #2 must be of type array, string given + +--mixed case string-- +array_intersect_key(): Argument #2 must be of type array, string given +array_intersect_key(): Argument #2 must be of type array, string given + +--heredoc-- +array_intersect_key(): Argument #2 must be of type array, string given +array_intersect_key(): Argument #2 must be of type array, string given + +--instance of classWithToString-- +array_intersect_key(): Argument #2 must be of type array, classWithToString given +array_intersect_key(): Argument #2 must be of type array, classWithToString given + +--instance of classWithoutToString-- +array_intersect_key(): Argument #2 must be of type array, classWithoutToString given +array_intersect_key(): Argument #2 must be of type array, classWithoutToString given + +--undefined var-- +array_intersect_key(): Argument #2 must be of type array, null given +array_intersect_key(): Argument #2 must be of type array, null given + +--unset var-- +array_intersect_key(): Argument #2 must be of type array, null given +array_intersect_key(): Argument #2 must be of type array, null given + +--resource var-- +array_intersect_key(): Argument #2 must be of type array, resource given +array_intersect_key(): Argument #2 must be of type array, resource given diff --git a/tests/std/array/array_intersect_key_variation4.phpt b/tests/std/array/array_intersect_key_variation4.phpt new file mode 100644 index 00000000..50b2828f --- /dev/null +++ b/tests/std/array/array_intersect_key_variation4.phpt @@ -0,0 +1,53 @@ +--TEST-- +Test array_intersect_key() function : usage variation - Passing integer indexed array +--FILE-- + '0', -1 => '-1' , 02 => 'two', -07 => '-07', 0xA => '0xA', -0xC => '-0xc'); + +$input_arrays = array( + 'decimal indexed' => array(10 => '10', '-17' => '-17'), + 'octal indexed' => array(-011 => '-011', 012 => '012'), + 'hexa indexed' => array(0x12 => '0x12', -0x7 => '-0x7', ), +); + +foreach($input_arrays as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_intersect_key($input_array, $value) ); + var_dump( array_intersect_key($value,$input_array ) ); +} +?> +--EXPECT-- +*** Testing array_intersect_key() : usage variation *** + +--decimal indexed-- +array(1) { + [10]=> + string(3) "0xA" +} +array(1) { + [10]=> + string(2) "10" +} + +--octal indexed-- +array(1) { + [10]=> + string(3) "0xA" +} +array(1) { + [10]=> + string(3) "012" +} + +--hexa indexed-- +array(1) { + [-7]=> + string(3) "-07" +} +array(1) { + [-7]=> + string(4) "-0x7" +} diff --git a/tests/std/array/array_intersect_key_variation6.phpt b/tests/std/array/array_intersect_key_variation6.phpt new file mode 100644 index 00000000..b0113628 --- /dev/null +++ b/tests/std/array/array_intersect_key_variation6.phpt @@ -0,0 +1,31 @@ +--TEST-- +Test array_intersect_key() function : usage variation - Passing boolean indexed array +--SKIPIF-- +--FILE-- + '0', 1 => '1' , -10 => '-10'); +$boolean_indx_array = array(true => 'boolt', false => 'boolf', TRUE => 'boolT', FALSE => 'boolF'); + +echo "\n-- Testing array_intersect_key() function with boolean indexed array --\n"; +var_dump( array_intersect_key($input_array, $boolean_indx_array) ); +var_dump( array_intersect_key($boolean_indx_array,$input_array ) ); +?> +--EXPECT-- +*** Testing array_intersect_key() : usage variation *** + +-- Testing array_intersect_key() function with boolean indexed array -- +array(2) { + [0]=> + string(1) "0" + [1]=> + string(1) "1" +} +array(2) { + [1]=> + string(5) "boolT" + [0]=> + string(5) "boolF" +} diff --git a/tests/std/array/array_intersect_key_variation7.phpt b/tests/std/array/array_intersect_key_variation7.phpt new file mode 100644 index 00000000..06126612 --- /dev/null +++ b/tests/std/array/array_intersect_key_variation7.phpt @@ -0,0 +1,61 @@ +--TEST-- +Test array_intersect_key() function : usage variation - Passing null,unset and undefeined variable indexed array +--SKIPIF-- + + +--FILE-- + '0', 1 => '1' , -10 => '-10' , null => 'null'); +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +$input_arrays = array( + 'null indexed' => array(NULL => 'null 1', null => 'null 2'), + 'undefined indexed' => array(@$undefined_var => 'undefined'), + 'unset indexed' => array(@$unset_var => 'unset'), +); + +foreach($input_arrays as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_intersect_key($input_array, $value) ); + var_dump( array_intersect_key($value,$input_array ) ); +} +?> +--EXPECT-- +*** Testing array_intersect_key() : usage variation *** + +--null indexed-- +array(1) { + [""]=> + string(4) "null" +} +array(1) { + [""]=> + string(6) "null 2" +} + +--undefined indexed-- +array(1) { + [""]=> + string(4) "null" +} +array(1) { + [""]=> + string(9) "undefined" +} + +--unset indexed-- +array(1) { + [""]=> + string(4) "null" +} +array(1) { + [""]=> + string(5) "unset" +} diff --git a/tests/std/array/array_intersect_key_variation8.phpt b/tests/std/array/array_intersect_key_variation8.phpt new file mode 100644 index 00000000..b16c324d --- /dev/null +++ b/tests/std/array/array_intersect_key_variation8.phpt @@ -0,0 +1,57 @@ +--TEST-- +Test array_intersect_key() function : usage variation - Passing Multi dimensional array +--FILE-- + array('blue' => 1, 'red' => 2), + + 'second' => array('yellow' => 7), + + 'third' => array(0 =>'zero'), +); + +$array2 = array ( + + 'first' => array('blue' => 1, 'red' => 2,), + + 'second' => array('cyan' => 8), + + 'fourth' => array(2 => 'two'), +); +var_dump( array_intersect_key($array1, $array2) ); +var_dump( array_intersect_key($array2,$array1 ) ); +?> +--EXPECT-- +*** Testing array_intersect_key() : usage variation *** +array(2) { + ["first"]=> + array(2) { + ["blue"]=> + int(1) + ["red"]=> + int(2) + } + ["second"]=> + array(1) { + ["yellow"]=> + int(7) + } +} +array(2) { + ["first"]=> + array(2) { + ["blue"]=> + int(1) + ["red"]=> + int(2) + } + ["second"]=> + array(1) { + ["cyan"]=> + int(8) + } +} diff --git a/tests/std/array/array_intersect_uassoc_basic.phpt b/tests/std/array/array_intersect_uassoc_basic.phpt new file mode 100644 index 00000000..7721772d --- /dev/null +++ b/tests/std/array/array_intersect_uassoc_basic.phpt @@ -0,0 +1,28 @@ +--TEST-- +array_intersect_uassoc(): Basic test +--FILE-- + $b ? 1 : -1; +} +function main() +{ + $array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red"); + $array2 = array("a" => "green", "yellow", "red"); + $result = array_intersect_uassoc($array1, $array2, "key_compare_func"); + var_dump($result); +} +?> +--EXPECT-- +array(1) { + ["a"]=> + string(5) "green" +} diff --git a/tests/std/array/array_intersect_uassoc_variation1.phpt b/tests/std/array/array_intersect_uassoc_variation1.phpt new file mode 100644 index 00000000..c5bbded7 --- /dev/null +++ b/tests/std/array/array_intersect_uassoc_variation1.phpt @@ -0,0 +1,207 @@ +--TEST-- +Test array_intersect_uassoc() function : usage variation - Passing unexpected values to first argument +--SKIPIF-- + + +--FILE-- + $b ? 1 : -1; +} +// define some classes +class classWithToString +{ + public function __toString(): string { + return "Class A object"; + } +} +class classWithoutToString +{ +} +function main() +{ + echo "*** Testing array_intersect_uassoc() : usage variation ***\n"; + // Initialise function arguments + $array2 = array("a" => "green", "yellow", "red"); + $array3 = array("a" => "green", "brown"); + //get an unset variable + $unset_var = 10; + unset($unset_var); + //resource variable + $fp = fopen(__FILE__, "r"); + // heredoc string + $heredoc = << 1, 'two' => 2); + //array of values to iterate over + $inputs = array( + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -12345, + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 123456789000.0, + 'float -12.3456789000e10' => -123456789000.0, + 'float .5' => 0.5, + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + // boolean data + 'lowercase true' => true, + 'lowercase false' => false, + 'uppercase TRUE' => TRUE, + 'uppercase FALSE' => FALSE, + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + // undefined data + 'undefined var' => @$undefined_var, + // unset data + 'unset var' => @$unset_var, + // resource data + 'resource' => $fp, + ); + // loop through each element of the array for array1 + foreach ($inputs as $key => $value) { + echo "\n--{$key}--\n"; + try { + var_dump(array_intersect_uassoc($value, $array2, 'key_compare_func')); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + try { + var_dump(array_intersect_uassoc($value, $array2, $array3, 'key_compare_func')); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + } + fclose($fp); +} +?> +--EXPECT-- +*** Testing array_intersect_uassoc() : usage variation *** + +--int 0-- +array_intersect_uassoc(): Argument #1 ($array) must be of type array, int given +array_intersect_uassoc(): Argument #1 ($array) must be of type array, int given + +--int 1-- +array_intersect_uassoc(): Argument #1 ($array) must be of type array, int given +array_intersect_uassoc(): Argument #1 ($array) must be of type array, int given + +--int 12345-- +array_intersect_uassoc(): Argument #1 ($array) must be of type array, int given +array_intersect_uassoc(): Argument #1 ($array) must be of type array, int given + +--int -12345-- +array_intersect_uassoc(): Argument #1 ($array) must be of type array, int given +array_intersect_uassoc(): Argument #1 ($array) must be of type array, int given + +--float 10.5-- +array_intersect_uassoc(): Argument #1 ($array) must be of type array, float given +array_intersect_uassoc(): Argument #1 ($array) must be of type array, float given + +--float -10.5-- +array_intersect_uassoc(): Argument #1 ($array) must be of type array, float given +array_intersect_uassoc(): Argument #1 ($array) must be of type array, float given + +--float 12.3456789000e10-- +array_intersect_uassoc(): Argument #1 ($array) must be of type array, float given +array_intersect_uassoc(): Argument #1 ($array) must be of type array, float given + +--float -12.3456789000e10-- +array_intersect_uassoc(): Argument #1 ($array) must be of type array, float given +array_intersect_uassoc(): Argument #1 ($array) must be of type array, float given + +--float .5-- +array_intersect_uassoc(): Argument #1 ($array) must be of type array, float given +array_intersect_uassoc(): Argument #1 ($array) must be of type array, float given + +--uppercase NULL-- +array_intersect_uassoc(): Argument #1 ($array) must be of type array, null given +array_intersect_uassoc(): Argument #1 ($array) must be of type array, null given + +--lowercase null-- +array_intersect_uassoc(): Argument #1 ($array) must be of type array, null given +array_intersect_uassoc(): Argument #1 ($array) must be of type array, null given + +--lowercase true-- +array_intersect_uassoc(): Argument #1 ($array) must be of type array, true given +array_intersect_uassoc(): Argument #1 ($array) must be of type array, true given + +--lowercase false-- +array_intersect_uassoc(): Argument #1 ($array) must be of type array, false given +array_intersect_uassoc(): Argument #1 ($array) must be of type array, false given + +--uppercase TRUE-- +array_intersect_uassoc(): Argument #1 ($array) must be of type array, true given +array_intersect_uassoc(): Argument #1 ($array) must be of type array, true given + +--uppercase FALSE-- +array_intersect_uassoc(): Argument #1 ($array) must be of type array, false given +array_intersect_uassoc(): Argument #1 ($array) must be of type array, false given + +--empty string DQ-- +array_intersect_uassoc(): Argument #1 ($array) must be of type array, string given +array_intersect_uassoc(): Argument #1 ($array) must be of type array, string given + +--empty string SQ-- +array_intersect_uassoc(): Argument #1 ($array) must be of type array, string given +array_intersect_uassoc(): Argument #1 ($array) must be of type array, string given + +--string DQ-- +array_intersect_uassoc(): Argument #1 ($array) must be of type array, string given +array_intersect_uassoc(): Argument #1 ($array) must be of type array, string given + +--string SQ-- +array_intersect_uassoc(): Argument #1 ($array) must be of type array, string given +array_intersect_uassoc(): Argument #1 ($array) must be of type array, string given + +--mixed case string-- +array_intersect_uassoc(): Argument #1 ($array) must be of type array, string given +array_intersect_uassoc(): Argument #1 ($array) must be of type array, string given + +--heredoc-- +array_intersect_uassoc(): Argument #1 ($array) must be of type array, string given +array_intersect_uassoc(): Argument #1 ($array) must be of type array, string given + +--instance of classWithToString-- +array_intersect_uassoc(): Argument #1 ($array) must be of type array, classWithToString given +array_intersect_uassoc(): Argument #1 ($array) must be of type array, classWithToString given + +--instance of classWithoutToString-- +array_intersect_uassoc(): Argument #1 ($array) must be of type array, classWithoutToString given +array_intersect_uassoc(): Argument #1 ($array) must be of type array, classWithoutToString given + +--undefined var-- +array_intersect_uassoc(): Argument #1 ($array) must be of type array, null given +array_intersect_uassoc(): Argument #1 ($array) must be of type array, null given + +--unset var-- +array_intersect_uassoc(): Argument #1 ($array) must be of type array, null given +array_intersect_uassoc(): Argument #1 ($array) must be of type array, null given + +--resource-- +array_intersect_uassoc(): Argument #1 ($array) must be of type array, resource given +array_intersect_uassoc(): Argument #1 ($array) must be of type array, resource given diff --git a/tests/std/array/array_intersect_uassoc_variation10.phpt b/tests/std/array/array_intersect_uassoc_variation10.phpt new file mode 100644 index 00000000..c18a90aa --- /dev/null +++ b/tests/std/array/array_intersect_uassoc_variation10.phpt @@ -0,0 +1,48 @@ +--TEST-- +Test array_intersect_uassoc() function : usage variation - Passing class/object methods to callback +--FILE-- + "green", "c" => "blue", "red"); + $array2 = array("a" => "green", "yellow", "red"); + echo "\n-- Testing array_intersect_uassoc() function using class with static method as callback --\n"; + var_dump(array_intersect_uassoc($array1, $array2, array('MyClass', 'static_compare_func'))); + var_dump(array_intersect_uassoc($array1, $array2, 'MyClass::static_compare_func')); + echo "\n-- Testing array_intersect_uassoc() function using class with regular method as callback --\n"; + $obj = new MyClass(); + var_dump(array_intersect_uassoc($array1, $array2, array($obj, 'class_compare_func'))); +} +?> +--EXPECT-- +*** Testing array_intersect_uassoc() : usage variation *** + +-- Testing array_intersect_uassoc() function using class with static method as callback -- +array(1) { + ["a"]=> + string(5) "green" +} +array(1) { + ["a"]=> + string(5) "green" +} + +-- Testing array_intersect_uassoc() function using class with regular method as callback -- +array(1) { + ["a"]=> + string(5) "green" +} diff --git a/tests/std/array/array_intersect_uassoc_variation2.phpt b/tests/std/array/array_intersect_uassoc_variation2.phpt new file mode 100644 index 00000000..b775702f --- /dev/null +++ b/tests/std/array/array_intersect_uassoc_variation2.phpt @@ -0,0 +1,207 @@ +--TEST-- +Test array_intersect_uassoc() function : usage variation - Passing unexpected values to second argument +--SKIPIF-- + + +--FILE-- + $b ? 1 : -1; +} +// define some classes +class classWithToString +{ + public function __toString(): string { + return "Class A object"; + } +} +class classWithoutToString +{ +} +function main() +{ + echo "*** Testing array_intersect_uassoc() : usage variation ***\n"; + // Initialise function arguments + $array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red"); + $array3 = array("a" => "green", "brown"); + //get an unset variable + $unset_var = 10; + unset($unset_var); + //resource variable + $fp = fopen(__FILE__, "r"); + // heredoc string + $heredoc = << 1, 'two' => 2); + //array of values to iterate over + $inputs = array( + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -12345, + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 123456789000.0, + 'float -12.3456789000e10' => -123456789000.0, + 'float .5' => 0.5, + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + // boolean data + 'lowercase true' => true, + 'lowercase false' => false, + 'uppercase TRUE' => TRUE, + 'uppercase FALSE' => FALSE, + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + // undefined data + 'undefined var' => @$undefined_var, + // unset data + 'unset var' => @$unset_var, + // resource data + 'resource' => $fp, + ); + // loop through each element of the array for array1 + foreach ($inputs as $key => $value) { + echo "\n--{$key}--\n"; + try { + var_dump(array_intersect_uassoc($array1, $value, 'key_compare_func')); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + try { + var_dump(array_intersect_uassoc($array1, $value, $array3, 'key_compare_func')); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + } + fclose($fp); +} +?> +--EXPECT-- +*** Testing array_intersect_uassoc() : usage variation *** + +--int 0-- +array_intersect_uassoc(): Argument #2 must be of type array, int given +array_intersect_uassoc(): Argument #2 must be of type array, int given + +--int 1-- +array_intersect_uassoc(): Argument #2 must be of type array, int given +array_intersect_uassoc(): Argument #2 must be of type array, int given + +--int 12345-- +array_intersect_uassoc(): Argument #2 must be of type array, int given +array_intersect_uassoc(): Argument #2 must be of type array, int given + +--int -12345-- +array_intersect_uassoc(): Argument #2 must be of type array, int given +array_intersect_uassoc(): Argument #2 must be of type array, int given + +--float 10.5-- +array_intersect_uassoc(): Argument #2 must be of type array, float given +array_intersect_uassoc(): Argument #2 must be of type array, float given + +--float -10.5-- +array_intersect_uassoc(): Argument #2 must be of type array, float given +array_intersect_uassoc(): Argument #2 must be of type array, float given + +--float 12.3456789000e10-- +array_intersect_uassoc(): Argument #2 must be of type array, float given +array_intersect_uassoc(): Argument #2 must be of type array, float given + +--float -12.3456789000e10-- +array_intersect_uassoc(): Argument #2 must be of type array, float given +array_intersect_uassoc(): Argument #2 must be of type array, float given + +--float .5-- +array_intersect_uassoc(): Argument #2 must be of type array, float given +array_intersect_uassoc(): Argument #2 must be of type array, float given + +--uppercase NULL-- +array_intersect_uassoc(): Argument #2 must be of type array, null given +array_intersect_uassoc(): Argument #2 must be of type array, null given + +--lowercase null-- +array_intersect_uassoc(): Argument #2 must be of type array, null given +array_intersect_uassoc(): Argument #2 must be of type array, null given + +--lowercase true-- +array_intersect_uassoc(): Argument #2 must be of type array, true given +array_intersect_uassoc(): Argument #2 must be of type array, true given + +--lowercase false-- +array_intersect_uassoc(): Argument #2 must be of type array, false given +array_intersect_uassoc(): Argument #2 must be of type array, false given + +--uppercase TRUE-- +array_intersect_uassoc(): Argument #2 must be of type array, true given +array_intersect_uassoc(): Argument #2 must be of type array, true given + +--uppercase FALSE-- +array_intersect_uassoc(): Argument #2 must be of type array, false given +array_intersect_uassoc(): Argument #2 must be of type array, false given + +--empty string DQ-- +array_intersect_uassoc(): Argument #2 must be of type array, string given +array_intersect_uassoc(): Argument #2 must be of type array, string given + +--empty string SQ-- +array_intersect_uassoc(): Argument #2 must be of type array, string given +array_intersect_uassoc(): Argument #2 must be of type array, string given + +--string DQ-- +array_intersect_uassoc(): Argument #2 must be of type array, string given +array_intersect_uassoc(): Argument #2 must be of type array, string given + +--string SQ-- +array_intersect_uassoc(): Argument #2 must be of type array, string given +array_intersect_uassoc(): Argument #2 must be of type array, string given + +--mixed case string-- +array_intersect_uassoc(): Argument #2 must be of type array, string given +array_intersect_uassoc(): Argument #2 must be of type array, string given + +--heredoc-- +array_intersect_uassoc(): Argument #2 must be of type array, string given +array_intersect_uassoc(): Argument #2 must be of type array, string given + +--instance of classWithToString-- +array_intersect_uassoc(): Argument #2 must be of type array, classWithToString given +array_intersect_uassoc(): Argument #2 must be of type array, classWithToString given + +--instance of classWithoutToString-- +array_intersect_uassoc(): Argument #2 must be of type array, classWithoutToString given +array_intersect_uassoc(): Argument #2 must be of type array, classWithoutToString given + +--undefined var-- +array_intersect_uassoc(): Argument #2 must be of type array, null given +array_intersect_uassoc(): Argument #2 must be of type array, null given + +--unset var-- +array_intersect_uassoc(): Argument #2 must be of type array, null given +array_intersect_uassoc(): Argument #2 must be of type array, null given + +--resource-- +array_intersect_uassoc(): Argument #2 must be of type array, resource given +array_intersect_uassoc(): Argument #2 must be of type array, resource given diff --git a/tests/std/array/array_intersect_uassoc_variation5.phpt b/tests/std/array/array_intersect_uassoc_variation5.phpt new file mode 100644 index 00000000..9ed4fd68 --- /dev/null +++ b/tests/std/array/array_intersect_uassoc_variation5.phpt @@ -0,0 +1,49 @@ +--TEST-- +Test array_intersect_uassoc() function : usage variation - Intersection of integers with floats and strings. +--FILE-- + $b ? 1 : -1; +} +function main() +{ + echo "*** Testing array_intersect_uassoc() : usage variation ***\n"; + //Initialize variables + $arr_default_int = array(1, 2); + $arr_float = array(0 => 1.0, 1 => 2.0, 2 => 3.0); + $arr_string = array('1', '2', '3'); + $arr_string_float = array('1.00', '2.00'); + echo "\n-- Result of integers and floating point intersection --\n"; + var_dump(array_intersect_uassoc($arr_default_int, $arr_float, "key_compare_func")); + echo "\n-- Result of integers and strings containing integers intersection --\n"; + var_dump(array_intersect_uassoc($arr_default_int, $arr_string, "key_compare_func")); + echo "\n-- Result of integers and strings containing floating points intersection --\n"; + var_dump(array_intersect_uassoc($arr_default_int, $arr_string_float, "key_compare_func")); +} +?> +--EXPECT-- +*** Testing array_intersect_uassoc() : usage variation *** + +-- Result of integers and floating point intersection -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + +-- Result of integers and strings containing integers intersection -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + +-- Result of integers and strings containing floating points intersection -- +array(0) { +} diff --git a/tests/std/array/array_intersect_uassoc_variation6.phpt b/tests/std/array/array_intersect_uassoc_variation6.phpt new file mode 100644 index 00000000..77ef7bdc --- /dev/null +++ b/tests/std/array/array_intersect_uassoc_variation6.phpt @@ -0,0 +1,38 @@ +--TEST-- +Test array_intersect_uassoc() function : usage variation - Intersection of floating points with strings. +--FILE-- + $b ? 1 : -1; +} +function main() +{ + echo "*** Testing array_intersect_uassoc() : usage variation ***\n"; + //Initialize variables + $arr_float = array(0 => 1.0, 1 => 2.0); + $arr_string = array('1', '2', '3'); + $arr_string_float = array('1.00', '2.00'); + echo "\n-- Result of floating points and strings containing integers intersection --\n"; + var_dump(array_intersect_uassoc($arr_float, $arr_string, "key_compare_func")); + echo "\n-- Result of floating points and strings containing floating point intersection --\n"; + var_dump(array_intersect_uassoc($arr_float, $arr_string_float, "key_compare_func")); +} +?> +--EXPECT-- +*** Testing array_intersect_uassoc() : usage variation *** + +-- Result of floating points and strings containing integers intersection -- +array(2) { + [0]=> + float(1) + [1]=> + float(2) +} + +-- Result of floating points and strings containing floating point intersection -- +array(0) { +} diff --git a/tests/std/array/array_intersect_uassoc_variation7.phpt b/tests/std/array/array_intersect_uassoc_variation7.phpt new file mode 100644 index 00000000..0fc689e2 --- /dev/null +++ b/tests/std/array/array_intersect_uassoc_variation7.phpt @@ -0,0 +1,45 @@ +--TEST-- +Test array_intersect_uassoc() function : usage variation - Intersection of strings containing integers, float +--FILE-- + $b ? 1 : -1; +} +function main() +{ + echo "*** Testing array_intersect_uassoc() : usage variation ***\n"; + //Initialize variables + $arr1_string_int = array('1', '2'); + $arr2_string_int = array('1', '3'); + $arr1_string_float = array('1.00', '2.00'); + $arr2_string_float = array('1.00', '3.00'); + echo "\n-- Result of strings containing integers intersection --\n"; + var_dump(array_intersect_uassoc($arr1_string_int, $arr2_string_int, "key_compare_func")); + echo "\n-- Result of strings containing floating points intersection --\n"; + var_dump(array_intersect_uassoc($arr1_string_float, $arr2_string_float, "key_compare_func")); + echo "\n-- Result of strings containing integers and strings containing floating points intersection --\n"; + var_dump(array_intersect_uassoc($arr1_string_int, $arr2_string_float, "key_compare_func")); +} +?> +--EXPECT-- +*** Testing array_intersect_uassoc() : usage variation *** + +-- Result of strings containing integers intersection -- +array(1) { + [0]=> + string(1) "1" +} + +-- Result of strings containing floating points intersection -- +array(1) { + [0]=> + string(4) "1.00" +} + +-- Result of strings containing integers and strings containing floating points intersection -- +array(0) { +} diff --git a/tests/std/array/array_intersect_uassoc_variation8.phpt b/tests/std/array/array_intersect_uassoc_variation8.phpt new file mode 100644 index 00000000..fd94f4bc --- /dev/null +++ b/tests/std/array/array_intersect_uassoc_variation8.phpt @@ -0,0 +1,49 @@ +--TEST-- +Test array_intersect_uassoc() function : usage variation - arrays containing referenced variables +--SKIPIF-- + + +--FILE-- + 1, &$ref_var); + +echo "\n-- Testing array_intersect_uassoc() function with referenced variable \$ref_var has value '$ref_var' --\n"; +var_dump( array_intersect_uassoc($array1, $array2, "strcasecmp") ); + +// re-assign reference variable to different value +$ref_var = 10; +echo "\n-- Testing array_intersect_uassoc() function with referenced variable \$ref_var value changed to $ref_var --\n"; +var_dump( array_intersect_uassoc($array1, $array2, "strcasecmp") ); + +//When array are referenced +$array2 = &$array1; +echo "\n-- Testing array_intersect_uassoc() function when \$array2 is referencd to \$array1 --\n"; +var_dump( array_intersect_uassoc($array1, $array2, "strcasecmp") ); +?> +--EXPECT-- +*** Testing array_intersect_uassoc() : usage variation *** + +-- Testing array_intersect_uassoc() function with referenced variable $ref_var has value 'a' -- +array(1) { + [0]=> + string(1) "a" +} + +-- Testing array_intersect_uassoc() function with referenced variable $ref_var value changed to 10 -- +array(0) { +} + +-- Testing array_intersect_uassoc() function when $array2 is referencd to $array1 -- +array(2) { + [0]=> + string(1) "a" + [1]=> + string(1) "a" +} diff --git a/tests/std/array/array_intersect_ukey_basic.phpt b/tests/std/array/array_intersect_ukey_basic.phpt new file mode 100644 index 00000000..e16f110f --- /dev/null +++ b/tests/std/array/array_intersect_ukey_basic.phpt @@ -0,0 +1,31 @@ +--TEST-- +array_intersect_ukey(): Basic test. +--FILE-- + $key2) { + return 1; + } else { + return -1; + } +} +function main() +{ + $array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); + $array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); + var_dump(array_intersect_ukey($array1, $array2, 'key_compare_func')); +} +?> +--EXPECT-- +array(2) { + ["blue"]=> + int(1) + ["green"]=> + int(3) +} diff --git a/tests/std/array/array_intersect_ukey_variation1.phpt b/tests/std/array/array_intersect_ukey_variation1.phpt new file mode 100644 index 00000000..28b89895 --- /dev/null +++ b/tests/std/array/array_intersect_ukey_variation1.phpt @@ -0,0 +1,205 @@ +--TEST-- +Test array_intersect_ukey() function : usage variation - Passing unexpected values to first argument +--SKIPIF-- + + +--FILE-- + $key2 ? 1 : -1; + } +} +// define some classes +class classWithToString +{ + public function __toString(): string { + return "Class A object"; + } +} +class classWithoutToString +{ +} +function main() +{ + echo "*** Testing array_intersect_ukey() : usage variation ***\n"; + //Initialise arguments + $array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); + $array3 = array('green' => 5, 'cyan' => 8); + //get an unset variable + $unset_var = 10; + unset($unset_var); + //resource variable + $fp = fopen(__FILE__, "r"); + // heredoc string + $heredoc = << 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -12345, + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 123456789000.0, + 'float -12.3456789000e10' => -123456789000.0, + 'float .5' => 0.5, + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + // boolean data + 'lowercase true' => true, + 'lowercase false' => false, + 'uppercase TRUE' => TRUE, + 'uppercase FALSE' => FALSE, + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + // undefined data + 'undefined var' => @$undefined_var, + // unset data + 'unset var' => @$unset_var, + // resource data + 'resource var' => $fp, + ); + // loop through each element of the array for array1 + foreach ($inputs as $key => $value) { + echo "\n--{$key}--\n"; + try { + var_dump(array_intersect_ukey($value, $array2, 'key_compare_func')); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + try { + var_dump(array_intersect_ukey($value, $array2, $array3, 'key_compare_func')); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + } + fclose($fp); +} +?> +--EXPECT-- +*** Testing array_intersect_ukey() : usage variation *** + +--int 0-- +array_intersect_ukey(): Argument #1 ($array) must be of type array, int given +array_intersect_ukey(): Argument #1 ($array) must be of type array, int given + +--int 1-- +array_intersect_ukey(): Argument #1 ($array) must be of type array, int given +array_intersect_ukey(): Argument #1 ($array) must be of type array, int given + +--int 12345-- +array_intersect_ukey(): Argument #1 ($array) must be of type array, int given +array_intersect_ukey(): Argument #1 ($array) must be of type array, int given + +--int -12345-- +array_intersect_ukey(): Argument #1 ($array) must be of type array, int given +array_intersect_ukey(): Argument #1 ($array) must be of type array, int given + +--float 10.5-- +array_intersect_ukey(): Argument #1 ($array) must be of type array, float given +array_intersect_ukey(): Argument #1 ($array) must be of type array, float given + +--float -10.5-- +array_intersect_ukey(): Argument #1 ($array) must be of type array, float given +array_intersect_ukey(): Argument #1 ($array) must be of type array, float given + +--float 12.3456789000e10-- +array_intersect_ukey(): Argument #1 ($array) must be of type array, float given +array_intersect_ukey(): Argument #1 ($array) must be of type array, float given + +--float -12.3456789000e10-- +array_intersect_ukey(): Argument #1 ($array) must be of type array, float given +array_intersect_ukey(): Argument #1 ($array) must be of type array, float given + +--float .5-- +array_intersect_ukey(): Argument #1 ($array) must be of type array, float given +array_intersect_ukey(): Argument #1 ($array) must be of type array, float given + +--uppercase NULL-- +array_intersect_ukey(): Argument #1 ($array) must be of type array, null given +array_intersect_ukey(): Argument #1 ($array) must be of type array, null given + +--lowercase null-- +array_intersect_ukey(): Argument #1 ($array) must be of type array, null given +array_intersect_ukey(): Argument #1 ($array) must be of type array, null given + +--lowercase true-- +array_intersect_ukey(): Argument #1 ($array) must be of type array, true given +array_intersect_ukey(): Argument #1 ($array) must be of type array, true given + +--lowercase false-- +array_intersect_ukey(): Argument #1 ($array) must be of type array, false given +array_intersect_ukey(): Argument #1 ($array) must be of type array, false given + +--uppercase TRUE-- +array_intersect_ukey(): Argument #1 ($array) must be of type array, true given +array_intersect_ukey(): Argument #1 ($array) must be of type array, true given + +--uppercase FALSE-- +array_intersect_ukey(): Argument #1 ($array) must be of type array, false given +array_intersect_ukey(): Argument #1 ($array) must be of type array, false given + +--empty string DQ-- +array_intersect_ukey(): Argument #1 ($array) must be of type array, string given +array_intersect_ukey(): Argument #1 ($array) must be of type array, string given + +--empty string SQ-- +array_intersect_ukey(): Argument #1 ($array) must be of type array, string given +array_intersect_ukey(): Argument #1 ($array) must be of type array, string given + +--string DQ-- +array_intersect_ukey(): Argument #1 ($array) must be of type array, string given +array_intersect_ukey(): Argument #1 ($array) must be of type array, string given + +--string SQ-- +array_intersect_ukey(): Argument #1 ($array) must be of type array, string given +array_intersect_ukey(): Argument #1 ($array) must be of type array, string given + +--mixed case string-- +array_intersect_ukey(): Argument #1 ($array) must be of type array, string given +array_intersect_ukey(): Argument #1 ($array) must be of type array, string given + +--heredoc-- +array_intersect_ukey(): Argument #1 ($array) must be of type array, string given +array_intersect_ukey(): Argument #1 ($array) must be of type array, string given + +--instance of classWithToString-- +array_intersect_ukey(): Argument #1 ($array) must be of type array, classWithToString given +array_intersect_ukey(): Argument #1 ($array) must be of type array, classWithToString given + +--instance of classWithoutToString-- +array_intersect_ukey(): Argument #1 ($array) must be of type array, classWithoutToString given +array_intersect_ukey(): Argument #1 ($array) must be of type array, classWithoutToString given + +--undefined var-- +array_intersect_ukey(): Argument #1 ($array) must be of type array, null given +array_intersect_ukey(): Argument #1 ($array) must be of type array, null given + +--unset var-- +array_intersect_ukey(): Argument #1 ($array) must be of type array, null given +array_intersect_ukey(): Argument #1 ($array) must be of type array, null given + +--resource var-- +array_intersect_ukey(): Argument #1 ($array) must be of type array, resource given +array_intersect_ukey(): Argument #1 ($array) must be of type array, resource given diff --git a/tests/std/array/array_intersect_ukey_variation2.phpt b/tests/std/array/array_intersect_ukey_variation2.phpt new file mode 100644 index 00000000..43f411af --- /dev/null +++ b/tests/std/array/array_intersect_ukey_variation2.phpt @@ -0,0 +1,205 @@ +--TEST-- +Test array_intersect_ukey() function : usage variation - Passing unexpected values to second argument +--SKIPIF-- + + +--FILE-- + $key2 ? 1 : -1; + } +} +// define some classes +class classWithToString +{ + public function __toString(): string { + return "Class A object"; + } +} +class classWithoutToString +{ +} +function main() +{ + echo "*** Testing array_intersect_ukey() : usage variation ***\n"; + //Initialise arguments + $array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); + $array3 = array('green' => 5, 'cyan' => 8); + //get an unset variable + $unset_var = 10; + unset($unset_var); + //resource variable + $fp = fopen(__FILE__, "r"); + // heredoc string + $heredoc = << 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -12345, + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 123456789000.0, + 'float -12.3456789000e10' => -123456789000.0, + 'float .5' => 0.5, + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + // boolean data + 'lowercase true' => true, + 'lowercase false' => false, + 'uppercase TRUE' => TRUE, + 'uppercase FALSE' => FALSE, + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + // undefined data + 'undefined var' => @$undefined_var, + // unset data + 'unset var' => @$unset_var, + // resource data + 'resource var' => $fp, + ); + // loop through each element of the array for array2 + foreach ($inputs as $key => $value) { + echo "\n--{$key}--\n"; + try { + var_dump(array_intersect_ukey($array1, $value, 'key_compare_func')); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + try { + var_dump(array_intersect_ukey($array1, $value, $array3, 'key_compare_func')); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + } + fclose($fp); +} +?> +--EXPECT-- +*** Testing array_intersect_ukey() : usage variation *** + +--int 0-- +array_intersect_ukey(): Argument #2 must be of type array, int given +array_intersect_ukey(): Argument #2 must be of type array, int given + +--int 1-- +array_intersect_ukey(): Argument #2 must be of type array, int given +array_intersect_ukey(): Argument #2 must be of type array, int given + +--int 12345-- +array_intersect_ukey(): Argument #2 must be of type array, int given +array_intersect_ukey(): Argument #2 must be of type array, int given + +--int -12345-- +array_intersect_ukey(): Argument #2 must be of type array, int given +array_intersect_ukey(): Argument #2 must be of type array, int given + +--float 10.5-- +array_intersect_ukey(): Argument #2 must be of type array, float given +array_intersect_ukey(): Argument #2 must be of type array, float given + +--float -10.5-- +array_intersect_ukey(): Argument #2 must be of type array, float given +array_intersect_ukey(): Argument #2 must be of type array, float given + +--float 12.3456789000e10-- +array_intersect_ukey(): Argument #2 must be of type array, float given +array_intersect_ukey(): Argument #2 must be of type array, float given + +--float -12.3456789000e10-- +array_intersect_ukey(): Argument #2 must be of type array, float given +array_intersect_ukey(): Argument #2 must be of type array, float given + +--float .5-- +array_intersect_ukey(): Argument #2 must be of type array, float given +array_intersect_ukey(): Argument #2 must be of type array, float given + +--uppercase NULL-- +array_intersect_ukey(): Argument #2 must be of type array, null given +array_intersect_ukey(): Argument #2 must be of type array, null given + +--lowercase null-- +array_intersect_ukey(): Argument #2 must be of type array, null given +array_intersect_ukey(): Argument #2 must be of type array, null given + +--lowercase true-- +array_intersect_ukey(): Argument #2 must be of type array, true given +array_intersect_ukey(): Argument #2 must be of type array, true given + +--lowercase false-- +array_intersect_ukey(): Argument #2 must be of type array, false given +array_intersect_ukey(): Argument #2 must be of type array, false given + +--uppercase TRUE-- +array_intersect_ukey(): Argument #2 must be of type array, true given +array_intersect_ukey(): Argument #2 must be of type array, true given + +--uppercase FALSE-- +array_intersect_ukey(): Argument #2 must be of type array, false given +array_intersect_ukey(): Argument #2 must be of type array, false given + +--empty string DQ-- +array_intersect_ukey(): Argument #2 must be of type array, string given +array_intersect_ukey(): Argument #2 must be of type array, string given + +--empty string SQ-- +array_intersect_ukey(): Argument #2 must be of type array, string given +array_intersect_ukey(): Argument #2 must be of type array, string given + +--string DQ-- +array_intersect_ukey(): Argument #2 must be of type array, string given +array_intersect_ukey(): Argument #2 must be of type array, string given + +--string SQ-- +array_intersect_ukey(): Argument #2 must be of type array, string given +array_intersect_ukey(): Argument #2 must be of type array, string given + +--mixed case string-- +array_intersect_ukey(): Argument #2 must be of type array, string given +array_intersect_ukey(): Argument #2 must be of type array, string given + +--heredoc-- +array_intersect_ukey(): Argument #2 must be of type array, string given +array_intersect_ukey(): Argument #2 must be of type array, string given + +--instance of classWithToString-- +array_intersect_ukey(): Argument #2 must be of type array, classWithToString given +array_intersect_ukey(): Argument #2 must be of type array, classWithToString given + +--instance of classWithoutToString-- +array_intersect_ukey(): Argument #2 must be of type array, classWithoutToString given +array_intersect_ukey(): Argument #2 must be of type array, classWithoutToString given + +--undefined var-- +array_intersect_ukey(): Argument #2 must be of type array, null given +array_intersect_ukey(): Argument #2 must be of type array, null given + +--unset var-- +array_intersect_ukey(): Argument #2 must be of type array, null given +array_intersect_ukey(): Argument #2 must be of type array, null given + +--resource var-- +array_intersect_ukey(): Argument #2 must be of type array, resource given +array_intersect_ukey(): Argument #2 must be of type array, resource given diff --git a/tests/std/array/array_intersect_ukey_variation5.phpt b/tests/std/array/array_intersect_ukey_variation5.phpt new file mode 100644 index 00000000..b870b52b --- /dev/null +++ b/tests/std/array/array_intersect_ukey_variation5.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test array_intersect_ukey() function : usage variation - Intersection of integers with floats and strings. +--FILE-- + $key2 ? 1 : -1; + } +} +function main() +{ + echo "*** Testing array_intersect_ukey() : usage variation ***\n"; + //Initialize variables + $arr_default_int = array(1, 2); + $arr_float = array(0 => 1.0, 1 => 2.0, 2 => 3.0); + $arr_string = array('0' => '1', '1' => '2', '2' => '3'); + $arr_string_float = array('0.00' => '1.00', '1.00' => '2.00'); + echo "\n-- Result of integers and floating point intersection --\n"; + var_dump(array_intersect_ukey($arr_default_int, $arr_float, "key_compare_func")); + echo "\n-- Result of integers and strings containing integers intersection --\n"; + var_dump(array_intersect_ukey($arr_default_int, $arr_string, "key_compare_func")); + echo "\n-- Result of integers and strings containing floating points intersection --\n"; + var_dump(array_intersect_ukey($arr_default_int, $arr_string_float, "key_compare_func")); +} +?> +--EXPECT-- +*** Testing array_intersect_ukey() : usage variation *** + +-- Result of integers and floating point intersection -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + +-- Result of integers and strings containing integers intersection -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + +-- Result of integers and strings containing floating points intersection -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} diff --git a/tests/std/array/array_intersect_ukey_variation6.phpt b/tests/std/array/array_intersect_ukey_variation6.phpt new file mode 100644 index 00000000..b7da0c29 --- /dev/null +++ b/tests/std/array/array_intersect_ukey_variation6.phpt @@ -0,0 +1,44 @@ +--TEST-- +Test array_intersect_ukey() function : usage variation - Intersection of floating points with strings. +--FILE-- + $key2 ? 1 : -1; + } +} +function main() +{ + echo "*** Testing array_intersect_ukey() : usage variation ***\n"; + //Initialize variables + $arr_float = array(0 => 1.0, 1 => 2.0); + $arr_string = array('0' => '1', '1' => '2', '2' => '3'); + $arr_string_float = array('0.00' => '1.00', '1.00' => '2.00'); + echo "\n-- Result of floating points and strings containing integers intersection --\n"; + var_dump(array_intersect_ukey($arr_float, $arr_string, 'key_compare_func')); + echo "\n-- Result of floating points and strings containing floating point intersection --\n"; + var_dump(array_intersect_ukey($arr_float, $arr_string_float, 'key_compare_func')); +} +?> +--EXPECT-- +*** Testing array_intersect_ukey() : usage variation *** + +-- Result of floating points and strings containing integers intersection -- +array(2) { + [0]=> + float(1) + [1]=> + float(2) +} + +-- Result of floating points and strings containing floating point intersection -- +array(2) { + [0]=> + float(1) + [1]=> + float(2) +} diff --git a/tests/std/array/array_intersect_ukey_variation7.phpt b/tests/std/array/array_intersect_ukey_variation7.phpt new file mode 100644 index 00000000..832053f5 --- /dev/null +++ b/tests/std/array/array_intersect_ukey_variation7.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test array_intersect_ukey() function : usage variation - Intersection of strings containing integer and float +--FILE-- + $key2 ? 1 : -1; + } +} +function main() +{ + echo "*** Testing array_intersect_ukey() : usage variation ***\n"; + //Initialize variables + $arr1_string_int = array('0' => '1', '1' => '2'); + $arr2_string_int = array('0' => '1', '1' => '3'); + $arr1_string_float = array('0.00' => '1.00', '1.00' => '2.00'); + $arr2_string_float = array('0.00' => '1.00', '1.00' => '3.00'); + echo "\n-- Result of strings containing integers intersection --\n"; + var_dump(array_intersect_ukey($arr1_string_int, $arr2_string_int, 'key_compare_func')); + echo "\n-- Result of strings containing floating points intersection --\n"; + var_dump(array_intersect_ukey($arr1_string_float, $arr2_string_float, 'key_compare_func')); + echo "\n-- Result of strings containing integers and strings containing floating points intersection --\n"; + var_dump(array_intersect_ukey($arr1_string_int, $arr2_string_float, 'key_compare_func')); +} +?> +--EXPECT-- +*** Testing array_intersect_ukey() : usage variation *** + +-- Result of strings containing integers intersection -- +array(2) { + [0]=> + string(1) "1" + [1]=> + string(1) "2" +} + +-- Result of strings containing floating points intersection -- +array(2) { + ["0.00"]=> + string(4) "1.00" + ["1.00"]=> + string(4) "2.00" +} + +-- Result of strings containing integers and strings containing floating points intersection -- +array(2) { + [0]=> + string(1) "1" + [1]=> + string(1) "2" +} diff --git a/tests/std/array/array_intersect_ukey_variation8.phpt b/tests/std/array/array_intersect_ukey_variation8.phpt new file mode 100644 index 00000000..71126a1e --- /dev/null +++ b/tests/std/array/array_intersect_ukey_variation8.phpt @@ -0,0 +1,29 @@ +--TEST-- +Test array_intersect_ukey() function : usage variation - Passing non-existing function name to callback +--FILE-- + 1, 'red' => 2, 'green' => 3, 'purple' => 4); +$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); + +//function name within double quotes +try { + var_dump( array_intersect_ukey($array1, $array2, "unknown_function") ); +} catch (TypeError $e) { + echo $e->getMessage(), "\n"; +} + +//function name within single quotes +try { + var_dump( array_intersect_ukey($array1, $array2, 'unknown_function') ); +} catch (TypeError $e) { + echo $e->getMessage(), "\n"; +} + +?> +--EXPECT-- +*** Testing array_intersect_ukey() : usage variation *** +array_intersect_ukey(): Argument #3 must be a valid callback, function "unknown_function" not found or invalid function name +array_intersect_ukey(): Argument #3 must be a valid callback, function "unknown_function" not found or invalid function name diff --git a/tests/std/array/array_intersect_ukey_variation9.phpt b/tests/std/array/array_intersect_ukey_variation9.phpt new file mode 100644 index 00000000..1eb5d750 --- /dev/null +++ b/tests/std/array/array_intersect_ukey_variation9.phpt @@ -0,0 +1,53 @@ +--TEST-- +Test array_intersect_ukey() function : usage variation - Passing class/object methods to callback +--FILE-- + 1, 'red' => 2, 'green' => 3, 'purple' => 4); + $array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); + echo "\n-- Testing array_intersect_ukey() function using class with static method as callback --\n"; + var_dump(array_intersect_ukey($array1, $array2, array('MyClass', 'static_compare_func'))); + var_dump(array_intersect_ukey($array1, $array2, 'MyClass::static_compare_func')); + echo "\n-- Testing array_intersect_uassoc() function using class with regular method as callback --\n"; + $obj = new MyClass(); + var_dump(array_intersect_ukey($array1, $array2, array($obj, 'class_compare_func'))); +} +?> +--EXPECT-- +*** Testing array_intersect_ukey() : usage variation *** + +-- Testing array_intersect_ukey() function using class with static method as callback -- +array(2) { + ["blue"]=> + int(1) + ["green"]=> + int(3) +} +array(2) { + ["blue"]=> + int(1) + ["green"]=> + int(3) +} + +-- Testing array_intersect_uassoc() function using class with regular method as callback -- +array(2) { + ["blue"]=> + int(1) + ["green"]=> + int(3) +} diff --git a/tests/std/array/array_intersect_variation1.phpt b/tests/std/array/array_intersect_variation1.phpt new file mode 100644 index 00000000..22a31a3e --- /dev/null +++ b/tests/std/array/array_intersect_variation1.phpt @@ -0,0 +1,182 @@ +--TEST-- +Test array_intersect() function : usage variations - unexpected values for 'array1' argument +--SKIPIF-- + + +--FILE-- + 1, "two" => 2); + // get an unset variable + $unset_var = 10; + unset($unset_var); + // heredoc string + $heredoc = <<getMessage(), "\n"; + } + // Calling array_intersect() with more arguments + try { + var_dump(array_intersect($unexpected_value, $array2, $arr3)); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + $iterator++; + } + // close the file resource used + fclose($fp); + echo "Done"; +} +?> +--EXPECT-- +*** Testing array_intersect() : Passing non-array values to $array1 argument *** + +-- Iterator 1 --array_intersect(): Argument #1 ($array) must be of type array, int given +array_intersect(): Argument #1 ($array) must be of type array, int given + +-- Iterator 2 --array_intersect(): Argument #1 ($array) must be of type array, int given +array_intersect(): Argument #1 ($array) must be of type array, int given + +-- Iterator 3 --array_intersect(): Argument #1 ($array) must be of type array, int given +array_intersect(): Argument #1 ($array) must be of type array, int given + +-- Iterator 4 --array_intersect(): Argument #1 ($array) must be of type array, int given +array_intersect(): Argument #1 ($array) must be of type array, int given + +-- Iterator 5 --array_intersect(): Argument #1 ($array) must be of type array, float given +array_intersect(): Argument #1 ($array) must be of type array, float given + +-- Iterator 6 --array_intersect(): Argument #1 ($array) must be of type array, float given +array_intersect(): Argument #1 ($array) must be of type array, float given + +-- Iterator 7 --array_intersect(): Argument #1 ($array) must be of type array, float given +array_intersect(): Argument #1 ($array) must be of type array, float given + +-- Iterator 8 --array_intersect(): Argument #1 ($array) must be of type array, float given +array_intersect(): Argument #1 ($array) must be of type array, float given + +-- Iterator 9 --array_intersect(): Argument #1 ($array) must be of type array, float given +array_intersect(): Argument #1 ($array) must be of type array, float given + +-- Iterator 10 --array_intersect(): Argument #1 ($array) must be of type array, null given +array_intersect(): Argument #1 ($array) must be of type array, null given + +-- Iterator 11 --array_intersect(): Argument #1 ($array) must be of type array, null given +array_intersect(): Argument #1 ($array) must be of type array, null given + +-- Iterator 12 --array_intersect(): Argument #1 ($array) must be of type array, true given +array_intersect(): Argument #1 ($array) must be of type array, true given + +-- Iterator 13 --array_intersect(): Argument #1 ($array) must be of type array, false given +array_intersect(): Argument #1 ($array) must be of type array, false given + +-- Iterator 14 --array_intersect(): Argument #1 ($array) must be of type array, true given +array_intersect(): Argument #1 ($array) must be of type array, true given + +-- Iterator 15 --array_intersect(): Argument #1 ($array) must be of type array, false given +array_intersect(): Argument #1 ($array) must be of type array, false given + +-- Iterator 16 --array_intersect(): Argument #1 ($array) must be of type array, string given +array_intersect(): Argument #1 ($array) must be of type array, string given + +-- Iterator 17 --array_intersect(): Argument #1 ($array) must be of type array, string given +array_intersect(): Argument #1 ($array) must be of type array, string given + +-- Iterator 18 --array_intersect(): Argument #1 ($array) must be of type array, string given +array_intersect(): Argument #1 ($array) must be of type array, string given + +-- Iterator 19 --array_intersect(): Argument #1 ($array) must be of type array, string given +array_intersect(): Argument #1 ($array) must be of type array, string given + +-- Iterator 20 --array_intersect(): Argument #1 ($array) must be of type array, string given +array_intersect(): Argument #1 ($array) must be of type array, string given + +-- Iterator 21 --array_intersect(): Argument #1 ($array) must be of type array, classA given +array_intersect(): Argument #1 ($array) must be of type array, classA given + +-- Iterator 22 --array_intersect(): Argument #1 ($array) must be of type array, null given +array_intersect(): Argument #1 ($array) must be of type array, null given + +-- Iterator 23 --array_intersect(): Argument #1 ($array) must be of type array, null given +array_intersect(): Argument #1 ($array) must be of type array, null given + +-- Iterator 24 --array_intersect(): Argument #1 ($array) must be of type array, resource given +array_intersect(): Argument #1 ($array) must be of type array, resource given +Done diff --git a/tests/std/array/array_intersect_variation10.phpt b/tests/std/array/array_intersect_variation10.phpt new file mode 100644 index 00000000..e8ade132 --- /dev/null +++ b/tests/std/array/array_intersect_variation10.phpt @@ -0,0 +1,48 @@ +--TEST-- +Test array_intersect() function : usage variations - binary safe checking +--FILE-- + +--EXPECT-- +*** Testing array_intersect() : binary safe checking *** +array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" +} +array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" +} +array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" +} +Done diff --git a/tests/std/array/array_intersect_variation2.phpt b/tests/std/array/array_intersect_variation2.phpt new file mode 100644 index 00000000..613e6a28 --- /dev/null +++ b/tests/std/array/array_intersect_variation2.phpt @@ -0,0 +1,182 @@ +--TEST-- +Test array_intersect() function : usage variations - unexpected values for 'array2' argument +--SKIPIF-- + + +--FILE-- + 1, "two" => 2); + // get an unset variable + $unset_var = 10; + unset($unset_var); + // heredoc string + $heredoc = <<getMessage(), "\n"; + } + // Calling array_intersect() with more arguments + try { + var_dump(array_intersect($array1, $unexpected_value, $arr3)); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + $iterator++; + } + // close the file resource used + fclose($fp); + echo "Done"; +} +?> +--EXPECT-- +*** Testing array_intersect() : Passing non-array values to $array2 argument *** + +-- Iterator 1 --array_intersect(): Argument #2 must be of type array, int given +array_intersect(): Argument #2 must be of type array, int given + +-- Iterator 2 --array_intersect(): Argument #2 must be of type array, int given +array_intersect(): Argument #2 must be of type array, int given + +-- Iterator 3 --array_intersect(): Argument #2 must be of type array, int given +array_intersect(): Argument #2 must be of type array, int given + +-- Iterator 4 --array_intersect(): Argument #2 must be of type array, int given +array_intersect(): Argument #2 must be of type array, int given + +-- Iterator 5 --array_intersect(): Argument #2 must be of type array, float given +array_intersect(): Argument #2 must be of type array, float given + +-- Iterator 6 --array_intersect(): Argument #2 must be of type array, float given +array_intersect(): Argument #2 must be of type array, float given + +-- Iterator 7 --array_intersect(): Argument #2 must be of type array, float given +array_intersect(): Argument #2 must be of type array, float given + +-- Iterator 8 --array_intersect(): Argument #2 must be of type array, float given +array_intersect(): Argument #2 must be of type array, float given + +-- Iterator 9 --array_intersect(): Argument #2 must be of type array, float given +array_intersect(): Argument #2 must be of type array, float given + +-- Iterator 10 --array_intersect(): Argument #2 must be of type array, null given +array_intersect(): Argument #2 must be of type array, null given + +-- Iterator 11 --array_intersect(): Argument #2 must be of type array, null given +array_intersect(): Argument #2 must be of type array, null given + +-- Iterator 12 --array_intersect(): Argument #2 must be of type array, true given +array_intersect(): Argument #2 must be of type array, true given + +-- Iterator 13 --array_intersect(): Argument #2 must be of type array, false given +array_intersect(): Argument #2 must be of type array, false given + +-- Iterator 14 --array_intersect(): Argument #2 must be of type array, true given +array_intersect(): Argument #2 must be of type array, true given + +-- Iterator 15 --array_intersect(): Argument #2 must be of type array, false given +array_intersect(): Argument #2 must be of type array, false given + +-- Iterator 16 --array_intersect(): Argument #2 must be of type array, string given +array_intersect(): Argument #2 must be of type array, string given + +-- Iterator 17 --array_intersect(): Argument #2 must be of type array, string given +array_intersect(): Argument #2 must be of type array, string given + +-- Iterator 18 --array_intersect(): Argument #2 must be of type array, string given +array_intersect(): Argument #2 must be of type array, string given + +-- Iterator 19 --array_intersect(): Argument #2 must be of type array, string given +array_intersect(): Argument #2 must be of type array, string given + +-- Iterator 20 --array_intersect(): Argument #2 must be of type array, string given +array_intersect(): Argument #2 must be of type array, string given + +-- Iterator 21 --array_intersect(): Argument #2 must be of type array, classA given +array_intersect(): Argument #2 must be of type array, classA given + +-- Iterator 22 --array_intersect(): Argument #2 must be of type array, null given +array_intersect(): Argument #2 must be of type array, null given + +-- Iterator 23 --array_intersect(): Argument #2 must be of type array, null given +array_intersect(): Argument #2 must be of type array, null given + +-- Iterator 24 --array_intersect(): Argument #2 must be of type array, resource given +array_intersect(): Argument #2 must be of type array, resource given +Done diff --git a/tests/std/array/array_intersect_variation3.phpt b/tests/std/array/array_intersect_variation3.phpt new file mode 100644 index 00000000..05fcf78d --- /dev/null +++ b/tests/std/array/array_intersect_variation3.phpt @@ -0,0 +1,340 @@ +--TEST-- +Test array_intersect() function : usage variations - different arrays for 'arr1' argument +--SKIPIF-- + +--FILE-- +22 +'single quoted string' +"double quoted string" +2222 != 1111.\t 0000 = 0000\n +EOT; + +// arrays to be passed to $arr1 argument +$arrays = array ( +/*1*/ array(1, 2), // array with default keys and numeric values + array(1.1, 2.2), // array with default keys & float values + array(false,true), // array with default keys and boolean values + array(), // empty array +/*5*/ array(NULL), // array with NULL + array("a\v\f","aaaa\r","b","b\tbbb","c","\[\]\!\@\#\$\%\^\&\*\(\)\{\}"), // array with double quoted strings + array('a\v\f','aaaa\r','b','b\tbbb','c','\[\]\!\@\#\$\%\^\&\*\(\)\{\}'), // array with single quoted strings + array($blank_line, $multiline_string, $diff_whitespaces, $numeric_string), // array with heredocs + + // associative arrays +/*9*/ array(1 => "one", 2 => "two", 3 => "three"), // explicit numeric keys, string values + array("one" => 1, "two" => 2, "three" => 3 ), // string keys & numeric values + array( 1 => 10, 2 => 20, 4 => 40, 3 => 30), // explicit numeric keys and numeric values + array( "one" => "ten", "two" => "twenty", "three" => "thirty"), // string key/value + array("one" => 1, 2 => "two", 4 => "four"), //mixed + + // associative array, containing null/empty/boolean values as key/value +/*14*/ array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null), + array(true => "true", false => "false", "false" => false, "true" => true), + array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''), + array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true), + array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6), + + // array with repetitive keys +/*19*/ array("One" => 1, "two" => 2, "One" => 10, "two" => 20, "three" => 3) +); + + +// array to be passsed to $arr2 argument +$arr2 = array ( + 1, 1.1, "hello", "one", NULL, 2, + 'world', true, false, false => 5, 'aaaa\r', "aaaa\r", + $numeric_string, $diff_whitespaces, + "one" => "ten", 4 => "four", "two" => 2, 2 => "two", + '', null => "null", '' => 'emptys' +); + +// loop through each sub-array within $arrays to check the behavior of array_intersect() +$iterator = 1; +foreach($arrays as $arr1) { + echo "-- Iterator $iterator --\n"; + + // Calling array_intersect() with default arguments + var_dump( array_intersect($arr1, $arr2) ); + + // Calling array_intersect() with more arguments. + // additional argument passed is the same as $arr1 argument + var_dump( array_intersect($arr1, $arr2, $arr1) ); + $iterator++; +} + +echo "Done"; +?> +--EXPECT-- +*** Testing array_intersect() : Passing different types of arrays to $arr1 argument *** +-- Iterator 1 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iterator 2 -- +array(1) { + [0]=> + float(1.1) +} +array(1) { + [0]=> + float(1.1) +} +-- Iterator 3 -- +array(2) { + [0]=> + bool(false) + [1]=> + bool(true) +} +array(2) { + [0]=> + bool(false) + [1]=> + bool(true) +} +-- Iterator 4 -- +array(0) { +} +array(0) { +} +-- Iterator 5 -- +array(1) { + [0]=> + NULL +} +array(1) { + [0]=> + NULL +} +-- Iterator 6 -- +array(1) { + [1]=> + string(5) "aaaa " +} +array(1) { + [1]=> + string(5) "aaaa " +} +-- Iterator 7 -- +array(1) { + [1]=> + string(6) "aaaa\r" +} +array(1) { + [1]=> + string(6) "aaaa\r" +} +-- Iterator 8 -- +array(2) { + [2]=> + string(88) "hello world +1111 != 2222 +heredoc +double quoted string. with different white spaces" + [3]=> + string(90) "11 < 12. 123 >22 +'single quoted string' +"double quoted string" +2222 != 1111. 0000 = 0000 +" +} +array(2) { + [2]=> + string(88) "hello world +1111 != 2222 +heredoc +double quoted string. with different white spaces" + [3]=> + string(90) "11 < 12. 123 >22 +'single quoted string' +"double quoted string" +2222 != 1111. 0000 = 0000 +" +} +-- Iterator 9 -- +array(2) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" +} +array(2) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" +} +-- Iterator 10 -- +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +-- Iterator 11 -- +array(0) { +} +array(0) { +} +-- Iterator 12 -- +array(1) { + ["one"]=> + string(3) "ten" +} +array(1) { + ["one"]=> + string(3) "ten" +} +-- Iterator 13 -- +array(3) { + ["one"]=> + int(1) + [2]=> + string(3) "two" + [4]=> + string(4) "four" +} +array(3) { + ["one"]=> + int(1) + [2]=> + string(3) "two" + [4]=> + string(4) "four" +} +-- Iterator 14 -- +array(2) { + ["NULL"]=> + NULL + ["null"]=> + NULL +} +array(2) { + ["NULL"]=> + NULL + ["null"]=> + NULL +} +-- Iterator 15 -- +array(2) { + ["false"]=> + bool(false) + ["true"]=> + bool(true) +} +array(2) { + ["false"]=> + bool(false) + ["true"]=> + bool(true) +} +-- Iterator 16 -- +array(3) { + [""]=> + string(6) "emptys" + ["emptyd"]=> + string(0) "" + ["emptys"]=> + string(0) "" +} +array(3) { + [""]=> + string(6) "emptys" + ["emptyd"]=> + string(0) "" + ["emptys"]=> + string(0) "" +} +-- Iterator 17 -- +array(6) { + [1]=> + string(0) "" + [2]=> + string(0) "" + [3]=> + NULL + [4]=> + NULL + [5]=> + bool(false) + [6]=> + bool(true) +} +array(6) { + [1]=> + string(0) "" + [2]=> + string(0) "" + [3]=> + NULL + [4]=> + NULL + [5]=> + bool(false) + [6]=> + bool(true) +} +-- Iterator 18 -- +array(1) { + [0]=> + int(5) +} +array(1) { + [0]=> + int(5) +} +-- Iterator 19 -- +array(0) { +} +array(0) { +} +Done diff --git a/tests/std/array/array_intersect_variation4.phpt b/tests/std/array/array_intersect_variation4.phpt new file mode 100644 index 00000000..f2fb9df5 --- /dev/null +++ b/tests/std/array/array_intersect_variation4.phpt @@ -0,0 +1,347 @@ +--TEST-- +Test array_intersect() function : usage variations - different arrays for 'arr2' argument +--SKIPIF-- + +--FILE-- +22 +'single quoted string' +"double quoted string" +2222 != 1111.\t 0000 = 0000\n +EOT; + +// array to be passsed to $arr1 argument +$arr1 = array ( + 1, 1.1, "hello", "one", NULL, 2, + 'world', true, false, false => 5, 'aaaa\r', "aaaa\r", + $numeric_string, $diff_whitespaces, + "one" => "ten", 4 => "four", "two" => 2, 2 => "two", + '', null => "null", '' => 'emptys' +); + +// arrays to be passed to $arr2 argument +$arrays = array ( +/*1*/ array(1, 2), // array with default keys and numeric values + array(1.1, 2.2), // array with default keys & float values + array(false,true), // array with default keys and boolean values + array(), // empty array +/*5*/ array(NULL), // array with NULL + array("a\v\f","aaaa\r","b","b\tbbb","c","\[\]\!\@\#\$\%\^\&\*\(\)\{\}"), // array with double quoted strings + array('a\v\f','aaaa\r','b','b\tbbb','c','\[\]\!\@\#\$\%\^\&\*\(\)\{\}'), // array with single quoted strings + array($blank_line, $multiline_string, $diff_whitespaces, $numeric_string), // array with heredocs + + // associative arrays +/*9*/ array(1 => "one", 2 => "two", 3 => "three"), // explicit numeric keys, string values + array("one" => 1, "two" => 2, "three" => 3 ), // string keys & numeric values + array( 1 => 10, 2 => 20, 4 => 40, 3 => 30), // explicit numeric keys and numeric values + array( "one" => "ten", "two" => "twenty", "three" => "thirty"), // string key/value + array("one" => 1, 2 => "two", 4 => "four"), //mixed + + // associative array, containing null/empty/boolean values as key/value +/*14*/ array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null), + array(true => "true", false => "false", "false" => false, "true" => true), + array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''), + array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true), + array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6), + + // array with repetitive keys +/*19*/ array("One" => 1, "two" => 2, "One" => 10, "two" => 20, "three" => 3) +); + +// loop through each sub-array within $arrays to check the behavior of array_intersect() +$iterator = 1; +foreach($arrays as $arr2) { + echo "-- Iteration $iterator --\n"; + + // Calling array_intersect() with default arguments + var_dump( array_intersect($arr1, $arr2) ); + + // Calling array_intersect() with more arguments + // additional argument passed is the same as $arr1 argument + var_dump( array_intersect($arr1, $arr2, $arr1) ); + $iterator++; +} + +echo "Done"; +?> +--EXPECT-- +*** Testing array_intersect() : Passing different types of arrays to $arr2 argument *** +-- Iteration 1 -- +array(3) { + [5]=> + int(2) + [7]=> + bool(true) + ["two"]=> + int(2) +} +array(3) { + [5]=> + int(2) + [7]=> + bool(true) + ["two"]=> + int(2) +} +-- Iteration 2 -- +array(1) { + [1]=> + float(1.1) +} +array(1) { + [1]=> + float(1.1) +} +-- Iteration 3 -- +array(3) { + [7]=> + bool(true) + [8]=> + bool(false) + [13]=> + string(0) "" +} +array(3) { + [7]=> + bool(true) + [8]=> + bool(false) + [13]=> + string(0) "" +} +-- Iteration 4 -- +array(0) { +} +array(0) { +} +-- Iteration 5 -- +array(2) { + [8]=> + bool(false) + [13]=> + string(0) "" +} +array(2) { + [8]=> + bool(false) + [13]=> + string(0) "" +} +-- Iteration 6 -- +array(1) { + [10]=> + string(5) "aaaa " +} +array(1) { + [10]=> + string(5) "aaaa " +} +-- Iteration 7 -- +array(1) { + [9]=> + string(6) "aaaa\r" +} +array(1) { + [9]=> + string(6) "aaaa\r" +} +-- Iteration 8 -- +array(2) { + [11]=> + string(90) "11 < 12. 123 >22 +'single quoted string' +"double quoted string" +2222 != 1111. 0000 = 0000 +" + [12]=> + string(88) "hello world +1111 != 2222 +heredoc +double quoted string. with different white spaces" +} +array(2) { + [11]=> + string(90) "11 < 12. 123 >22 +'single quoted string' +"double quoted string" +2222 != 1111. 0000 = 0000 +" + [12]=> + string(88) "hello world +1111 != 2222 +heredoc +double quoted string. with different white spaces" +} +-- Iteration 9 -- +array(2) { + [2]=> + string(3) "two" + [3]=> + string(3) "one" +} +array(2) { + [2]=> + string(3) "two" + [3]=> + string(3) "one" +} +-- Iteration 10 -- +array(3) { + [5]=> + int(2) + [7]=> + bool(true) + ["two"]=> + int(2) +} +array(3) { + [5]=> + int(2) + [7]=> + bool(true) + ["two"]=> + int(2) +} +-- Iteration 11 -- +array(0) { +} +array(0) { +} +-- Iteration 12 -- +array(1) { + ["one"]=> + string(3) "ten" +} +array(1) { + ["one"]=> + string(3) "ten" +} +-- Iteration 13 -- +array(3) { + [2]=> + string(3) "two" + [4]=> + string(4) "four" + [7]=> + bool(true) +} +array(3) { + [2]=> + string(3) "two" + [4]=> + string(4) "four" + [7]=> + bool(true) +} +-- Iteration 14 -- +array(2) { + [8]=> + bool(false) + [13]=> + string(0) "" +} +array(2) { + [8]=> + bool(false) + [13]=> + string(0) "" +} +-- Iteration 15 -- +array(3) { + [7]=> + bool(true) + [8]=> + bool(false) + [13]=> + string(0) "" +} +array(3) { + [7]=> + bool(true) + [8]=> + bool(false) + [13]=> + string(0) "" +} +-- Iteration 16 -- +array(3) { + [8]=> + bool(false) + [13]=> + string(0) "" + [""]=> + string(6) "emptys" +} +array(3) { + [8]=> + bool(false) + [13]=> + string(0) "" + [""]=> + string(6) "emptys" +} +-- Iteration 17 -- +array(3) { + [7]=> + bool(true) + [8]=> + bool(false) + [13]=> + string(0) "" +} +array(3) { + [7]=> + bool(true) + [8]=> + bool(false) + [13]=> + string(0) "" +} +-- Iteration 18 -- +array(1) { + [0]=> + int(5) +} +array(1) { + [0]=> + int(5) +} +-- Iteration 19 -- +array(0) { +} +array(0) { +} +Done diff --git a/tests/std/array/array_intersect_variation5.phpt b/tests/std/array/array_intersect_variation5.phpt new file mode 100644 index 00000000..12edea88 --- /dev/null +++ b/tests/std/array/array_intersect_variation5.phpt @@ -0,0 +1,159 @@ +--TEST-- +Test array_intersect() function : usage variations - assoc array with diff keys for 'arr1' argument +--FILE-- + "0"), + array(1 => "1"), + array(1 => "1", 2 => "2", 3 => "3", 4 => "4"), + + // arrays with string keys +/*7*/ array('\tHello' => 111, 're\td' => "color", + '\v\fworld' => 2.2, 'pen\n' => 33), + array("\tHello" => 111, "re\td" => "color", + "\v\fworld" => 2.2, "pen\n" => 33), + array("hello", $heredoc => "string"), // heredoc + + // array with unset variable +/*10*/ array( @$unset_var => "hello"), + + // array with mixed keys +/*11*/ array('hello' => 1, "fruit" => 2.2, + 133 => "int", + @$unset_var => "unset", $heredoc => "heredoc") +); + +// array to be passed to $arr2 argument +$arr2 = array(1, "float", "f4", "hello", 2.2, 'color', "string", "pen\n", 11); + +// loop through each sub-array within $arrays to check the behavior of array_intersect() +$iterator = 1; +foreach($arrays as $arr1) { + echo "-- Iterator $iterator --\n"; + + // Calling array_intersect() with default arguments + var_dump( array_intersect($arr1, $arr2) ); + + // Calling array_intersect() with more arguments. + // additional argument passed is the same as $arr1 argument + var_dump( array_intersect($arr1, $arr2, $arr1) ); + $iterator++; +} + +echo "Done"; +?> +--EXPECT-- +*** Testing array_intersect() : assoc array with diff keys to $arr1 argument *** +-- Iterator 1 -- +array(0) { +} +array(0) { +} +-- Iterator 2 -- +array(0) { +} +array(0) { +} +-- Iterator 3 -- +array(1) { + [1]=> + string(1) "1" +} +array(1) { + [1]=> + string(1) "1" +} +-- Iterator 4 -- +array(1) { + [1]=> + string(1) "1" +} +array(1) { + [1]=> + string(1) "1" +} +-- Iterator 5 -- +array(2) { + ["re\td"]=> + string(5) "color" + ["\v\fworld"]=> + float(2.2) +} +array(2) { + ["re\td"]=> + string(5) "color" + ["\v\fworld"]=> + float(2.2) +} +-- Iterator 6 -- +array(2) { + ["re d"]=> + string(5) "color" + [" world"]=> + float(2.2) +} +array(2) { + ["re d"]=> + string(5) "color" + [" world"]=> + float(2.2) +} +-- Iterator 7 -- +array(2) { + [0]=> + string(5) "hello" + ["Hello world"]=> + string(6) "string" +} +array(2) { + [0]=> + string(5) "hello" + ["Hello world"]=> + string(6) "string" +} +-- Iterator 8 -- +array(1) { + [""]=> + string(5) "hello" +} +array(1) { + [""]=> + string(5) "hello" +} +-- Iterator 9 -- +array(2) { + ["hello"]=> + int(1) + ["fruit"]=> + float(2.2) +} +array(2) { + ["hello"]=> + int(1) + ["fruit"]=> + float(2.2) +} +Done diff --git a/tests/std/array/array_intersect_variation6.phpt b/tests/std/array/array_intersect_variation6.phpt new file mode 100644 index 00000000..93ff4271 --- /dev/null +++ b/tests/std/array/array_intersect_variation6.phpt @@ -0,0 +1,159 @@ +--TEST-- +Test array_intersect() function : usage variations - assoc array with diff keys for 'arr2' argument +--FILE-- + "0"), + array(1 => "1"), + array(1 => "1", 2 => "2", 3 => "3", 4 => "4"), + + // arrays with string keys +/*7*/ array('\tHello' => 111, 're\td' => "color", + '\v\fworld' => 2.2, 'pen\n' => 33), + array("\tHello" => 111, "re\td" => "color", + "\v\fworld" => 2.2, "pen\n" => 33), + array("hello", $heredoc => "string"), // heredoc + + // array with unset variable +/*10*/ array( @$unset_var => "hello"), + + // array with mixed keys +/*11*/ array('hello' => 1, "fruit" => 2.2, + 133 => "int", + @$unset_var => "unset", $heredoc => "heredoc") +); + +// array to be passed to $arr1 argument +$arr1 = array(1, "float", "f4", "hello", 2.2, 'color', "string", "pen\n", 11); + +// loop through each sub-array within $arrays to check the behavior of array_intersect() +$iterator = 1; +foreach($arrays as $arr2) { + echo "-- Iterator $iterator --\n"; + + // Calling array_intersect() with default arguments + var_dump( array_intersect($arr1, $arr2) ); + + // Calling array_intersect() with more arguments. + // additional argument passed is the same as $arr1 argument + var_dump( array_intersect($arr1, $arr2, $arr1) ); + $iterator++; +} + +echo "Done"; +?> +--EXPECT-- +*** Testing array_intersect() : assoc array with diff keys to $arr2 argument *** +-- Iterator 1 -- +array(0) { +} +array(0) { +} +-- Iterator 2 -- +array(0) { +} +array(0) { +} +-- Iterator 3 -- +array(1) { + [0]=> + int(1) +} +array(1) { + [0]=> + int(1) +} +-- Iterator 4 -- +array(1) { + [0]=> + int(1) +} +array(1) { + [0]=> + int(1) +} +-- Iterator 5 -- +array(2) { + [4]=> + float(2.2) + [5]=> + string(5) "color" +} +array(2) { + [4]=> + float(2.2) + [5]=> + string(5) "color" +} +-- Iterator 6 -- +array(2) { + [4]=> + float(2.2) + [5]=> + string(5) "color" +} +array(2) { + [4]=> + float(2.2) + [5]=> + string(5) "color" +} +-- Iterator 7 -- +array(2) { + [3]=> + string(5) "hello" + [6]=> + string(6) "string" +} +array(2) { + [3]=> + string(5) "hello" + [6]=> + string(6) "string" +} +-- Iterator 8 -- +array(1) { + [3]=> + string(5) "hello" +} +array(1) { + [3]=> + string(5) "hello" +} +-- Iterator 9 -- +array(2) { + [0]=> + int(1) + [4]=> + float(2.2) +} +array(2) { + [0]=> + int(1) + [4]=> + float(2.2) +} +Done diff --git a/tests/std/array/array_intersect_variation7.phpt b/tests/std/array/array_intersect_variation7.phpt new file mode 100644 index 00000000..8282af87 --- /dev/null +++ b/tests/std/array/array_intersect_variation7.phpt @@ -0,0 +1,196 @@ +--TEST-- +Test array_intersect() function : usage variations - assoc array with diff values for 'arr1' argument +--SKIPIF-- + +--FILE-- + 0), + array("1" => 1), + array("one" => 1, 'two' => 2, "three" => 3, 4 => 4), + // arrays with float values + /*5*/ + array("float" => 2.3333), + array("f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => 33333333.333333), + // arrays with string values + /*7*/ + array(111 => "\tHello", "red" => "col\tor", 2 => "\v\fworld", 3 => "pen\n"), + array(111 => '\tHello', "red" => 'col\tor', 2 => '\v\fworld', 3 => 'pen\n'), + array(1 => "hello", "heredoc" => $heredoc), + // array with object, unset variable and resource variable + /*10*/ + array(11 => new classA(), "unset" => @$unset_var, "resource" => $fp), + // array with mixed values + /*11*/ + array(1 => 'hello', 2 => new classA(), 222 => "fruit", 'resource' => $fp, "int" => 133, "float" => 444.432, "unset" => @$unset_var, "heredoc" => $heredoc), + ); + // array to be passsed to $arr2 argument + $arr2 = array(1, 2, 1.2, 2.3333, "col\tor", '\v\fworld', $fp, "Hello world", $heredoc, new classA(), 444.432, "fruit"); + // loop through each sub-array within $arrays to check the behavior of array_intersect() + $iterator = 1; + foreach ($arrays as $arr1) { + echo "-- Iterator {$iterator} --\n"; + // Calling array_intersect() with default arguments + var_dump(array_intersect($arr1, $arr2)); + // Calling array_intersect() with more arguments. + // additional argument passed is the same as $arr1 argument + var_dump(array_intersect($arr1, $arr2, $arr1)); + $iterator++; + } + // close the file resource used + fclose($fp); + echo "Done"; +} +?> +--EXPECTF-- +*** Testing array_intersect() : assoc array with diff values to $arr1 argument *** +-- Iterator 1 -- +array(0) { +} +array(0) { +} +-- Iterator 2 -- +array(0) { +} +array(0) { +} +-- Iterator 3 -- +array(1) { + [1]=> + int(1) +} +array(1) { + [1]=> + int(1) +} +-- Iterator 4 -- +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +-- Iterator 5 -- +array(1) { + ["float"]=> + float(2.3333) +} +array(1) { + ["float"]=> + float(2.3333) +} +-- Iterator 6 -- +array(1) { + ["f1"]=> + float(1.2) +} +array(1) { + ["f1"]=> + float(1.2) +} +-- Iterator 7 -- +array(1) { + ["red"]=> + string(6) "col or" +} +array(1) { + ["red"]=> + string(6) "col or" +} +-- Iterator 8 -- +array(1) { + [2]=> + string(9) "\v\fworld" +} +array(1) { + [2]=> + string(9) "\v\fworld" +} +-- Iterator 9 -- +array(1) { + ["heredoc"]=> + string(11) "Hello world" +} +array(1) { + ["heredoc"]=> + string(11) "Hello world" +} +-- Iterator 10 -- +array(2) { + [11]=> + object(classA)#%d (0) { + } + ["resource"]=> + resource(%d) of type (stream) +} +array(2) { + [11]=> + object(classA)#%d (0) { + } + ["resource"]=> + resource(%d) of type (stream) +} +-- Iterator 11 -- +array(5) { + [2]=> + object(classA)#%d (0) { + } + [222]=> + string(5) "fruit" + ["resource"]=> + resource(%d) of type (stream) + ["float"]=> + float(444.432) + ["heredoc"]=> + string(11) "Hello world" +} +array(5) { + [2]=> + object(classA)#%d (0) { + } + [222]=> + string(5) "fruit" + ["resource"]=> + resource(%d) of type (stream) + ["float"]=> + float(444.432) + ["heredoc"]=> + string(11) "Hello world" +} +Done diff --git a/tests/std/array/array_intersect_variation8.phpt b/tests/std/array/array_intersect_variation8.phpt new file mode 100644 index 00000000..706480b1 --- /dev/null +++ b/tests/std/array/array_intersect_variation8.phpt @@ -0,0 +1,204 @@ +--TEST-- +Test array_intersect() function : usage variations - assoc array with diff values for 'arr2' argument +--SKIPIF-- + +--FILE-- + 0), + array("1" => 1), + array("one" => 1, 'two' => 2, "three" => 3, 4 => 4), + // arrays with float values + /*5*/ + array("float" => 2.3333), + array("f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => 33333333.333333), + // arrays with string values + /*7*/ + array(111 => "\tHello", "red" => "col\tor", 2 => "\v\fworld", 3 => "pen\n"), + array(111 => '\tHello', "red" => 'col\tor', 2 => '\v\fworld', 3 => 'pen\n'), + array(1 => "hello", "heredoc" => $heredoc), + // array with object, unset variable and resource variable + /*10*/ + array(11 => new classA(), "unset" => @$unset_var, "resource" => $fp), + // array with mixed values + /*11*/ + array(1 => 'hello', 2 => new classA(), 222 => "fruit", 'resource' => $fp, "int" => 133, "float" => 444.432, "unset" => @$unset_var, "heredoc" => $heredoc), + ); + // array to be passsed to $arr1 argument + $arr1 = array(1, 2, 1.2, 2.3333, "col\tor", '\v\fworld', $fp, "Hello world", $heredoc, new classA(), 444.432, "fruit"); + // loop through each sub-array within $arrays to check the behavior of array_intersect() + $iterator = 1; + foreach ($arrays as $arr2) { + echo "-- Iterator {$iterator} --\n"; + // Calling array_intersect() with default arguments + var_dump(array_intersect($arr1, $arr2)); + // Calling array_intersect() with more arguments. + // additional argument passed is the same as $arr1 argument + var_dump(array_intersect($arr1, $arr2, $arr1)); + $iterator++; + } + // close the file resource used + fclose($fp); + echo "Done"; +} +?> +--EXPECTF-- +*** Testing array_intersect() : assoc array with diff values to $arr2 argument *** +-- Iterator 1 -- +array(0) { +} +array(0) { +} +-- Iterator 2 -- +array(0) { +} +array(0) { +} +-- Iterator 3 -- +array(1) { + [0]=> + int(1) +} +array(1) { + [0]=> + int(1) +} +-- Iterator 4 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iterator 5 -- +array(1) { + [3]=> + float(2.3333) +} +array(1) { + [3]=> + float(2.3333) +} +-- Iterator 6 -- +array(1) { + [2]=> + float(1.2) +} +array(1) { + [2]=> + float(1.2) +} +-- Iterator 7 -- +array(1) { + [4]=> + string(6) "col or" +} +array(1) { + [4]=> + string(6) "col or" +} +-- Iterator 8 -- +array(1) { + [5]=> + string(9) "\v\fworld" +} +array(1) { + [5]=> + string(9) "\v\fworld" +} +-- Iterator 9 -- +array(2) { + [7]=> + string(11) "Hello world" + [8]=> + string(11) "Hello world" +} +array(2) { + [7]=> + string(11) "Hello world" + [8]=> + string(11) "Hello world" +} +-- Iterator 10 -- +array(2) { + [6]=> + resource(%d) of type (stream) + [9]=> + object(classA)#%d (0) { + } +} +array(2) { + [6]=> + resource(%d) of type (stream) + [9]=> + object(classA)#%d (0) { + } +} +-- Iterator 11 -- +array(6) { + [6]=> + resource(%d) of type (stream) + [7]=> + string(11) "Hello world" + [8]=> + string(11) "Hello world" + [9]=> + object(classA)#%d (0) { + } + [10]=> + float(444.432) + [11]=> + string(5) "fruit" +} +array(6) { + [6]=> + resource(%d) of type (stream) + [7]=> + string(11) "Hello world" + [8]=> + string(11) "Hello world" + [9]=> + object(classA)#%d (0) { + } + [10]=> + float(444.432) + [11]=> + string(5) "fruit" +} +Done diff --git a/tests/std/array/array_intersect_variation9.phpt b/tests/std/array/array_intersect_variation9.phpt new file mode 100644 index 00000000..c73b0f3d --- /dev/null +++ b/tests/std/array/array_intersect_variation9.phpt @@ -0,0 +1,238 @@ +--TEST-- +Test array_intersect() function : usage variations - two dimensional arrays for $arr1 and $arr2 arguments(Bug#43109) +--FILE-- + "one", 2 => "two", 3 => "three"), + array("ten" => 10, "twenty" => 20.00, "thirty" => 30) +); + +$arr2 = array ( + array(1, 2, 3, 4), + array(1 => "one", 2 => "two", 3 => "three") +); + +/* Passing the entire array as argument to $arr1 and $arr2 */ +// Calling array_intersect() with default arguments +echo "-- Passing the entire 2-D array to \$arr1 and \$arr2 --\n"; +echo "- With default arguments -\n"; +var_dump( array_intersect($arr1, $arr2) ); + +// Calling array_intersect() with more arguments +// additional argument passed is the same as $arr1 +echo "- With more arguments -\n"; +var_dump( array_intersect($arr1, $arr2, $arr1) ); + +/* Passing the sub-array as argument to $arr1 and $arr2 */ +// Calling array_intersect() with default arguments +echo "-- Passing the sub-array to \$arr1 and \$arr2 --\n"; +echo "- With default arguments -\n"; +var_dump( array_intersect($arr1[0], $arr2[0]) ); + +// Calling array_intersect() with more arguments +// additional argument passed is the same as $arr1 +echo "- With more arguments -\n"; +var_dump( array_intersect($arr1[0], $arr2[0], $arr1[0]) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_intersect() : passing two dimensional array to both $arr1 and $arr2 arguments *** +-- Passing the entire 2-D array to $arr1 and $arr2 -- +- With default arguments - + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d +array(4) { + [0]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(5) "hello" + [3]=> + string(5) "world" + } + [1]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + } + [2]=> + array(3) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + string(5) "three" + } + [3]=> + array(3) { + ["ten"]=> + int(10) + ["twenty"]=> + float(20) + ["thirty"]=> + int(30) + } +} +- With more arguments - + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d +array(4) { + [0]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(5) "hello" + [3]=> + string(5) "world" + } + [1]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + } + [2]=> + array(3) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + string(5) "three" + } + [3]=> + array(3) { + ["ten"]=> + int(10) + ["twenty"]=> + float(20) + ["thirty"]=> + int(30) + } +} +-- Passing the sub-array to $arr1 and $arr2 -- +- With default arguments - +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +- With more arguments - +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +Done diff --git a/tests/std/array/array_key_exists.phpt b/tests/std/array/array_key_exists.phpt new file mode 100644 index 00000000..0e9bc66b --- /dev/null +++ b/tests/std/array/array_key_exists.phpt @@ -0,0 +1,197 @@ +--TEST-- +Test array_key_exists() function +--SKIPIF-- + +--FILE-- + "Jack", "Loc" => "Mars", "Id" => "MS123"), array('Red' => 'Rose', 'I' => 'You'), array(0 => 'Zero', 1 => 'One', 2 => 'Two', 3 => "Three")); + /* keys to search in $search_arrays. $keys[0] + is the key to be searched in $search_arrays[0] and so on */ + $keys = array(1, 'a', 2, 4, "Name", "Red", 0, 3); + $key_counter = 0; + foreach ($search_arrays as $search_array) { + $key = $keys[$key_counter++]; + echo "-- Iteration {$key_counter} --\n"; + var_dump(array_key_exists($key, $search_array)); + } + echo "\n*** Testing possible variations ***\n"; + // use different keys on each sub array of $search_arrays + $key_variations = array("", NULL, null, " ", '', "test", 1); + $key_counter = 0; + $key_count = count($key_variations); + echo "\n** Variation loop 1 **\n"; + $out_loop_count = 0; + foreach ($search_arrays as $search_array) { + $key_counter = 0; + $out_loop_count++; + echo "-- Iteration {$out_loop_count} --\n"; + while ($key_counter < $key_count) { + $key = $key_variations[$key_counter++]; + var_dump(array_key_exists($key, $search_array)); + } + } + // arrays with variation in elements + $search_arrays_v = array(array(), array(NULL), array(array(), 1, 2), array(1, 2, 3, "" => "value", NULL => "value", true => "value"), array(array(2, 4, 5), array("a", "b", "d"))); + // search for $key_variations in each sub array of $search_arrays_v + echo "\n** Variation loop 2 **\n"; + $out_loop_count = 0; + foreach ($search_arrays_v as $search_array) { + $key_counter = 0; + $out_loop_count++; + echo "-- Iteration {$out_loop_count} --\n"; + while ($key_counter < $key_count) { + $key = $key_variations[$key_counter++]; + var_dump(array_key_exists($key, $search_array)); + } + } + echo "\n*** Testing error conditions ***\n"; + // first args as array + try { + array_key_exists(array(), array()); + } catch (TypeError $exception) { + echo $exception->getMessage() . "\n"; + } + echo "\n*** Testing operation on objects ***\n"; + $key_check_obj = new key_check(); + //new object + try { + var_dump(array_key_exists("public_var", $key_check_obj)); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + echo "Done\n"; +} +?> +--EXPECT-- +*** Testing basic functionalities *** +-- Iteration 1 -- +bool(true) +-- Iteration 2 -- +bool(false) +-- Iteration 3 -- +bool(true) +-- Iteration 4 -- +bool(false) +-- Iteration 5 -- +bool(true) +-- Iteration 6 -- +bool(true) +-- Iteration 7 -- +bool(true) + +*** Testing possible variations *** + +** Variation loop 1 ** +-- Iteration 1 -- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(true) +-- Iteration 2 -- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(true) +-- Iteration 3 -- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(true) +-- Iteration 4 -- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(true) +-- Iteration 5 -- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +-- Iteration 6 -- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +-- Iteration 7 -- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(true) + +** Variation loop 2 ** +-- Iteration 1 -- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +-- Iteration 2 -- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +-- Iteration 3 -- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(true) +-- Iteration 4 -- +bool(true) +bool(true) +bool(true) +bool(false) +bool(true) +bool(false) +bool(true) +-- Iteration 5 -- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(true) + +*** Testing error conditions *** +Cannot access offset of type array on array + +*** Testing operation on objects *** +array_key_exists(): Argument #2 ($array) must be of type array, key_check given +Done diff --git a/tests/std/array/array_key_exists_basic.phpt b/tests/std/array/array_key_exists_basic.phpt new file mode 100644 index 00000000..4753633d --- /dev/null +++ b/tests/std/array/array_key_exists_basic.phpt @@ -0,0 +1,23 @@ +--TEST-- +Test array_key_exists() function : basic functionality +--FILE-- + 'value', 'val'); +var_dump(array_key_exists($key1, $search)); +var_dump(array_key_exists($key2, $search)); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_key_exists() : basic functionality *** +bool(true) +bool(false) +Done diff --git a/tests/std/array/array_key_exists_variation1.phpt b/tests/std/array/array_key_exists_variation1.phpt new file mode 100644 index 00000000..e45364dd --- /dev/null +++ b/tests/std/array/array_key_exists_variation1.phpt @@ -0,0 +1,154 @@ +--TEST-- +Test array_key_exists() function : usage variations - Pass different data types as $key arg +--SKIPIF-- + + +--FILE-- + 'val', 'two', 10 => 'value'); + //get an unset variable + $unset_var = 10; + unset($unset_var); + // heredoc string + $heredoc = <<getMessage() . "\n"; + } + $iterator++; + } + fclose($fp); + echo "Done"; +} +?> +--EXPECTF-- +*** Testing array_key_exists() : usage variations *** + +-- Iteration 1 -- +bool(true) + +-- Iteration 2 -- +bool(true) + +-- Iteration 3 -- +bool(false) + +-- Iteration 4 -- +bool(false) + +-- Iteration 5 -- +bool(false) + +-- Iteration 6 -- +bool(false) + +-- Iteration 7 -- +bool(true) + +-- Iteration 8 -- +bool(true) + +-- Iteration 9 -- +bool(true) + +-- Iteration 10 -- +bool(true) + +-- Iteration 11 -- +bool(false) + +-- Iteration 12 -- +bool(false) + +-- Iteration 13 -- +Cannot access offset of type array on array + +-- Iteration 14 -- +bool(true) + +-- Iteration 15 -- +bool(true) + +-- Iteration 16 -- +bool(true) + +-- Iteration 17 -- +Cannot access offset of type classA on array + +-- Iteration 18 -- +bool(false) + +-- Iteration 19 -- +bool(false) + +-- Iteration 20 -- + +Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d +bool(false) +Done diff --git a/tests/std/array/array_key_exists_variation3.phpt b/tests/std/array/array_key_exists_variation3.phpt new file mode 100644 index 00000000..1eaab11b --- /dev/null +++ b/tests/std/array/array_key_exists_variation3.phpt @@ -0,0 +1,59 @@ +--TEST-- +Test array_key_exists() function : usage variations - floats and casting to ints +--SKIPIF-- + +--FILE-- +getMessage() . "\n"; + } + echo "Cast float to int:\n"; + var_dump(array_key_exists((int)$key, $search)); +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_key_exists() : usage variations *** + +-- Iteration 1 -- +Pass float as $key: + +Deprecated: Implicit conversion from float 1.23456789E-10 to int loses precision in %s on line %d +bool(true) +Cast float to int: +bool(true) + +-- Iteration 1 -- +Pass float as $key: + +Deprecated: Implicit conversion from float 1.00000000000001 to int loses precision in %s on line %d +bool(true) +Cast float to int: +bool(true) + +-- Iteration 1 -- +Pass float as $key: + +Deprecated: Implicit conversion from float 1.99999999999999 to int loses precision in %s on line %d +bool(true) +Cast float to int: +bool(true) +Done diff --git a/tests/std/array/array_key_exists_variation4.phpt b/tests/std/array/array_key_exists_variation4.phpt new file mode 100644 index 00000000..8d768042 --- /dev/null +++ b/tests/std/array/array_key_exists_variation4.phpt @@ -0,0 +1,24 @@ +--TEST-- +Test array_key_exists() function : usage variations - referenced variables +--FILE-- + 1, 'two' => 2, 'three' => 3); + +echo "\n-- \$search is a reference to \$array --\n"; +$search = &$array; +var_dump(array_key_exists('one', $search)); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_key_exists() : usage variations *** + +-- $search is a reference to $array -- +bool(true) +Done diff --git a/tests/std/array/array_key_exists_variation5.phpt b/tests/std/array/array_key_exists_variation5.phpt new file mode 100644 index 00000000..41a28c5b --- /dev/null +++ b/tests/std/array/array_key_exists_variation5.phpt @@ -0,0 +1,32 @@ +--TEST-- +Test array_key_exists() function : usage variations - multidimensional arrays +--FILE-- + 'val1', + 'one' => 'val2', + 'sub1' => array (1, 2, 3)); + +echo "\n-- Attempt to match key in sub-array --\n"; +// this key is in the sub-array +var_dump(array_key_exists(0, $multi_array)); + +echo "\n-- \$search arg points to sub-array --\n"; +var_dump(array_key_exists(0, $multi_array['sub1'])); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_key_exists() : usage variations *** + +-- Attempt to match key in sub-array -- +bool(false) + +-- $search arg points to sub-array -- +bool(true) +Done diff --git a/tests/std/array/array_key_exists_variation6.phpt b/tests/std/array/array_key_exists_variation6.phpt new file mode 100644 index 00000000..ef25b45a --- /dev/null +++ b/tests/std/array/array_key_exists_variation6.phpt @@ -0,0 +1,94 @@ +--TEST-- +Test array_key_exists() function : usage variations - equality test for certain data types +--SKIPIF-- + + +--FILE-- + null, + 'NULL' => NULL, + 'empty single quoted string' => '', + "empty double quoted string" => "", + 'undefined variable' => @$undefined, + 'unset variable' => @$unset); + +//iterate through original array +foreach($array as $name => $input) { + $iterator = 1; + echo "\n-- Key in \$search array is : $name --\n"; + $search[$input] = 'test'; + + //iterate through array again to see which values are considered equal + foreach($array as $key) { + echo "Iteration $iterator: "; + var_dump(array_key_exists($key, $search)); + $iterator++; + } + $search = null; +} + +echo "Done"; +?> +--EXPECT-- +*** Testing array_key_exists() : usage variations *** + +-- Key in $search array is : null -- +Iteration 1: bool(true) +Iteration 2: bool(true) +Iteration 3: bool(true) +Iteration 4: bool(true) +Iteration 5: bool(true) +Iteration 6: bool(true) + +-- Key in $search array is : NULL -- +Iteration 1: bool(true) +Iteration 2: bool(true) +Iteration 3: bool(true) +Iteration 4: bool(true) +Iteration 5: bool(true) +Iteration 6: bool(true) + +-- Key in $search array is : empty single quoted string -- +Iteration 1: bool(true) +Iteration 2: bool(true) +Iteration 3: bool(true) +Iteration 4: bool(true) +Iteration 5: bool(true) +Iteration 6: bool(true) + +-- Key in $search array is : empty double quoted string -- +Iteration 1: bool(true) +Iteration 2: bool(true) +Iteration 3: bool(true) +Iteration 4: bool(true) +Iteration 5: bool(true) +Iteration 6: bool(true) + +-- Key in $search array is : undefined variable -- +Iteration 1: bool(true) +Iteration 2: bool(true) +Iteration 3: bool(true) +Iteration 4: bool(true) +Iteration 5: bool(true) +Iteration 6: bool(true) + +-- Key in $search array is : unset variable -- +Iteration 1: bool(true) +Iteration 2: bool(true) +Iteration 3: bool(true) +Iteration 4: bool(true) +Iteration 5: bool(true) +Iteration 6: bool(true) +Done diff --git a/tests/std/array/array_key_exists_variation7.phpt b/tests/std/array/array_key_exists_variation7.phpt new file mode 100644 index 00000000..2d001bd4 --- /dev/null +++ b/tests/std/array/array_key_exists_variation7.phpt @@ -0,0 +1,29 @@ +--TEST-- +Test array_key_exists() function : usage variations - position of internal array pointer +--FILE-- + 'un', 'two' => 'deux', 'three' => 'trois'); + +echo "\n-- Call array_key_exists() --\n"; +var_dump($result = array_key_exists('one', $input)); + +echo "\n-- Position of Internal Pointer in Original Array: --\n"; +echo key($input) . " => " . current ($input) . "\n"; + +echo "Done"; +?> +--EXPECT-- +*** Testing array_key_exists() : usage variations *** + +-- Call array_key_exists() -- +bool(true) + +-- Position of Internal Pointer in Original Array: -- +one => un +Done diff --git a/tests/std/array/array_key_exists_variation8.phpt b/tests/std/array/array_key_exists_variation8.phpt new file mode 100644 index 00000000..15810b91 --- /dev/null +++ b/tests/std/array/array_key_exists_variation8.phpt @@ -0,0 +1,391 @@ +--TEST-- +Test array_key_exists() function : usage variations - array keys are different data types +--SKIPIF-- + + +--FILE-- + array( + 0 => 'zero', + 1 => 'one', + 12345 => 'positive', + -2345 => 'negative', + ), + + // null data +/*3*/ 'null uppercase' => array( + NULL => 'null 1', + ), + 'null lowercase' => array( + null => 'null 2', + ), + + // boolean data +/*4*/ 'bool lowercase' => array( + true => 'lowert', + false => 'lowerf', + ), + 'bool uppercase' => array( + TRUE => 'uppert', + FALSE => 'upperf', + ), + + // empty data +/*5*/ 'empty double quotes' => array( + "" => 'emptyd', + ), + 'empty single quotes' => array( + '' => 'emptys', + ), + + // string data +/*6*/ 'string' => array( + "stringd" => 'stringd', + 'strings' => 'strings', + $heredoc => 'stringh', + ), + + // undefined data +/*8*/ 'undefined' => array( + @$undefined_var => 'undefined', + ), + + // unset data +/*9*/ 'unset' => array( + @$unset_var => 'unset', + ), +); + +// loop through each element of $inputs to check the behavior of array_key_exists() +$iterator = 1; +foreach($inputs as $type => $input) { + echo "\n-- Iteration $iterator: $type data --\n"; + + //iterate over again to get all different key values + foreach ($inputs as $new_type => $new_input) { + echo "-- \$key arguments are $new_type data:\n"; + foreach ($new_input as $key => $search) { + var_dump(array_key_exists($key, $input)); + } + } + $iterator++; +}; + +echo "Done"; +?> +--EXPECT-- +*** Testing array_key_exists() : usage variations *** + +-- Iteration 1: int data -- +-- $key arguments are int data: +bool(true) +bool(true) +bool(true) +bool(true) +-- $key arguments are null uppercase data: +bool(false) +-- $key arguments are null lowercase data: +bool(false) +-- $key arguments are bool lowercase data: +bool(true) +bool(true) +-- $key arguments are bool uppercase data: +bool(true) +bool(true) +-- $key arguments are empty double quotes data: +bool(false) +-- $key arguments are empty single quotes data: +bool(false) +-- $key arguments are string data: +bool(false) +bool(false) +bool(false) +-- $key arguments are undefined data: +bool(false) +-- $key arguments are unset data: +bool(false) + +-- Iteration 2: null uppercase data -- +-- $key arguments are int data: +bool(false) +bool(false) +bool(false) +bool(false) +-- $key arguments are null uppercase data: +bool(true) +-- $key arguments are null lowercase data: +bool(true) +-- $key arguments are bool lowercase data: +bool(false) +bool(false) +-- $key arguments are bool uppercase data: +bool(false) +bool(false) +-- $key arguments are empty double quotes data: +bool(true) +-- $key arguments are empty single quotes data: +bool(true) +-- $key arguments are string data: +bool(false) +bool(false) +bool(false) +-- $key arguments are undefined data: +bool(true) +-- $key arguments are unset data: +bool(true) + +-- Iteration 3: null lowercase data -- +-- $key arguments are int data: +bool(false) +bool(false) +bool(false) +bool(false) +-- $key arguments are null uppercase data: +bool(true) +-- $key arguments are null lowercase data: +bool(true) +-- $key arguments are bool lowercase data: +bool(false) +bool(false) +-- $key arguments are bool uppercase data: +bool(false) +bool(false) +-- $key arguments are empty double quotes data: +bool(true) +-- $key arguments are empty single quotes data: +bool(true) +-- $key arguments are string data: +bool(false) +bool(false) +bool(false) +-- $key arguments are undefined data: +bool(true) +-- $key arguments are unset data: +bool(true) + +-- Iteration 4: bool lowercase data -- +-- $key arguments are int data: +bool(true) +bool(true) +bool(false) +bool(false) +-- $key arguments are null uppercase data: +bool(false) +-- $key arguments are null lowercase data: +bool(false) +-- $key arguments are bool lowercase data: +bool(true) +bool(true) +-- $key arguments are bool uppercase data: +bool(true) +bool(true) +-- $key arguments are empty double quotes data: +bool(false) +-- $key arguments are empty single quotes data: +bool(false) +-- $key arguments are string data: +bool(false) +bool(false) +bool(false) +-- $key arguments are undefined data: +bool(false) +-- $key arguments are unset data: +bool(false) + +-- Iteration 5: bool uppercase data -- +-- $key arguments are int data: +bool(true) +bool(true) +bool(false) +bool(false) +-- $key arguments are null uppercase data: +bool(false) +-- $key arguments are null lowercase data: +bool(false) +-- $key arguments are bool lowercase data: +bool(true) +bool(true) +-- $key arguments are bool uppercase data: +bool(true) +bool(true) +-- $key arguments are empty double quotes data: +bool(false) +-- $key arguments are empty single quotes data: +bool(false) +-- $key arguments are string data: +bool(false) +bool(false) +bool(false) +-- $key arguments are undefined data: +bool(false) +-- $key arguments are unset data: +bool(false) + +-- Iteration 6: empty double quotes data -- +-- $key arguments are int data: +bool(false) +bool(false) +bool(false) +bool(false) +-- $key arguments are null uppercase data: +bool(true) +-- $key arguments are null lowercase data: +bool(true) +-- $key arguments are bool lowercase data: +bool(false) +bool(false) +-- $key arguments are bool uppercase data: +bool(false) +bool(false) +-- $key arguments are empty double quotes data: +bool(true) +-- $key arguments are empty single quotes data: +bool(true) +-- $key arguments are string data: +bool(false) +bool(false) +bool(false) +-- $key arguments are undefined data: +bool(true) +-- $key arguments are unset data: +bool(true) + +-- Iteration 7: empty single quotes data -- +-- $key arguments are int data: +bool(false) +bool(false) +bool(false) +bool(false) +-- $key arguments are null uppercase data: +bool(true) +-- $key arguments are null lowercase data: +bool(true) +-- $key arguments are bool lowercase data: +bool(false) +bool(false) +-- $key arguments are bool uppercase data: +bool(false) +bool(false) +-- $key arguments are empty double quotes data: +bool(true) +-- $key arguments are empty single quotes data: +bool(true) +-- $key arguments are string data: +bool(false) +bool(false) +bool(false) +-- $key arguments are undefined data: +bool(true) +-- $key arguments are unset data: +bool(true) + +-- Iteration 8: string data -- +-- $key arguments are int data: +bool(false) +bool(false) +bool(false) +bool(false) +-- $key arguments are null uppercase data: +bool(false) +-- $key arguments are null lowercase data: +bool(false) +-- $key arguments are bool lowercase data: +bool(false) +bool(false) +-- $key arguments are bool uppercase data: +bool(false) +bool(false) +-- $key arguments are empty double quotes data: +bool(false) +-- $key arguments are empty single quotes data: +bool(false) +-- $key arguments are string data: +bool(true) +bool(true) +bool(true) +-- $key arguments are undefined data: +bool(false) +-- $key arguments are unset data: +bool(false) + +-- Iteration 9: undefined data -- +-- $key arguments are int data: +bool(false) +bool(false) +bool(false) +bool(false) +-- $key arguments are null uppercase data: +bool(true) +-- $key arguments are null lowercase data: +bool(true) +-- $key arguments are bool lowercase data: +bool(false) +bool(false) +-- $key arguments are bool uppercase data: +bool(false) +bool(false) +-- $key arguments are empty double quotes data: +bool(true) +-- $key arguments are empty single quotes data: +bool(true) +-- $key arguments are string data: +bool(false) +bool(false) +bool(false) +-- $key arguments are undefined data: +bool(true) +-- $key arguments are unset data: +bool(true) + +-- Iteration 10: unset data -- +-- $key arguments are int data: +bool(false) +bool(false) +bool(false) +bool(false) +-- $key arguments are null uppercase data: +bool(true) +-- $key arguments are null lowercase data: +bool(true) +-- $key arguments are bool lowercase data: +bool(false) +bool(false) +-- $key arguments are bool uppercase data: +bool(false) +bool(false) +-- $key arguments are empty double quotes data: +bool(true) +-- $key arguments are empty single quotes data: +bool(true) +-- $key arguments are string data: +bool(false) +bool(false) +bool(false) +-- $key arguments are undefined data: +bool(true) +-- $key arguments are unset data: +bool(true) +Done diff --git a/tests/std/array/array_key_first.phpt b/tests/std/array/array_key_first.phpt new file mode 100644 index 00000000..9d5452d3 --- /dev/null +++ b/tests/std/array/array_key_first.phpt @@ -0,0 +1,296 @@ +--TEST-- +Test array_key_first() function +--SKIPIF-- + + +--FILE-- + "aaa", "A" => "AAA", "c" => "ccc", "d" => "ddd", "e" => "eee" ), + array( "1" => "one", "2" => "two", "3" => "three", "4" => "four", "5" => "five" ), + array( 1 => "one", 2 => "two", 3 => 7, 4 => "four", 5 => "five" ), + array( "f" => "fff", "1" => "one", 4 => 6, "" => "blank", 2 => "float", "F" => "FFF", + "blank" => "", 3 => 3.7, 5 => 7, 6 => 8.6, '5' => "Five", "4name" => "jonny", "a" => NULL, NULL => 3 ), + array( 12, "name", 'age', '45' ), + array( array("oNe", "tWo", 4), array(10, 20, 30, 40, 50), array() ), + array( "one" => 1, "one" => 2, "three" => 3, 3, 4, 3 => 33, 4 => 44, 5, 6, + 5 => 57, "5.4" => 554, "5.7" => 557 ), + array( "foo" ), + array( 1 => "42" ) +); + +/* Loop to test normal functionality with different arrays inputs */ +echo "\n*** Normal testing with various array inputs ***\n"; + +$counter = 1; +foreach( $mixed_array as $sub_array ) +{ + echo "\n-- Input Array for Iteration $counter is --\n"; + var_dump( $sub_array ); + echo "\nFirst key is :\n"; + var_dump( array_key_first($sub_array) ); + $counter++; +} + +echo"\nDone"; +?> +--EXPECT-- +*** Normal testing with various array inputs *** + +-- Input Array for Iteration 1 is -- +array(0) { +} + +First key is : +NULL + +-- Input Array for Iteration 2 is -- +array(9) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + [6]=> + int(7) + [7]=> + int(8) + [8]=> + int(9) +} + +First key is : +int(0) + +-- Input Array for Iteration 3 is -- +array(5) { + [0]=> + string(3) "One" + [1]=> + string(4) "_Two" + [2]=> + string(5) "Three" + [3]=> + string(4) "Four" + [4]=> + string(4) "Five" +} + +First key is : +int(0) + +-- Input Array for Iteration 4 is -- +array(8) { + [0]=> + int(6) + [1]=> + string(3) "six" + [2]=> + int(7) + [3]=> + string(5) "seven" + [4]=> + int(8) + [5]=> + string(5) "eight" + [6]=> + int(9) + [7]=> + string(4) "nine" +} + +First key is : +int(0) + +-- Input Array for Iteration 5 is -- +array(5) { + ["a"]=> + string(3) "aaa" + ["A"]=> + string(3) "AAA" + ["c"]=> + string(3) "ccc" + ["d"]=> + string(3) "ddd" + ["e"]=> + string(3) "eee" +} + +First key is : +string(1) "a" + +-- Input Array for Iteration 6 is -- +array(5) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + string(5) "three" + [4]=> + string(4) "four" + [5]=> + string(4) "five" +} + +First key is : +int(1) + +-- Input Array for Iteration 7 is -- +array(5) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + int(7) + [4]=> + string(4) "four" + [5]=> + string(4) "five" +} + +First key is : +int(1) + +-- Input Array for Iteration 8 is -- +array(12) { + ["f"]=> + string(3) "fff" + [1]=> + string(3) "one" + [4]=> + int(6) + [""]=> + int(3) + [2]=> + string(5) "float" + ["F"]=> + string(3) "FFF" + ["blank"]=> + string(0) "" + [3]=> + float(3.7) + [5]=> + string(4) "Five" + [6]=> + float(8.6) + ["4name"]=> + string(5) "jonny" + ["a"]=> + NULL +} + +First key is : +string(1) "f" + +-- Input Array for Iteration 9 is -- +array(4) { + [0]=> + int(12) + [1]=> + string(4) "name" + [2]=> + string(3) "age" + [3]=> + string(2) "45" +} + +First key is : +int(0) + +-- Input Array for Iteration 10 is -- +array(3) { + [0]=> + array(3) { + [0]=> + string(3) "oNe" + [1]=> + string(3) "tWo" + [2]=> + int(4) + } + [1]=> + array(5) { + [0]=> + int(10) + [1]=> + int(20) + [2]=> + int(30) + [3]=> + int(40) + [4]=> + int(50) + } + [2]=> + array(0) { + } +} + +First key is : +int(0) + +-- Input Array for Iteration 11 is -- +array(10) { + ["one"]=> + int(2) + ["three"]=> + int(3) + [0]=> + int(3) + [1]=> + int(4) + [3]=> + int(33) + [4]=> + int(44) + [5]=> + int(57) + [6]=> + int(6) + ["5.4"]=> + int(554) + ["5.7"]=> + int(557) +} + +First key is : +string(3) "one" + +-- Input Array for Iteration 12 is -- +array(1) { + [0]=> + string(3) "foo" +} + +First key is : +int(0) + +-- Input Array for Iteration 13 is -- +array(1) { + [1]=> + string(2) "42" +} + +First key is : +int(1) + +Done diff --git a/tests/std/array/array_key_first_variation.phpt b/tests/std/array/array_key_first_variation.phpt new file mode 100644 index 00000000..d619ed01 --- /dev/null +++ b/tests/std/array/array_key_first_variation.phpt @@ -0,0 +1,36 @@ +--TEST-- +Test array_key_first() function (variation) +--FILE-- + +--EXPECT-- +*** Checking for internal array pointer not being changed by array_key_first *** + +Current Element is : int(1) + +Next Element is : int(2) + +First key is : int(0) + +Current Element after array_key_first operation is: int(2) + +Done diff --git a/tests/std/array/array_key_last.phpt b/tests/std/array/array_key_last.phpt new file mode 100644 index 00000000..a81d7ca9 --- /dev/null +++ b/tests/std/array/array_key_last.phpt @@ -0,0 +1,296 @@ +--TEST-- +Test array_key_last() function +--SKIPIF-- + + +--FILE-- + "aaa", "A" => "AAA", "c" => "ccc", "d" => "ddd", "e" => "eee" ), + array( "1" => "one", "2" => "two", "3" => "three", "4" => "four", "5" => "five" ), + array( 1 => "one", 2 => "two", 3 => 7, 4 => "four", 5 => "five" ), + array( "f" => "fff", "1" => "one", 4 => 6, "" => "blank", 2 => "float", "F" => "FFF", + "blank" => "", 3 => 3.7, 5 => 7, 6 => 8.6, '5' => "Five", "4name" => "jonny", "a" => NULL, NULL => 3 ), + array( 12, "name", 'age', '45' ), + array( array("oNe", "tWo", 4), array(10, 20, 30, 40, 50), array() ), + array( "one" => 1, "one" => 2, "three" => 3, 3, 4, 3 => 33, 4 => 44, 5, 6, + 5 => 57, "5.4" => 554, "5.7" => 557 ), + array( "foo" ), + array( 1 => "42" ) +); + +/* Loop to test normal functionality with different arrays inputs */ +echo "\n*** Normal testing with various array inputs ***\n"; + +$counter = 1; +foreach( $mixed_array as $sub_array ) +{ + echo "\n-- Input Array for Iteration $counter is --\n"; + var_dump( $sub_array ); + echo "\nLast key is :\n"; + var_dump( array_key_last($sub_array) ); + $counter++; +} + +echo"\nDone"; +?> +--EXPECT-- +*** Normal testing with various array inputs *** + +-- Input Array for Iteration 1 is -- +array(0) { +} + +Last key is : +NULL + +-- Input Array for Iteration 2 is -- +array(9) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + [6]=> + int(7) + [7]=> + int(8) + [8]=> + int(9) +} + +Last key is : +int(8) + +-- Input Array for Iteration 3 is -- +array(5) { + [0]=> + string(3) "One" + [1]=> + string(4) "_Two" + [2]=> + string(5) "Three" + [3]=> + string(4) "Four" + [4]=> + string(4) "Five" +} + +Last key is : +int(4) + +-- Input Array for Iteration 4 is -- +array(8) { + [0]=> + int(6) + [1]=> + string(3) "six" + [2]=> + int(7) + [3]=> + string(5) "seven" + [4]=> + int(8) + [5]=> + string(5) "eight" + [6]=> + int(9) + [7]=> + string(4) "nine" +} + +Last key is : +int(7) + +-- Input Array for Iteration 5 is -- +array(5) { + ["a"]=> + string(3) "aaa" + ["A"]=> + string(3) "AAA" + ["c"]=> + string(3) "ccc" + ["d"]=> + string(3) "ddd" + ["e"]=> + string(3) "eee" +} + +Last key is : +string(1) "e" + +-- Input Array for Iteration 6 is -- +array(5) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + string(5) "three" + [4]=> + string(4) "four" + [5]=> + string(4) "five" +} + +Last key is : +int(5) + +-- Input Array for Iteration 7 is -- +array(5) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + int(7) + [4]=> + string(4) "four" + [5]=> + string(4) "five" +} + +Last key is : +int(5) + +-- Input Array for Iteration 8 is -- +array(12) { + ["f"]=> + string(3) "fff" + [1]=> + string(3) "one" + [4]=> + int(6) + [""]=> + int(3) + [2]=> + string(5) "float" + ["F"]=> + string(3) "FFF" + ["blank"]=> + string(0) "" + [3]=> + float(3.7) + [5]=> + string(4) "Five" + [6]=> + float(8.6) + ["4name"]=> + string(5) "jonny" + ["a"]=> + NULL +} + +Last key is : +string(1) "a" + +-- Input Array for Iteration 9 is -- +array(4) { + [0]=> + int(12) + [1]=> + string(4) "name" + [2]=> + string(3) "age" + [3]=> + string(2) "45" +} + +Last key is : +int(3) + +-- Input Array for Iteration 10 is -- +array(3) { + [0]=> + array(3) { + [0]=> + string(3) "oNe" + [1]=> + string(3) "tWo" + [2]=> + int(4) + } + [1]=> + array(5) { + [0]=> + int(10) + [1]=> + int(20) + [2]=> + int(30) + [3]=> + int(40) + [4]=> + int(50) + } + [2]=> + array(0) { + } +} + +Last key is : +int(2) + +-- Input Array for Iteration 11 is -- +array(10) { + ["one"]=> + int(2) + ["three"]=> + int(3) + [0]=> + int(3) + [1]=> + int(4) + [3]=> + int(33) + [4]=> + int(44) + [5]=> + int(57) + [6]=> + int(6) + ["5.4"]=> + int(554) + ["5.7"]=> + int(557) +} + +Last key is : +string(3) "5.7" + +-- Input Array for Iteration 12 is -- +array(1) { + [0]=> + string(3) "foo" +} + +Last key is : +int(0) + +-- Input Array for Iteration 13 is -- +array(1) { + [1]=> + string(2) "42" +} + +Last key is : +int(1) + +Done diff --git a/tests/std/array/array_key_last_variation.phpt b/tests/std/array/array_key_last_variation.phpt new file mode 100644 index 00000000..3b2a4867 --- /dev/null +++ b/tests/std/array/array_key_last_variation.phpt @@ -0,0 +1,36 @@ +--TEST-- +Test array_key_last() function (variation) +--FILE-- + +--EXPECT-- +*** Checking for internal array pointer not being changed by array_key_last *** + +Current Element is : int(1) + +Next Element is : int(2) + +Last key is : int(8) + +Current Element after array_key_last operation is: int(2) + +Done diff --git a/tests/std/array/array_keys_basic.phpt b/tests/std/array/array_keys_basic.phpt new file mode 100644 index 00000000..dc54976d --- /dev/null +++ b/tests/std/array/array_keys_basic.phpt @@ -0,0 +1,27 @@ +--TEST-- +Test array_keys() function (basic) +--FILE-- + 1, "b" => 2, 2 => 2.0, -23 => "asdasd", + array(1,2,3)); +var_dump(array_keys($basic_arr)); + +echo "Done\n"; +?> +--EXPECT-- +*** Testing array_keys() on basic array operation *** +array(5) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + int(2) + [3]=> + int(-23) + [4]=> + int(3) +} +Done diff --git a/tests/std/array/array_keys_on_GLOBALS.phpt b/tests/std/array/array_keys_on_GLOBALS.phpt new file mode 100644 index 00000000..6231d5e6 --- /dev/null +++ b/tests/std/array/array_keys_on_GLOBALS.phpt @@ -0,0 +1,17 @@ +--TEST-- +Using array_keys() on $GLOBALS +--SKIPIF-- + + +--FILE-- + +--EXPECT-- +bool(false) diff --git a/tests/std/array/array_keys_variation_001.phpt b/tests/std/array/array_keys_variation_001.phpt new file mode 100644 index 00000000..1e194ae8 --- /dev/null +++ b/tests/std/array/array_keys_variation_001.phpt @@ -0,0 +1,149 @@ +--TEST-- +Test array_keys() function (variation - 1) +--SKIPIF-- + +--FILE-- + "World"), + array("" => ""), + array(1,2,3, "d" => array(4,6, "d")), + array("a" => 1, "b" => 2, "c" =>3, "d" => array()), + array(0 => 0, 1 => 1, 2 => 2, 3 => 3), + array(0 =>3.000, 1 =>2, 1 =>3, "a"=>3, 3=>5, "5"=>3.000), + array(TRUE => TRUE, FALSE => FALSE, NULL => NULL, "\x000", "\000"), + array("a" => "abcd", "a" => "", "ab" => -6, "cd" => -0.5 ), + array(0 => array(), 1=> array(0), 2 => array(1), ""=> array(),""=>"" ) +); + +$i = 0; +/* loop through to test array_keys() with different arrays */ +foreach ($arrays as $array) { + echo "\n-- Iteration $i --\n"; + var_dump(array_keys($array)); + $i++; +} + +echo "Done\n"; +?> +--EXPECT-- +*** Testing array_keys() on various arrays *** +-- Iteration 0 -- +array(0) { +} + +-- Iteration 1 -- +array(1) { + [0]=> + int(0) +} + +-- Iteration 2 -- +array(1) { + [0]=> + int(0) +} + +-- Iteration 3 -- +array(1) { + [0]=> + string(5) "Hello" +} + +-- Iteration 4 -- +array(1) { + [0]=> + string(0) "" +} + +-- Iteration 5 -- +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + string(1) "d" +} + +-- Iteration 6 -- +array(4) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + [3]=> + string(1) "d" +} + +-- Iteration 7 -- +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) +} + +-- Iteration 8 -- +array(5) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + string(1) "a" + [3]=> + int(3) + [4]=> + int(5) +} + +-- Iteration 9 -- +array(5) { + [0]=> + int(1) + [1]=> + int(0) + [2]=> + string(0) "" + [3]=> + int(2) + [4]=> + int(3) +} + +-- Iteration 10 -- +array(3) { + [0]=> + string(1) "a" + [1]=> + string(2) "ab" + [2]=> + string(2) "cd" +} + +-- Iteration 11 -- +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + string(0) "" +} +Done diff --git a/tests/std/array/array_keys_variation_002.phpt b/tests/std/array/array_keys_variation_002.phpt new file mode 100644 index 00000000..1765c217 --- /dev/null +++ b/tests/std/array/array_keys_variation_002.phpt @@ -0,0 +1,24 @@ +--TEST-- +Test array_keys() function (variation - 2) +--FILE-- + 1, "b" => 2, "c" => 3))); +var_dump(array_keys(array())); // null array + +echo "Done\n"; +?> +--EXPECT-- +*** Testing array_keys() on an array created on the fly *** +array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" +} +array(0) { +} +Done diff --git a/tests/std/array/array_keys_variation_003.phpt b/tests/std/array/array_keys_variation_003.phpt new file mode 100644 index 00000000..b04c5445 --- /dev/null +++ b/tests/std/array/array_keys_variation_003.phpt @@ -0,0 +1,114 @@ +--TEST-- +Test array_keys() function (variation - 3) +--SKIPIF-- + +--FILE-- + TRUE, + FALSE => FALSE, + 1 => 1, + 0 => 0, + -1 => -1, + "1" => "1", + "0" => "0", + "-1" => "-1", + NULL, + array(), + "php" => "php", + "" => "" +); +$values = array(TRUE, FALSE, 1, 0, -1, "1", "0", "-1", NULL, array(), "php", ""); +foreach ($values as $value){ + var_dump($value); + var_dump(array_keys($types_arr, $value)); +} + +echo "Done\n"; +?> +--EXPECT-- +*** Testing array_keys() on all the types other than arrays *** +bool(true) +array(3) { + [0]=> + int(1) + [1]=> + int(-1) + [2]=> + string(3) "php" +} +bool(false) +array(4) { + [0]=> + int(0) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + string(0) "" +} +int(1) +array(1) { + [0]=> + int(1) +} +int(0) +array(2) { + [0]=> + int(0) + [1]=> + int(2) +} +int(-1) +array(1) { + [0]=> + int(-1) +} +string(1) "1" +array(1) { + [0]=> + int(1) +} +string(1) "0" +array(1) { + [0]=> + int(0) +} +string(2) "-1" +array(1) { + [0]=> + int(-1) +} +NULL +array(3) { + [0]=> + int(2) + [1]=> + int(3) + [2]=> + string(0) "" +} +array(0) { +} +array(2) { + [0]=> + int(2) + [1]=> + int(3) +} +string(3) "php" +array(1) { + [0]=> + string(3) "php" +} +string(0) "" +array(2) { + [0]=> + int(2) + [1]=> + string(0) "" +} +Done diff --git a/tests/std/array/array_keys_variation_004.phpt b/tests/std/array/array_keys_variation_004.phpt new file mode 100644 index 00000000..a919d69e --- /dev/null +++ b/tests/std/array/array_keys_variation_004.phpt @@ -0,0 +1,73 @@ +--TEST-- +Test array_keys() function (variation - 4) +--SKIPIF-- + + +--FILE-- + TRUE, + FALSE => FALSE, + 1 => 1, + 0 => 0, + -1 => -1, + "1" => "1", + "0" => "0", + "-1" => "-1", + NULL, + array(), + "php" => "php", + "" => "" +); +$values = array(TRUE, FALSE, 1, 0, -1, "1", "0", "-1", NULL, array(), "php", ""); +foreach ($values as $value){ + var_dump(array_keys($types_arr, $value, TRUE)); +} + +echo "Done\n"; +?> +--EXPECT-- +*** Testing array_keys() on all the types other than arrays *** +array(0) { +} +array(0) { +} +array(0) { +} +array(0) { +} +array(0) { +} +array(1) { + [0]=> + int(1) +} +array(1) { + [0]=> + int(0) +} +array(1) { + [0]=> + int(-1) +} +array(1) { + [0]=> + int(2) +} +array(1) { + [0]=> + int(3) +} +array(1) { + [0]=> + string(3) "php" +} +array(1) { + [0]=> + string(0) "" +} +Done diff --git a/tests/std/array/array_keys_variation_005.phpt b/tests/std/array/array_keys_variation_005.phpt new file mode 100644 index 00000000..c9870ec6 --- /dev/null +++ b/tests/std/array/array_keys_variation_005.phpt @@ -0,0 +1,45 @@ +--TEST-- +Test array_keys() function (variation - 5) +--SKIPIF-- + + +--FILE-- + +--EXPECT-- +*** Testing array_keys() with resource type *** +array(1) { + [0]=> + int(0) +} +array(1) { + [0]=> + int(0) +} +array(1) { + [0]=> + int(1) +} +array(1) { + [0]=> + int(1) +} diff --git a/tests/std/array/array_map_001.phpt b/tests/std/array/array_map_001.phpt new file mode 100644 index 00000000..964480cd --- /dev/null +++ b/tests/std/array/array_map_001.phpt @@ -0,0 +1,24 @@ +--TEST-- +array_map() and exceptions in the callback +--SKIPIF-- + +--FILE-- + +--EXPECT-- +string(17) "exception caught!" +Done diff --git a/tests/std/array/array_map_basic.phpt b/tests/std/array/array_map_basic.phpt new file mode 100644 index 00000000..70d260c1 --- /dev/null +++ b/tests/std/array/array_map_basic.phpt @@ -0,0 +1,62 @@ +--TEST-- +Test array_map() function : basic functionality +--FILE-- + +--EXPECT-- +*** Testing array_map() : basic functionality *** +-- With two integer array -- +array(3) { + [0]=> + int(4) + [1]=> + int(10) + [2]=> + int(18) +} +-- With single integer array -- +array(3) { + [0]=> + int(1) + [1]=> + int(4) + [2]=> + int(9) +} +-- With string array -- +array(2) { + [0]=> + string(12) "one = single" + [1]=> + string(12) "two = double" +} +Done diff --git a/tests/std/array/array_map_error.phpt b/tests/std/array/array_map_error.phpt new file mode 100644 index 00000000..aaacbebc --- /dev/null +++ b/tests/std/array/array_map_error.phpt @@ -0,0 +1,58 @@ +--TEST-- +Test array_map() function : error conditions +--SKIPIF-- + + +--FILE-- +getMessage() . "\n"; + } + echo "\n-- Testing array_map() function with less no. of arrays than callback function arguments --\n"; + $arr1 = array(1, 2); + try { + var_dump(array_map('callback2', $arr1)); + } catch (Throwable $e) { + echo "Exception: " . $e->getMessage() . "\n"; + } + echo "\n-- Testing array_map() function with more no. of arrays than callback function arguments --\n"; + $arr2 = array(3, 4); + $arr3 = array(5, 6); + var_dump(array_map('callback2', $arr1, $arr2, $arr3)); + echo "Done"; +} +?> +--EXPECT-- +*** Testing array_map() : error conditions *** + +-- Testing array_map() function with one less than expected no. of arguments -- +Exception: array_map() expects at least 2 arguments, 1 given + +-- Testing array_map() function with less no. of arrays than callback function arguments -- +Exception: Too few arguments to function callback2(), 1 passed and exactly 2 expected + +-- Testing array_map() function with more no. of arrays than callback function arguments -- +array(2) { + [0]=> + int(3) + [1]=> + int(8) +} +Done diff --git a/tests/std/array/array_map_object1.phpt b/tests/std/array/array_map_object1.phpt new file mode 100644 index 00000000..1baeeba6 --- /dev/null +++ b/tests/std/array/array_map_object1.phpt @@ -0,0 +1,195 @@ +--TEST-- +Test array_map() function : usage variations - object functionality +--SKIPIF-- + + +--FILE-- +getMessage(), "\n"; + } +} +class SimpleClassPri +{ + private $var1 = 10; + private static function add($n) + { + return $var + $n; + } +} +class SimpleClassPro +{ + protected $var1 = 5; + protected static function mul($n) + { + return $var1 * $n; + } +} +class EmptyClass +{ +} +abstract class AbstractClass +{ + protected $var2 = 5; + abstract static function emptyFunction(); +} +// class deriving the above abstract class +class ChildClass extends AbstractClass +{ + private $var3; + public static function emptyFunction() + { + echo "defined in child\n"; + } +} +class FinalClass +{ + private $var4; + final static function finalMethod() + { + echo "This function can't be overloaded\n"; + } +} +class StaticClass +{ + static $var5 = 2; + public static function square($n) + { + return $n * $n; + } + private static function cube($n) + { + return $n * $n * $n; + } + protected static function retVal($n) + { + return array($n); + } +} +interface myInterface +{ + public function toImplement(); +} +class InterClass implements myInterface +{ + public static function square($n) + { + return $n * $n; + } + public function toImplement() + { + return 1; + } +} +function main() +{ + /* + * Testing array_map() for object functionalities: + * 1) simple class with variable and method + * 2) class without members + * 3) class with only one method and no variable + * 4) abstract and child class + * 5) class with static and final members + * 6) interface and implemented class + */ + echo "*** Testing array_map() : object functionality ***\n"; + echo "-- simple class with public variable and method --\n"; + test(array('SimpleClass', 'square'), array(1, 2)); + echo "\n-- simple class with private variable and method --\n"; + test(array('SimpleClassPri', 'add'), array(1)); + echo "\n-- simple class with protected variable and method --\n"; + test(array('SimpleClassPro', 'mul'), array(2)); + echo "\n-- class without members --\n"; + test(array('EmptyClass'), array(1, 2)); + echo "\n-- abstract class --\n"; + test(array('ChildClass', 'emptyFunction'), array(1, 2)); + echo "\n-- class with final method --\n"; + test(array('FinalClass', 'finalMethod'), array(1, 2)); + echo "\n-- class with static members --\n"; + test(array('StaticClass', 'square'), array(1, 2)); + test(array('StaticClass', 'cube'), array(2)); + test(array('StaticClass', 'retVal'), array(3, 4)); + echo "-- class implementing an interface --\n"; + test(array('InterClass', 'square'), array(1, 2)); +} +?> +--EXPECT-- +*** Testing array_map() : object functionality *** +-- simple class with public variable and method -- +SimpleClass::square +array(2) { + [0]=> + int(1) + [1]=> + int(4) +} + +-- simple class with private variable and method -- +SimpleClassPri::add +array_map(): Argument #1 ($callback) must be a valid callback or null, cannot access private method SimpleClassPri::add() + +-- simple class with protected variable and method -- +SimpleClassPro::mul +array_map(): Argument #1 ($callback) must be a valid callback or null, cannot access protected method SimpleClassPro::mul() + +-- class without members -- +EmptyClass +array_map(): Argument #1 ($callback) must be a valid callback or null, array callback must have exactly two members + +-- abstract class -- +ChildClass::emptyFunction +defined in child +defined in child +array(2) { + [0]=> + NULL + [1]=> + NULL +} + +-- class with final method -- +FinalClass::finalMethod +This function can't be overloaded +This function can't be overloaded +array(2) { + [0]=> + NULL + [1]=> + NULL +} + +-- class with static members -- +StaticClass::square +array(2) { + [0]=> + int(1) + [1]=> + int(4) +} +StaticClass::cube +array_map(): Argument #1 ($callback) must be a valid callback or null, cannot access private method StaticClass::cube() +StaticClass::retVal +array_map(): Argument #1 ($callback) must be a valid callback or null, cannot access protected method StaticClass::retVal() +-- class implementing an interface -- +InterClass::square +array(2) { + [0]=> + int(1) + [1]=> + int(4) +} diff --git a/tests/std/array/array_map_object2.phpt b/tests/std/array/array_map_object2.phpt new file mode 100644 index 00000000..3f281e0a --- /dev/null +++ b/tests/std/array/array_map_object2.phpt @@ -0,0 +1,46 @@ +--TEST-- +Test array_map() function : object functionality - with non-existent class and method +--FILE-- +getMessage(), "\n"; + } + echo "-- with existent class and non-existent method --\n"; + try { + var_dump(array_map(array('SimpleClass', 'non-existent'), array(1, 2))); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + echo "Done"; +} +?> +--EXPECT-- +*** Testing array_map() : with non-existent class and method *** +-- with non-existent class -- +array_map(): Argument #1 ($callback) must be a valid callback or null, class "non-existent" not found +-- with existent class and non-existent method -- +array_map(): Argument #1 ($callback) must be a valid callback or null, class SimpleClass does not have a method "non-existent" +Done diff --git a/tests/std/array/array_map_object3.phpt b/tests/std/array/array_map_object3.phpt new file mode 100644 index 00000000..7786801a --- /dev/null +++ b/tests/std/array/array_map_object3.phpt @@ -0,0 +1,90 @@ +--TEST-- +Test array_map() function : object functionality - class methods as callback function +--FILE-- +parent_obj = new ParentClass(); + } + public $var2 = 5; + public static function staticChild($n) + { + return $n; + } + public function nonstaticChild($n) + { + return $n; + } +} +function main() +{ + /* + * Testing array_map() for object functionality with following callback function variations: + * 1) child class method using parent object + * 2) parent class method using child object + * 3) child class method using parent class + * 4) parent class method using child class + */ + echo "*** Testing array_map() : class methods as callback function ***\n"; + $arr1 = array(1, 5, 7); + $childobj = new ChildClass(); + $parentobj = new ParentClass(); + echo "-- accessing parent method from child class --\n"; + var_dump(array_map(array('ChildClass', 'staticParent1'), $arr1)); + echo "-- accessing child method from parent class --\n"; + try { + var_dump(array_map(array('ParentClass', 'staticChild'), $arr1)); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + echo "-- accessing parent method using child class object --\n"; + var_dump(array_map(array($childobj, 'staticParent1'), $arr1)); + echo "-- accessing child method using parent class object --\n"; + try { + var_dump(array_map(array($parentobj, 'staticChild'), $arr1)); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + echo "Done"; +} +?> +--EXPECT-- +*** Testing array_map() : class methods as callback function *** +-- accessing parent method from child class -- +array(3) { + [0]=> + int(1) + [1]=> + int(5) + [2]=> + int(7) +} +-- accessing child method from parent class -- +array_map(): Argument #1 ($callback) must be a valid callback or null, class ParentClass does not have a method "staticChild" +-- accessing parent method using child class object -- +array(3) { + [0]=> + int(1) + [1]=> + int(5) + [2]=> + int(7) +} +-- accessing child method using parent class object -- +array_map(): Argument #1 ($callback) must be a valid callback or null, class ParentClass does not have a method "staticChild" +Done diff --git a/tests/std/array/array_map_variation1.phpt b/tests/std/array/array_map_variation1.phpt new file mode 100644 index 00000000..68f77437 --- /dev/null +++ b/tests/std/array/array_map_variation1.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test array_map() function : usage variations - string keys +--FILE-- + "value"); + var_dump(array_map("cb1", $arr)); + var_dump(array_map("cb2", $arr, $arr)); + var_dump(array_map(null, $arr)); + var_dump(array_map(null, $arr, $arr)); + echo "Done"; +} +?> +--EXPECT-- +*** Testing array_map() : string keys *** +array(1) { + ["stringkey"]=> + array(1) { + [0]=> + string(5) "value" + } +} +array(1) { + [0]=> + array(2) { + [0]=> + string(5) "value" + [1]=> + string(5) "value" + } +} +array(1) { + ["stringkey"]=> + string(5) "value" +} +array(1) { + [0]=> + array(2) { + [0]=> + string(5) "value" + [1]=> + string(5) "value" + } +} +Done diff --git a/tests/std/array/array_map_variation10.phpt b/tests/std/array/array_map_variation10.phpt new file mode 100644 index 00000000..1d79ffed --- /dev/null +++ b/tests/std/array/array_map_variation10.phpt @@ -0,0 +1,89 @@ +--TEST-- +Test array_map() function : usage variations - anonymous callback function +--SKIPIF-- + +--FILE-- +getMessage() . "\n"; +} + +echo "-- anonymous function with NULL parameter --\n"; +var_dump( array_map( function() { return NULL; }, $array1)); + +echo "-- anonymous function with NULL body --\n"; +var_dump( array_map( function($a) { }, $array1)); + +echo "-- passing NULL as 'array1' --\n"; +try { + var_dump( array_map( function($a) { return array($a); }, NULL)); +} catch (TypeError $e) { + echo $e->getMessage(), "\n"; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : anonymous callback function *** +-- anonymous function with all parameters and body -- +array(3) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(3) + } + [1]=> + array(2) { + [0]=> + int(2) + [1]=> + int(4) + } + [2]=> + array(2) { + [0]=> + int(3) + [1]=> + int(5) + } +} +-- anonymous function with two parameters and passing one array -- +Exception: Too few arguments to function {closure:%s:%d}(), 1 passed and exactly 2 expected +-- anonymous function with NULL parameter -- +array(3) { + [0]=> + NULL + [1]=> + NULL + [2]=> + NULL +} +-- anonymous function with NULL body -- +array(3) { + [0]=> + NULL + [1]=> + NULL + [2]=> + NULL +} +-- passing NULL as 'array1' -- +array_map(): Argument #2 ($array) must be of type array, null given +Done diff --git a/tests/std/array/array_map_variation11.phpt b/tests/std/array/array_map_variation11.phpt new file mode 100644 index 00000000..7749af78 --- /dev/null +++ b/tests/std/array/array_map_variation11.phpt @@ -0,0 +1,46 @@ +--TEST-- +Test array_map() function : usage variations - with recursive callback +--FILE-- + +--EXPECT-- +*** Testing array_map() : recursive callback function *** +array(3) { + [0]=> + int(1) + [1]=> + array(3) { + [0]=> + int(4) + [1]=> + int(9) + [2]=> + array(1) { + [0]=> + int(25) + } + } + [2]=> + array(1) { + [0]=> + int(16) + } +} +Done diff --git a/tests/std/array/array_map_variation12.phpt b/tests/std/array/array_map_variation12.phpt new file mode 100644 index 00000000..d3fa62e9 --- /dev/null +++ b/tests/std/array/array_map_variation12.phpt @@ -0,0 +1,48 @@ +--TEST-- +Test array_map() function : usage variations - built-in function as callback +--FILE-- +getMessage(), "\n"; +} + +echo "-- with language construct --\n"; +try { + var_dump( array_map('echo', $array1)); +} catch (TypeError $e) { + echo $e->getMessage(), "\n"; +} + +echo "Done"; +?> +--EXPECT-- +*** Testing array_map() : built-in function *** +-- with built-in function 'pow' and two parameters -- +array(3) { + [0]=> + int(1) + [1]=> + int(16) + [2]=> + int(243) +} +-- with built-in function 'pow' and one parameter -- +pow() expects exactly 2 arguments, 1 given +-- with language construct -- +array_map(): Argument #1 ($callback) must be a valid callback or null, function "echo" not found or invalid function name +Done diff --git a/tests/std/array/array_map_variation13.phpt b/tests/std/array/array_map_variation13.phpt new file mode 100644 index 00000000..596e04af --- /dev/null +++ b/tests/std/array/array_map_variation13.phpt @@ -0,0 +1,97 @@ +--TEST-- +Test array_map() function : usage variations - callback function with different return types +--FILE-- + +--EXPECT-- +*** Testing array_map() : callback with diff return value *** +-- with integer return value -- +array(3) { + [0]=> + int(4) + [1]=> + int(6) + [2]=> + int(8) +} +-- with string return value -- +array(3) { + [0]=> + string(2) "13" + [1]=> + string(2) "24" + [2]=> + string(2) "35" +} +-- with bool return value -- +array(3) { + [0]=> + bool(true) + [1]=> + bool(true) + [2]=> + bool(true) +} +-- with null return value -- +array(3) { + [0]=> + NULL + [1]=> + NULL + [2]=> + NULL +} +-- with no return value -- +callback_without_ret called +callback_without_ret called +callback_without_ret called +array(3) { + [0]=> + NULL + [1]=> + NULL + [2]=> + NULL +} +Done diff --git a/tests/std/array/array_map_variation14.phpt b/tests/std/array/array_map_variation14.phpt new file mode 100644 index 00000000..b1276b92 --- /dev/null +++ b/tests/std/array/array_map_variation14.phpt @@ -0,0 +1,129 @@ +--TEST-- +Test array_map() function : usage variations - null value for 'callback' argument +--SKIPIF-- + + +--FILE-- +getMessage(), "\n"; +} + +echo "-- with empty array --\n"; +try { + var_dump( array_map(array(), $arr1, $arr2) ); +} catch (TypeError $e) { + echo $e->getMessage(), "\n"; +} + +echo "Done"; +?> +--EXPECT-- +*** Testing array_map() : null value for 'callback' argument *** +-- with null -- +array(2) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + string(3) "one" + [2]=> + float(1.1) + } + [1]=> + array(3) { + [0]=> + int(2) + [1]=> + string(3) "two" + [2]=> + float(2.2) + } +} +array(2) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + string(3) "one" + [2]=> + float(1.1) + } + [1]=> + array(3) { + [0]=> + int(2) + [1]=> + string(3) "two" + [2]=> + float(2.2) + } +} +-- with unset variable -- +array(2) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + string(3) "one" + [2]=> + float(1.1) + } + [1]=> + array(3) { + [0]=> + int(2) + [1]=> + string(3) "two" + [2]=> + float(2.2) + } +} +-- with undefined variable -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- with empty string -- +array_map(): Argument #1 ($callback) must be a valid callback or null, function "" not found or invalid function name +-- with empty array -- +array_map(): Argument #1 ($callback) must be a valid callback or null, array callback must have exactly two members +Done diff --git a/tests/std/array/array_map_variation15.phpt b/tests/std/array/array_map_variation15.phpt new file mode 100644 index 00000000..d053a720 --- /dev/null +++ b/tests/std/array/array_map_variation15.phpt @@ -0,0 +1,27 @@ +--TEST-- +Test array_map() function : usage variations - non existent 'callback' function +--FILE-- +getMessage(), "\n"; +} + +echo "Done"; +?> +--EXPECT-- +*** Testing array_map() : non existent 'callback' function *** +array_map(): Argument #1 ($callback) must be a valid callback or null, function "non_existent" not found or invalid function name +Done diff --git a/tests/std/array/array_map_variation16.phpt b/tests/std/array/array_map_variation16.phpt new file mode 100644 index 00000000..7ee1f049 --- /dev/null +++ b/tests/std/array/array_map_variation16.phpt @@ -0,0 +1,38 @@ +--TEST-- +Test array_map() function : usage variations - failing built-in functions & language constructs +--FILE-- +getMessage(), "\n"; + } +} + +echo "Done"; +?> +--EXPECT-- +array_map(): Argument #1 ($callback) must be a valid callback or null, function "echo" not found or invalid function name +array_map(): Argument #1 ($callback) must be a valid callback or null, function "array" not found or invalid function name +array_map(): Argument #1 ($callback) must be a valid callback or null, function "empty" not found or invalid function name +array_map(): Argument #1 ($callback) must be a valid callback or null, function "eval" not found or invalid function name +array_map(): Argument #1 ($callback) must be a valid callback or null, function "isset" not found or invalid function name +array_map(): Argument #1 ($callback) must be a valid callback or null, function "list" not found or invalid function name +array_map(): Argument #1 ($callback) must be a valid callback or null, function "print" not found or invalid function name +Done diff --git a/tests/std/array/array_map_variation17.phpt b/tests/std/array/array_map_variation17.phpt new file mode 100644 index 00000000..24cf2892 --- /dev/null +++ b/tests/std/array/array_map_variation17.phpt @@ -0,0 +1,133 @@ +--TEST-- +Test array_map() function : usage variations - unexpected values for 'callback' argument +--FILE-- +getMessage(), "\n"; + } + } + fclose($fp); + echo "Done"; +} +?> +--EXPECT-- +*** Testing array_map() : unexpected values for 'callback' argument *** + +-- Iteration 1 -- +array_map(): Argument #1 ($callback) must be a valid callback or null, no array or string given + +-- Iteration 2 -- +array_map(): Argument #1 ($callback) must be a valid callback or null, no array or string given + +-- Iteration 3 -- +array_map(): Argument #1 ($callback) must be a valid callback or null, no array or string given + +-- Iteration 4 -- +array_map(): Argument #1 ($callback) must be a valid callback or null, no array or string given + +-- Iteration 5 -- +array_map(): Argument #1 ($callback) must be a valid callback or null, no array or string given + +-- Iteration 6 -- +array_map(): Argument #1 ($callback) must be a valid callback or null, no array or string given + +-- Iteration 7 -- +array_map(): Argument #1 ($callback) must be a valid callback or null, no array or string given + +-- Iteration 8 -- +array_map(): Argument #1 ($callback) must be a valid callback or null, no array or string given + +-- Iteration 9 -- +array_map(): Argument #1 ($callback) must be a valid callback or null, no array or string given + +-- Iteration 10 -- +array_map(): Argument #1 ($callback) must be a valid callback or null, no array or string given + +-- Iteration 11 -- +array_map(): Argument #1 ($callback) must be a valid callback or null, no array or string given + +-- Iteration 12 -- +array_map(): Argument #1 ($callback) must be a valid callback or null, no array or string given + +-- Iteration 13 -- +array_map(): Argument #1 ($callback) must be a valid callback or null, no array or string given + +-- Iteration 14 -- +array_map(): Argument #1 ($callback) must be a valid callback or null, function "" not found or invalid function name + +-- Iteration 15 -- +array_map(): Argument #1 ($callback) must be a valid callback or null, function "" not found or invalid function name + +-- Iteration 16 -- +array_map(): Argument #1 ($callback) must be a valid callback or null, array callback must have exactly two members + +-- Iteration 17 -- +array_map(): Argument #1 ($callback) must be a valid callback or null, first array member is not a valid class name or object + +-- Iteration 18 -- +array_map(): Argument #1 ($callback) must be a valid callback or null, first array member is not a valid class name or object + +-- Iteration 19 -- +array_map(): Argument #1 ($callback) must be a valid callback or null, no array or string given + +-- Iteration 20 -- +array_map(): Argument #1 ($callback) must be a valid callback or null, no array or string given +Done diff --git a/tests/std/array/array_map_variation19.phpt b/tests/std/array/array_map_variation19.phpt new file mode 100644 index 00000000..a725117a --- /dev/null +++ b/tests/std/array/array_map_variation19.phpt @@ -0,0 +1,35 @@ +--TEST-- +Test array_map() function : usage variations - callback pass semantics +--FILE-- + +--EXPECT-- +array(2) { + [0]=> + string(10) "original.0" + [1]=> + string(10) "original.1" +} +array(2) { + [0]=> + &string(10) "original.0" + [1]=> + string(10) "original.1" +} diff --git a/tests/std/array/array_map_variation2.phpt b/tests/std/array/array_map_variation2.phpt new file mode 100644 index 00000000..6101ca2f --- /dev/null +++ b/tests/std/array/array_map_variation2.phpt @@ -0,0 +1,134 @@ +--TEST-- +Test array_map() function : usage variations - references +--SKIPIF-- + + +--FILE-- + "v1", "k2" => "v2"); + $arr[] =& $arr["k1"]; + $arr[] =& $arr; + var_dump(array_map("cb1", $arr)); + var_dump(array_map(null, $arr)); + var_dump(array_map(null, $arr, $arr)); + // break cycles + $arr[0] = null; + $arr[1] = null; + echo "Done"; +} +?> +--EXPECT-- +*** Testing array_map() : references *** +string(2) "v1" +string(2) "v2" +string(2) "v1" +array(4) { + ["k1"]=> + &string(2) "v1" + ["k2"]=> + string(2) "v2" + [0]=> + &string(2) "v1" + [1]=> + *RECURSION* +} +array(4) { + ["k1"]=> + array(1) { + [0]=> + string(2) "v1" + } + ["k2"]=> + array(1) { + [0]=> + string(2) "v2" + } + [0]=> + array(1) { + [0]=> + string(2) "v1" + } + [1]=> + array(1) { + [0]=> + array(4) { + ["k1"]=> + &string(2) "v1" + ["k2"]=> + string(2) "v2" + [0]=> + &string(2) "v1" + [1]=> + *RECURSION* + } + } +} +array(4) { + ["k1"]=> + &string(2) "v1" + ["k2"]=> + string(2) "v2" + [0]=> + &string(2) "v1" + [1]=> + *RECURSION* +} +array(4) { + [0]=> + array(2) { + [0]=> + &string(2) "v1" + [1]=> + &string(2) "v1" + } + [1]=> + array(2) { + [0]=> + string(2) "v2" + [1]=> + string(2) "v2" + } + [2]=> + array(2) { + [0]=> + &string(2) "v1" + [1]=> + &string(2) "v1" + } + [3]=> + array(2) { + [0]=> + &array(4) { + ["k1"]=> + &string(2) "v1" + ["k2"]=> + string(2) "v2" + [0]=> + &string(2) "v1" + [1]=> + *RECURSION* + } + [1]=> + &array(4) { + ["k1"]=> + &string(2) "v1" + ["k2"]=> + string(2) "v2" + [0]=> + &string(2) "v1" + [1]=> + *RECURSION* + } + } +} +Done diff --git a/tests/std/array/array_map_variation3.phpt b/tests/std/array/array_map_variation3.phpt new file mode 100644 index 00000000..778fdc6a --- /dev/null +++ b/tests/std/array/array_map_variation3.phpt @@ -0,0 +1,234 @@ +--TEST-- +Test array_map() function : usage variations - different arrays for 'arr1' argument +--SKIPIF-- + +--FILE-- + "one", 2 => "two", 3 => "three"), + // explicit numeric keys, string values + array("one" => 1, "two" => 2, "three" => 3), + // string keys & numeric values + array(1 => 10, 2 => 20, 4 => 40, 3 => 30), + // explicit numeric keys and numeric values + array("one" => "ten", "two" => "twenty", "three" => "thirty"), + // string key/value + array("one" => 1, 2 => "two", 4 => "four"), + //mixed + // associative array, containing null/empty/boolean values as key/value + /*13*/ + array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null), + array(true => "true", false => "false", "false" => false, "true" => true), + array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''), + array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true), + array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6), + // array with repetitive keys + /*18*/ + array("One" => 1, "two" => 2, "One" => 10, "two" => 20, "three" => 3), + ); + // loop through the various elements of $arrays to test array_map() + $iterator = 1; + foreach ($arrays as $arr1) { + echo "-- Iteration {$iterator} --\n"; + var_dump(array_map('callback', $arr1)); + $iterator++; + } + echo "Done"; +} +?> +--EXPECT-- +*** Testing array_map() : different arrays for 'arr1' argument *** +-- Iteration 1 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 2 -- +array(2) { + [0]=> + float(1.1) + [1]=> + float(2.2) +} +-- Iteration 3 -- +array(2) { + [0]=> + array(1) { + [0]=> + int(2) + } + [1]=> + array(1) { + [0]=> + int(1) + } +} +-- Iteration 4 -- +array(2) { + [0]=> + bool(false) + [1]=> + bool(true) +} +-- Iteration 5 -- +array(0) { +} +-- Iteration 6 -- +array(1) { + [0]=> + NULL +} +-- Iteration 7 -- +array(6) { + [0]=> + string(1) "a" + [1]=> + string(4) "aaaa" + [2]=> + string(1) "b" + [3]=> + string(4) "bbbb" + [4]=> + string(1) "c" + [5]=> + string(5) "ccccc" +} +-- Iteration 8 -- +array(3) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + string(5) "three" +} +-- Iteration 9 -- +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} +-- Iteration 10 -- +array(4) { + [1]=> + int(10) + [2]=> + int(20) + [4]=> + int(40) + [3]=> + int(30) +} +-- Iteration 11 -- +array(3) { + ["one"]=> + string(3) "ten" + ["two"]=> + string(6) "twenty" + ["three"]=> + string(6) "thirty" +} +-- Iteration 12 -- +array(3) { + ["one"]=> + int(1) + [2]=> + string(3) "two" + [4]=> + string(4) "four" +} +-- Iteration 13 -- +array(3) { + [""]=> + string(4) "null" + ["NULL"]=> + NULL + ["null"]=> + NULL +} +-- Iteration 14 -- +array(4) { + [1]=> + string(4) "true" + [0]=> + string(5) "false" + ["false"]=> + bool(false) + ["true"]=> + bool(true) +} +-- Iteration 15 -- +array(3) { + [""]=> + string(6) "emptys" + ["emptyd"]=> + string(0) "" + ["emptys"]=> + string(0) "" +} +-- Iteration 16 -- +array(6) { + [1]=> + string(0) "" + [2]=> + string(0) "" + [3]=> + NULL + [4]=> + NULL + [5]=> + bool(false) + [6]=> + bool(true) +} +-- Iteration 17 -- +array(3) { + [""]=> + int(4) + [0]=> + int(5) + [1]=> + int(6) +} +-- Iteration 18 -- +array(3) { + ["One"]=> + int(10) + ["two"]=> + int(20) + ["three"]=> + int(3) +} +Done diff --git a/tests/std/array/array_map_variation4.phpt b/tests/std/array/array_map_variation4.phpt new file mode 100644 index 00000000..9190ffdf --- /dev/null +++ b/tests/std/array/array_map_variation4.phpt @@ -0,0 +1,147 @@ +--TEST-- +Test array_map() function : usage variations - associative array with different keys +--SKIPIF-- + +--FILE-- + "0"), + array(1 => "1"), + array(1 => "1", 2 => "2", 3 => "3", 4 => "4"), + // arrays with string keys + array('\tHello' => 111, 're\td' => 'color', '\v\fworld' => 2.2, 'pen\n' => 33), + /*8*/ + array("\tHello" => 111, "re\td" => "color", "\v\fworld" => 2.2, "pen\n" => 33), + array("hello", $heredoc => "string"), + // heredoc + // array with object, unset variable and resource variable + array(@$unset_var => "hello", $fp => 'resource'), + // array with mixed values + /*11*/ + array('hello' => 1, "fruit" => 2.2, $fp => 'resource', 133 => "int", @$unset_var => "unset", $heredoc => "heredoc"), + ); + // loop through the various elements of $arrays to test array_map() + $iterator = 1; + foreach ($arrays as $arr1) { + echo "-- Iteration {$iterator} --\n"; + var_dump(array_map('callback', $arr1)); + $iterator++; + } + echo "Done"; +} +?> +--EXPECTF-- +*** Testing array_map() : associative array with diff. keys for 'arr1' argument *** + +Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d + +Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d +-- Iteration 1 -- +array(0) { +} +-- Iteration 2 -- +array(1) { + [0]=> + string(1) "0" +} +-- Iteration 3 -- +array(1) { + [1]=> + string(1) "1" +} +-- Iteration 4 -- +array(4) { + [1]=> + string(1) "1" + [2]=> + string(1) "2" + [3]=> + string(1) "3" + [4]=> + string(1) "4" +} +-- Iteration 5 -- +array(4) { + ["\tHello"]=> + int(111) + ["re\td"]=> + string(5) "color" + ["\v\fworld"]=> + float(2.2) + ["pen\n"]=> + int(33) +} +-- Iteration 6 -- +array(4) { + [" Hello"]=> + int(111) + ["re d"]=> + string(5) "color" + [" world"]=> + float(2.2) + ["pen +"]=> + int(33) +} +-- Iteration 7 -- +array(2) { + [0]=> + string(5) "hello" + ["Hello world"]=> + string(6) "string" +} +-- Iteration 8 -- +array(2) { + [""]=> + string(5) "hello" + [5]=> + string(8) "resource" +} +-- Iteration 9 -- +array(6) { + ["hello"]=> + int(1) + ["fruit"]=> + float(2.2) + [5]=> + string(8) "resource" + [133]=> + string(3) "int" + [""]=> + string(5) "unset" + ["Hello world"]=> + string(7) "heredoc" +} +Done diff --git a/tests/std/array/array_map_variation5.phpt b/tests/std/array/array_map_variation5.phpt new file mode 100644 index 00000000..dfb9ecf2 --- /dev/null +++ b/tests/std/array/array_map_variation5.phpt @@ -0,0 +1,169 @@ +--TEST-- +Test array_map() function : usage variations - associative array with different values +--SKIPIF-- + +--FILE-- + 0), + array("1" => 1), + array("one" => 1, 'two' => 2, "three" => 3, 4 => 4), + // arrays with float values + /*5*/ + array("float" => 2.3333), + array("f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => 33333333.3333), + // arrays with string values + array(111 => "\tHello", "red" => "col\tor", 2 => "\v\fworld", 3 => "pen\n"), + /*8*/ + array(111 => '\tHello', "red" => 'col\tor', 2 => '\v\fworld', 3 => 'pen\n'), + array(1 => "hello", "heredoc" => $heredoc), + // array with object, unset variable and resource variable + array(11 => new classA(), "unset" => @$unset_var, "resource" => $fp), + // array with mixed values + /*11*/ + array(1 => 'hello', 2 => new classA(), 222 => "fruit", 'resource' => $fp, "int" => 133, "float" => 444.432, "unset" => @$unset_var, "heredoc" => $heredoc), + ); + // loop through the various elements of $arrays to test array_map() + $iterator = 1; + foreach ($arrays as $arr1) { + echo "-- Iteration {$iterator} --\n"; + var_dump(array_map('callback', $arr1)); + $iterator++; + } + echo "Done"; +} +?> +--EXPECTF-- +*** Testing array_map() : associative array with diff. values for 'arr1' argument *** +-- Iteration 1 -- +array(0) { +} +-- Iteration 2 -- +array(1) { + [0]=> + int(0) +} +-- Iteration 3 -- +array(1) { + [1]=> + int(1) +} +-- Iteration 4 -- +array(4) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) + [4]=> + int(4) +} +-- Iteration 5 -- +array(1) { + ["float"]=> + float(2.3333) +} +-- Iteration 6 -- +array(4) { + ["f1"]=> + float(1.2) + ["f2"]=> + float(3.33) + [3]=> + float(4.89999922839999) + ["f4"]=> + float(33333333.3333) +} +-- Iteration 7 -- +array(4) { + [111]=> + string(6) " Hello" + ["red"]=> + string(6) "col or" + [2]=> + string(7) " world" + [3]=> + string(4) "pen +" +} +-- Iteration 8 -- +array(4) { + [111]=> + string(7) "\tHello" + ["red"]=> + string(7) "col\tor" + [2]=> + string(9) "\v\fworld" + [3]=> + string(5) "pen\n" +} +-- Iteration 9 -- +array(2) { + [1]=> + string(5) "hello" + ["heredoc"]=> + string(11) "Hello world" +} +-- Iteration 10 -- +array(3) { + [11]=> + object(classA)#%d (0) { + } + ["unset"]=> + NULL + ["resource"]=> + resource(%d) of type (stream) +} +-- Iteration 11 -- +array(8) { + [1]=> + string(5) "hello" + [2]=> + object(classA)#%d (0) { + } + [222]=> + string(5) "fruit" + ["resource"]=> + resource(%d) of type (stream) + ["int"]=> + int(133) + ["float"]=> + float(444.432) + ["unset"]=> + NULL + ["heredoc"]=> + string(11) "Hello world" +} +Done diff --git a/tests/std/array/array_map_variation6.phpt b/tests/std/array/array_map_variation6.phpt new file mode 100644 index 00000000..d82eebb9 --- /dev/null +++ b/tests/std/array/array_map_variation6.phpt @@ -0,0 +1,60 @@ +--TEST-- +Test array_map() function : usage variations - array having subarrays +--FILE-- + 'a', 'b' => 2)); + var_dump(array_map('callback', $arr1)); + echo "Done"; +} +?> +--EXPECT-- +*** Testing array_map() : array having subarrays *** +array(5) { + [0]=> + array(0) { + } + [1]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [2]=> + array(2) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + } + [3]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(1) "a" + [3]=> + string(1) "b" + } + [4]=> + array(2) { + [1]=> + string(1) "a" + ["b"]=> + int(2) + } +} +Done diff --git a/tests/std/array/array_map_variation7.phpt b/tests/std/array/array_map_variation7.phpt new file mode 100644 index 00000000..6ac8b51b --- /dev/null +++ b/tests/std/array/array_map_variation7.phpt @@ -0,0 +1,101 @@ +--TEST-- +Test array_map() function : usage variations - arrays of different size +--SKIPIF-- + + +--FILE-- + $b); +} +function main() +{ + /* + * Test array_map() by passing array having different size + * 1) first array as empty array + * 2) second array as empty array + * 3) second array shorter than first array + * 4) first array shorter than second array + * 5) one more array than callback function arguments + */ + echo "*** Testing array_map() : arrays with diff. size ***\n"; + // calling array_map with different arrays + var_dump(array_map('callback', array(1, 2, 3), array())); + var_dump(array_map('callback', array(), array('a', 'b', 'c'))); + var_dump(array_map('callback', array(1, 2, 3), array('a', 'b'))); + var_dump(array_map('callback', array(012, 0x2f, 0x1a), array(2.3, 1240.0))); + echo "Done"; +} +?> +--EXPECT-- +*** Testing array_map() : arrays with diff. size *** +array(3) { + [0]=> + array(1) { + [1]=> + NULL + } + [1]=> + array(1) { + [2]=> + NULL + } + [2]=> + array(1) { + [3]=> + NULL + } +} +array(3) { + [0]=> + array(1) { + [0]=> + string(1) "a" + } + [1]=> + array(1) { + [0]=> + string(1) "b" + } + [2]=> + array(1) { + [0]=> + string(1) "c" + } +} +array(3) { + [0]=> + array(1) { + [1]=> + string(1) "a" + } + [1]=> + array(1) { + [2]=> + string(1) "b" + } + [2]=> + array(1) { + [3]=> + NULL + } +} +array(3) { + [0]=> + array(1) { + [10]=> + float(2.3) + } + [1]=> + array(1) { + [47]=> + float(1240) + } + [2]=> + array(1) { + [26]=> + NULL + } +} +Done diff --git a/tests/std/array/array_map_variation8.phpt b/tests/std/array/array_map_variation8.phpt new file mode 100644 index 00000000..28391ff4 --- /dev/null +++ b/tests/std/array/array_map_variation8.phpt @@ -0,0 +1,65 @@ +--TEST-- +Test array_map() function : usage variations - array with references +--FILE-- + 0, 1 => &$value4, 2 => &$value2, 3 => "hello", 4 => &$value3, $value4 => &$value2); + echo "-- with one array --\n"; + var_dump(array_map('callback1', $arr1)); + echo "-- with two arrays --\n"; + var_dump(array_map('callback_cat', $arr1, $arr1)); + echo "Done"; +} +?> +--EXPECT-- +*** Testing array_map() : array with references for 'arr1' argument *** +-- with one array -- +array(6) { + [0]=> + int(0) + [1]=> + string(5) "hello" + [2]=> + string(5) "hello" + [3]=> + string(5) "hello" + [4]=> + int(0) + ["hello"]=> + string(5) "hello" +} +-- with two arrays -- +array(6) { + [0]=> + string(2) "00" + [1]=> + string(10) "hellohello" + [2]=> + string(10) "hellohello" + [3]=> + string(10) "hellohello" + [4]=> + string(2) "00" + [5]=> + string(10) "hellohello" +} +Done diff --git a/tests/std/array/array_map_variation9.phpt b/tests/std/array/array_map_variation9.phpt new file mode 100644 index 00000000..4ac45686 --- /dev/null +++ b/tests/std/array/array_map_variation9.phpt @@ -0,0 +1,50 @@ +--TEST-- +Test array_map() function : usage variations - binary safe checking +--SKIPIF-- + + +--FILE-- + $b); +} +function main() +{ + /* + * Test array_map() by passing array having binary values for $arr1 argument + */ + echo "*** Testing array_map() : array with binary data for 'arr1' argument ***\n"; + // array with binary data + $arr1 = array("hello", "world", "1", "22.22"); + echo "-- checking binary safe array with one parameter callback function --\n"; + var_dump(array_map('callback1', $arr1)); + echo "-- checking binary safe array with two parameter callback function --\n"; + try { + var_dump(array_map("callback2", $arr1)); + } catch (Throwable $e) { + echo "Exception: " . $e->getMessage() . "\n"; + } + echo "Done"; +} +?> +--EXPECT-- +*** Testing array_map() : array with binary data for 'arr1' argument *** +-- checking binary safe array with one parameter callback function -- +array(4) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + [2]=> + string(1) "1" + [3]=> + string(5) "22.22" +} +-- checking binary safe array with two parameter callback function -- +Exception: Too few arguments to function callback2(), 1 passed and exactly 2 expected +Done diff --git a/tests/std/array/array_merge.phpt b/tests/std/array/array_merge.phpt new file mode 100644 index 00000000..5890f94a --- /dev/null +++ b/tests/std/array/array_merge.phpt @@ -0,0 +1,914 @@ +--TEST-- +Test array_merge() function +--INI-- +precision=14 +--SKIPIF-- + +--FILE-- + "string"), + array( "" => "string"), + array( -2 => 12), + array( "a" => 1, "b" => -2.344, "b" => "string", "c" => NULL, "d" => -2.344), + array( 4 => 1, 3 => -2.344, "3" => "string", "2" => NULL,1 => -2.344), + array( NULL, 1 => "Hi", "string" => "hello", + array("" => "World", "-2.34" => "a", "0" => "b")) +); + +$end_array = array( + array(), + array( 1 => "string"), + array( "" => "string"), + array( -2 => 12), + array( "a" => 1, "b" => -2.344, "b" => "string", "c" => NULL, "d" => -2.344), + array( 4 => 1, 3 => -2.344, "3" => "string", "2" => NULL, 1=> -2.344), + array( NULL, 1 => "Hi", "string" => "hello", + array("" => "World", "-2.34" => "a", "0" => "b")) +); + +/* loop through to merge two arrays */ +$count_outer = 0; +foreach($begin_array as $first) { + echo "\n\n--- Iteration $count_outer ---"; + $count_inner = 0; + foreach($end_array as $second) { + echo "\n-- Inner iteration $count_inner of Iteration $count_outer --\n"; + $result = array_merge($first, $second); + var_dump($result); + $count_inner++; + } + $count_outer++; +} + + +echo "\n*** Testing array_merge() with three or more arrays ***\n"; +var_dump( array_merge( $end_array[0], + $end_array[5], + $end_array[4], + $end_array[6] + ) + ); + +var_dump( array_merge( $end_array[0], + $end_array[5], + array("array on fly"), + array("nullarray" => array()) + ) + ); + + +echo "\n*** Testing single array argument ***\n"; +/* Empty array */ +var_dump(array_merge(array())); + +/* associative array with string keys, which will not be re-indexed */ +var_dump(array_merge($begin_array[4])); + +/* associative array with numeric keys, which will be re-indexed */ +var_dump(array_merge($begin_array[5])); + +/* associative array with mixed keys and sub-array as element */ +var_dump(array_merge($begin_array[6])); + +echo "\n*** Testing array_merge() with typecasting non-array to array ***\n"; +var_dump(array_merge($begin_array[4], (array)"type1", (array)10, (array)12.34)); + +echo "\n*** Testing array_merge without any arguments ***\n"; +var_dump(array_merge()); + +echo "Done\n"; +?> +--EXPECT-- +*** Testing array_merge() basic functionality *** + +--- Iteration 0 --- +-- Inner iteration 0 of Iteration 0 -- +array(0) { +} + +-- Inner iteration 1 of Iteration 0 -- +array(1) { + [0]=> + string(6) "string" +} + +-- Inner iteration 2 of Iteration 0 -- +array(1) { + [""]=> + string(6) "string" +} + +-- Inner iteration 3 of Iteration 0 -- +array(1) { + [0]=> + int(12) +} + +-- Inner iteration 4 of Iteration 0 -- +array(4) { + ["a"]=> + int(1) + ["b"]=> + string(6) "string" + ["c"]=> + NULL + ["d"]=> + float(-2.344) +} + +-- Inner iteration 5 of Iteration 0 -- +array(4) { + [0]=> + int(1) + [1]=> + string(6) "string" + [2]=> + NULL + [3]=> + float(-2.344) +} + +-- Inner iteration 6 of Iteration 0 -- +array(4) { + [0]=> + NULL + [1]=> + string(2) "Hi" + ["string"]=> + string(5) "hello" + [2]=> + array(3) { + [""]=> + string(5) "World" + ["-2.34"]=> + string(1) "a" + [0]=> + string(1) "b" + } +} + + +--- Iteration 1 --- +-- Inner iteration 0 of Iteration 1 -- +array(1) { + [0]=> + string(6) "string" +} + +-- Inner iteration 1 of Iteration 1 -- +array(2) { + [0]=> + string(6) "string" + [1]=> + string(6) "string" +} + +-- Inner iteration 2 of Iteration 1 -- +array(2) { + [0]=> + string(6) "string" + [""]=> + string(6) "string" +} + +-- Inner iteration 3 of Iteration 1 -- +array(2) { + [0]=> + string(6) "string" + [1]=> + int(12) +} + +-- Inner iteration 4 of Iteration 1 -- +array(5) { + [0]=> + string(6) "string" + ["a"]=> + int(1) + ["b"]=> + string(6) "string" + ["c"]=> + NULL + ["d"]=> + float(-2.344) +} + +-- Inner iteration 5 of Iteration 1 -- +array(5) { + [0]=> + string(6) "string" + [1]=> + int(1) + [2]=> + string(6) "string" + [3]=> + NULL + [4]=> + float(-2.344) +} + +-- Inner iteration 6 of Iteration 1 -- +array(5) { + [0]=> + string(6) "string" + [1]=> + NULL + [2]=> + string(2) "Hi" + ["string"]=> + string(5) "hello" + [3]=> + array(3) { + [""]=> + string(5) "World" + ["-2.34"]=> + string(1) "a" + [0]=> + string(1) "b" + } +} + + +--- Iteration 2 --- +-- Inner iteration 0 of Iteration 2 -- +array(1) { + [""]=> + string(6) "string" +} + +-- Inner iteration 1 of Iteration 2 -- +array(2) { + [""]=> + string(6) "string" + [0]=> + string(6) "string" +} + +-- Inner iteration 2 of Iteration 2 -- +array(1) { + [""]=> + string(6) "string" +} + +-- Inner iteration 3 of Iteration 2 -- +array(2) { + [""]=> + string(6) "string" + [0]=> + int(12) +} + +-- Inner iteration 4 of Iteration 2 -- +array(5) { + [""]=> + string(6) "string" + ["a"]=> + int(1) + ["b"]=> + string(6) "string" + ["c"]=> + NULL + ["d"]=> + float(-2.344) +} + +-- Inner iteration 5 of Iteration 2 -- +array(5) { + [""]=> + string(6) "string" + [0]=> + int(1) + [1]=> + string(6) "string" + [2]=> + NULL + [3]=> + float(-2.344) +} + +-- Inner iteration 6 of Iteration 2 -- +array(5) { + [""]=> + string(6) "string" + [0]=> + NULL + [1]=> + string(2) "Hi" + ["string"]=> + string(5) "hello" + [2]=> + array(3) { + [""]=> + string(5) "World" + ["-2.34"]=> + string(1) "a" + [0]=> + string(1) "b" + } +} + + +--- Iteration 3 --- +-- Inner iteration 0 of Iteration 3 -- +array(1) { + [0]=> + int(12) +} + +-- Inner iteration 1 of Iteration 3 -- +array(2) { + [0]=> + int(12) + [1]=> + string(6) "string" +} + +-- Inner iteration 2 of Iteration 3 -- +array(2) { + [0]=> + int(12) + [""]=> + string(6) "string" +} + +-- Inner iteration 3 of Iteration 3 -- +array(2) { + [0]=> + int(12) + [1]=> + int(12) +} + +-- Inner iteration 4 of Iteration 3 -- +array(5) { + [0]=> + int(12) + ["a"]=> + int(1) + ["b"]=> + string(6) "string" + ["c"]=> + NULL + ["d"]=> + float(-2.344) +} + +-- Inner iteration 5 of Iteration 3 -- +array(5) { + [0]=> + int(12) + [1]=> + int(1) + [2]=> + string(6) "string" + [3]=> + NULL + [4]=> + float(-2.344) +} + +-- Inner iteration 6 of Iteration 3 -- +array(5) { + [0]=> + int(12) + [1]=> + NULL + [2]=> + string(2) "Hi" + ["string"]=> + string(5) "hello" + [3]=> + array(3) { + [""]=> + string(5) "World" + ["-2.34"]=> + string(1) "a" + [0]=> + string(1) "b" + } +} + + +--- Iteration 4 --- +-- Inner iteration 0 of Iteration 4 -- +array(4) { + ["a"]=> + int(1) + ["b"]=> + string(6) "string" + ["c"]=> + NULL + ["d"]=> + float(-2.344) +} + +-- Inner iteration 1 of Iteration 4 -- +array(5) { + ["a"]=> + int(1) + ["b"]=> + string(6) "string" + ["c"]=> + NULL + ["d"]=> + float(-2.344) + [0]=> + string(6) "string" +} + +-- Inner iteration 2 of Iteration 4 -- +array(5) { + ["a"]=> + int(1) + ["b"]=> + string(6) "string" + ["c"]=> + NULL + ["d"]=> + float(-2.344) + [""]=> + string(6) "string" +} + +-- Inner iteration 3 of Iteration 4 -- +array(5) { + ["a"]=> + int(1) + ["b"]=> + string(6) "string" + ["c"]=> + NULL + ["d"]=> + float(-2.344) + [0]=> + int(12) +} + +-- Inner iteration 4 of Iteration 4 -- +array(4) { + ["a"]=> + int(1) + ["b"]=> + string(6) "string" + ["c"]=> + NULL + ["d"]=> + float(-2.344) +} + +-- Inner iteration 5 of Iteration 4 -- +array(8) { + ["a"]=> + int(1) + ["b"]=> + string(6) "string" + ["c"]=> + NULL + ["d"]=> + float(-2.344) + [0]=> + int(1) + [1]=> + string(6) "string" + [2]=> + NULL + [3]=> + float(-2.344) +} + +-- Inner iteration 6 of Iteration 4 -- +array(8) { + ["a"]=> + int(1) + ["b"]=> + string(6) "string" + ["c"]=> + NULL + ["d"]=> + float(-2.344) + [0]=> + NULL + [1]=> + string(2) "Hi" + ["string"]=> + string(5) "hello" + [2]=> + array(3) { + [""]=> + string(5) "World" + ["-2.34"]=> + string(1) "a" + [0]=> + string(1) "b" + } +} + + +--- Iteration 5 --- +-- Inner iteration 0 of Iteration 5 -- +array(4) { + [0]=> + int(1) + [1]=> + string(6) "string" + [2]=> + NULL + [3]=> + float(-2.344) +} + +-- Inner iteration 1 of Iteration 5 -- +array(5) { + [0]=> + int(1) + [1]=> + string(6) "string" + [2]=> + NULL + [3]=> + float(-2.344) + [4]=> + string(6) "string" +} + +-- Inner iteration 2 of Iteration 5 -- +array(5) { + [0]=> + int(1) + [1]=> + string(6) "string" + [2]=> + NULL + [3]=> + float(-2.344) + [""]=> + string(6) "string" +} + +-- Inner iteration 3 of Iteration 5 -- +array(5) { + [0]=> + int(1) + [1]=> + string(6) "string" + [2]=> + NULL + [3]=> + float(-2.344) + [4]=> + int(12) +} + +-- Inner iteration 4 of Iteration 5 -- +array(8) { + [0]=> + int(1) + [1]=> + string(6) "string" + [2]=> + NULL + [3]=> + float(-2.344) + ["a"]=> + int(1) + ["b"]=> + string(6) "string" + ["c"]=> + NULL + ["d"]=> + float(-2.344) +} + +-- Inner iteration 5 of Iteration 5 -- +array(8) { + [0]=> + int(1) + [1]=> + string(6) "string" + [2]=> + NULL + [3]=> + float(-2.344) + [4]=> + int(1) + [5]=> + string(6) "string" + [6]=> + NULL + [7]=> + float(-2.344) +} + +-- Inner iteration 6 of Iteration 5 -- +array(8) { + [0]=> + int(1) + [1]=> + string(6) "string" + [2]=> + NULL + [3]=> + float(-2.344) + [4]=> + NULL + [5]=> + string(2) "Hi" + ["string"]=> + string(5) "hello" + [6]=> + array(3) { + [""]=> + string(5) "World" + ["-2.34"]=> + string(1) "a" + [0]=> + string(1) "b" + } +} + + +--- Iteration 6 --- +-- Inner iteration 0 of Iteration 6 -- +array(4) { + [0]=> + NULL + [1]=> + string(2) "Hi" + ["string"]=> + string(5) "hello" + [2]=> + array(3) { + [""]=> + string(5) "World" + ["-2.34"]=> + string(1) "a" + [0]=> + string(1) "b" + } +} + +-- Inner iteration 1 of Iteration 6 -- +array(5) { + [0]=> + NULL + [1]=> + string(2) "Hi" + ["string"]=> + string(5) "hello" + [2]=> + array(3) { + [""]=> + string(5) "World" + ["-2.34"]=> + string(1) "a" + [0]=> + string(1) "b" + } + [3]=> + string(6) "string" +} + +-- Inner iteration 2 of Iteration 6 -- +array(5) { + [0]=> + NULL + [1]=> + string(2) "Hi" + ["string"]=> + string(5) "hello" + [2]=> + array(3) { + [""]=> + string(5) "World" + ["-2.34"]=> + string(1) "a" + [0]=> + string(1) "b" + } + [""]=> + string(6) "string" +} + +-- Inner iteration 3 of Iteration 6 -- +array(5) { + [0]=> + NULL + [1]=> + string(2) "Hi" + ["string"]=> + string(5) "hello" + [2]=> + array(3) { + [""]=> + string(5) "World" + ["-2.34"]=> + string(1) "a" + [0]=> + string(1) "b" + } + [3]=> + int(12) +} + +-- Inner iteration 4 of Iteration 6 -- +array(8) { + [0]=> + NULL + [1]=> + string(2) "Hi" + ["string"]=> + string(5) "hello" + [2]=> + array(3) { + [""]=> + string(5) "World" + ["-2.34"]=> + string(1) "a" + [0]=> + string(1) "b" + } + ["a"]=> + int(1) + ["b"]=> + string(6) "string" + ["c"]=> + NULL + ["d"]=> + float(-2.344) +} + +-- Inner iteration 5 of Iteration 6 -- +array(8) { + [0]=> + NULL + [1]=> + string(2) "Hi" + ["string"]=> + string(5) "hello" + [2]=> + array(3) { + [""]=> + string(5) "World" + ["-2.34"]=> + string(1) "a" + [0]=> + string(1) "b" + } + [3]=> + int(1) + [4]=> + string(6) "string" + [5]=> + NULL + [6]=> + float(-2.344) +} + +-- Inner iteration 6 of Iteration 6 -- +array(7) { + [0]=> + NULL + [1]=> + string(2) "Hi" + ["string"]=> + string(5) "hello" + [2]=> + array(3) { + [""]=> + string(5) "World" + ["-2.34"]=> + string(1) "a" + [0]=> + string(1) "b" + } + [3]=> + NULL + [4]=> + string(2) "Hi" + [5]=> + array(3) { + [""]=> + string(5) "World" + ["-2.34"]=> + string(1) "a" + [0]=> + string(1) "b" + } +} + +*** Testing array_merge() with three or more arrays *** +array(12) { + [0]=> + int(1) + [1]=> + string(6) "string" + [2]=> + NULL + [3]=> + float(-2.344) + ["a"]=> + int(1) + ["b"]=> + string(6) "string" + ["c"]=> + NULL + ["d"]=> + float(-2.344) + [4]=> + NULL + [5]=> + string(2) "Hi" + ["string"]=> + string(5) "hello" + [6]=> + array(3) { + [""]=> + string(5) "World" + ["-2.34"]=> + string(1) "a" + [0]=> + string(1) "b" + } +} +array(6) { + [0]=> + int(1) + [1]=> + string(6) "string" + [2]=> + NULL + [3]=> + float(-2.344) + [4]=> + string(12) "array on fly" + ["nullarray"]=> + array(0) { + } +} + +*** Testing single array argument *** +array(0) { +} +array(4) { + ["a"]=> + int(1) + ["b"]=> + string(6) "string" + ["c"]=> + NULL + ["d"]=> + float(-2.344) +} +array(4) { + [0]=> + int(1) + [1]=> + string(6) "string" + [2]=> + NULL + [3]=> + float(-2.344) +} +array(4) { + [0]=> + NULL + [1]=> + string(2) "Hi" + ["string"]=> + string(5) "hello" + [2]=> + array(3) { + [""]=> + string(5) "World" + ["-2.34"]=> + string(1) "a" + [0]=> + string(1) "b" + } +} + +*** Testing array_merge() with typecasting non-array to array *** +array(7) { + ["a"]=> + int(1) + ["b"]=> + string(6) "string" + ["c"]=> + NULL + ["d"]=> + float(-2.344) + [0]=> + string(5) "type1" + [1]=> + int(10) + [2]=> + float(12.34) +} + +*** Testing array_merge without any arguments *** +array(0) { +} +Done diff --git a/tests/std/array/array_merge_basic.phpt b/tests/std/array/array_merge_basic.phpt new file mode 100644 index 00000000..e58d0cf5 --- /dev/null +++ b/tests/std/array/array_merge_basic.phpt @@ -0,0 +1,52 @@ +--TEST-- +Test array_merge() function : basic functionality +--FILE-- + 1, 'b' => 2, 'c' => 3); + +var_dump(array_merge($array1, $array2)); + +var_dump(array_merge($array2, $array1)); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_merge() : basic functionality *** +array(6) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + string(3) "two" + ["a"]=> + int(1) + ["b"]=> + int(2) + ["c"]=> + int(3) +} +array(6) { + ["a"]=> + int(1) + ["b"]=> + int(2) + ["c"]=> + int(3) + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + string(3) "two" +} +Done diff --git a/tests/std/array/array_merge_recursive_basic1.phpt b/tests/std/array/array_merge_recursive_basic1.phpt new file mode 100644 index 00000000..97f38706 --- /dev/null +++ b/tests/std/array/array_merge_recursive_basic1.phpt @@ -0,0 +1,99 @@ +--TEST-- +Test array_merge_recursive() function : basic functionality - array with default keys +--FILE-- + +--EXPECT-- +*** Testing array_merge_recursive() : array with default keys *** +-- Without arguments -- +array(0) { +} +-- With default argument -- +array(2) { + [0]=> + int(1) + [1]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} +-- With more arguments -- +array(4) { + [0]=> + int(1) + [1]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [2]=> + int(3) + [3]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } +} +array(6) { + [0]=> + int(1) + [1]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [2]=> + int(3) + [3]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } + [4]=> + array(2) { + [0]=> + int(6) + [1]=> + int(7) + } + [5]=> + array(2) { + [0]=> + string(4) "str1" + [1]=> + string(4) "str2" + } +} +Done diff --git a/tests/std/array/array_merge_recursive_basic2.phpt b/tests/std/array/array_merge_recursive_basic2.phpt new file mode 100644 index 00000000..ee311113 --- /dev/null +++ b/tests/std/array/array_merge_recursive_basic2.phpt @@ -0,0 +1,89 @@ +--TEST-- +Test array_merge_recursive() function : basic functionality - associative arrays +--FILE-- + "one", 2 => array(1, 2)); +$arr2 = array(2 => 'three', "four" => array("hello", 'world')); +$arr3 = array(1 => array(6, 7), 'four' => array("str1", 'str2')); + +// Calling array_merge_recursive() with default arguments +echo "-- With default argument --\n"; +var_dump( array_merge_recursive($arr1) ); + +// Calling array_merge_recursive() with more arguments +echo "-- With more arguments --\n"; +var_dump( array_merge_recursive($arr1,$arr2) ); +var_dump( array_merge_recursive($arr1,$arr2,$arr3) ); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_merge_recursive() : associative arrays *** +-- With default argument -- +array(2) { + [0]=> + string(3) "one" + [1]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} +-- With more arguments -- +array(4) { + [0]=> + string(3) "one" + [1]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [2]=> + string(5) "three" + ["four"]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } +} +array(5) { + [0]=> + string(3) "one" + [1]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [2]=> + string(5) "three" + ["four"]=> + array(4) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + [2]=> + string(4) "str1" + [3]=> + string(4) "str2" + } + [3]=> + array(2) { + [0]=> + int(6) + [1]=> + int(7) + } +} +Done diff --git a/tests/std/array/array_merge_recursive_variation1.phpt b/tests/std/array/array_merge_recursive_variation1.phpt new file mode 100644 index 00000000..f94a7165 --- /dev/null +++ b/tests/std/array/array_merge_recursive_variation1.phpt @@ -0,0 +1,205 @@ +--TEST-- +Test array_merge_recursive() function : usage variations - unexpected values for $arr1 argument +--SKIPIF-- + + +--FILE-- +getMessage(), "\n"; + } + // with more arguments + echo "-- With more arguments --"; + try { + var_dump(array_merge_recursive($arr1, $arr2)); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + $iterator++; + } + // close the file resource used + fclose($fp); + echo "Done"; +} +?> +--EXPECT-- +*** Testing array_merge_recursive() : Passing non array values to $arr1 argument *** + +-- Iteration 1 -- +-- With default argument --array_merge_recursive(): Argument #1 must be of type array, int given +-- With more arguments --array_merge_recursive(): Argument #1 must be of type array, int given + +-- Iteration 2 -- +-- With default argument --array_merge_recursive(): Argument #1 must be of type array, int given +-- With more arguments --array_merge_recursive(): Argument #1 must be of type array, int given + +-- Iteration 3 -- +-- With default argument --array_merge_recursive(): Argument #1 must be of type array, int given +-- With more arguments --array_merge_recursive(): Argument #1 must be of type array, int given + +-- Iteration 4 -- +-- With default argument --array_merge_recursive(): Argument #1 must be of type array, int given +-- With more arguments --array_merge_recursive(): Argument #1 must be of type array, int given + +-- Iteration 5 -- +-- With default argument --array_merge_recursive(): Argument #1 must be of type array, float given +-- With more arguments --array_merge_recursive(): Argument #1 must be of type array, float given + +-- Iteration 6 -- +-- With default argument --array_merge_recursive(): Argument #1 must be of type array, float given +-- With more arguments --array_merge_recursive(): Argument #1 must be of type array, float given + +-- Iteration 7 -- +-- With default argument --array_merge_recursive(): Argument #1 must be of type array, float given +-- With more arguments --array_merge_recursive(): Argument #1 must be of type array, float given + +-- Iteration 8 -- +-- With default argument --array_merge_recursive(): Argument #1 must be of type array, float given +-- With more arguments --array_merge_recursive(): Argument #1 must be of type array, float given + +-- Iteration 9 -- +-- With default argument --array_merge_recursive(): Argument #1 must be of type array, float given +-- With more arguments --array_merge_recursive(): Argument #1 must be of type array, float given + +-- Iteration 10 -- +-- With default argument --array_merge_recursive(): Argument #1 must be of type array, null given +-- With more arguments --array_merge_recursive(): Argument #1 must be of type array, null given + +-- Iteration 11 -- +-- With default argument --array_merge_recursive(): Argument #1 must be of type array, null given +-- With more arguments --array_merge_recursive(): Argument #1 must be of type array, null given + +-- Iteration 12 -- +-- With default argument --array_merge_recursive(): Argument #1 must be of type array, true given +-- With more arguments --array_merge_recursive(): Argument #1 must be of type array, true given + +-- Iteration 13 -- +-- With default argument --array_merge_recursive(): Argument #1 must be of type array, false given +-- With more arguments --array_merge_recursive(): Argument #1 must be of type array, false given + +-- Iteration 14 -- +-- With default argument --array_merge_recursive(): Argument #1 must be of type array, true given +-- With more arguments --array_merge_recursive(): Argument #1 must be of type array, true given + +-- Iteration 15 -- +-- With default argument --array_merge_recursive(): Argument #1 must be of type array, false given +-- With more arguments --array_merge_recursive(): Argument #1 must be of type array, false given + +-- Iteration 16 -- +-- With default argument --array_merge_recursive(): Argument #1 must be of type array, string given +-- With more arguments --array_merge_recursive(): Argument #1 must be of type array, string given + +-- Iteration 17 -- +-- With default argument --array_merge_recursive(): Argument #1 must be of type array, string given +-- With more arguments --array_merge_recursive(): Argument #1 must be of type array, string given + +-- Iteration 18 -- +-- With default argument --array_merge_recursive(): Argument #1 must be of type array, string given +-- With more arguments --array_merge_recursive(): Argument #1 must be of type array, string given + +-- Iteration 19 -- +-- With default argument --array_merge_recursive(): Argument #1 must be of type array, string given +-- With more arguments --array_merge_recursive(): Argument #1 must be of type array, string given + +-- Iteration 20 -- +-- With default argument --array_merge_recursive(): Argument #1 must be of type array, string given +-- With more arguments --array_merge_recursive(): Argument #1 must be of type array, string given + +-- Iteration 21 -- +-- With default argument --array_merge_recursive(): Argument #1 must be of type array, null given +-- With more arguments --array_merge_recursive(): Argument #1 must be of type array, null given + +-- Iteration 22 -- +-- With default argument --array_merge_recursive(): Argument #1 must be of type array, null given +-- With more arguments --array_merge_recursive(): Argument #1 must be of type array, null given + +-- Iteration 23 -- +-- With default argument --array_merge_recursive(): Argument #1 must be of type array, resource given +-- With more arguments --array_merge_recursive(): Argument #1 must be of type array, resource given + +-- Iteration 24 -- +-- With default argument --array_merge_recursive(): Argument #1 must be of type array, A given +-- With more arguments --array_merge_recursive(): Argument #1 must be of type array, A given +Done diff --git a/tests/std/array/array_merge_recursive_variation10.phpt b/tests/std/array/array_merge_recursive_variation10.phpt new file mode 100644 index 00000000..7f03779c --- /dev/null +++ b/tests/std/array/array_merge_recursive_variation10.phpt @@ -0,0 +1,169 @@ +--TEST-- +Test array_merge_recursive() function : usage variations - two dimensional arrays +--FILE-- + array("hello", "world", "str1" => "hello", "str2" => 'world'), + array(1 => "one", 2 => "two", "one", 'two'), + array(1, 2, 3, 1) +); + +// initialize the second argument +$arr2 = array(1, "hello", "array" => array("hello", 'world')); + +echo "-- Passing the entire 2-d array --\n"; +echo "-- With default argument --\n"; +var_dump( array_merge_recursive($arr1) ); +echo "-- With more arguments --\n"; +var_dump( array_merge_recursive($arr1, $arr2) ); + +echo "-- Passing the sub-array --\n"; +echo "-- With default argument --\n"; +var_dump( array_merge_recursive($arr1["array"]) ); +echo "-- With more arguments --\n"; +var_dump( array_merge_recursive($arr1["array"], $arr2["array"]) ); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_merge_recursive() : two dimensional array for $arr1 argument *** +-- Passing the entire 2-d array -- +-- With default argument -- +array(4) { + [0]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(1) + } + ["array"]=> + array(4) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + ["str1"]=> + string(5) "hello" + ["str2"]=> + string(5) "world" + } + [1]=> + array(4) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + string(3) "one" + [4]=> + string(3) "two" + } + [2]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(1) + } +} +-- With more arguments -- +array(6) { + [0]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(1) + } + ["array"]=> + array(6) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + ["str1"]=> + string(5) "hello" + ["str2"]=> + string(5) "world" + [2]=> + string(5) "hello" + [3]=> + string(5) "world" + } + [1]=> + array(4) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + string(3) "one" + [4]=> + string(3) "two" + } + [2]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(1) + } + [3]=> + int(1) + [4]=> + string(5) "hello" +} +-- Passing the sub-array -- +-- With default argument -- +array(4) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + ["str1"]=> + string(5) "hello" + ["str2"]=> + string(5) "world" +} +-- With more arguments -- +array(6) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + ["str1"]=> + string(5) "hello" + ["str2"]=> + string(5) "world" + [2]=> + string(5) "hello" + [3]=> + string(5) "world" +} +Done diff --git a/tests/std/array/array_merge_recursive_variation2.phpt b/tests/std/array/array_merge_recursive_variation2.phpt new file mode 100644 index 00000000..ff656dc8 --- /dev/null +++ b/tests/std/array/array_merge_recursive_variation2.phpt @@ -0,0 +1,148 @@ +--TEST-- +Test array_merge_recursive() function : usage variations - unexpected values for $arr2 argument +--SKIPIF-- + + +--FILE-- +getMessage(), "\n"; + } + $iterator++; + } + // close the file resource used + fclose($fp); + echo "Done"; +} +?> +--EXPECT-- +*** Testing array_merge_recursive() : Passing non array values to $arr2 argument *** + +-- Iteration 1 --array_merge_recursive(): Argument #2 must be of type array, int given + +-- Iteration 2 --array_merge_recursive(): Argument #2 must be of type array, int given + +-- Iteration 3 --array_merge_recursive(): Argument #2 must be of type array, int given + +-- Iteration 4 --array_merge_recursive(): Argument #2 must be of type array, int given + +-- Iteration 5 --array_merge_recursive(): Argument #2 must be of type array, float given + +-- Iteration 6 --array_merge_recursive(): Argument #2 must be of type array, float given + +-- Iteration 7 --array_merge_recursive(): Argument #2 must be of type array, float given + +-- Iteration 8 --array_merge_recursive(): Argument #2 must be of type array, float given + +-- Iteration 9 --array_merge_recursive(): Argument #2 must be of type array, float given + +-- Iteration 10 --array_merge_recursive(): Argument #2 must be of type array, null given + +-- Iteration 11 --array_merge_recursive(): Argument #2 must be of type array, null given + +-- Iteration 12 --array_merge_recursive(): Argument #2 must be of type array, true given + +-- Iteration 13 --array_merge_recursive(): Argument #2 must be of type array, false given + +-- Iteration 14 --array_merge_recursive(): Argument #2 must be of type array, true given + +-- Iteration 15 --array_merge_recursive(): Argument #2 must be of type array, false given + +-- Iteration 16 --array_merge_recursive(): Argument #2 must be of type array, string given + +-- Iteration 17 --array_merge_recursive(): Argument #2 must be of type array, string given + +-- Iteration 18 --array_merge_recursive(): Argument #2 must be of type array, string given + +-- Iteration 19 --array_merge_recursive(): Argument #2 must be of type array, string given + +-- Iteration 20 --array_merge_recursive(): Argument #2 must be of type array, string given + +-- Iteration 21 --array_merge_recursive(): Argument #2 must be of type array, null given + +-- Iteration 22 --array_merge_recursive(): Argument #2 must be of type array, null given + +-- Iteration 23 --array_merge_recursive(): Argument #2 must be of type array, resource given + +-- Iteration 24 --array_merge_recursive(): Argument #2 must be of type array, A given +Done diff --git a/tests/std/array/array_merge_recursive_variation3.phpt b/tests/std/array/array_merge_recursive_variation3.phpt new file mode 100644 index 00000000..8e1ff9f5 --- /dev/null +++ b/tests/std/array/array_merge_recursive_variation3.phpt @@ -0,0 +1,758 @@ +--TEST-- +Test array_merge_recursive() function : usage variations - different arrays for 'arr1' argument +--SKIPIF-- + +--FILE-- +22 +'single quoted string' +"double quoted string" +2222 != 1111.\t 0000 = 0000\n +EOT; + +// arrays passed to $arr1 argument +$arrays = array ( +/*1*/ array(1, 2,), // with default keys and numeric values + array(1.1, 2.2), // with default keys & float values + array(false, true), // with default keys and boolean values + array(), // empty array +/*5*/ array(NULL), // with NULL + array("a\v\f", "aaaa\r", "b", "\[\]\!\@\#\$\%\^\&\*\(\)\{\}"), // with double quoted strings + array('a\v\f', 'aaaa\r', 'b', '\[\]\!\@\#\$\%\^\&\*\(\)\{\}'), // with single quoted strings + array("h1" => $blank_line, "h2" => $multiline_string, "h3" => $diff_whitespaces), // with heredocs + + // associative arrays +/*9*/ array(1 => "one", 2 => "two"), // explicit numeric keys, string values + array("one" => 1, "two" => 2, "1" => 1 ), // string keys & numeric values + array( 1 => 10, 2 => 20, 4 => 40), // explicit numeric keys and numeric values + array( "one" => "ten", "two" => "twenty"), // string key/value + array("one" => 1, 2 => "two", 4 => "four"), //mixed + + // associative array, containing null/empty/boolean values as key/value +/*14*/ array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null), + array(true => "true", false => "false", "false" => false, "true" => true), + array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''), + array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true), + array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6), + + // array containing embedded arrays +/*15*/ array("str1", "array" => array("hello", 'world'), array(1, 2)) +); + +// initialise the second argument +$arr2 = array( 1 => "one", 2, "string" => "hello", "array" => array("a", "b", "c")); + +// loop through each sub array of $arrays and check the behavior of array_merge_recursive() +$iterator = 1; +foreach($arrays as $arr1) { + echo "-- Iteration $iterator --\n"; + + // with default argument + echo "-- With default argument --\n"; + var_dump( array_merge_recursive($arr1) ); + + // with more arguments + echo "-- With more arguments --\n"; + var_dump( array_merge_recursive($arr1, $arr2) ); + + $iterator++; +} + +echo "Done"; +?> +--EXPECT-- +*** Testing array_merge_recursive() : Passing different arrays to $arr1 argument *** +-- Iteration 1 -- +-- With default argument -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- With more arguments -- +array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(3) "one" + [3]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 2 -- +-- With default argument -- +array(2) { + [0]=> + float(1.1) + [1]=> + float(2.2) +} +-- With more arguments -- +array(6) { + [0]=> + float(1.1) + [1]=> + float(2.2) + [2]=> + string(3) "one" + [3]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 3 -- +-- With default argument -- +array(2) { + [0]=> + bool(false) + [1]=> + bool(true) +} +-- With more arguments -- +array(6) { + [0]=> + bool(false) + [1]=> + bool(true) + [2]=> + string(3) "one" + [3]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 4 -- +-- With default argument -- +array(0) { +} +-- With more arguments -- +array(4) { + [0]=> + string(3) "one" + [1]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 5 -- +-- With default argument -- +array(1) { + [0]=> + NULL +} +-- With more arguments -- +array(5) { + [0]=> + NULL + [1]=> + string(3) "one" + [2]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 6 -- +-- With default argument -- +array(4) { + [0]=> + string(3) "a " + [1]=> + string(5) "aaaa " + [2]=> + string(1) "b" + [3]=> + string(27) "\[\]\!\@\#$\%\^\&\*\(\)\{\}" +} +-- With more arguments -- +array(8) { + [0]=> + string(3) "a " + [1]=> + string(5) "aaaa " + [2]=> + string(1) "b" + [3]=> + string(27) "\[\]\!\@\#$\%\^\&\*\(\)\{\}" + [4]=> + string(3) "one" + [5]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 7 -- +-- With default argument -- +array(4) { + [0]=> + string(5) "a\v\f" + [1]=> + string(6) "aaaa\r" + [2]=> + string(1) "b" + [3]=> + string(28) "\[\]\!\@\#\$\%\^\&\*\(\)\{\}" +} +-- With more arguments -- +array(8) { + [0]=> + string(5) "a\v\f" + [1]=> + string(6) "aaaa\r" + [2]=> + string(1) "b" + [3]=> + string(28) "\[\]\!\@\#\$\%\^\&\*\(\)\{\}" + [4]=> + string(3) "one" + [5]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 8 -- +-- With default argument -- +array(3) { + ["h1"]=> + string(1) " +" + ["h2"]=> + string(88) "hello world +The quick brown fox jumped over; +the lazy dog +This is a double quoted string" + ["h3"]=> + string(88) "hello world +1111 != 2222 +heredoc +double quoted string. with different white spaces" +} +-- With more arguments -- +array(7) { + ["h1"]=> + string(1) " +" + ["h2"]=> + string(88) "hello world +The quick brown fox jumped over; +the lazy dog +This is a double quoted string" + ["h3"]=> + string(88) "hello world +1111 != 2222 +heredoc +double quoted string. with different white spaces" + [0]=> + string(3) "one" + [1]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 9 -- +-- With default argument -- +array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" +} +-- With more arguments -- +array(6) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + [2]=> + string(3) "one" + [3]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 10 -- +-- With default argument -- +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + [0]=> + int(1) +} +-- With more arguments -- +array(7) { + ["one"]=> + int(1) + ["two"]=> + int(2) + [0]=> + int(1) + [1]=> + string(3) "one" + [2]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 11 -- +-- With default argument -- +array(3) { + [0]=> + int(10) + [1]=> + int(20) + [2]=> + int(40) +} +-- With more arguments -- +array(7) { + [0]=> + int(10) + [1]=> + int(20) + [2]=> + int(40) + [3]=> + string(3) "one" + [4]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 12 -- +-- With default argument -- +array(2) { + ["one"]=> + string(3) "ten" + ["two"]=> + string(6) "twenty" +} +-- With more arguments -- +array(6) { + ["one"]=> + string(3) "ten" + ["two"]=> + string(6) "twenty" + [0]=> + string(3) "one" + [1]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 13 -- +-- With default argument -- +array(3) { + ["one"]=> + int(1) + [0]=> + string(3) "two" + [1]=> + string(4) "four" +} +-- With more arguments -- +array(7) { + ["one"]=> + int(1) + [0]=> + string(3) "two" + [1]=> + string(4) "four" + [2]=> + string(3) "one" + [3]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 14 -- +-- With default argument -- +array(3) { + [""]=> + string(4) "null" + ["NULL"]=> + NULL + ["null"]=> + NULL +} +-- With more arguments -- +array(7) { + [""]=> + string(4) "null" + ["NULL"]=> + NULL + ["null"]=> + NULL + [0]=> + string(3) "one" + [1]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 15 -- +-- With default argument -- +array(4) { + [0]=> + string(4) "true" + [1]=> + string(5) "false" + ["false"]=> + bool(false) + ["true"]=> + bool(true) +} +-- With more arguments -- +array(8) { + [0]=> + string(4) "true" + [1]=> + string(5) "false" + ["false"]=> + bool(false) + ["true"]=> + bool(true) + [2]=> + string(3) "one" + [3]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 16 -- +-- With default argument -- +array(3) { + [""]=> + string(6) "emptys" + ["emptyd"]=> + string(0) "" + ["emptys"]=> + string(0) "" +} +-- With more arguments -- +array(7) { + [""]=> + string(6) "emptys" + ["emptyd"]=> + string(0) "" + ["emptys"]=> + string(0) "" + [0]=> + string(3) "one" + [1]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 17 -- +-- With default argument -- +array(6) { + [0]=> + string(0) "" + [1]=> + string(0) "" + [2]=> + NULL + [3]=> + NULL + [4]=> + bool(false) + [5]=> + bool(true) +} +-- With more arguments -- +array(10) { + [0]=> + string(0) "" + [1]=> + string(0) "" + [2]=> + NULL + [3]=> + NULL + [4]=> + bool(false) + [5]=> + bool(true) + [6]=> + string(3) "one" + [7]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 18 -- +-- With default argument -- +array(3) { + [""]=> + int(4) + [0]=> + int(5) + [1]=> + int(6) +} +-- With more arguments -- +array(7) { + [""]=> + int(4) + [0]=> + int(5) + [1]=> + int(6) + [2]=> + string(3) "one" + [3]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 19 -- +-- With default argument -- +array(3) { + [0]=> + string(4) "str1" + ["array"]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } + [1]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} +-- With more arguments -- +array(6) { + [0]=> + string(4) "str1" + ["array"]=> + array(5) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + [2]=> + string(1) "a" + [3]=> + string(1) "b" + [4]=> + string(1) "c" + } + [1]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [2]=> + string(3) "one" + [3]=> + int(2) + ["string"]=> + string(5) "hello" +} +Done diff --git a/tests/std/array/array_merge_recursive_variation4.phpt b/tests/std/array/array_merge_recursive_variation4.phpt new file mode 100644 index 00000000..ebdeed23 --- /dev/null +++ b/tests/std/array/array_merge_recursive_variation4.phpt @@ -0,0 +1,330 @@ +--TEST-- +Test array_merge_recursive() function : usage variations - associative array with different keys +--SKIPIF-- + +--FILE-- + "0", 1 => array(1 => "one")), + array(1 => "1", 2 => array(1 => "one", 2 => "two", 3 => 1, 4 => "4")), + // arrays with string keys + /*5*/ + array('\tHello' => array("hello", 'world'), '\v\fworld' => 2.2, 'pen\n' => 111), + array("\tHello" => array("hello", 'world'), "\v\fworld" => 2.2, "pen\n" => 111), + array("hello", $heredoc => array("heredoc", 'string'), "string"), + // array with object, unset variable and resource variable + /*8*/ + array(@$unset_var => array("unset"), $fp => 'resource', 11, "hello"), + ); + // initialise the second array + $arr2 = array(1 => "one", 2, "string" => "hello", "array" => array("a", "b", "c")); + // loop through each sub array of $arrays and check the behavior of array_merge_recursive() + $iterator = 1; + foreach ($arrays as $arr1) { + echo "-- Iteration {$iterator} --\n"; + // with default argument + echo "-- With default argument --\n"; + var_dump(array_merge_recursive($arr1)); + // with more arguments + echo "-- With more arguments --\n"; + var_dump(array_merge_recursive($arr1, $arr2)); + $iterator++; + } + // close the file resource used + fclose($fp); + echo "Done"; +} +?> +--EXPECTF-- +*** Testing array_merge_recursive() : assoc. array with diff. keys to $arr1 argument *** + +Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d +-- Iteration 1 -- +-- With default argument -- +array(2) { + [0]=> + string(1) "0" + [1]=> + array(1) { + [1]=> + string(3) "one" + } +} +-- With more arguments -- +array(6) { + [0]=> + string(1) "0" + [1]=> + array(1) { + [1]=> + string(3) "one" + } + [2]=> + string(3) "one" + [3]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 2 -- +-- With default argument -- +array(2) { + [0]=> + string(1) "1" + [1]=> + array(4) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + int(1) + [4]=> + string(1) "4" + } +} +-- With more arguments -- +array(6) { + [0]=> + string(1) "1" + [1]=> + array(4) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + int(1) + [4]=> + string(1) "4" + } + [2]=> + string(3) "one" + [3]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 3 -- +-- With default argument -- +array(3) { + ["\tHello"]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } + ["\v\fworld"]=> + float(2.2) + ["pen\n"]=> + int(111) +} +-- With more arguments -- +array(7) { + ["\tHello"]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } + ["\v\fworld"]=> + float(2.2) + ["pen\n"]=> + int(111) + [0]=> + string(3) "one" + [1]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 4 -- +-- With default argument -- +array(3) { + [" Hello"]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } + [" world"]=> + float(2.2) + ["pen +"]=> + int(111) +} +-- With more arguments -- +array(7) { + [" Hello"]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } + [" world"]=> + float(2.2) + ["pen +"]=> + int(111) + [0]=> + string(3) "one" + [1]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 5 -- +-- With default argument -- +array(3) { + [0]=> + string(5) "hello" + ["Hello world"]=> + array(2) { + [0]=> + string(7) "heredoc" + [1]=> + string(6) "string" + } + [1]=> + string(6) "string" +} +-- With more arguments -- +array(7) { + [0]=> + string(5) "hello" + ["Hello world"]=> + array(2) { + [0]=> + string(7) "heredoc" + [1]=> + string(6) "string" + } + [1]=> + string(6) "string" + [2]=> + string(3) "one" + [3]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 6 -- +-- With default argument -- +array(4) { + [""]=> + array(1) { + [0]=> + string(5) "unset" + } + [0]=> + string(8) "resource" + [1]=> + int(11) + [2]=> + string(5) "hello" +} +-- With more arguments -- +array(8) { + [""]=> + array(1) { + [0]=> + string(5) "unset" + } + [0]=> + string(8) "resource" + [1]=> + int(11) + [2]=> + string(5) "hello" + [3]=> + string(3) "one" + [4]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +Done diff --git a/tests/std/array/array_merge_recursive_variation5.phpt b/tests/std/array/array_merge_recursive_variation5.phpt new file mode 100644 index 00000000..b6425c87 --- /dev/null +++ b/tests/std/array/array_merge_recursive_variation5.phpt @@ -0,0 +1,392 @@ +--TEST-- +Test array_merge_recursive() function : usage variations - associative array with different values +--SKIPIF-- + +--FILE-- + 0, '1' => 0), + array("one" => 1, 'two' => 2, "three" => 1, 4 => 1), + // arrays with float values + /*3*/ + array("f1" => 2.3333, "f2" => 2.3333, "f3" => array(1.1, 2.22)), + array("f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => array(1.2, 'f4' => 1.2)), + // arrays with string values + /*5*/ + array(111 => "\tHello", "array" => "col\tor", 2 => "\v\fworld", 3 => "\tHello"), + array(111 => '\tHello', 'array' => 'col\tor', 2 => '\v\fworld', 3 => '\tHello'), + array(1 => "hello", "string" => $heredoc, $heredoc), + // array with object, unset variable and resource variable + /*8*/ + array(11 => new classA(), "string" => @$unset_var, "resource" => $fp, new classA(), $fp), + ); + // initialise the second array + $arr2 = array(1 => "one", 2, "string" => "hello", "array" => array("a", "b", "c")); + // loop through each sub array of $arrays and check the behavior of array_merge_recursive() + $iterator = 1; + foreach ($arrays as $arr1) { + echo "-- Iteration {$iterator} --\n"; + // with default argument + echo "-- With default argument --\n"; + var_dump(array_merge_recursive($arr1)); + // with more arguments + echo "-- With more arguments --\n"; + var_dump(array_merge_recursive($arr1, $arr2)); + $iterator++; + } + // close the file resource used + fclose($fp); + echo "Done"; +} +?> +--EXPECTF-- +*** Testing array_merge_recursive() : assoc. array with diff. values to $arr1 argument *** +-- Iteration 1 -- +-- With default argument -- +array(2) { + [0]=> + int(0) + [1]=> + int(0) +} +-- With more arguments -- +array(6) { + [0]=> + int(0) + [1]=> + int(0) + [2]=> + string(3) "one" + [3]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 2 -- +-- With default argument -- +array(4) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(1) + [0]=> + int(1) +} +-- With more arguments -- +array(8) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(1) + [0]=> + int(1) + [1]=> + string(3) "one" + [2]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 3 -- +-- With default argument -- +array(3) { + ["f1"]=> + float(2.3333) + ["f2"]=> + float(2.3333) + ["f3"]=> + array(2) { + [0]=> + float(1.1) + [1]=> + float(2.22) + } +} +-- With more arguments -- +array(7) { + ["f1"]=> + float(2.3333) + ["f2"]=> + float(2.3333) + ["f3"]=> + array(2) { + [0]=> + float(1.1) + [1]=> + float(2.22) + } + [0]=> + string(3) "one" + [1]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 4 -- +-- With default argument -- +array(4) { + ["f1"]=> + float(1.2) + ["f2"]=> + float(3.33) + [0]=> + float(4.89999922839999) + ["f4"]=> + array(2) { + [0]=> + float(1.2) + ["f4"]=> + float(1.2) + } +} +-- With more arguments -- +array(8) { + ["f1"]=> + float(1.2) + ["f2"]=> + float(3.33) + [0]=> + float(4.89999922839999) + ["f4"]=> + array(2) { + [0]=> + float(1.2) + ["f4"]=> + float(1.2) + } + [1]=> + string(3) "one" + [2]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 5 -- +-- With default argument -- +array(4) { + [0]=> + string(6) " Hello" + ["array"]=> + string(6) "col or" + [1]=> + string(7) " world" + [2]=> + string(6) " Hello" +} +-- With more arguments -- +array(7) { + [0]=> + string(6) " Hello" + ["array"]=> + array(4) { + [0]=> + string(6) "col or" + [1]=> + string(1) "a" + [2]=> + string(1) "b" + [3]=> + string(1) "c" + } + [1]=> + string(7) " world" + [2]=> + string(6) " Hello" + [3]=> + string(3) "one" + [4]=> + int(2) + ["string"]=> + string(5) "hello" +} +-- Iteration 6 -- +-- With default argument -- +array(4) { + [0]=> + string(7) "\tHello" + ["array"]=> + string(7) "col\tor" + [1]=> + string(9) "\v\fworld" + [2]=> + string(7) "\tHello" +} +-- With more arguments -- +array(7) { + [0]=> + string(7) "\tHello" + ["array"]=> + array(4) { + [0]=> + string(7) "col\tor" + [1]=> + string(1) "a" + [2]=> + string(1) "b" + [3]=> + string(1) "c" + } + [1]=> + string(9) "\v\fworld" + [2]=> + string(7) "\tHello" + [3]=> + string(3) "one" + [4]=> + int(2) + ["string"]=> + string(5) "hello" +} +-- Iteration 7 -- +-- With default argument -- +array(3) { + [0]=> + string(5) "hello" + ["string"]=> + string(11) "Hello world" + [1]=> + string(11) "Hello world" +} +-- With more arguments -- +array(6) { + [0]=> + string(5) "hello" + ["string"]=> + array(2) { + [0]=> + string(11) "Hello world" + [1]=> + string(5) "hello" + } + [1]=> + string(11) "Hello world" + [2]=> + string(3) "one" + [3]=> + int(2) + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 8 -- +-- With default argument -- +array(5) { + [0]=> + object(classA)#%d (0) { + } + ["string"]=> + NULL + ["resource"]=> + resource(%d) of type (stream) + [1]=> + object(classA)#%d (0) { + } + [2]=> + resource(%d) of type (stream) +} +-- With more arguments -- +array(8) { + [0]=> + object(classA)#%d (0) { + } + ["string"]=> + array(2) { + [0]=> + NULL + [1]=> + string(5) "hello" + } + ["resource"]=> + resource(%d) of type (stream) + [1]=> + object(classA)#%d (0) { + } + [2]=> + resource(%d) of type (stream) + [3]=> + string(3) "one" + [4]=> + int(2) + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +Done diff --git a/tests/std/array/array_merge_recursive_variation6.phpt b/tests/std/array/array_merge_recursive_variation6.phpt new file mode 100644 index 00000000..9540a6cf --- /dev/null +++ b/tests/std/array/array_merge_recursive_variation6.phpt @@ -0,0 +1,108 @@ +--TEST-- +Test array_merge_recursive() function : usage variations - array with duplicate keys +--FILE-- + "one", 2 => "two", 2 => array(1, 2), 3 => "three", 1 => array("duplicate", 'strings')); +// array with string keys +$arr1_string_key = array("str1" => "hello", "str2" => 111, "str1" => "world", "str2" => 111.111); + +// initialize the second argument +$arr2 = array("one", "str1" => "two", array("one", "two")); + +echo "-- With default argument --\n"; +var_dump( array_merge_recursive($arr1_numeric_key) ); +var_dump( array_merge_recursive($arr1_string_key) ); + +echo "-- With more arguments --\n"; +var_dump( array_merge_recursive($arr1_numeric_key, $arr2) ); +var_dump( array_merge_recursive($arr1_string_key, $arr2) ); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_merge_recursive() : array with duplicate keys for $arr1 argument *** +-- With default argument -- +array(3) { + [0]=> + array(2) { + [0]=> + string(9) "duplicate" + [1]=> + string(7) "strings" + } + [1]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [2]=> + string(5) "three" +} +array(2) { + ["str1"]=> + string(5) "world" + ["str2"]=> + float(111.111) +} +-- With more arguments -- +array(6) { + [0]=> + array(2) { + [0]=> + string(9) "duplicate" + [1]=> + string(7) "strings" + } + [1]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [2]=> + string(5) "three" + [3]=> + string(3) "one" + ["str1"]=> + string(3) "two" + [4]=> + array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + } +} +array(4) { + ["str1"]=> + array(2) { + [0]=> + string(5) "world" + [1]=> + string(3) "two" + } + ["str2"]=> + float(111.111) + [0]=> + string(3) "one" + [1]=> + array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + } +} +Done diff --git a/tests/std/array/array_merge_recursive_variation7.phpt b/tests/std/array/array_merge_recursive_variation7.phpt new file mode 100644 index 00000000..e1e5c951 --- /dev/null +++ b/tests/std/array/array_merge_recursive_variation7.phpt @@ -0,0 +1,79 @@ +--TEST-- +Test array_merge_recursive() function : usage variations - array with reference variables +--SKIPIF-- + +--FILE-- + 0, + 1 => &$value4, + 2 => &$value2, + 3 => "hello", + 4 => &$value3, + $value4 => &$value2 +); + +// initialize the second argument +$arr2 = array($value4 => "hello", &$value2); + +echo "-- With default argument --\n"; +var_dump( array_merge_recursive($arr1) ); + +echo "-- With more arguments --\n"; +var_dump( array_merge_recursive($arr1, $arr2) ); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_merge_recursive() : array with reference variables for $arr1 argument *** +-- With default argument -- +array(6) { + [0]=> + int(0) + [1]=> + &string(5) "hello" + [2]=> + &string(5) "hello" + [3]=> + string(5) "hello" + [4]=> + &int(0) + ["hello"]=> + &string(5) "hello" +} +-- With more arguments -- +array(7) { + [0]=> + int(0) + [1]=> + &string(5) "hello" + [2]=> + &string(5) "hello" + [3]=> + string(5) "hello" + [4]=> + &int(0) + ["hello"]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "hello" + } + [5]=> + &string(5) "hello" +} +Done diff --git a/tests/std/array/array_merge_recursive_variation8.phpt b/tests/std/array/array_merge_recursive_variation8.phpt new file mode 100644 index 00000000..bd41e57e --- /dev/null +++ b/tests/std/array/array_merge_recursive_variation8.phpt @@ -0,0 +1,68 @@ +--TEST-- +Test array_merge_recursive() function : usage variations - binary safe checking +--FILE-- + "hello", b"world", "str1" => b"hello", "str2" => "world"); + +// initialize the second argument +$arr2 = array(b"str1" => b"binary", b"hello" => "binary", b"str2" => b"binary"); + +echo "-- With default argument --\n"; +var_dump( array_merge_recursive($arr1) ); + +echo "-- With more arguments --\n"; +var_dump( array_merge_recursive($arr1, $arr2) ); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_merge_recursive() : array with binary data for $arr1 argument *** +-- With default argument -- +array(5) { + [0]=> + string(1) "1" + ["hello"]=> + string(5) "hello" + [1]=> + string(5) "world" + ["str1"]=> + string(5) "hello" + ["str2"]=> + string(5) "world" +} +-- With more arguments -- +array(5) { + [0]=> + string(1) "1" + ["hello"]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(6) "binary" + } + [1]=> + string(5) "world" + ["str1"]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(6) "binary" + } + ["str2"]=> + array(2) { + [0]=> + string(5) "world" + [1]=> + string(6) "binary" + } +} +Done diff --git a/tests/std/array/array_merge_recursive_variation9.phpt b/tests/std/array/array_merge_recursive_variation9.phpt new file mode 100644 index 00000000..ff12e86b --- /dev/null +++ b/tests/std/array/array_merge_recursive_variation9.phpt @@ -0,0 +1,112 @@ +--TEST-- +Test array_merge_recursive() function : usage variations - common key and value(Bug#43559) +--FILE-- + 1, "b" => 2); +$arr2 = array("b" => 2, "c" => 4); +echo "-- Integer values --\n"; +var_dump( array_merge_recursive($arr1, $arr2) ); + +// float values +$arr1 = array("a" => 1.1, "b" => 2.2); +$arr2 = array("b" => 2.2, "c" => 3.3); +echo "-- Float values --\n"; +var_dump( array_merge_recursive($arr1, $arr2) ); + +// string values +$arr1 = array("a" => "hello", "b" => "world"); +$arr2 = array("b" => "world", "c" => "string"); +echo "-- String values --\n"; +var_dump( array_merge_recursive($arr1, $arr2) ); + +// boolean values +$arr1 = array("a" => true, "b" => false); +$arr2 = array("b" => false); +echo "-- Boolean values --\n"; +var_dump( array_merge_recursive($arr1, $arr2) ); + +// null values +$arr1 = array( "a" => NULL); +$arr2 = array( "a" => NULL); +echo "-- Null values --\n"; +var_dump( array_merge_recursive($arr1, $arr2) ); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_merge_recursive() : arrays with common key and value *** +-- Integer values -- +array(3) { + ["a"]=> + int(1) + ["b"]=> + array(2) { + [0]=> + int(2) + [1]=> + int(2) + } + ["c"]=> + int(4) +} +-- Float values -- +array(3) { + ["a"]=> + float(1.1) + ["b"]=> + array(2) { + [0]=> + float(2.2) + [1]=> + float(2.2) + } + ["c"]=> + float(3.3) +} +-- String values -- +array(3) { + ["a"]=> + string(5) "hello" + ["b"]=> + array(2) { + [0]=> + string(5) "world" + [1]=> + string(5) "world" + } + ["c"]=> + string(6) "string" +} +-- Boolean values -- +array(2) { + ["a"]=> + bool(true) + ["b"]=> + array(2) { + [0]=> + bool(false) + [1]=> + bool(false) + } +} +-- Null values -- +array(1) { + ["a"]=> + array(2) { + [0]=> + NULL + [1]=> + NULL + } +} +Done diff --git a/tests/std/array/array_merge_replace_recursive_refs.phpt b/tests/std/array/array_merge_replace_recursive_refs.phpt new file mode 100644 index 00000000..ac8be2ba --- /dev/null +++ b/tests/std/array/array_merge_replace_recursive_refs.phpt @@ -0,0 +1,38 @@ +--TEST-- +array_merge/replace_recursive() should unwrap references with rc=1 +--FILE-- + +--EXPECT-- +array(1) { + [0]=> + array(1) { + [0]=> + int(24) + } +} +array(2) { + [0]=> + int(42) + [1]=> + int(24) +} diff --git a/tests/std/array/array_merge_variation1.phpt b/tests/std/array/array_merge_variation1.phpt new file mode 100644 index 00000000..0b98797a --- /dev/null +++ b/tests/std/array/array_merge_variation1.phpt @@ -0,0 +1,102 @@ +--TEST-- +Test array_merge() function : usage variations - Pass different data types to $arr1 arg +--SKIPIF-- + + +--FILE-- + +--EXPECTF-- +*** Testing array_merge() : usage variations *** + +-- Iteration 1 -- + +Fatal error: Uncaught TypeError: array_merge(): Argument #1 must be of type array, int given in %s:%d +Stack trace: +#0 %s(%d): array_merge(0, Array) +#1 {main} + thrown in %s on line %d diff --git a/tests/std/array/array_merge_variation10.phpt b/tests/std/array/array_merge_variation10.phpt new file mode 100644 index 00000000..1877cece --- /dev/null +++ b/tests/std/array/array_merge_variation10.phpt @@ -0,0 +1,64 @@ +--TEST-- +Test array_merge() function : usage variations - position of internal array pointer +--FILE-- + " . current($result) . "\n"; + +echo "\n-- Position of Internal Pointer in Original Array: --\n"; +echo "\$arr1: "; +echo key($arr1) . " => " . current ($arr1) . "\n"; +echo "\$arr2: "; +echo key($arr2) . " => " . current ($arr2) . "\n"; +echo "\$arr3: "; +echo key($arr3) . " => " . current ($arr3) . "\n"; + +echo "Done"; +?> +--EXPECT-- +*** Testing array_merge() : usage variations *** + +-- Call array_merge() -- +array(9) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + string(4) "zero" + [4]=> + string(2) "un" + [5]=> + string(4) "deux" + [6]=> + string(4) "null" + [7]=> + string(4) "eins" + [8]=> + string(4) "zwei" +} + +-- Position of Internal Pointer in Result: -- +0 => zero + +-- Position of Internal Pointer in Original Array: -- +$arr1: 0 => zero +$arr2: 0 => zero +$arr3: 0 => null +Done diff --git a/tests/std/array/array_merge_variation2.phpt b/tests/std/array/array_merge_variation2.phpt new file mode 100644 index 00000000..b1657957 --- /dev/null +++ b/tests/std/array/array_merge_variation2.phpt @@ -0,0 +1,179 @@ +--TEST-- +Test array_merge() function : usage variations - Pass different data types as $arr2 arg +--SKIPIF-- + + +--FILE-- +getMessage(), "\n"; + } + $iterator++; + } + fclose($fp); + echo "Done"; +} +?> +--EXPECT-- +*** Testing array_merge() : usage variations *** + +-- Iteration 1 -- +array_merge(): Argument #2 must be of type array, int given + +-- Iteration 2 -- +array_merge(): Argument #2 must be of type array, int given + +-- Iteration 3 -- +array_merge(): Argument #2 must be of type array, int given + +-- Iteration 4 -- +array_merge(): Argument #2 must be of type array, int given + +-- Iteration 5 -- +array_merge(): Argument #2 must be of type array, float given + +-- Iteration 6 -- +array_merge(): Argument #2 must be of type array, float given + +-- Iteration 7 -- +array_merge(): Argument #2 must be of type array, float given + +-- Iteration 8 -- +array_merge(): Argument #2 must be of type array, float given + +-- Iteration 9 -- +array_merge(): Argument #2 must be of type array, float given + +-- Iteration 10 -- +array_merge(): Argument #2 must be of type array, null given + +-- Iteration 11 -- +array_merge(): Argument #2 must be of type array, null given + +-- Iteration 12 -- +array_merge(): Argument #2 must be of type array, true given + +-- Iteration 13 -- +array_merge(): Argument #2 must be of type array, false given + +-- Iteration 14 -- +array_merge(): Argument #2 must be of type array, true given + +-- Iteration 15 -- +array_merge(): Argument #2 must be of type array, false given + +-- Iteration 16 -- +array_merge(): Argument #2 must be of type array, string given + +-- Iteration 17 -- +array_merge(): Argument #2 must be of type array, string given + +-- Iteration 18 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + +-- Iteration 19 -- +array_merge(): Argument #2 must be of type array, string given + +-- Iteration 20 -- +array_merge(): Argument #2 must be of type array, string given + +-- Iteration 21 -- +array_merge(): Argument #2 must be of type array, string given + +-- Iteration 22 -- +array_merge(): Argument #2 must be of type array, classA given + +-- Iteration 23 -- +array_merge(): Argument #2 must be of type array, null given + +-- Iteration 24 -- +array_merge(): Argument #2 must be of type array, null given + +-- Iteration 25 -- +array_merge(): Argument #2 must be of type array, resource given +Done diff --git a/tests/std/array/array_merge_variation3.phpt b/tests/std/array/array_merge_variation3.phpt new file mode 100644 index 00000000..64154540 --- /dev/null +++ b/tests/std/array/array_merge_variation3.phpt @@ -0,0 +1,336 @@ +--TEST-- +Test array_merge() function : usage variations - arrays of diff. data types +--SKIPIF-- + + +--FILE-- + array(0, 1, 12345, -2345), + // float data + /*2*/ + 'float' => array(10.5, -10.5, 123456789000.0, 1.23456789E-9, 0.5), + // null data + /*3*/ + 'null' => array(NULL, null), + // boolean data + /*4*/ + 'bool' => array(true, false, TRUE, FALSE), + // empty data + /*5*/ + 'empty string' => array("", ''), + /*6*/ + 'empty array' => array(), + // string data + /*7*/ + 'string' => array("string", 'string', $heredoc), + // object data + /*8*/ + 'object' => array(new classA()), + // undefined data + /*9*/ + 'undefined' => array(@$undefined_var), + // unset data + /*10*/ + 'unset' => array(@$unset_var), + // resource variable + /*11*/ + 'resource' => array($fp), + ); + // loop through each element of $inputs to check the behavior of array_merge + $iterator = 1; + foreach ($inputs as $key => $input) { + echo "\n-- Iteration {$iterator}: {$key} data --\n"; + var_dump(array_merge($input, $arr)); + var_dump(array_merge($arr, $input)); + $iterator++; + } + fclose($fp); + echo "Done"; +} +?> +--EXPECTF-- +*** Testing array_merge() : usage variations *** + +-- Iteration 1: int data -- +array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(12345) + [3]=> + int(-2345) + [4]=> + int(1) + [5]=> + int(2) +} +array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(0) + [3]=> + int(1) + [4]=> + int(12345) + [5]=> + int(-2345) +} + +-- Iteration 2: float data -- +array(7) { + [0]=> + float(10.5) + [1]=> + float(-10.5) + [2]=> + float(123456789000) + [3]=> + float(1.23456789E-9) + [4]=> + float(0.5) + [5]=> + int(1) + [6]=> + int(2) +} +array(7) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + float(10.5) + [3]=> + float(-10.5) + [4]=> + float(123456789000) + [5]=> + float(1.23456789E-9) + [6]=> + float(0.5) +} + +-- Iteration 3: null data -- +array(4) { + [0]=> + NULL + [1]=> + NULL + [2]=> + int(1) + [3]=> + int(2) +} +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + NULL + [3]=> + NULL +} + +-- Iteration 4: bool data -- +array(6) { + [0]=> + bool(true) + [1]=> + bool(false) + [2]=> + bool(true) + [3]=> + bool(false) + [4]=> + int(1) + [5]=> + int(2) +} +array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + bool(true) + [3]=> + bool(false) + [4]=> + bool(true) + [5]=> + bool(false) +} + +-- Iteration 5: empty string data -- +array(4) { + [0]=> + string(0) "" + [1]=> + string(0) "" + [2]=> + int(1) + [3]=> + int(2) +} +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(0) "" + [3]=> + string(0) "" +} + +-- Iteration 6: empty array data -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + +-- Iteration 7: string data -- +array(5) { + [0]=> + string(6) "string" + [1]=> + string(6) "string" + [2]=> + string(11) "hello world" + [3]=> + int(1) + [4]=> + int(2) +} +array(5) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(6) "string" + [3]=> + string(6) "string" + [4]=> + string(11) "hello world" +} + +-- Iteration 8: object data -- +array(3) { + [0]=> + object(classA)#%d (0) { + } + [1]=> + int(1) + [2]=> + int(2) +} +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + object(classA)#%d (0) { + } +} + +-- Iteration 9: undefined data -- +array(3) { + [0]=> + NULL + [1]=> + int(1) + [2]=> + int(2) +} +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + NULL +} + +-- Iteration 10: unset data -- +array(3) { + [0]=> + NULL + [1]=> + int(1) + [2]=> + int(2) +} +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + NULL +} + +-- Iteration 11: resource data -- +array(3) { + [0]=> + resource(%d) of type (stream) + [1]=> + int(1) + [2]=> + int(2) +} +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + resource(%d) of type (stream) +} +Done diff --git a/tests/std/array/array_merge_variation4.phpt b/tests/std/array/array_merge_variation4.phpt new file mode 100644 index 00000000..4fa12783 --- /dev/null +++ b/tests/std/array/array_merge_variation4.phpt @@ -0,0 +1,308 @@ +--TEST-- +Test array_merge() function : usage variations - Diff. data types as array keys +--SKIPIF-- + + +--FILE-- + 1, 'two' => 2); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// heredoc string +$heredoc = << array( + 0 => 'zero', + 1 => 'one', + 12345 => 'positive', + -2345 => 'negative', + ), + + // null data +/*4*/ 'null uppercase' => array( + NULL => 'null 1', + ), + +/*5*/ 'null lowercase' => array( + null => 'null 2', + ), + + // boolean data +/*6*/ 'bool lowercase' => array( + true => 'lowert', + false => 'lowerf', + ), + +/*7*/ 'bool uppercase' => array( + TRUE => 'uppert', + FALSE => 'upperf', + ), + + // empty data +/*8*/ 'empty double quotes' => array( + "" => 'emptyd', + ), + +/*9*/ 'empty single quotes' => array( + '' => 'emptys', + ), + + // string data +/*10*/ 'string' => array( + "stringd" => 'stringd', + 'strings' => 'strings', + $heredoc => 'stringh', + ), + + // undefined data +/*11*/ 'undefined' => array( + @$undefined_var => 'undefined', + ), + + // unset data +/*12*/ 'unset' => array( + @$unset_var => 'unset', + ), +); + +// loop through each element of $inputs to check the behavior of array_merge +$iterator = 1; +foreach($inputs as $key => $input) { + echo "\n-- Iteration $iterator: $key data --\n"; + var_dump( array_merge($input, $arr) ); + var_dump( array_merge($arr, $input) ); + $iterator++; +}; + +echo "Done"; +?> +--EXPECT-- +*** Testing array_merge() : usage variations *** + +-- Iteration 1: int data -- +array(6) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + string(8) "positive" + [3]=> + string(8) "negative" + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(6) { + ["one"]=> + int(1) + ["two"]=> + int(2) + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + string(8) "positive" + [3]=> + string(8) "negative" +} + +-- Iteration 2: null uppercase data -- +array(3) { + [""]=> + string(6) "null 1" + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + [""]=> + string(6) "null 1" +} + +-- Iteration 3: null lowercase data -- +array(3) { + [""]=> + string(6) "null 2" + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + [""]=> + string(6) "null 2" +} + +-- Iteration 4: bool lowercase data -- +array(4) { + [0]=> + string(6) "lowert" + [1]=> + string(6) "lowerf" + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(4) { + ["one"]=> + int(1) + ["two"]=> + int(2) + [0]=> + string(6) "lowert" + [1]=> + string(6) "lowerf" +} + +-- Iteration 5: bool uppercase data -- +array(4) { + [0]=> + string(6) "uppert" + [1]=> + string(6) "upperf" + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(4) { + ["one"]=> + int(1) + ["two"]=> + int(2) + [0]=> + string(6) "uppert" + [1]=> + string(6) "upperf" +} + +-- Iteration 6: empty double quotes data -- +array(3) { + [""]=> + string(6) "emptyd" + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + [""]=> + string(6) "emptyd" +} + +-- Iteration 7: empty single quotes data -- +array(3) { + [""]=> + string(6) "emptys" + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + [""]=> + string(6) "emptys" +} + +-- Iteration 8: string data -- +array(5) { + ["stringd"]=> + string(7) "stringd" + ["strings"]=> + string(7) "strings" + ["hello world"]=> + string(7) "stringh" + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(5) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["stringd"]=> + string(7) "stringd" + ["strings"]=> + string(7) "strings" + ["hello world"]=> + string(7) "stringh" +} + +-- Iteration 9: undefined data -- +array(3) { + [""]=> + string(9) "undefined" + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + [""]=> + string(9) "undefined" +} + +-- Iteration 10: unset data -- +array(3) { + [""]=> + string(5) "unset" + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + [""]=> + string(5) "unset" +} +Done diff --git a/tests/std/array/array_merge_variation5.phpt b/tests/std/array/array_merge_variation5.phpt new file mode 100644 index 00000000..5ef9699d --- /dev/null +++ b/tests/std/array/array_merge_variation5.phpt @@ -0,0 +1,57 @@ +--TEST-- +Test array_merge() function : usage variations - numeric keys +--SKIPIF-- + +--FILE-- + 'one', 20 => 'twenty', 30 => 'thirty'); + +var_dump(array_merge($arr1, $arr2)); +var_dump(array_merge($arr2, $arr1)); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_merge() : usage variations *** +array(7) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + string(5) "three" + [4]=> + string(3) "one" + [5]=> + string(6) "twenty" + [6]=> + string(6) "thirty" +} +array(7) { + [0]=> + string(3) "one" + [1]=> + string(6) "twenty" + [2]=> + string(6) "thirty" + [3]=> + string(4) "zero" + [4]=> + string(3) "one" + [5]=> + string(3) "two" + [6]=> + string(5) "three" +} +Done diff --git a/tests/std/array/array_merge_variation6.phpt b/tests/std/array/array_merge_variation6.phpt new file mode 100644 index 00000000..b2297883 --- /dev/null +++ b/tests/std/array/array_merge_variation6.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test array_merge() function : usage variations - string keys +--FILE-- + 'zero', 'one' => 'un', 'two' => 'deux'); +$arr2 = array('zero' => 'zero', 'un' => 'eins', 'deux' => 'zwei'); + +var_dump(array_merge($arr1, $arr2)); +var_dump(array_merge($arr2, $arr1)); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_merge() : usage variations *** +array(5) { + ["zero"]=> + string(4) "zero" + ["one"]=> + string(2) "un" + ["two"]=> + string(4) "deux" + ["un"]=> + string(4) "eins" + ["deux"]=> + string(4) "zwei" +} +array(5) { + ["zero"]=> + string(4) "zero" + ["un"]=> + string(4) "eins" + ["deux"]=> + string(4) "zwei" + ["one"]=> + string(2) "un" + ["two"]=> + string(4) "deux" +} +Done diff --git a/tests/std/array/array_merge_variation7.phpt b/tests/std/array/array_merge_variation7.phpt new file mode 100644 index 00000000..d0d4f53b --- /dev/null +++ b/tests/std/array/array_merge_variation7.phpt @@ -0,0 +1,61 @@ +--TEST-- +Test array_merge() function : usage variations - Mixed keys +--SKIPIF-- + +--FILE-- + 'twenty', 'thirty' => 30, true => 'bool'); +$arr2 = array(0, 1, 2, null => 'null', 0 => 'float'); + +var_dump(array_merge($arr1, $arr2)); +var_dump(array_merge($arr2, $arr1)); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_merge() : usage variations *** +array(8) { + [0]=> + string(4) "zero" + [1]=> + string(6) "twenty" + ["thirty"]=> + int(30) + [2]=> + string(4) "bool" + [3]=> + string(5) "float" + [4]=> + int(1) + [5]=> + int(2) + [""]=> + string(4) "null" +} +array(8) { + [0]=> + string(5) "float" + [1]=> + int(1) + [2]=> + int(2) + [""]=> + string(4) "null" + [3]=> + string(4) "zero" + [4]=> + string(6) "twenty" + ["thirty"]=> + int(30) + [5]=> + string(4) "bool" +} +Done diff --git a/tests/std/array/array_merge_variation8.phpt b/tests/std/array/array_merge_variation8.phpt new file mode 100644 index 00000000..e4dbeba2 --- /dev/null +++ b/tests/std/array/array_merge_variation8.phpt @@ -0,0 +1,68 @@ +--TEST-- +Test array_merge() function : usage variations - multi-dimensional arrays +--FILE-- + +--EXPECT-- +*** Testing array_merge() : usage variations *** + +-- Merge a two-dimensional and a one-dimensional array -- +array(7) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + array(1) { + [0]=> + int(0) + } + [4]=> + int(1) + [5]=> + int(2) + [6]=> + int(3) +} + +-- Merge an array and a sub-array -- +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) +} +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(0) +} +Done diff --git a/tests/std/array/array_merge_variation9.phpt b/tests/std/array/array_merge_variation9.phpt new file mode 100644 index 00000000..a615298e --- /dev/null +++ b/tests/std/array/array_merge_variation9.phpt @@ -0,0 +1,95 @@ +--TEST-- +Test array_merge() function : usage variations - referenced variables +--SKIPIF-- + +--FILE-- + 'val1', 'key2' => 'val2', 'key3' => 'val3'); + +echo "\n-- Merge an array made up of referenced variables to an assoc. array --\n"; +var_dump(array_merge($arr1, $arr2)); +var_dump(array_merge($arr2, $arr1)); + +$val2 = 'hello world'; + +echo "\n-- Change \$val2 --\n"; +var_dump(array_merge($arr1, $arr2)); +var_dump(array_merge($arr2, $arr1)); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_merge() : usage variations *** + +-- Merge an array made up of referenced variables to an assoc. array -- +array(6) { + [0]=> + &string(3) "foo" + [1]=> + &string(3) "bar" + [2]=> + &string(3) "baz" + ["key1"]=> + string(4) "val1" + ["key2"]=> + string(4) "val2" + ["key3"]=> + string(4) "val3" +} +array(6) { + ["key1"]=> + string(4) "val1" + ["key2"]=> + string(4) "val2" + ["key3"]=> + string(4) "val3" + [0]=> + &string(3) "foo" + [1]=> + &string(3) "bar" + [2]=> + &string(3) "baz" +} + +-- Change $val2 -- +array(6) { + [0]=> + &string(3) "foo" + [1]=> + &string(11) "hello world" + [2]=> + &string(3) "baz" + ["key1"]=> + string(4) "val1" + ["key2"]=> + string(4) "val2" + ["key3"]=> + string(4) "val3" +} +array(6) { + ["key1"]=> + string(4) "val1" + ["key2"]=> + string(4) "val2" + ["key3"]=> + string(4) "val3" + [0]=> + &string(3) "foo" + [1]=> + &string(11) "hello world" + [2]=> + &string(3) "baz" +} +Done diff --git a/tests/std/array/array_multisort_basic1.phpt b/tests/std/array/array_multisort_basic1.phpt new file mode 100644 index 00000000..f73c6d32 --- /dev/null +++ b/tests/std/array/array_multisort_basic1.phpt @@ -0,0 +1,53 @@ +--TEST-- +Test array_multisort() function : basic functionality +--SKIPIF-- +--FILE-- + 2, "row2" => 1, "row3" => 1); +$ar2 = array("row1" => 2, "row2" => "aa", "row3" => "1"); + +echo "\n-- Testing array_multisort() function with all normal arguments --\n"; +var_dump( array_multisort($ar1, SORT_ASC, SORT_REGULAR, $ar2, SORT_DESC, SORT_STRING) ); +var_dump($ar1, $ar2); + +echo "\n-- Testing array_multisort() function with one argument --\n"; +var_dump( array_multisort($ar2) ); +var_dump($ar2); + + +?> +--EXPECT-- +*** Testing array_multisort() : basic functionality *** + +-- Testing array_multisort() function with all normal arguments -- +bool(true) +array(3) { + ["row2"]=> + int(1) + ["row3"]=> + int(1) + ["row1"]=> + int(2) +} +array(3) { + ["row2"]=> + string(2) "aa" + ["row3"]=> + string(1) "1" + ["row1"]=> + int(2) +} + +-- Testing array_multisort() function with one argument -- +bool(true) +array(3) { + ["row3"]=> + string(1) "1" + ["row1"]=> + int(2) + ["row2"]=> + string(2) "aa" +} diff --git a/tests/std/array/array_multisort_basic2.phpt b/tests/std/array/array_multisort_basic2.phpt new file mode 100644 index 00000000..9c13589b --- /dev/null +++ b/tests/std/array/array_multisort_basic2.phpt @@ -0,0 +1,38 @@ +--TEST-- +Test array_multisort() function : basic functionality +--SKIPIF-- + +--FILE-- + 2, 1, 9 => 1); +$ar2 = array( 2, "aa" , "1"); + +echo "\n-- Testing array_multisort() function with all normal arguments --\n"; +var_dump( array_multisort($ar1, SORT_ASC, SORT_REGULAR, $ar2, SORT_ASC, SORT_NUMERIC) ); +var_dump($ar1, $ar2); + +?> +--EXPECT-- +*** Testing array_multisort() : basic functionality - renumbering of numeric keys *** + +-- Testing array_multisort() function with all normal arguments -- +bool(true) +array(3) { + [0]=> + int(1) + [1]=> + int(1) + ["strkey"]=> + int(2) +} +array(3) { + [0]=> + string(2) "aa" + [1]=> + string(1) "1" + [2]=> + int(2) +} diff --git a/tests/std/array/array_multisort_case.phpt b/tests/std/array/array_multisort_case.phpt new file mode 100644 index 00000000..cc619df3 --- /dev/null +++ b/tests/std/array/array_multisort_case.phpt @@ -0,0 +1,67 @@ +--TEST-- +Test array_multisort() function : case-sensitive +--SKIPIF-- + +--FILE-- + +--EXPECT-- +*** Testing array_multisort() : case-sensitive +array(7) { + [0]=> + string(7) "First.3" + [1]=> + string(7) "First.2" + [2]=> + string(7) "First.1" + [3]=> + string(5) "Tenth" + [4]=> + string(6) "Second" + [5]=> + string(9) "Twentieth" + [6]=> + string(5) "Third" +} +array(7) { + [0]=> + string(6) "1 BB 3" + [1]=> + string(6) "1 bB 2" + [2]=> + string(6) "1 bb 1" + [3]=> + string(4) "10 d" + [4]=> + string(3) "2 a" + [5]=> + string(4) "20 c" + [6]=> + string(3) "3 e" +} diff --git a/tests/std/array/array_multisort_error.phpt b/tests/std/array/array_multisort_error.phpt new file mode 100644 index 00000000..d184b2ac --- /dev/null +++ b/tests/std/array/array_multisort_error.phpt @@ -0,0 +1,32 @@ +--TEST-- +Test array_multisort() function : error conditions +--SKIPIF-- +--FILE-- +getMessage() . "\n"; +} + +echo "\n-- Testing array_multisort() function with repeated flags --\n"; +$ar1 = array(1); +try { + var_dump( array_multisort($ar1, SORT_STRING, SORT_NUMERIC) ); +} catch (\TypeError $e) { + echo $e->getMessage() . "\n"; +} + +?> +--EXPECT-- +*** Testing array_multisort() : error conditions *** + +-- Testing array_multisort() function with repeated flags -- +array_multisort(): Argument #3 must be an array or a sort flag that has not already been specified + +-- Testing array_multisort() function with repeated flags -- +array_multisort(): Argument #3 must be an array or a sort flag that has not already been specified diff --git a/tests/std/array/array_multisort_incase.phpt b/tests/std/array/array_multisort_incase.phpt new file mode 100644 index 00000000..043432c7 --- /dev/null +++ b/tests/std/array/array_multisort_incase.phpt @@ -0,0 +1,67 @@ +--TEST-- +Test array_multisort() function : case-insensitive +--SKIPIF-- + +--FILE-- + +--EXPECT-- +*** Testing array_multisort() : case-insensitive +array(7) { + [0]=> + string(7) "First.1" + [1]=> + string(7) "First.2" + [2]=> + string(7) "First.3" + [3]=> + string(5) "Tenth" + [4]=> + string(6) "Second" + [5]=> + string(9) "Twentieth" + [6]=> + string(5) "Third" +} +array(7) { + [0]=> + string(6) "1 bb 1" + [1]=> + string(6) "1 bB 2" + [2]=> + string(6) "1 BB 3" + [3]=> + string(4) "10 d" + [4]=> + string(3) "2 a" + [5]=> + string(4) "20 c" + [6]=> + string(3) "3 e" +} diff --git a/tests/std/array/array_multisort_natural.phpt b/tests/std/array/array_multisort_natural.phpt new file mode 100644 index 00000000..1295a83c --- /dev/null +++ b/tests/std/array/array_multisort_natural.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test array_multisort() function : natural sorting +--SKIPIF-- + +--FILE-- + +--EXPECT-- +*** Testing array_multisort() : natural sorting +array(5) { + [0]=> + string(5) "First" + [1]=> + string(6) "Second" + [2]=> + string(5) "Third" + [3]=> + string(5) "Tenth" + [4]=> + string(9) "Twentieth" +} +array(5) { + [0]=> + string(3) "1 b" + [1]=> + string(3) "2 a" + [2]=> + string(3) "3 e" + [3]=> + string(4) "10 d" + [4]=> + string(4) "20 c" +} diff --git a/tests/std/array/array_multisort_natural_case.phpt b/tests/std/array/array_multisort_natural_case.phpt new file mode 100644 index 00000000..d7192342 --- /dev/null +++ b/tests/std/array/array_multisort_natural_case.phpt @@ -0,0 +1,67 @@ +--TEST-- +Test array_multisort() function : natural sorting case-sensitive +--SKIPIF-- + +--FILE-- + +--EXPECT-- +*** Testing array_multisort() : natural sorting case-sensitive +array(7) { + [0]=> + string(7) "First.3" + [1]=> + string(7) "First.2" + [2]=> + string(7) "First.1" + [3]=> + string(6) "Second" + [4]=> + string(5) "Third" + [5]=> + string(5) "Tenth" + [6]=> + string(9) "Twentieth" +} +array(7) { + [0]=> + string(6) "1 BB 3" + [1]=> + string(6) "1 bB 2" + [2]=> + string(6) "1 bb 1" + [3]=> + string(3) "2 a" + [4]=> + string(3) "3 e" + [5]=> + string(4) "10 d" + [6]=> + string(4) "20 c" +} diff --git a/tests/std/array/array_multisort_natural_incase.phpt b/tests/std/array/array_multisort_natural_incase.phpt new file mode 100644 index 00000000..a73516b9 --- /dev/null +++ b/tests/std/array/array_multisort_natural_incase.phpt @@ -0,0 +1,67 @@ +--TEST-- +Test array_multisort() function : natural sorting case-insensitive +--SKIPIF-- + +--FILE-- + +--EXPECT-- +*** Testing array_multisort() : natural sorting case-insensitive +array(7) { + [0]=> + string(7) "First.1" + [1]=> + string(7) "First.2" + [2]=> + string(7) "First.3" + [3]=> + string(6) "Second" + [4]=> + string(5) "Third" + [5]=> + string(5) "Tenth" + [6]=> + string(9) "Twentieth" +} +array(7) { + [0]=> + string(6) "1 bb 1" + [1]=> + string(6) "1 bB 2" + [2]=> + string(6) "1 BB 3" + [3]=> + string(3) "2 a" + [4]=> + string(3) "3 e" + [5]=> + string(4) "10 d" + [6]=> + string(4) "20 c" +} diff --git a/tests/std/array/array_multisort_stability.phpt b/tests/std/array/array_multisort_stability.phpt new file mode 100644 index 00000000..67814254 --- /dev/null +++ b/tests/std/array/array_multisort_stability.phpt @@ -0,0 +1,15 @@ +--TEST-- +array_multisort() is stable +--FILE-- + +--EXPECT-- +bool(true) diff --git a/tests/std/array/array_multisort_variation1.phpt b/tests/std/array/array_multisort_variation1.phpt new file mode 100644 index 00000000..5e69c985 --- /dev/null +++ b/tests/std/array/array_multisort_variation1.phpt @@ -0,0 +1,167 @@ +--TEST-- +Test array_multisort() function : usage variation +--SKIPIF-- + + +--FILE-- + 1, 'two' => 2); + //array of values to iterate over + $inputs = array( + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 123456789000.0, + 'float -12.3456789000e10' => -123456789000.0, + 'float .5' => 0.5, + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + // boolean data + 'lowercase true' => true, + 'lowercase false' => false, + 'uppercase TRUE' => TRUE, + 'uppercase FALSE' => FALSE, + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + // undefined data + 'undefined var' => @$undefined_var, + // unset data + 'unset var' => @$unset_var, + ); + // loop through each element of the array for ar1 + foreach ($inputs as $key => $value) { + echo "\n--{$key}--\n"; + try { + var_dump(array_multisort($value)); + } catch (\ValueError|\TypeError $e) { + echo $e->getMessage() . "\n"; + } + } +} +?> +--EXPECT-- +*** Testing array_multisort() : usage variation *** + +--int 0-- +array_multisort(): Argument #1 ($array) must be an array or a sort flag that has not already been specified + +--int 1-- +array_multisort(): Argument #1 ($array) must be an array or a sort flag that has not already been specified + +--int 12345-- +array_multisort(): Argument #1 ($array) must be a valid sort flag + +--int -12345-- +array_multisort(): Argument #1 ($array) must be a valid sort flag + +--float 10.5-- +array_multisort(): Argument #1 ($array) must be an array or a sort flag + +--float -10.5-- +array_multisort(): Argument #1 ($array) must be an array or a sort flag + +--float 12.3456789000e10-- +array_multisort(): Argument #1 ($array) must be an array or a sort flag + +--float -12.3456789000e10-- +array_multisort(): Argument #1 ($array) must be an array or a sort flag + +--float .5-- +array_multisort(): Argument #1 ($array) must be an array or a sort flag + +--uppercase NULL-- +array_multisort(): Argument #1 ($array) must be an array or a sort flag + +--lowercase null-- +array_multisort(): Argument #1 ($array) must be an array or a sort flag + +--lowercase true-- +array_multisort(): Argument #1 ($array) must be an array or a sort flag + +--lowercase false-- +array_multisort(): Argument #1 ($array) must be an array or a sort flag + +--uppercase TRUE-- +array_multisort(): Argument #1 ($array) must be an array or a sort flag + +--uppercase FALSE-- +array_multisort(): Argument #1 ($array) must be an array or a sort flag + +--empty string DQ-- +array_multisort(): Argument #1 ($array) must be an array or a sort flag + +--empty string SQ-- +array_multisort(): Argument #1 ($array) must be an array or a sort flag + +--string DQ-- +array_multisort(): Argument #1 ($array) must be an array or a sort flag + +--string SQ-- +array_multisort(): Argument #1 ($array) must be an array or a sort flag + +--mixed case string-- +array_multisort(): Argument #1 ($array) must be an array or a sort flag + +--heredoc-- +array_multisort(): Argument #1 ($array) must be an array or a sort flag + +--instance of classWithToString-- +array_multisort(): Argument #1 ($array) must be an array or a sort flag + +--instance of classWithoutToString-- +array_multisort(): Argument #1 ($array) must be an array or a sort flag + +--undefined var-- +array_multisort(): Argument #1 ($array) must be an array or a sort flag + +--unset var-- +array_multisort(): Argument #1 ($array) must be an array or a sort flag diff --git a/tests/std/array/array_multisort_variation10.phpt b/tests/std/array/array_multisort_variation10.phpt new file mode 100644 index 00000000..6d61ae04 --- /dev/null +++ b/tests/std/array/array_multisort_variation10.phpt @@ -0,0 +1,14 @@ +--TEST-- +Test array_multisort() function : usage variation - testing with anonymous array arguments +--SKIPIF-- + +--FILE-- + +--EXPECT-- +*** Testing array_multisort() : Testing with anonymous arguments *** +bool(true) diff --git a/tests/std/array/array_multisort_variation11.phpt b/tests/std/array/array_multisort_variation11.phpt new file mode 100644 index 00000000..a3565022 --- /dev/null +++ b/tests/std/array/array_multisort_variation11.phpt @@ -0,0 +1,14 @@ +--TEST-- +Test array_multisort() function : usage variation - testing with empty array +--SKIPIF-- + +--FILE-- + +--EXPECT-- +*** Testing array_multisort() : Testing with empty array *** +bool(true) diff --git a/tests/std/array/array_multisort_variation2.phpt b/tests/std/array/array_multisort_variation2.phpt new file mode 100644 index 00000000..eab827e4 --- /dev/null +++ b/tests/std/array/array_multisort_variation2.phpt @@ -0,0 +1,186 @@ +--TEST-- +Test array_multisort() function : usage variation +--SKIPIF-- + + +--FILE-- + 1, 'two' => 2); + //array of values to iterate over + $inputs = array( + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 123456789000.0, + 'float -12.3456789000e10' => -123456789000.0, + 'float .5' => 0.5, + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + // boolean data + 'lowercase true' => true, + 'lowercase false' => false, + 'uppercase TRUE' => TRUE, + 'uppercase FALSE' => FALSE, + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + // undefined data + 'undefined var' => @$undefined_var, + // unset data + 'unset var' => @$unset_var, + ); + // loop through each element of the array for SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]] + foreach ($inputs as $key => $value) { + echo "\n--{$key}--\n"; + try { + var_dump(array_multisort($ar1, $value)); + } catch (\ValueError|\TypeError $e) { + echo $e->getMessage() . "\n"; + } + } +} +?> +--EXPECT-- +*** Testing array_multisort() : usage variation *** + +--int 0-- +bool(true) + +--int 1-- +bool(true) + +--int 12345-- +array_multisort(): Argument #2 must be a valid sort flag + +--int -12345-- +array_multisort(): Argument #2 must be a valid sort flag + +--float 10.5-- +array_multisort(): Argument #2 must be an array or a sort flag + +--float -10.5-- +array_multisort(): Argument #2 must be an array or a sort flag + +--float 12.3456789000e10-- +array_multisort(): Argument #2 must be an array or a sort flag + +--float -12.3456789000e10-- +array_multisort(): Argument #2 must be an array or a sort flag + +--float .5-- +array_multisort(): Argument #2 must be an array or a sort flag + +--empty array-- +Array sizes are inconsistent + +--int indexed array-- +Array sizes are inconsistent + +--associative array-- +bool(true) + +--nested arrays-- +Array sizes are inconsistent + +--uppercase NULL-- +array_multisort(): Argument #2 must be an array or a sort flag + +--lowercase null-- +array_multisort(): Argument #2 must be an array or a sort flag + +--lowercase true-- +array_multisort(): Argument #2 must be an array or a sort flag + +--lowercase false-- +array_multisort(): Argument #2 must be an array or a sort flag + +--uppercase TRUE-- +array_multisort(): Argument #2 must be an array or a sort flag + +--uppercase FALSE-- +array_multisort(): Argument #2 must be an array or a sort flag + +--empty string DQ-- +array_multisort(): Argument #2 must be an array or a sort flag + +--empty string SQ-- +array_multisort(): Argument #2 must be an array or a sort flag + +--string DQ-- +array_multisort(): Argument #2 must be an array or a sort flag + +--string SQ-- +array_multisort(): Argument #2 must be an array or a sort flag + +--mixed case string-- +array_multisort(): Argument #2 must be an array or a sort flag + +--heredoc-- +array_multisort(): Argument #2 must be an array or a sort flag + +--instance of classWithToString-- +array_multisort(): Argument #2 must be an array or a sort flag + +--instance of classWithoutToString-- +array_multisort(): Argument #2 must be an array or a sort flag + +--undefined var-- +array_multisort(): Argument #2 must be an array or a sort flag + +--unset var-- +array_multisort(): Argument #2 must be an array or a sort flag diff --git a/tests/std/array/array_multisort_variation3.phpt b/tests/std/array/array_multisort_variation3.phpt new file mode 100644 index 00000000..f345b44a --- /dev/null +++ b/tests/std/array/array_multisort_variation3.phpt @@ -0,0 +1,168 @@ +--TEST-- +Test array_multisort() function : usage variation +--SKIPIF-- + + +--FILE-- + 1, 'two' => 2); + //array of values to iterate over + $inputs = array( + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 123456789000.0, + 'float -12.3456789000e10' => -123456789000.0, + 'float .5' => 0.5, + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + // boolean data + 'lowercase true' => true, + 'lowercase false' => false, + 'uppercase TRUE' => TRUE, + 'uppercase FALSE' => FALSE, + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + // undefined data + 'undefined var' => @$undefined_var, + // unset data + 'unset var' => @$unset_var, + ); + // loop through each element of the array for ar2 + foreach ($inputs as $key => $value) { + echo "\n--{$key}--\n"; + try { + var_dump(array_multisort($ar1, SORT_REGULAR, $value)); + } catch (\ValueError|\TypeError $e) { + echo $e->getMessage() . "\n"; + } + } +} +?> +--EXPECT-- +*** Testing array_multisort() : usage variation *** + +--int 0-- +array_multisort(): Argument #3 must be an array or a sort flag that has not already been specified + +--int 1-- +array_multisort(): Argument #3 must be an array or a sort flag that has not already been specified + +--int 12345-- +array_multisort(): Argument #3 must be a valid sort flag + +--int -12345-- +array_multisort(): Argument #3 must be a valid sort flag + +--float 10.5-- +array_multisort(): Argument #3 must be an array or a sort flag + +--float -10.5-- +array_multisort(): Argument #3 must be an array or a sort flag + +--float 12.3456789000e10-- +array_multisort(): Argument #3 must be an array or a sort flag + +--float -12.3456789000e10-- +array_multisort(): Argument #3 must be an array or a sort flag + +--float .5-- +array_multisort(): Argument #3 must be an array or a sort flag + +--uppercase NULL-- +array_multisort(): Argument #3 must be an array or a sort flag + +--lowercase null-- +array_multisort(): Argument #3 must be an array or a sort flag + +--lowercase true-- +array_multisort(): Argument #3 must be an array or a sort flag + +--lowercase false-- +array_multisort(): Argument #3 must be an array or a sort flag + +--uppercase TRUE-- +array_multisort(): Argument #3 must be an array or a sort flag + +--uppercase FALSE-- +array_multisort(): Argument #3 must be an array or a sort flag + +--empty string DQ-- +array_multisort(): Argument #3 must be an array or a sort flag + +--empty string SQ-- +array_multisort(): Argument #3 must be an array or a sort flag + +--string DQ-- +array_multisort(): Argument #3 must be an array or a sort flag + +--string SQ-- +array_multisort(): Argument #3 must be an array or a sort flag + +--mixed case string-- +array_multisort(): Argument #3 must be an array or a sort flag + +--heredoc-- +array_multisort(): Argument #3 must be an array or a sort flag + +--instance of classWithToString-- +array_multisort(): Argument #3 must be an array or a sort flag + +--instance of classWithoutToString-- +array_multisort(): Argument #3 must be an array or a sort flag + +--undefined var-- +array_multisort(): Argument #3 must be an array or a sort flag + +--unset var-- +array_multisort(): Argument #3 must be an array or a sort flag diff --git a/tests/std/array/array_multisort_variation4.phpt b/tests/std/array/array_multisort_variation4.phpt new file mode 100644 index 00000000..6f88dda2 --- /dev/null +++ b/tests/std/array/array_multisort_variation4.phpt @@ -0,0 +1,52 @@ +--TEST-- +Test array_multisort() function : usage variation - testing with multiple array arguments +--SKIPIF-- + +--FILE-- + +--EXPECT-- +*** Testing array_multisort() : Testing with multiple array arguments *** +bool(true) +array(4) { + [0]=> + int(3) + [1]=> + int(3) + [2]=> + int(3) + [3]=> + int(4) +} +array(4) { + [0]=> + int(2) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(9) +} +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(9) + [3]=> + int(9) +} diff --git a/tests/std/array/array_multisort_variation5.phpt b/tests/std/array/array_multisort_variation5.phpt new file mode 100644 index 00000000..088e4628 --- /dev/null +++ b/tests/std/array/array_multisort_variation5.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test array_multisort() function : usage variation - testing with multiple array arguments +--SKIPIF-- + +--FILE-- + +--EXPECT-- +*** Testing array_multisort() : Testing all array sort specifiers *** +array(3) { + [0]=> + string(1) "1" + [1]=> + int(2) + [2]=> + string(2) "aa" +} +array(3) { + [0]=> + string(1) "1" + [1]=> + int(2) + [2]=> + string(2) "aa" +} +array(3) { + [0]=> + string(2) "aa" + [1]=> + string(1) "1" + [2]=> + int(2) +} diff --git a/tests/std/array/array_multisort_variation6.phpt b/tests/std/array/array_multisort_variation6.phpt new file mode 100644 index 00000000..3528e7e4 --- /dev/null +++ b/tests/std/array/array_multisort_variation6.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test array_multisort() function : usage variation - testing with multiple array arguments +--SKIPIF-- + +--FILE-- + +--EXPECT-- +*** Testing array_multisort() : Testing all array sort specifiers *** +array(3) { + [0]=> + string(2) "aa" + [1]=> + int(2) + [2]=> + string(1) "1" +} +array(3) { + [0]=> + string(2) "aa" + [1]=> + int(2) + [2]=> + string(1) "1" +} +array(3) { + [0]=> + int(2) + [1]=> + string(1) "1" + [2]=> + string(2) "aa" +} diff --git a/tests/std/array/array_multisort_variation7.phpt b/tests/std/array/array_multisort_variation7.phpt new file mode 100644 index 00000000..a584182c --- /dev/null +++ b/tests/std/array/array_multisort_variation7.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test array_multisort() function : usage variation - test sort order of all types +--SKIPIF-- + + +--FILE-- + 0, 'float -10.5' => -10.5, array(), 'uppercase NULL' => NULL, 'lowercase true' => true, 'empty string DQ' => "", 'string DQ' => "string", 'instance of classWithToString' => new classWithToString(), 'instance of classWithoutToString' => new classWithoutToString(), 'undefined var' => @$undefined_var); + var_dump(array_multisort($inputs)); + var_dump($inputs); +} +?> +--EXPECT-- +*** Testing array_multisort() : usage variation - test sort order of all types*** +bool(true) +array(10) { + ["float -10.5"]=> + float(-10.5) + ["int 0"]=> + int(0) + [0]=> + array(0) { + } + ["uppercase NULL"]=> + NULL + ["empty string DQ"]=> + string(0) "" + ["undefined var"]=> + NULL + ["lowercase true"]=> + bool(true) + ["instance of classWithToString"]=> + object(classWithToString)#1 (0) { + } + ["string DQ"]=> + string(6) "string" + ["instance of classWithoutToString"]=> + object(classWithoutToString)#2 (0) { + } +} diff --git a/tests/std/array/array_multisort_variation8.phpt b/tests/std/array/array_multisort_variation8.phpt new file mode 100644 index 00000000..5213010c --- /dev/null +++ b/tests/std/array/array_multisort_variation8.phpt @@ -0,0 +1,58 @@ +--TEST-- +Test array_multisort() function : usage variation - test sort order of all types +--SKIPIF-- + + +--FILE-- + 0, 'float -10.5' => -10.5, array(), 'uppercase NULL' => NULL, 'lowercase true' => true, 'empty string DQ' => "", 'string DQ' => "string", 'instance of classWithToString' => new classWithToString(), 'undefined var' => @$undefined_var); + var_dump(array_multisort($inputs, SORT_STRING)); + var_dump($inputs); +} +?> +--EXPECT-- +*** Testing array_multisort() : usage variation - test sort order of all types*** +bool(true) +array(9) { + ["uppercase NULL"]=> + NULL + ["empty string DQ"]=> + string(0) "" + ["undefined var"]=> + NULL + ["float -10.5"]=> + float(-10.5) + ["int 0"]=> + int(0) + ["lowercase true"]=> + bool(true) + [0]=> + array(0) { + } + ["instance of classWithToString"]=> + object(classWithToString)#1 (0) { + } + ["string DQ"]=> + string(6) "string" +} diff --git a/tests/std/array/array_multisort_variation9.phpt b/tests/std/array/array_multisort_variation9.phpt new file mode 100644 index 00000000..d19d6cbe --- /dev/null +++ b/tests/std/array/array_multisort_variation9.phpt @@ -0,0 +1,63 @@ +--TEST-- +Test array_multisort() function : usage variation - test sort order of all types +--SKIPIF-- + + +--FILE-- + 0, 'float -10.5' => -10.5, array(), 'uppercase NULL' => NULL, 'lowercase true' => true, 'empty string DQ' => "", 'string DQ' => "string", 'instance of classWithToString' => new classWithToString(), 'instance of classWithoutToString' => new classWithoutToString(), 'undefined var' => @$undefined_var); + var_dump(array_multisort($inputs, SORT_NUMERIC)); + var_dump($inputs); +} +?> +--EXPECTF-- +*** Testing array_multisort() : usage variation - test sort order of all types*** + +Warning: Object of class classWithToString could not be converted to float in %s on line %d + +Warning: Object of class classWithToString could not be converted to float in %s on line %d + +Warning: Object of class classWithoutToString could not be converted to float in %s on line %d + +Warning: Object of class classWithoutToString could not be converted to float in %s on line %d +bool(true) +array(10) { + ["float -10.5"]=> + float(-10.5) + ["int 0"]=> + int(0) + [0]=> + array(0) { + } + ["uppercase NULL"]=> + NULL + ["empty string DQ"]=> + string(0) "" + ["string DQ"]=> + string(6) "string" + ["undefined var"]=> + NULL + ["lowercase true"]=> + bool(true) + ["instance of classWithToString"]=> + object(classWithToString)#1 (0) { + } + ["instance of classWithoutToString"]=> + object(classWithoutToString)#2 (0) { + } +} diff --git a/tests/std/array/array_next_error1.phpt b/tests/std/array/array_next_error1.phpt new file mode 100644 index 00000000..13911b89 --- /dev/null +++ b/tests/std/array/array_next_error1.phpt @@ -0,0 +1,18 @@ +--TEST-- +next - ensure warning is received when passing an indirect temporary. +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +Notice: Only variables should be passed by reference in %s on line %d +int(2) diff --git a/tests/std/array/array_next_error2.phpt b/tests/std/array/array_next_error2.phpt new file mode 100644 index 00000000..68789be6 --- /dev/null +++ b/tests/std/array/array_next_error2.phpt @@ -0,0 +1,20 @@ +--TEST-- +next - ensure we cannot pass a temporary +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +Fatal error: Uncaught Error: next(): Argument #1 ($array) could not be passed by reference in %s:%d +Stack trace: +#0 {main} + thrown in %s on line %d diff --git a/tests/std/array/array_pad.phpt b/tests/std/array/array_pad.phpt new file mode 100644 index 00000000..67cb4234 --- /dev/null +++ b/tests/std/array/array_pad.phpt @@ -0,0 +1,80 @@ +--TEST-- +array_pad() tests +--FILE-- + +--EXPECT-- +array(1) { + [0]=> + int(0) +} +array(0) { +} +array(1) { + [0]=> + int(0) +} +array(5) { + [0]=> + string(0) "" + [1]=> + int(-1) + [2]=> + float(2) + [3]=> + int(0) + [4]=> + int(0) +} +array(5) { + [0]=> + string(0) "" + [1]=> + int(-1) + [2]=> + float(2) + [3]=> + array(0) { + } + [4]=> + array(0) { + } +} +array(3) { + [0]=> + string(0) "" + [1]=> + int(-1) + [2]=> + float(2) +} +array(3) { + [0]=> + string(0) "" + [1]=> + int(-1) + [2]=> + float(2) +} +array(4) { + [0]=> + array(0) { + } + [1]=> + string(0) "" + [2]=> + int(-1) + [3]=> + float(2) +} diff --git a/tests/std/array/array_pad_too_large_padding.phpt b/tests/std/array/array_pad_too_large_padding.phpt new file mode 100644 index 00000000..41c25fd7 --- /dev/null +++ b/tests/std/array/array_pad_too_large_padding.phpt @@ -0,0 +1,21 @@ +--TEST-- +array_pad() with too large padding should fail +--FILE-- +getMessage() . "\n"; + } +} +function main() +{ + test(PHP_INT_MIN); + test(PHP_INT_MAX); +} +?> +--EXPECT-- +array_pad(): Argument #2 ($length) must not exceed the maximum allowed array size +array_pad(): Argument #2 ($length) must not exceed the maximum allowed array size diff --git a/tests/std/array/array_pad_variation3.phpt b/tests/std/array/array_pad_variation3.phpt new file mode 100644 index 00000000..fe2f7236 --- /dev/null +++ b/tests/std/array/array_pad_variation3.phpt @@ -0,0 +1,864 @@ +--TEST-- +Test array_pad() function : usage variations - possible values for 'pad_value' argument +--SKIPIF-- + + +--FILE-- + 'red', 'item' => 'pen'), + // null data + /*15*/ + NULL, + null, + // boolean data + /*17*/ + true, + false, + TRUE, + FALSE, + // empty data + /*21*/ + "", + '', + // string data + /*23*/ + "string", + 'string', + $heredoc, + // strings with different white spaces + /*26*/ + "\v\fHello\t world!! \rstring\n", + '\v\fHello\t world!! \rstring\n', + // object data + /*28*/ + new classA(), + // undefined data + /*29*/ + @$undefined_var, + // unset data + /*30*/ + @$unset_var, + // resource variable + /*31*/ + $fp, + // reference variable + /*32*/ + $reference, + ); + // loop through each element of $pad_values to check the behavior of array_pad() + $iterator = 1; + foreach ($pad_values as $pad_value) { + echo "-- Iteration {$iterator} --\n"; + var_dump(array_pad($input, $pad_size, $pad_value)); + // positive 'pad_size' + var_dump(array_pad($input, -$pad_size, $pad_value)); + // negative 'pad_size' + $iterator++; + } + echo "Done"; +} +?> +--EXPECTF-- +*** Testing array_pad() : possible values for $pad_value argument *** +-- Iteration 1 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(0) + [3]=> + int(0) +} +array(4) { + [0]=> + int(0) + [1]=> + int(0) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 2 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(1) + [3]=> + int(1) +} +array(4) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 3 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(12345) + [3]=> + int(12345) +} +array(4) { + [0]=> + int(12345) + [1]=> + int(12345) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 4 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(-2345) + [3]=> + int(-2345) +} +array(4) { + [0]=> + int(-2345) + [1]=> + int(-2345) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 5 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + float(10.5) + [3]=> + float(10.5) +} +array(4) { + [0]=> + float(10.5) + [1]=> + float(10.5) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 6 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + float(-10.5) + [3]=> + float(-10.5) +} +array(4) { + [0]=> + float(-10.5) + [1]=> + float(-10.5) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 7 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + float(123456789000) + [3]=> + float(123456789000) +} +array(4) { + [0]=> + float(123456789000) + [1]=> + float(123456789000) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 8 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + float(1.23456789E-9) + [3]=> + float(1.23456789E-9) +} +array(4) { + [0]=> + float(1.23456789E-9) + [1]=> + float(1.23456789E-9) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 9 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + float(0.5) + [3]=> + float(0.5) +} +array(4) { + [0]=> + float(0.5) + [1]=> + float(0.5) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 10 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + array(0) { + } + [3]=> + array(0) { + } +} +array(4) { + [0]=> + array(0) { + } + [1]=> + array(0) { + } + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 11 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + array(1) { + [0]=> + int(0) + } + [3]=> + array(1) { + [0]=> + int(0) + } +} +array(4) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [0]=> + int(0) + } + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 12 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + array(1) { + [0]=> + int(1) + } + [3]=> + array(1) { + [0]=> + int(1) + } +} +array(4) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(1) + } + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 13 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [3]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} +array(4) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 14 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + array(2) { + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + } + [3]=> + array(2) { + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + } +} +array(4) { + [0]=> + array(2) { + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + } + [1]=> + array(2) { + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + } + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 15 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + NULL + [3]=> + NULL +} +array(4) { + [0]=> + NULL + [1]=> + NULL + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 16 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + NULL + [3]=> + NULL +} +array(4) { + [0]=> + NULL + [1]=> + NULL + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 17 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + bool(true) + [3]=> + bool(true) +} +array(4) { + [0]=> + bool(true) + [1]=> + bool(true) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 18 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + bool(false) + [3]=> + bool(false) +} +array(4) { + [0]=> + bool(false) + [1]=> + bool(false) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 19 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + bool(true) + [3]=> + bool(true) +} +array(4) { + [0]=> + bool(true) + [1]=> + bool(true) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 20 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + bool(false) + [3]=> + bool(false) +} +array(4) { + [0]=> + bool(false) + [1]=> + bool(false) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 21 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(0) "" + [3]=> + string(0) "" +} +array(4) { + [0]=> + string(0) "" + [1]=> + string(0) "" + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 22 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(0) "" + [3]=> + string(0) "" +} +array(4) { + [0]=> + string(0) "" + [1]=> + string(0) "" + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 23 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(6) "string" + [3]=> + string(6) "string" +} +array(4) { + [0]=> + string(6) "string" + [1]=> + string(6) "string" + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 24 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(6) "string" + [3]=> + string(6) "string" +} +array(4) { + [0]=> + string(6) "string" + [1]=> + string(6) "string" + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 25 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(11) "hello world" + [3]=> + string(11) "hello world" +} +array(4) { + [0]=> + string(11) "hello world" + [1]=> + string(11) "hello world" + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 26 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(25) " Hello world!! string +" + [3]=> + string(25) " Hello world!! string +" +} +array(4) { + [0]=> + string(25) " Hello world!! string +" + [1]=> + string(25) " Hello world!! string +" + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 27 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(30) "\v\fHello\t world!! \rstring\n" + [3]=> + string(30) "\v\fHello\t world!! \rstring\n" +} +array(4) { + [0]=> + string(30) "\v\fHello\t world!! \rstring\n" + [1]=> + string(30) "\v\fHello\t world!! \rstring\n" + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 28 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + object(classA)#%d (0) { + } + [3]=> + object(classA)#%d (0) { + } +} +array(4) { + [0]=> + object(classA)#%d (0) { + } + [1]=> + object(classA)#%d (0) { + } + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 29 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + NULL + [3]=> + NULL +} +array(4) { + [0]=> + NULL + [1]=> + NULL + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 30 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + NULL + [3]=> + NULL +} +array(4) { + [0]=> + NULL + [1]=> + NULL + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 31 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + resource(%d) of type (stream) + [3]=> + resource(%d) of type (stream) +} +array(4) { + [0]=> + resource(%d) of type (stream) + [1]=> + resource(%d) of type (stream) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 32 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(5) "hello" + [3]=> + string(5) "hello" +} +array(4) { + [0]=> + string(5) "hello" + [1]=> + string(5) "hello" + [2]=> + int(1) + [3]=> + int(2) +} +Done diff --git a/tests/std/array/array_pad_variation4.phpt b/tests/std/array/array_pad_variation4.phpt new file mode 100644 index 00000000..0c7c6534 --- /dev/null +++ b/tests/std/array/array_pad_variation4.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test array_pad() function : usage variations - binary safe checking +--FILE-- + +--EXPECT-- +*** Testing array_pad() : Passing binary values to $pad_value argument *** +array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + string(5) "hello" + [4]=> + string(5) "hello" + [5]=> + string(5) "hello" +} +array(6) { + [0]=> + string(5) "hello" + [1]=> + string(5) "hello" + [2]=> + string(5) "hello" + [3]=> + int(1) + [4]=> + int(2) + [5]=> + int(3) +} +Done diff --git a/tests/std/array/array_pad_variation5.phpt b/tests/std/array/array_pad_variation5.phpt new file mode 100644 index 00000000..40df2bf2 --- /dev/null +++ b/tests/std/array/array_pad_variation5.phpt @@ -0,0 +1,135 @@ +--TEST-- +Test array_pad() function : usage variations - two dimensional array for 'pad_value' argument +--FILE-- + 1, 'two' => 2) +); + +var_dump( array_pad($input, $pad_size, $pad_value) ); // positive 'pad_value' +var_dump( array_pad($input, -$pad_size, $pad_value) ); // negative 'pad_value' + +echo "Done"; +?> +--EXPECT-- +*** Testing array_pad() : Passing 2-d array to $pad_value argument *** +array(5) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } + [2]=> + array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) + } + } + [4]=> + array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } + [2]=> + array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) + } + } +} +array(5) { + [0]=> + array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } + [2]=> + array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) + } + } + [1]=> + array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } + [2]=> + array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) + } + } + [2]=> + int(1) + [3]=> + int(2) + [4]=> + int(3) +} +Done diff --git a/tests/std/array/array_pad_variation6.phpt b/tests/std/array/array_pad_variation6.phpt new file mode 100644 index 00000000..7c12baa8 --- /dev/null +++ b/tests/std/array/array_pad_variation6.phpt @@ -0,0 +1,665 @@ +--TEST-- +Test array_pad() function : usage variations - different arrays for 'input' argument +--SKIPIF-- + +--FILE-- +22 +'single quoted string' +"double quoted string" +2222 != 1111.\t 0000 = 0000\n +EOT; + +// different arrays to be passed to $input argument +$inputs = array ( +/*1*/ array(1, 2), // with default keys and numeric values + array(1.1, 2.2), // with default keys & float values + array(false,true), // with default keys and boolean values + array(), // empty array +/*5*/ array(NULL), // with NULL + array("a\v\f", "aaaa\r", "b\tbbb", "\[\]\!\@\#\$\%\^\&\*\(\)\{\}"), // with double quoted strings + array('a\v\f', 'aaaa\r', 'b\tbbb', '\[\]\!\@\#\$\%\^\&\*\(\)\{\}'), // with single quoted strings + array("h1" => $blank_line, "h2" => $multiline_string, "h3" => $diff_whitespaces, $numeric_string), // with heredocs + + // associative arrays +/*9*/ array(1 => "one", 2 => "two", 3 => "three"), // explicit numeric keys, string values + array("one" => 1, "two" => 2, "three" => 3 ), // string keys & numeric values + array( 1 => 10, 2 => 20, 4 => 40, 3 => 30), // explicit numeric keys and numeric values + array( "one" => "ten", "two" => "twenty", "three" => "thirty"), // string key/value + array("one" => 1, 2 => "two", 4 => "four"), //mixed + + // associative array, containing null/empty/boolean values as key/value +/*14*/ array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null), + array(true => "true", false => "false", "false" => false, "true" => true), + array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''), + array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true), + array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6), + + // array with repetitive keys +/*19*/ array("One" => 1, "two" => 2, "One" => 10, "two" => 20, "three" => 3) +); + +// initialize the $pad_size and $pad_value arguments +$pad_size = 6; +$pad_value = "HELLO"; + +// loop through each sub-array within $inputs to check the behavior of array_pad() +$iterator = 1; +foreach($inputs as $input) { + echo "-- Iteration $iterator --\n"; + var_dump( array_pad($input, $pad_size, $pad_value) ); // positive 'pad_size' + var_dump( array_pad($input, -$pad_size, $pad_value) ); // negative 'pad_size' + $iterator++; +}; + +echo "Done"; +?> +--EXPECT-- +*** Testing array_pad() : Passing different arrays to $input argument *** +-- Iteration 1 -- +array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" + [5]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + int(1) + [5]=> + int(2) +} +-- Iteration 2 -- +array(6) { + [0]=> + float(1.1) + [1]=> + float(2.2) + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" + [5]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + float(1.1) + [5]=> + float(2.2) +} +-- Iteration 3 -- +array(6) { + [0]=> + bool(false) + [1]=> + bool(true) + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" + [5]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + bool(false) + [5]=> + bool(true) +} +-- Iteration 4 -- +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" + [5]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" + [5]=> + string(5) "HELLO" +} +-- Iteration 5 -- +array(6) { + [0]=> + NULL + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" + [5]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" + [5]=> + NULL +} +-- Iteration 6 -- +array(6) { + [0]=> + string(3) "a " + [1]=> + string(5) "aaaa " + [2]=> + string(5) "b bbb" + [3]=> + string(27) "\[\]\!\@\#$\%\^\&\*\(\)\{\}" + [4]=> + string(5) "HELLO" + [5]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(3) "a " + [3]=> + string(5) "aaaa " + [4]=> + string(5) "b bbb" + [5]=> + string(27) "\[\]\!\@\#$\%\^\&\*\(\)\{\}" +} +-- Iteration 7 -- +array(6) { + [0]=> + string(5) "a\v\f" + [1]=> + string(6) "aaaa\r" + [2]=> + string(6) "b\tbbb" + [3]=> + string(28) "\[\]\!\@\#\$\%\^\&\*\(\)\{\}" + [4]=> + string(5) "HELLO" + [5]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "a\v\f" + [3]=> + string(6) "aaaa\r" + [4]=> + string(6) "b\tbbb" + [5]=> + string(28) "\[\]\!\@\#\$\%\^\&\*\(\)\{\}" +} +-- Iteration 8 -- +array(6) { + ["h1"]=> + string(1) " +" + ["h2"]=> + string(86) "hello world +The big brown fox jumped over; +the lazy dog +This is a double quoted string" + ["h3"]=> + string(88) "hello world +1111 != 2222 +heredoc +double quoted string. with different white spaces" + [0]=> + string(90) "11 < 12. 123 >22 +'single quoted string' +"double quoted string" +2222 != 1111. 0000 = 0000 +" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + ["h1"]=> + string(1) " +" + ["h2"]=> + string(86) "hello world +The big brown fox jumped over; +the lazy dog +This is a double quoted string" + ["h3"]=> + string(88) "hello world +1111 != 2222 +heredoc +double quoted string. with different white spaces" + [2]=> + string(90) "11 < 12. 123 >22 +'single quoted string' +"double quoted string" +2222 != 1111. 0000 = 0000 +" +} +-- Iteration 9 -- +array(6) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + [2]=> + string(5) "three" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" + [5]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [3]=> + string(3) "one" + [4]=> + string(3) "two" + [5]=> + string(5) "three" +} +-- Iteration 10 -- +array(6) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} +-- Iteration 11 -- +array(6) { + [0]=> + int(10) + [1]=> + int(20) + [2]=> + int(40) + [3]=> + int(30) + [4]=> + string(5) "HELLO" + [5]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + int(10) + [3]=> + int(20) + [4]=> + int(40) + [5]=> + int(30) +} +-- Iteration 12 -- +array(6) { + ["one"]=> + string(3) "ten" + ["two"]=> + string(6) "twenty" + ["three"]=> + string(6) "thirty" + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + ["one"]=> + string(3) "ten" + ["two"]=> + string(6) "twenty" + ["three"]=> + string(6) "thirty" +} +-- Iteration 13 -- +array(6) { + ["one"]=> + int(1) + [0]=> + string(3) "two" + [1]=> + string(4) "four" + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + ["one"]=> + int(1) + [3]=> + string(3) "two" + [4]=> + string(4) "four" +} +-- Iteration 14 -- +array(6) { + [""]=> + string(4) "null" + ["NULL"]=> + NULL + ["null"]=> + NULL + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [""]=> + string(4) "null" + ["NULL"]=> + NULL + ["null"]=> + NULL +} +-- Iteration 15 -- +array(6) { + [0]=> + string(4) "true" + [1]=> + string(5) "false" + ["false"]=> + bool(false) + ["true"]=> + bool(true) + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(4) "true" + [3]=> + string(5) "false" + ["false"]=> + bool(false) + ["true"]=> + bool(true) +} +-- Iteration 16 -- +array(6) { + [""]=> + string(6) "emptys" + ["emptyd"]=> + string(0) "" + ["emptys"]=> + string(0) "" + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [""]=> + string(6) "emptys" + ["emptyd"]=> + string(0) "" + ["emptys"]=> + string(0) "" +} +-- Iteration 17 -- +array(6) { + [1]=> + string(0) "" + [2]=> + string(0) "" + [3]=> + NULL + [4]=> + NULL + [5]=> + bool(false) + [6]=> + bool(true) +} +array(6) { + [1]=> + string(0) "" + [2]=> + string(0) "" + [3]=> + NULL + [4]=> + NULL + [5]=> + bool(false) + [6]=> + bool(true) +} +-- Iteration 18 -- +array(6) { + [""]=> + int(4) + [0]=> + int(5) + [1]=> + int(6) + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [""]=> + int(4) + [3]=> + int(5) + [4]=> + int(6) +} +-- Iteration 19 -- +array(6) { + ["One"]=> + int(10) + ["two"]=> + int(20) + ["three"]=> + int(3) + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + ["One"]=> + int(10) + ["two"]=> + int(20) + ["three"]=> + int(3) +} +Done diff --git a/tests/std/array/array_pad_variation7.phpt b/tests/std/array/array_pad_variation7.phpt new file mode 100644 index 00000000..06f2bfa6 --- /dev/null +++ b/tests/std/array/array_pad_variation7.phpt @@ -0,0 +1,122 @@ +--TEST-- +Test array_pad() function : usage variations - two dimensional array for 'input' argument +--FILE-- + 1, "two" => 2) +); + +// initialize the $pad_size and $pad_value arguments +$pad_size = 5; +$pad_value = "HELLO"; + +// entire 2-d array +echo "-- Entire 2-d array for \$input argument --\n"; +var_dump( array_pad($input, $pad_size, $pad_value) ); // positive 'pad_size' +var_dump( array_pad($input, -$pad_size, $pad_value) ); // negative 'pad_size' + +// sub array +echo "-- Sub array for \$input argument --\n"; +var_dump( array_pad($input[1], $pad_size, $pad_value) ); // positive 'pad_size' +var_dump( array_pad($input[1], -$pad_size, $pad_value) ); // negative 'pad_size' + +echo "Done"; +?> +--EXPECT-- +*** Testing array_pad() : Passing 2-D array to $input argument *** +-- Entire 2-d array for $input argument -- +array(5) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + [1]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } + [2]=> + array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) + } + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" +} +array(5) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + [3]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } + [4]=> + array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) + } +} +-- Sub array for $input argument -- +array(5) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" +} +array(5) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [3]=> + string(5) "hello" + [4]=> + string(5) "world" +} +Done diff --git a/tests/std/array/array_pop.phpt b/tests/std/array/array_pop.phpt new file mode 100644 index 00000000..fb0c74b0 --- /dev/null +++ b/tests/std/array/array_pop.phpt @@ -0,0 +1,277 @@ +--TEST-- +Test array_pop() function +--SKIPIF-- + +--FILE-- + "aaa", "A" => "AAA", "c" => "ccc", "d" => "ddd", "e" => "eee" ), + array( "1" => "one", "2" => "two", "3" => "three", "4" => "four", "5" => "five" ), + array( 1 => "one", 2 => "two", 3 => 7, 4 => "four", 5 => "five" ), + array( "f" => "fff", "1" => "one", 4 => 6, "" => "blank", 2 => "float", "F" => "FFF", + "blank" => "", 3 => 3.7, 5 => 7, 6 => 8.6, '5' => "Five", "4name" => "jonny", "a" => NULL, NULL => 3 ), + array( 12, "name", 'age', '45' ), + array( array("oNe", "tWo", 4), array(10, 20, 30, 40, 50), array() ), + array( "one" => 1, "one" => 2, "three" => 3, 3, 4, 3 => 33, 4 => 44, 5, 6, + 5 => 57, "5.4" => 554, "5.7" => 557 ) +); + +/* Loop to test normal functionality with different arrays inputs */ +echo "\n*** Normal testing with various array inputs ***\n"; + +$counter = 1; +foreach( $mixed_array as $sub_array ) +{ + echo "\n-- Input Array for Iteration $counter is --\n"; + var_dump( $sub_array ); + echo "\nOutput after Pop is :\n"; + var_dump( array_pop($sub_array) ); + $counter++; +} + +echo"\nDone"; +?> +--EXPECT-- +*** Normal testing with various array inputs *** + +-- Input Array for Iteration 1 is -- +array(0) { +} + +Output after Pop is : +NULL + +-- Input Array for Iteration 2 is -- +array(9) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + [6]=> + int(7) + [7]=> + int(8) + [8]=> + int(9) +} + +Output after Pop is : +int(9) + +-- Input Array for Iteration 3 is -- +array(5) { + [0]=> + string(3) "One" + [1]=> + string(4) "_Two" + [2]=> + string(5) "Three" + [3]=> + string(4) "Four" + [4]=> + string(4) "Five" +} + +Output after Pop is : +string(4) "Five" + +-- Input Array for Iteration 4 is -- +array(8) { + [0]=> + int(6) + [1]=> + string(3) "six" + [2]=> + int(7) + [3]=> + string(5) "seven" + [4]=> + int(8) + [5]=> + string(5) "eight" + [6]=> + int(9) + [7]=> + string(4) "nine" +} + +Output after Pop is : +string(4) "nine" + +-- Input Array for Iteration 5 is -- +array(5) { + ["a"]=> + string(3) "aaa" + ["A"]=> + string(3) "AAA" + ["c"]=> + string(3) "ccc" + ["d"]=> + string(3) "ddd" + ["e"]=> + string(3) "eee" +} + +Output after Pop is : +string(3) "eee" + +-- Input Array for Iteration 6 is -- +array(5) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + string(5) "three" + [4]=> + string(4) "four" + [5]=> + string(4) "five" +} + +Output after Pop is : +string(4) "five" + +-- Input Array for Iteration 7 is -- +array(5) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + int(7) + [4]=> + string(4) "four" + [5]=> + string(4) "five" +} + +Output after Pop is : +string(4) "five" + +-- Input Array for Iteration 8 is -- +array(12) { + ["f"]=> + string(3) "fff" + [1]=> + string(3) "one" + [4]=> + int(6) + [""]=> + int(3) + [2]=> + string(5) "float" + ["F"]=> + string(3) "FFF" + ["blank"]=> + string(0) "" + [3]=> + float(3.7) + [5]=> + string(4) "Five" + [6]=> + float(8.6) + ["4name"]=> + string(5) "jonny" + ["a"]=> + NULL +} + +Output after Pop is : +NULL + +-- Input Array for Iteration 9 is -- +array(4) { + [0]=> + int(12) + [1]=> + string(4) "name" + [2]=> + string(3) "age" + [3]=> + string(2) "45" +} + +Output after Pop is : +string(2) "45" + +-- Input Array for Iteration 10 is -- +array(3) { + [0]=> + array(3) { + [0]=> + string(3) "oNe" + [1]=> + string(3) "tWo" + [2]=> + int(4) + } + [1]=> + array(5) { + [0]=> + int(10) + [1]=> + int(20) + [2]=> + int(30) + [3]=> + int(40) + [4]=> + int(50) + } + [2]=> + array(0) { + } +} + +Output after Pop is : +array(0) { +} + +-- Input Array for Iteration 11 is -- +array(10) { + ["one"]=> + int(2) + ["three"]=> + int(3) + [0]=> + int(3) + [1]=> + int(4) + [3]=> + int(33) + [4]=> + int(44) + [5]=> + int(57) + [6]=> + int(6) + ["5.4"]=> + int(554) + ["5.7"]=> + int(557) +} + +Output after Pop is : +int(557) + +Done diff --git a/tests/std/array/array_pop_variation.phpt b/tests/std/array/array_pop_variation.phpt new file mode 100644 index 00000000..af8b0cc0 --- /dev/null +++ b/tests/std/array/array_pop_variation.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test array_pop() function (variation) +--FILE-- + "aaa", "A" => "AAA", "c" => "ccc", "d" => "ddd", "e" => "eee" ), + array( "1" => "one", "2" => "two", "3" => "three", "4" => "four", "5" => "five" ), + array( 1 => "one", 2 => "two", 3 => 7, 4 => "four", 5 => "five" ), + array( "f" => "fff", "1" => "one", 4 => 6, "" => "blank", 2 => "float", "F" => "FFF", + "blank" => "", 3 => 3.7, 5 => 7, 6 => 8.6, '5' => "Five", "4name" => "jonny", "a" => NULL, NULL => 3 ), + array( 12, "name", 'age', '45' ), + array( array("oNe", "tWo", 4), array(10, 20, 30, 40, 50), array() ), + array( "one" => 1, "one" => 2, "three" => 3, 3, 4, 3 => 33, 4 => 44, 5, 6, + 5 => 57, "5.4" => 554, "5.7" => 557 ) +); + +echo"\n*** Checking for internal array pointer being reset when pop is called ***\n"; + +echo "\nCurrent Element is : "; +var_dump( current($mixed_array[1]) ); + +echo "\nNext Element is : "; +var_dump( next($mixed_array[1]) ); + +echo "\nNext Element is : "; +var_dump( next($mixed_array[1]) ); + +echo "\nPOPed Element is : "; +var_dump( array_pop($mixed_array[1]) ); + +echo "\nCurrent Element after POP operation is: "; +var_dump( current($mixed_array[1]) ); + +echo"\nDone"; +?> +--EXPECT-- +*** Checking for internal array pointer being reset when pop is called *** + +Current Element is : int(1) + +Next Element is : int(2) + +Next Element is : int(3) + +POPed Element is : int(9) + +Current Element after POP operation is: int(1) + +Done diff --git a/tests/std/array/array_product_empty_array.phpt b/tests/std/array/array_product_empty_array.phpt new file mode 100644 index 00000000..714030d1 --- /dev/null +++ b/tests/std/array/array_product_empty_array.phpt @@ -0,0 +1,17 @@ +--TEST-- +Test array_product() function with empty array +--FILE-- + $carry * $value, 1)); +?> +--EXPECT-- +array_product() version: +int(1) +array_reduce() version: +int(1) diff --git a/tests/std/array/array_product_objects_operation_no_cast.phpt b/tests/std/array/array_product_objects_operation_no_cast.phpt new file mode 100644 index 00000000..7f4af375 --- /dev/null +++ b/tests/std/array/array_product_objects_operation_no_cast.phpt @@ -0,0 +1,28 @@ +--TEST-- +Test array_product() function with objects that implement addition but not castable to numeric type +--EXTENSIONS-- +zend_test +--FILE-- + $carry * $value, 1)); +?> +--EXPECTF-- +array_product() version: + +Warning: array_product(): Multiplication is not supported on type DoOperationNoCast in %s on line %d + +Warning: array_product(): Multiplication is not supported on type DoOperationNoCast in %s on line %d + +Warning: array_product(): Multiplication is not supported on type DoOperationNoCast in %s on line %d +int(1) +array_reduce() version: +object(DoOperationNoCast)#5 (1) { + ["val":"DoOperationNoCast":private]=> + int(1500) +} diff --git a/tests/std/array/array_product_variation1.phpt b/tests/std/array/array_product_variation1.phpt new file mode 100644 index 00000000..ad92aa11 --- /dev/null +++ b/tests/std/array/array_product_variation1.phpt @@ -0,0 +1,56 @@ +--TEST-- +Test array_product() function : variation +--FILE-- + true, "boolean (false)" => false, "string" => "hello", "numeric string" => "12", "resource" => STDERR, "object" => new A(), "null" => null, "array" => array(3, 2)); + foreach ($types as $desc => $type) { + echo $desc, "\n"; + var_dump(array_product([1, $type])); + echo "\n"; + } +} +?> +--EXPECTF-- +*** Testing array_product() : variation - using non numeric values *** +boolean (true) +int(1) + +boolean (false) +int(0) + +string + +Warning:%S Multiplication is not supported on type string in %s on line %d +int(0) + +numeric string +int(12) + +resource + +Warning:%S Multiplication is not supported on type resource in %s on line %d +int(3) + +object + +Warning:%S Multiplication is not supported on type A in %s on line %d +int(1) + +null +int(0) + +array + +Warning:%S Multiplication is not supported on type array in %s on line %d +int(1) + diff --git a/tests/std/array/array_product_variation2.phpt b/tests/std/array/array_product_variation2.phpt new file mode 100644 index 00000000..167e46ec --- /dev/null +++ b/tests/std/array/array_product_variation2.phpt @@ -0,0 +1,14 @@ +--TEST-- +Test array_product() function : variation +--FILE-- + 2, "janet" => 5)) ); +?> +--EXPECT-- +*** Testing array_product() : variations *** + +-- Testing array_product() function with a keyed array array -- +int(10) diff --git a/tests/std/array/array_product_variation3.phpt b/tests/std/array/array_product_variation3.phpt new file mode 100644 index 00000000..03c7da17 --- /dev/null +++ b/tests/std/array/array_product_variation3.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test array_product() function : variation +--FILE-- + +--EXPECT-- +*** Testing array_product() : variations - negative numbers*** + +-- Testing array_product() function with one negative number -- +int(-2) + +-- Testing array_product() function with two negative numbers -- +int(6) + +-- Testing array_product() function with three negative numbers -- +int(-24) + +-- Testing array_product() function with negative floats -- +float(-1.5) + +-- Testing array_product() function with negative floats -- +float(-9999999900000000) diff --git a/tests/std/array/array_product_variation4.phpt b/tests/std/array/array_product_variation4.phpt new file mode 100644 index 00000000..c142cea6 --- /dev/null +++ b/tests/std/array/array_product_variation4.phpt @@ -0,0 +1,21 @@ +--TEST-- +Test array_product() function : variation +--FILE-- + +--EXPECT-- +*** Testing array_product() : variations *** + +-- Testing array_product() function with a very large array -- +float(INF) diff --git a/tests/std/array/array_product_variation5.phpt b/tests/std/array/array_product_variation5.phpt new file mode 100644 index 00000000..557c2b33 --- /dev/null +++ b/tests/std/array/array_product_variation5.phpt @@ -0,0 +1,24 @@ +--TEST-- +Test array_product() function: resources in array +--FILE-- + $carry * $value, 1)); +} catch (TypeError $e) { + echo $e->getMessage(); +} +?> +--EXPECTF-- +array_product() version: + +Warning:%S Multiplication is not supported on type resource in %s on line %d +int(30) +array_reduce() version: +Unsupported operand types: int * resource%S +%a diff --git a/tests/std/array/array_product_variation6.phpt b/tests/std/array/array_product_variation6.phpt new file mode 100644 index 00000000..6526197c --- /dev/null +++ b/tests/std/array/array_product_variation6.phpt @@ -0,0 +1,22 @@ +--TEST-- +Test array_product() function with objects castable to numeric type +--EXTENSIONS-- +gmp +--FILE-- + $carry * $value, 1)); +?> +--EXPECT-- +array_product() version: +int(150) +array_reduce() version: +object(GMP)#5 (1) { + ["num"]=> + string(3) "150" +} diff --git a/tests/std/array/array_push.phpt b/tests/std/array/array_push.phpt new file mode 100644 index 00000000..32fcf0d3 --- /dev/null +++ b/tests/std/array/array_push.phpt @@ -0,0 +1,320 @@ +--TEST-- +Test array_push() function +--SKIPIF-- + +--FILE-- + "aaa", "A" => "AAA", "c" => "ccc", "d" => "ddd", "e" => "eee" ), + array( "1" => "one", "2" => "two", "3" => "three", "4" => "four", "5" => "five" ), + array( 1 => "one", 2 => "two", 3 => 7, 4 => "four", 5 => "five" ), + array( "f" => "fff", "1" => "one", 4 => 6, "" => "blank", 2 => "float", "F" => "FFF", + "blank" => "", 3 => 3.7, 5 => 7, 6 => 8.6, '5' => "Five", "4name" => "jonny", "a" => NULL, NULL => 3 ), + array( 12, "name", 'age', '45' ), + array( array("oNe", "tWo", 4), array(10, 20, 30, 40, 50), array() ), + array( "one" => 1, "one" => 2, "three" => 3, 3, 4, 3 => 33, 4 => 44, 5, 6, + 5 => 57, "5.4" => 554, "5.7" => 557 ) +); + +/* Error Conditions */ +echo "\n*** Testing Edge Conditions ***\n"; + +/* Invalid Number of arguments */ +var_dump( array_push($mixed_array[1],1,2) ); + +/* Empty Array as argument */ +var_dump( array_push($empty_array, 2) ); + + +/* Loop to test normal functionality with different arrays inputs */ +echo "\n*** Testing with various array inputs ***\n"; + +$counter = 1; +foreach( $mixed_array as $sub_array ) +{ + echo "\n-- Input Array for Iteration $counter is --\n"; + var_dump( $sub_array ); + echo "\nOutput after push is :\n"; + var_dump( array_push($sub_array, 22, "abc") ); + $counter++; +} + +/* Checking for return value and the new array formed from push operation */ +echo "\n*** Checking for return value and the new array formed from push operation ***\n"; +var_dump( array_push($mixed_array[2], 22, 33, "44") ); +var_dump( $mixed_array[2] ); + +echo"\nDone"; +?> +--EXPECT-- +*** Testing Edge Conditions *** +int(11) +int(1) + +*** Testing with various array inputs *** + +-- Input Array for Iteration 1 is -- +array(0) { +} + +Output after push is : +int(2) + +-- Input Array for Iteration 2 is -- +array(11) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + [6]=> + int(7) + [7]=> + int(8) + [8]=> + int(9) + [9]=> + int(1) + [10]=> + int(2) +} + +Output after push is : +int(13) + +-- Input Array for Iteration 3 is -- +array(5) { + [0]=> + string(3) "One" + [1]=> + string(4) "_Two" + [2]=> + string(5) "Three" + [3]=> + string(4) "Four" + [4]=> + string(4) "Five" +} + +Output after push is : +int(7) + +-- Input Array for Iteration 4 is -- +array(8) { + [0]=> + int(6) + [1]=> + string(3) "six" + [2]=> + int(7) + [3]=> + string(5) "seven" + [4]=> + int(8) + [5]=> + string(5) "eight" + [6]=> + int(9) + [7]=> + string(4) "nine" +} + +Output after push is : +int(10) + +-- Input Array for Iteration 5 is -- +array(5) { + ["a"]=> + string(3) "aaa" + ["A"]=> + string(3) "AAA" + ["c"]=> + string(3) "ccc" + ["d"]=> + string(3) "ddd" + ["e"]=> + string(3) "eee" +} + +Output after push is : +int(7) + +-- Input Array for Iteration 6 is -- +array(5) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + string(5) "three" + [4]=> + string(4) "four" + [5]=> + string(4) "five" +} + +Output after push is : +int(7) + +-- Input Array for Iteration 7 is -- +array(5) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + int(7) + [4]=> + string(4) "four" + [5]=> + string(4) "five" +} + +Output after push is : +int(7) + +-- Input Array for Iteration 8 is -- +array(12) { + ["f"]=> + string(3) "fff" + [1]=> + string(3) "one" + [4]=> + int(6) + [""]=> + int(3) + [2]=> + string(5) "float" + ["F"]=> + string(3) "FFF" + ["blank"]=> + string(0) "" + [3]=> + float(3.7) + [5]=> + string(4) "Five" + [6]=> + float(8.6) + ["4name"]=> + string(5) "jonny" + ["a"]=> + NULL +} + +Output after push is : +int(14) + +-- Input Array for Iteration 9 is -- +array(4) { + [0]=> + int(12) + [1]=> + string(4) "name" + [2]=> + string(3) "age" + [3]=> + string(2) "45" +} + +Output after push is : +int(6) + +-- Input Array for Iteration 10 is -- +array(3) { + [0]=> + array(3) { + [0]=> + string(3) "oNe" + [1]=> + string(3) "tWo" + [2]=> + int(4) + } + [1]=> + array(5) { + [0]=> + int(10) + [1]=> + int(20) + [2]=> + int(30) + [3]=> + int(40) + [4]=> + int(50) + } + [2]=> + array(0) { + } +} + +Output after push is : +int(5) + +-- Input Array for Iteration 11 is -- +array(10) { + ["one"]=> + int(2) + ["three"]=> + int(3) + [0]=> + int(3) + [1]=> + int(4) + [3]=> + int(33) + [4]=> + int(44) + [5]=> + int(57) + [6]=> + int(6) + ["5.4"]=> + int(554) + ["5.7"]=> + int(557) +} + +Output after push is : +int(12) + +*** Checking for return value and the new array formed from push operation *** +int(8) +array(8) { + [0]=> + string(3) "One" + [1]=> + string(4) "_Two" + [2]=> + string(5) "Three" + [3]=> + string(4) "Four" + [4]=> + string(4) "Five" + [5]=> + int(22) + [6]=> + int(33) + [7]=> + string(2) "44" +} + +Done diff --git a/tests/std/array/array_push_basic.phpt b/tests/std/array/array_push_basic.phpt new file mode 100644 index 00000000..c0d66b70 --- /dev/null +++ b/tests/std/array/array_push_basic.phpt @@ -0,0 +1,57 @@ +--TEST-- +Test array_push() function : basic functionality +--FILE-- + 'un', 'two' => 'deux'); + +echo "\n-- Push values onto an associative array --\n"; +var_dump(array_push($array_assoc, $var1, $var2)); +var_dump($array_assoc); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_push() : basic functionality *** + +-- Push values onto an indexed array -- +int(5) +array(5) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + string(5) "three" + [4]=> + string(4) "four" +} + +-- Push values onto an associative array -- +int(4) +array(4) { + ["one"]=> + string(2) "un" + ["two"]=> + string(4) "deux" + [0]=> + string(5) "three" + [1]=> + string(4) "four" +} +Done diff --git a/tests/std/array/array_push_empty.phpt b/tests/std/array/array_push_empty.phpt new file mode 100644 index 00000000..1c7f935a --- /dev/null +++ b/tests/std/array/array_push_empty.phpt @@ -0,0 +1,25 @@ +--TEST-- +Test array_push() function : push empty set to the array +--FILE-- + +--EXPECT-- +int(3) +int(3) +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +Done diff --git a/tests/std/array/array_push_error2.phpt b/tests/std/array/array_push_error2.phpt new file mode 100644 index 00000000..0ed0af6e --- /dev/null +++ b/tests/std/array/array_push_error2.phpt @@ -0,0 +1,27 @@ +--TEST-- +Test array_push() function : error conditions - max int value as key +--FILE-- + 'max'); +try { + var_dump(array_push($array, 'new')); +} catch (\Error $e) { + echo $e->getMessage() . "\n"; +} +var_dump($array); + +?> +--EXPECTF-- +*** Testing array_push() : error conditions *** +Cannot add element to the array as the next element is already occupied +array(1) { + [%d]=> + string(3) "max" +} diff --git a/tests/std/array/array_push_variation2.phpt b/tests/std/array/array_push_variation2.phpt new file mode 100644 index 00000000..6533a67e --- /dev/null +++ b/tests/std/array/array_push_variation2.phpt @@ -0,0 +1,171 @@ +--TEST-- +Test array_push() function : usage variations - Pass different data types as $var arg +--SKIPIF-- + + +--FILE-- + +--EXPECT-- +*** Testing array_push() : usage variations *** + +-- Iteration 1 -- +int(3) + +-- Iteration 2 -- +int(3) + +-- Iteration 3 -- +int(3) + +-- Iteration 4 -- +int(3) + +-- Iteration 5 -- +int(3) + +-- Iteration 6 -- +int(3) + +-- Iteration 7 -- +int(3) + +-- Iteration 8 -- +int(3) + +-- Iteration 9 -- +int(3) + +-- Iteration 10 -- +int(3) + +-- Iteration 11 -- +int(3) + +-- Iteration 12 -- +int(3) + +-- Iteration 13 -- +int(3) + +-- Iteration 14 -- +int(3) + +-- Iteration 15 -- +int(3) + +-- Iteration 16 -- +int(3) + +-- Iteration 17 -- +int(3) + +-- Iteration 18 -- +int(3) + +-- Iteration 19 -- +int(3) + +-- Iteration 20 -- +int(3) + +-- Iteration 21 -- +int(3) + +-- Iteration 22 -- +int(3) + +-- Iteration 23 -- +int(3) + +-- Iteration 24 -- +int(3) + +-- Iteration 25 -- +int(3) +Done diff --git a/tests/std/array/array_push_variation3.phpt b/tests/std/array/array_push_variation3.phpt new file mode 100644 index 00000000..4ce4e7d9 --- /dev/null +++ b/tests/std/array/array_push_variation3.phpt @@ -0,0 +1,65 @@ +--TEST-- +Test array_push() function : usage variations - multidimensional arrays +--FILE-- + +--EXPECT-- +*** Testing array_push() : usage variations *** + +-- Pass array as $var argument -- +int(4) +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + } +} + +-- Pass sub-array as $stack argument -- +int(3) +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + array(3) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + [2]=> + string(1) "a" + } +} +Done diff --git a/tests/std/array/array_push_variation5.phpt b/tests/std/array/array_push_variation5.phpt new file mode 100644 index 00000000..32e541ef --- /dev/null +++ b/tests/std/array/array_push_variation5.phpt @@ -0,0 +1,30 @@ +--TEST-- +Test array_push() function : usage variations - position of internal array pointer +--FILE-- + 'un', 'two' => 'deux'); +$var0 = 'zero'; + +echo "\n-- Call array_push() --\n"; +var_dump($result = array_push($stack, $var0)); + +echo "\n-- Position of Internal Pointer in Original Array: --\n"; +echo key($stack) . " => " . current ($stack) . "\n"; + +echo "Done"; +?> +--EXPECT-- +*** Testing array_push() : usage variations *** + +-- Call array_push() -- +int(3) + +-- Position of Internal Pointer in Original Array: -- +one => un +Done diff --git a/tests/std/array/array_push_variation6.phpt b/tests/std/array/array_push_variation6.phpt new file mode 100644 index 00000000..b5ebbb3c --- /dev/null +++ b/tests/std/array/array_push_variation6.phpt @@ -0,0 +1,138 @@ +--TEST-- +Test array_push() function : usage variations - array keys are different data types +--SKIPIF-- + + +--FILE-- + array( + 0 => 'zero', + 1 => 'one', + 12345 => 'positive', + -2345 => 'negative', + ), + + // null data +/*3*/ 'null uppercase' => array( + NULL => 'null 1', + ), + 'null lowercase' => array( + null => 'null 2', + ), + + // boolean data +/*4*/ 'bool lowercase' => array( + true => 'lowert', + false => 'lowerf', + ), + 'bool uppercase' => array( + TRUE => 'uppert', + FALSE => 'upperf', + ), + + // empty data +/*5*/ 'empty double quotes' => array( + "" => 'emptyd', + ), + 'empty single quotes' => array( + '' => 'emptys', + ), + + // string data +/*6*/ 'string' => array( + "stringd" => 'stringd', + 'strings' => 'strings', + $heredoc => 'stringh', + ), + + // undefined data +/*8*/ 'undefined' => array( + @$undefined_var => 'undefined', + ), + + // unset data +/*9*/ 'unset' => array( + @$unset_var => 'unset', + ), +); + +// loop through each sub-array of $inputs to check the behavior of array_push() +$iterator = 1; +foreach($inputs as $key => $input) { + echo "\n-- Iteration $iterator : $key data --\n"; + echo "Before : "; + var_dump(count($input)); + echo "After : "; + var_dump( array_push($input, $var) ); + $iterator++; +}; + +echo "Done"; +?> +--EXPECT-- +*** Testing array_push() : usage variations *** + +-- Iteration 1 : int data -- +Before : int(4) +After : int(5) + +-- Iteration 2 : null uppercase data -- +Before : int(1) +After : int(2) + +-- Iteration 3 : null lowercase data -- +Before : int(1) +After : int(2) + +-- Iteration 4 : bool lowercase data -- +Before : int(2) +After : int(3) + +-- Iteration 5 : bool uppercase data -- +Before : int(2) +After : int(3) + +-- Iteration 6 : empty double quotes data -- +Before : int(1) +After : int(2) + +-- Iteration 7 : empty single quotes data -- +Before : int(1) +After : int(2) + +-- Iteration 8 : string data -- +Before : int(3) +After : int(4) + +-- Iteration 9 : undefined data -- +Before : int(1) +After : int(2) + +-- Iteration 10 : unset data -- +Before : int(1) +After : int(2) +Done diff --git a/tests/std/array/array_rand.phpt b/tests/std/array/array_rand.phpt new file mode 100644 index 00000000..24f6966b --- /dev/null +++ b/tests/std/array/array_rand.phpt @@ -0,0 +1,59 @@ +--TEST-- +array_rand() tests +--FILE-- +getMessage() . "\n"; +} + +try { + var_dump(array_rand(array(), 0)); +} catch (\ValueError $e) { + echo $e->getMessage() . "\n"; +} + +try { + var_dump(array_rand(array(1,2,3), 0)); +} catch (\ValueError $e) { + echo $e->getMessage() . "\n"; +} + +try { + var_dump(array_rand(array(1,2,3), -1)); +} catch (\ValueError $e) { + echo $e->getMessage() . "\n"; +} + +try { + var_dump(array_rand(array(1,2,3), 10)); +} catch (\ValueError $e) { + echo $e->getMessage() . "\n"; +} + +var_dump(array_rand(array(1,2,3), 3)); +var_dump(array_rand(array(1,2,3), 2)); + +?> +--EXPECTF-- +array_rand(): Argument #1 ($array) must not be empty +array_rand(): Argument #1 ($array) must not be empty +array_rand(): Argument #2 ($num) must be between 1 and the number of elements in argument #1 ($array) +array_rand(): Argument #2 ($num) must be between 1 and the number of elements in argument #1 ($array) +array_rand(): Argument #2 ($num) must be between 1 and the number of elements in argument #1 ($array) +array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) +} +array(2) { + [0]=> + int(%d) + [1]=> + int(%d) +} diff --git a/tests/std/array/array_rand_basic1.phpt b/tests/std/array/array_rand_basic1.phpt new file mode 100644 index 00000000..0f2d79df --- /dev/null +++ b/tests/std/array/array_rand_basic1.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test array_rand() function : basic functionality - array with default keys +--FILE-- + +--EXPECTF-- +*** Testing array_rand() : array with default keys *** + +-- with all default and optional arguments -- +array(%d) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + [3]=> + int(%d) + [4]=> + int(%d) + [5]=> + int(%d) +} + +-- with default argument -- +int(%d) +Done diff --git a/tests/std/array/array_rand_basic2.phpt b/tests/std/array/array_rand_basic2.phpt new file mode 100644 index 00000000..747cb562 --- /dev/null +++ b/tests/std/array/array_rand_basic2.phpt @@ -0,0 +1,52 @@ +--TEST-- +Test array_rand() function : basic functionality - with associative array for 'input' argument +--FILE-- + 1, 'two' => 2, 'three' => 3, + 'FoUr' => 'four', '#5' => 5, 'SIX' => 'six', + "seven" => 7, "#8" => "eight", "nine" => "NINE" +); + +$num_req = 6; + +// Calling array_rand() with optional argument +echo"\n-- with all default and optional arguments --\n"; +var_dump( array_rand($input,$num_req) ); + +// Calling array_rand() with default arguments +echo"\n-- with default argument --\n"; +var_dump( array_rand($input) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_rand() : with associative array *** + +-- with all default and optional arguments -- +array(6) { + [0]=> + string(%d) "%s" + [1]=> + string(%d) "%s" + [2]=> + string(%d) "%s" + [3]=> + string(%d) "%s" + [4]=> + string(%d) "%s" + [5]=> + string(%d) "%s" +} + +-- with default argument -- +string(%d) "%s" +Done diff --git a/tests/std/array/array_rand_variation3.phpt b/tests/std/array/array_rand_variation3.phpt new file mode 100644 index 00000000..34f2db6e --- /dev/null +++ b/tests/std/array/array_rand_variation3.phpt @@ -0,0 +1,144 @@ +--TEST-- +Test array_rand() function : usage variation - with MultiDimensional array +--FILE-- + +--EXPECTF-- +*** Testing array_rand() : with multi-dimensional array *** +array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) +} + +*** Testing array_rand() with arrays having different types of values *** + +-- Iteration 1 -- +int(%d) +array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) +} + +-- Iteration 2 -- +int(%d) +array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) +} + +-- Iteration 3 -- +int(%d) +array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) +} + +-- Iteration 4 -- +int(%d) +array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) +} + +-- Iteration 5 -- +int(%d) +array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) +} + +-- Iteration 6 -- +int(%d) +array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) +} + +-- Iteration 7 -- +int(%d) +array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) +} +Done diff --git a/tests/std/array/array_rand_variation4.phpt b/tests/std/array/array_rand_variation4.phpt new file mode 100644 index 00000000..c7d90783 --- /dev/null +++ b/tests/std/array/array_rand_variation4.phpt @@ -0,0 +1,163 @@ +--TEST-- +Test array_rand() function : usage variation - with associative arrays for 'input' parameter +--SKIPIF-- + +--FILE-- + 'one', 2 => 2, 1234567890 => 'big', -1 => 'negative key', + 0 => "zero key"), + + // array with string keys + array('one' => 1, "two" => 2.0, "three" => 'three', + '12twelve' => 12.00, "" => 'empty string', " " => "space key"), + + // array with hexa values as keys +/*3*/ array(0xabc => 2748, 0x12f => '303', 0xff => "255", -0xff => "-255"), + + // array with octal values as keys + array(0123 => 83, 012 => 10, 010 => "8", -034 => "-28", 0012 => '10'), + + // array with bool values as keys + array(TRUE => '1', true => true, TrUe => "TRUE", + FALSE => '0', false => false, FaLsE => "FALSE"), + + // array with special chars as keys +/*6*/ array('##' => "key1", '&$r' => 'key2', '!' => "key3", '<>' =>'key4', + "NULL" => 'key5', "\n" => 'newline as key', + "\t" => "tab as key", "'" => 'single quote as key', + '"' => 'double quote as key', "\0" => "null char as key") +); + +/* looping to test array_rand() function with different arrays having + * different types of keys +*/ +$counter = 1; +foreach($asso_arrays as $input) { + echo "\n-- Iteration $counter --\n"; + + // with default argument + echo"\nWith default argument\n"; + var_dump( array_rand($input) ); + + // with default and optional arguments + echo"\nWith num_req = 1\n"; + var_dump( array_rand($input, 1) ); // with $num_req=1 + echo"\nWith num_req = 2\n"; + var_dump( array_rand($input, 2) ); // with $num_req=2 + + $counter++; +} // end of for loop + + +echo "Done"; +?> +--EXPECTREGEX-- +\*\*\* Testing array_rand\(\) : with associative arrays \*\*\* + +-- Iteration 1 -- + +With default argument +int\([012-][12.e]*[23e]*[34]*[5]*[6]*[7]*[8]*[9]*[0]*\) + +With num_req = 1 +int\([012-][12.e]*[23e]*[34]*[5]*[6]*[7]*[8]*[9]*[0]*\) + +With num_req = 2 +array\(2\) { + \[0\]=> + int\([012-][12.e]*[23e]*[34]*[5]*[6]*[7]*[8]*[9]*[0]*\) + \[1\]=> + int\([012-][12.e]*[23e]*[34]*[5]*[6]*[7]*[8]*[9]*[0]*\) +} + +-- Iteration 2 -- + +With default argument +string\([0-9]*\) "[ot1 ]*[hnw2]*[eort]*[ew]*[e]*[l]*[v]*[e]*" + +With num_req = 1 +string\([0-9]*\) "[ot1 ]*[hnw2]*[eort]*[ew]*[e]*[l]*[v]*[e]*" + +With num_req = 2 +array\(2\) { + \[0\]=> + string\([0-9]*\) "[ot1 ]*[hnw2]*[eort]*[ew]*[e]*[l]*[v]*[e]*" + \[1\]=> + string\([0-9]*\) "[ot1 ]*[hnw2]*[eort]*[ew]*[e]*[l]*[v]*[e]*" +} + +-- Iteration 3 -- + +With default argument +int\([23-]*[2570]*[345]*[58]*\) + +With num_req = 1 +int\([23-]*[2570]*[345]*[58]*\) + +With num_req = 2 +array\(2\) { + \[0\]=> + int\([23-]*[2570]*[345]*[58]*\) + \[1\]=> + int\([23-]*[2570]*[345]*[58]*\) +} + +-- Iteration 4 -- + +With default argument +int\([18-]*[023]*[8]*\) + +With num_req = 1 +int\([18-]*[023]*[8]*\) + +With num_req = 2 +array\(2\) { + \[0\]=> + int\([18-]*[023]*[8]*\) + \[1\]=> + int\([18-]*[023]*[8]*\) +} + +-- Iteration 5 -- + +With default argument +int\([01]\) + +With num_req = 1 +int\([01]\) + +With num_req = 2 +array\(2\) { + \[0\]=> + int\([01]\) + \[1\]=> + int\([01]\) +} + +-- Iteration 6 -- + +With default argument +string\([0-9]*\) "[#&!N <\n\t'"\0]*[U#$>]*[rL]*[L]*" + +With num_req = 1 +string\([0-9]*\) "[#&!N <\n\t'"\0]*[U#$>]*[rL]*[L]*" + +With num_req = 2 +array\(2\) { + \[0\]=> + string\([0-9]*\) "[#&!N <\n\t'"\0]*[U#$>]*[rL]*[L]*" + \[1\]=> + string\([0-9]*\) "[#&!N <\n\t'"\0]*[U#$>]*[rL]*[L]*" +} +Done diff --git a/tests/std/array/array_rand_variation5.phpt b/tests/std/array/array_rand_variation5.phpt new file mode 100644 index 00000000..57f5ee03 --- /dev/null +++ b/tests/std/array/array_rand_variation5.phpt @@ -0,0 +1,76 @@ +--TEST-- +Test array_rand() function : usage variation - invalid values for 'req_num' parameter +--FILE-- + 'one', + 0xabc => 2748, 0x12f => '303', 0xff => "255", + 0123 => 83, 012 => 10, 010 => "8" +); + +// Testing array_rand() function with various invalid 'req_num' values +// with valid num_req values +echo"\n-- With default num_req value --\n"; +var_dump( array_rand($input) ); // with default $num_req value +echo"\n-- With num_req = 1 --\n"; +var_dump( array_rand($input, 1) ); // with valid $num_req value + +// with invalid num_req value +echo"\n-- With num_req = 0 --\n"; +try { + var_dump( array_rand($input, 0) ); // with $num_req=0 +} catch (\ValueError $e) { + echo $e->getMessage() . "\n"; +} + +echo"\n-- With num_req = -1 --\n"; +try { + var_dump( array_rand($input, -1) ); // with $num_req=-1 +} catch (\ValueError $e) { + echo $e->getMessage() . "\n"; +} + +echo"\n-- With num_req = -2 --\n"; +try { + var_dump( array_rand($input, -2) ); // with $num_req=-2 +} catch (\ValueError $e) { + echo $e->getMessage() . "\n"; +} + +echo"\n-- With num_req more than number of members in 'input' array --\n"; +try { + var_dump( array_rand($input, 13) ); // with $num_req=13 +} catch (\ValueError $e) { + echo $e->getMessage() . "\n"; +} + +?> +--EXPECTF-- +*** Testing array_rand() : with invalid values for 'req_num' *** + +-- With default num_req value -- +int(%d) + +-- With num_req = 1 -- +int(%d) + +-- With num_req = 0 -- +array_rand(): Argument #2 ($num) must be between 1 and the number of elements in argument #1 ($array) + +-- With num_req = -1 -- +array_rand(): Argument #2 ($num) must be between 1 and the number of elements in argument #1 ($array) + +-- With num_req = -2 -- +array_rand(): Argument #2 ($num) must be between 1 and the number of elements in argument #1 ($array) + +-- With num_req more than number of members in 'input' array -- +array_rand(): Argument #2 ($num) must be between 1 and the number of elements in argument #1 ($array) diff --git a/tests/std/array/array_rand_variation6.phpt b/tests/std/array/array_rand_variation6.phpt new file mode 100644 index 00000000..e8113fc1 --- /dev/null +++ b/tests/std/array/array_rand_variation6.phpt @@ -0,0 +1,98 @@ +--TEST-- +Test array_rand() function : usage variation - with heredoc string as key in the 'input' array +--FILE-- + "heredoc1", + $heredoc_with_newline => "heredoc2", + $heredoc_with_characters => "heredoc3", + $heredoc_with_newline_and_tabs => "heredoc3", + $heredoc_with_alphanumerics => "heredoc4", + $heredoc_with_embedded_nulls => "heredoc5" +); + +// Test array_rand() function with different valid 'req_num' values +echo "\n-- with default parameters --\n"; +var_dump( array_rand($input) ); + +echo "\n-- with num_req = 1 --\n"; +var_dump( array_rand($input, 1) ); + +echo "\n-- with num_req = 3 --\n"; +var_dump( array_rand($input, 3) ); + +echo "\n-- with num_req = 6 --\n"; +var_dump( array_rand($input, 6) ); + + +echo "Done"; +?> +--EXPECTREGEX-- +\*\*\* Testing array_rand\(\) : with keys of input array as heredoc strings \*\*\* + +-- with default parameters -- +string\([0-9]*\) "[a-z \n \t \0 0-9 ]*" + +-- with num_req = 1 -- +string\([0-9]*\) "[a-z \n \t \0 0-9 ]*" + +-- with num_req = 3 -- +array\(3\) { + \[0\]=> + string\([0-9]*\) "[a-z \n \t \0 0-9 ]*" + \[1\]=> + string\([0-9]*\) "[a-z \n \t \0 0-9 ]*" + \[2\]=> + string\([0-9]*\) "[a-z \n \t \0 0-9 ]*" +} + +-- with num_req = 6 -- +array\(6\) { + \[0\]=> + string\([0-9]*\) "[a-z \n \t \0 0-9 ]*" + \[1\]=> + string\([0-9]*\) "[a-z \n \t \0 0-9 ]*" + \[2\]=> + string\([0-9]*\) "[a-z \n \t \0 0-9 ]*" + \[3\]=> + string\([0-9]*\) "[a-z \n \t \0 0-9 ]*" + \[4\]=> + string\([0-9]*\) "[a-z \n \t \0 0-9 ]*" + \[5\]=> + string\([0-9]*\) "[a-z \n \t \0 0-9 ]*" +} +Done diff --git a/tests/std/array/array_reduce.phpt b/tests/std/array/array_reduce.phpt new file mode 100644 index 00000000..f3e9c021 --- /dev/null +++ b/tests/std/array/array_reduce.phpt @@ -0,0 +1,90 @@ +--TEST-- +Test array_reduce() function +--INI-- +precision=14 +--SKIPIF-- + +--FILE-- + 42, 'bar' => 17, 'qux' => -2, 'quux' => 0); + var_dump(array_reduce($array, 'reduce_array', $initial), $initial); + echo "\n*** Testing array_reduce() to null ***\n"; + $initial = null; + var_dump(array_reduce($array, 'reduce_null', $initial), $initial); + echo "\nDone"; +} +?> +--EXPECT-- +*** Testing array_reduce() to integer *** +int(61) +int(42) + +*** Testing array_reduce() to float *** +float(6.1) +float(4.2) + +*** Testing array_reduce() to string *** +string(23) "quuxfoofoobarquxquxquux" +string(4) "quux" + +*** Testing array_reduce() to array *** +array(4) { + ["foo"]=> + int(44) + ["bar"]=> + int(18) + ["qux"]=> + int(0) + ["quux"]=> + int(1) +} +array(4) { + ["foo"]=> + int(42) + ["bar"]=> + int(17) + ["qux"]=> + int(-2) + ["quux"]=> + int(0) +} + +*** Testing array_reduce() to null *** +string(19) "foofoobarquxquxquux" +NULL + +Done diff --git a/tests/std/array/array_reduce_return_by_ref.phpt b/tests/std/array/array_reduce_return_by_ref.phpt new file mode 100644 index 00000000..8da7018c --- /dev/null +++ b/tests/std/array/array_reduce_return_by_ref.phpt @@ -0,0 +1,11 @@ +--TEST-- +Return by reference from array_reduce() callback +--FILE-- + +--EXPECT-- +int(2) diff --git a/tests/std/array/array_reduce_variation1.phpt b/tests/std/array/array_reduce_variation1.phpt new file mode 100644 index 00000000..97ed759e --- /dev/null +++ b/tests/std/array/array_reduce_variation1.phpt @@ -0,0 +1,37 @@ +--TEST-- +Test array_reduce() function : variation +--SKIPIF-- + + +--FILE-- +getMessage() . "\n"; + } +} +?> +--EXPECT-- +*** Testing array_reduce() : variation *** + +--- Testing with a callback with too few parameters --- +int(2) + +--- Testing with a callback with too many parameters --- +Exception: Too few arguments to function threeArgs(), 2 passed and exactly 3 expected diff --git a/tests/std/array/array_reduce_variation3.phpt b/tests/std/array/array_reduce_variation3.phpt new file mode 100644 index 00000000..4cc6d011 --- /dev/null +++ b/tests/std/array/array_reduce_variation3.phpt @@ -0,0 +1,33 @@ +--TEST-- +Test array_reduce() function : variation - object callbacks +--FILE-- + +--EXPECT-- +*** Testing array_reduce() : variation - object callbacks *** + +--- Static method callback --- +int(1) + +--- Instance method callback --- +int(1) diff --git a/tests/std/array/array_replace.phpt b/tests/std/array/array_replace.phpt new file mode 100644 index 00000000..c3edba00 --- /dev/null +++ b/tests/std/array/array_replace.phpt @@ -0,0 +1,114 @@ +--TEST-- +Test array_replace and array_replace_recursive +--FILE-- + 'dontclobber', + '1' => 'unclobbered', + 'test2' => 0.0, + 'test3' => array( + 'testarray2' => true, + 1 => array( + 'testsubarray1' => 'dontclobber2', + 'testsubarray2' => 'dontclobber3', + ), + ), +); + +$array2 = array( + 1 => 'clobbered', + 'test3' => array( + 'testarray2' => false, + ), + 'test4' => array( + 'clobbered3' => array(0, 1, 2), + ), +); + +$array3 = array(array(array(array()))); + +$array4 = array(); +$array4[] = &$array4; + +echo " -- Testing array_replace() --\n"; +$data = array_replace($array1, $array2); + +var_dump($data); + +echo " -- Testing array_replace_recursive() --\n"; +$data = array_replace_recursive($array1, $array2); + +var_dump($data); + +echo " -- Testing array_replace_recursive() w/ endless recusrsion --\n"; +try { + $data = array_replace_recursive($array3, $array4); + var_dump($data); +} catch (\Error $e) { + echo $e->getMessage() . "\n"; +} + +?> +--EXPECT-- + -- Testing array_replace() -- +array(5) { + [0]=> + string(11) "dontclobber" + [1]=> + string(9) "clobbered" + ["test2"]=> + float(0) + ["test3"]=> + array(1) { + ["testarray2"]=> + bool(false) + } + ["test4"]=> + array(1) { + ["clobbered3"]=> + array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + } + } +} + -- Testing array_replace_recursive() -- +array(5) { + [0]=> + string(11) "dontclobber" + [1]=> + string(9) "clobbered" + ["test2"]=> + float(0) + ["test3"]=> + array(2) { + ["testarray2"]=> + bool(false) + [1]=> + array(2) { + ["testsubarray1"]=> + string(12) "dontclobber2" + ["testsubarray2"]=> + string(12) "dontclobber3" + } + } + ["test4"]=> + array(1) { + ["clobbered3"]=> + array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + } + } +} + -- Testing array_replace_recursive() w/ endless recusrsion -- +Recursion detected diff --git a/tests/std/array/array_replace_merge_recursive_ref.phpt b/tests/std/array/array_replace_merge_recursive_ref.phpt new file mode 100644 index 00000000..e8d4f8e0 --- /dev/null +++ b/tests/std/array/array_replace_merge_recursive_ref.phpt @@ -0,0 +1,31 @@ +--TEST-- +Test array_(replace|merge)_recursive with references +--FILE-- + &$one]; +$arr2 = ['k' => &$two]; +var_dump(current($one), current($two)); +array_replace_recursive($arr1, $arr2); +var_dump(current($one), current($two)); + +$one = [1]; +$two = [42]; +$arr1 = ['k' => &$one]; +$arr2 = ['k' => &$two]; +var_dump(current($one), current($two)); +array_merge_recursive($arr1, $arr2); +var_dump(current($one), current($two)); + +?> +--EXPECT-- +int(1) +int(42) +int(1) +int(42) +int(1) +int(42) +int(1) +int(42) diff --git a/tests/std/array/array_reverse_basic1.phpt b/tests/std/array/array_reverse_basic1.phpt new file mode 100644 index 00000000..6f7197d8 --- /dev/null +++ b/tests/std/array/array_reverse_basic1.phpt @@ -0,0 +1,67 @@ +--TEST-- +Test array_reverse() function : basic functionality - simple array for 'array' argument +--FILE-- + +--EXPECT-- +*** Testing array_reverse() : basic functionality *** +array(6) { + [0]=> + float(13.33) + [1]=> + int(10) + [2]=> + string(4) "blue" + [3]=> + string(3) "red" + [4]=> + string(5) "green" + [5]=> + string(1) "a" +} +array(6) { + [5]=> + float(13.33) + [4]=> + int(10) + [3]=> + string(4) "blue" + [2]=> + string(3) "red" + [1]=> + string(5) "green" + [0]=> + string(1) "a" +} +array(6) { + [0]=> + float(13.33) + [1]=> + int(10) + [2]=> + string(4) "blue" + [3]=> + string(3) "red" + [4]=> + string(5) "green" + [5]=> + string(1) "a" +} +Done diff --git a/tests/std/array/array_reverse_basic2.phpt b/tests/std/array/array_reverse_basic2.phpt new file mode 100644 index 00000000..c10c12b0 --- /dev/null +++ b/tests/std/array/array_reverse_basic2.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test array_reverse() function : basic functionality - associative array for 'array' argument +--FILE-- + "hello", 123 => "number", 'string' => 'blue', "10" => 13.33); + +// Calling array_reverse() with default arguments +var_dump( array_reverse($array) ); + +// Calling array_reverse() with all possible arguments +var_dump( array_reverse($array, true) ); // expects the keys to be preserved +var_dump( array_reverse($array, false) ); // expects the keys not to be preserved + +echo "Done"; +?> +--EXPECT-- +*** Testing array_reverse() : basic functionality *** +array(4) { + [0]=> + float(13.33) + ["string"]=> + string(4) "blue" + [1]=> + string(6) "number" + ["a"]=> + string(5) "hello" +} +array(4) { + [10]=> + float(13.33) + ["string"]=> + string(4) "blue" + [123]=> + string(6) "number" + ["a"]=> + string(5) "hello" +} +array(4) { + [0]=> + float(13.33) + ["string"]=> + string(4) "blue" + [1]=> + string(6) "number" + ["a"]=> + string(5) "hello" +} +Done diff --git a/tests/std/array/array_reverse_variation3.phpt b/tests/std/array/array_reverse_variation3.phpt new file mode 100644 index 00000000..78299e68 --- /dev/null +++ b/tests/std/array/array_reverse_variation3.phpt @@ -0,0 +1,605 @@ +--TEST-- +Test array_reverse() function : usage variations - different array values for 'array' argument +--SKIPIF-- + +--FILE-- + "one", 2 => "two", 3 => "three"), + // explicit numeric keys, string values + array("one" => 1, "two" => 2, "three" => 3), + // string keys & numeric values + array(1 => 10, 2 => 20, 4 => 40, 3 => 30), + // explicit numeric keys and numeric values + array("one" => "ten", "two" => "twenty", "three" => "thirty"), + // string key/value + array("one" => 1, 2 => "two", 4 => "four"), + //mixed + // associative array, containing null/empty/boolean values as key/value + /*13*/ + array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null), + array(true => "true", false => "false", "false" => false, "true" => true), + array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''), + array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true), + array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6), + // array with repetitive keys + /*18*/ + array("One" => 1, "two" => 2, "One" => 10, "two" => 20, "three" => 3), + ); + // loop through the various elements of $arrays to test array_reverse() + $iterator = 1; + foreach ($arrays as $array) { + echo "-- Iteration {$iterator} --\n"; + // with default argument + echo "- with default argument -\n"; + var_dump(array_reverse($array)); + // with all possible arguments + echo "- with \$preserve keys = true -\n"; + var_dump(array_reverse($array, true)); + echo "- with \$preserve_keys = false -\n"; + var_dump(array_reverse($array, false)); + $iterator++; + } + // close the file resource used + fclose($fp); + echo "Done"; +} +?> +--EXPECT-- +*** Testing array_reverse() : usage variations *** +-- Iteration 1 -- +- with default argument - +array(2) { + [0]=> + int(2) + [1]=> + int(1) +} +- with $preserve keys = true - +array(2) { + [1]=> + int(2) + [0]=> + int(1) +} +- with $preserve_keys = false - +array(2) { + [0]=> + int(2) + [1]=> + int(1) +} +-- Iteration 2 -- +- with default argument - +array(2) { + [0]=> + float(2.2) + [1]=> + float(1.1) +} +- with $preserve keys = true - +array(2) { + [1]=> + float(2.2) + [0]=> + float(1.1) +} +- with $preserve_keys = false - +array(2) { + [0]=> + float(2.2) + [1]=> + float(1.1) +} +-- Iteration 3 -- +- with default argument - +array(2) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } +} +- with $preserve keys = true - +array(2) { + [1]=> + array(1) { + [0]=> + int(1) + } + [0]=> + array(1) { + [0]=> + int(2) + } +} +- with $preserve_keys = false - +array(2) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } +} +-- Iteration 4 -- +- with default argument - +array(2) { + [0]=> + bool(true) + [1]=> + bool(false) +} +- with $preserve keys = true - +array(2) { + [1]=> + bool(true) + [0]=> + bool(false) +} +- with $preserve_keys = false - +array(2) { + [0]=> + bool(true) + [1]=> + bool(false) +} +-- Iteration 5 -- +- with default argument - +array(0) { +} +- with $preserve keys = true - +array(0) { +} +- with $preserve_keys = false - +array(0) { +} +-- Iteration 6 -- +- with default argument - +array(1) { + [0]=> + NULL +} +- with $preserve keys = true - +array(1) { + [0]=> + NULL +} +- with $preserve_keys = false - +array(1) { + [0]=> + NULL +} +-- Iteration 7 -- +- with default argument - +array(6) { + [0]=> + string(5) "ccccc" + [1]=> + string(1) "c" + [2]=> + string(4) "bbbb" + [3]=> + string(1) "b" + [4]=> + string(4) "aaaa" + [5]=> + string(1) "a" +} +- with $preserve keys = true - +array(6) { + [5]=> + string(5) "ccccc" + [4]=> + string(1) "c" + [3]=> + string(4) "bbbb" + [2]=> + string(1) "b" + [1]=> + string(4) "aaaa" + [0]=> + string(1) "a" +} +- with $preserve_keys = false - +array(6) { + [0]=> + string(5) "ccccc" + [1]=> + string(1) "c" + [2]=> + string(4) "bbbb" + [3]=> + string(1) "b" + [4]=> + string(4) "aaaa" + [5]=> + string(1) "a" +} +-- Iteration 8 -- +- with default argument - +array(3) { + [0]=> + string(5) "three" + [1]=> + string(3) "two" + [2]=> + string(3) "one" +} +- with $preserve keys = true - +array(3) { + [3]=> + string(5) "three" + [2]=> + string(3) "two" + [1]=> + string(3) "one" +} +- with $preserve_keys = false - +array(3) { + [0]=> + string(5) "three" + [1]=> + string(3) "two" + [2]=> + string(3) "one" +} +-- Iteration 9 -- +- with default argument - +array(3) { + ["three"]=> + int(3) + ["two"]=> + int(2) + ["one"]=> + int(1) +} +- with $preserve keys = true - +array(3) { + ["three"]=> + int(3) + ["two"]=> + int(2) + ["one"]=> + int(1) +} +- with $preserve_keys = false - +array(3) { + ["three"]=> + int(3) + ["two"]=> + int(2) + ["one"]=> + int(1) +} +-- Iteration 10 -- +- with default argument - +array(4) { + [0]=> + int(30) + [1]=> + int(40) + [2]=> + int(20) + [3]=> + int(10) +} +- with $preserve keys = true - +array(4) { + [3]=> + int(30) + [4]=> + int(40) + [2]=> + int(20) + [1]=> + int(10) +} +- with $preserve_keys = false - +array(4) { + [0]=> + int(30) + [1]=> + int(40) + [2]=> + int(20) + [3]=> + int(10) +} +-- Iteration 11 -- +- with default argument - +array(3) { + ["three"]=> + string(6) "thirty" + ["two"]=> + string(6) "twenty" + ["one"]=> + string(3) "ten" +} +- with $preserve keys = true - +array(3) { + ["three"]=> + string(6) "thirty" + ["two"]=> + string(6) "twenty" + ["one"]=> + string(3) "ten" +} +- with $preserve_keys = false - +array(3) { + ["three"]=> + string(6) "thirty" + ["two"]=> + string(6) "twenty" + ["one"]=> + string(3) "ten" +} +-- Iteration 12 -- +- with default argument - +array(3) { + [0]=> + string(4) "four" + [1]=> + string(3) "two" + ["one"]=> + int(1) +} +- with $preserve keys = true - +array(3) { + [4]=> + string(4) "four" + [2]=> + string(3) "two" + ["one"]=> + int(1) +} +- with $preserve_keys = false - +array(3) { + [0]=> + string(4) "four" + [1]=> + string(3) "two" + ["one"]=> + int(1) +} +-- Iteration 13 -- +- with default argument - +array(3) { + ["null"]=> + NULL + ["NULL"]=> + NULL + [""]=> + string(4) "null" +} +- with $preserve keys = true - +array(3) { + ["null"]=> + NULL + ["NULL"]=> + NULL + [""]=> + string(4) "null" +} +- with $preserve_keys = false - +array(3) { + ["null"]=> + NULL + ["NULL"]=> + NULL + [""]=> + string(4) "null" +} +-- Iteration 14 -- +- with default argument - +array(4) { + ["true"]=> + bool(true) + ["false"]=> + bool(false) + [0]=> + string(5) "false" + [1]=> + string(4) "true" +} +- with $preserve keys = true - +array(4) { + ["true"]=> + bool(true) + ["false"]=> + bool(false) + [0]=> + string(5) "false" + [1]=> + string(4) "true" +} +- with $preserve_keys = false - +array(4) { + ["true"]=> + bool(true) + ["false"]=> + bool(false) + [0]=> + string(5) "false" + [1]=> + string(4) "true" +} +-- Iteration 15 -- +- with default argument - +array(3) { + ["emptys"]=> + string(0) "" + ["emptyd"]=> + string(0) "" + [""]=> + string(6) "emptys" +} +- with $preserve keys = true - +array(3) { + ["emptys"]=> + string(0) "" + ["emptyd"]=> + string(0) "" + [""]=> + string(6) "emptys" +} +- with $preserve_keys = false - +array(3) { + ["emptys"]=> + string(0) "" + ["emptyd"]=> + string(0) "" + [""]=> + string(6) "emptys" +} +-- Iteration 16 -- +- with default argument - +array(6) { + [0]=> + bool(true) + [1]=> + bool(false) + [2]=> + NULL + [3]=> + NULL + [4]=> + string(0) "" + [5]=> + string(0) "" +} +- with $preserve keys = true - +array(6) { + [6]=> + bool(true) + [5]=> + bool(false) + [4]=> + NULL + [3]=> + NULL + [2]=> + string(0) "" + [1]=> + string(0) "" +} +- with $preserve_keys = false - +array(6) { + [0]=> + bool(true) + [1]=> + bool(false) + [2]=> + NULL + [3]=> + NULL + [4]=> + string(0) "" + [5]=> + string(0) "" +} +-- Iteration 17 -- +- with default argument - +array(3) { + [0]=> + int(6) + [1]=> + int(5) + [""]=> + int(4) +} +- with $preserve keys = true - +array(3) { + [1]=> + int(6) + [0]=> + int(5) + [""]=> + int(4) +} +- with $preserve_keys = false - +array(3) { + [0]=> + int(6) + [1]=> + int(5) + [""]=> + int(4) +} +-- Iteration 18 -- +- with default argument - +array(3) { + ["three"]=> + int(3) + ["two"]=> + int(20) + ["One"]=> + int(10) +} +- with $preserve keys = true - +array(3) { + ["three"]=> + int(3) + ["two"]=> + int(20) + ["One"]=> + int(10) +} +- with $preserve_keys = false - +array(3) { + ["three"]=> + int(3) + ["two"]=> + int(20) + ["One"]=> + int(10) +} +Done diff --git a/tests/std/array/array_reverse_variation4.phpt b/tests/std/array/array_reverse_variation4.phpt new file mode 100644 index 00000000..1e367884 --- /dev/null +++ b/tests/std/array/array_reverse_variation4.phpt @@ -0,0 +1,317 @@ +--TEST-- +Test array_reverse() function : usage variations - assoc. array with diff. keys for 'array' argument +--SKIPIF-- + +--FILE-- + "0"), + array(1 => "1"), + array(1 => "1", 2 => "2", 3 => "3", 4 => "4"), + // arrays with string keys + array("\tHello" => 111, "re\td" => "color", "\v\fworld" => 2.2, "pen\n" => 33), + /*8*/ + array("\tHello" => 111, "re\td" => "color", "\v\fworld" => 2.2, "pen\n" => 33), + array("hello", $heredoc => "string"), + // heredoc + // array with object, unset variable and resource variable + array(@$unset_var => "hello", $fp => 'resource'), + // array with mixed values + /*11*/ + array('hello' => 1, "fruit" => 2.2, $fp => 'resource', 133 => "int", @$unset_var => "unset", $heredoc => "heredoc"), + ); + // loop through the various elements of $arrays to test array_reverse() + $iterator = 1; + foreach ($arrays as $array) { + echo "-- Iteration {$iterator} --\n"; + // with default argument + echo "- default argument -\n"; + var_dump(array_reverse($array)); + // with $preserve_keys argument + echo "- \$preserve keys = true -\n"; + var_dump(array_reverse($array, true)); + echo "- \$preserve_keys = false -\n"; + var_dump(array_reverse($array, false)); + $iterator++; + } + // close the file resource used + fclose($fp); + echo "Done"; +} +?> +--EXPECTF-- +*** Testing array_reverse() : usage variations *** + +Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d + +Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d +-- Iteration 1 -- +- default argument - +array(0) { +} +- $preserve keys = true - +array(0) { +} +- $preserve_keys = false - +array(0) { +} +-- Iteration 2 -- +- default argument - +array(1) { + [0]=> + string(1) "0" +} +- $preserve keys = true - +array(1) { + [0]=> + string(1) "0" +} +- $preserve_keys = false - +array(1) { + [0]=> + string(1) "0" +} +-- Iteration 3 -- +- default argument - +array(1) { + [0]=> + string(1) "1" +} +- $preserve keys = true - +array(1) { + [1]=> + string(1) "1" +} +- $preserve_keys = false - +array(1) { + [0]=> + string(1) "1" +} +-- Iteration 4 -- +- default argument - +array(4) { + [0]=> + string(1) "4" + [1]=> + string(1) "3" + [2]=> + string(1) "2" + [3]=> + string(1) "1" +} +- $preserve keys = true - +array(4) { + [4]=> + string(1) "4" + [3]=> + string(1) "3" + [2]=> + string(1) "2" + [1]=> + string(1) "1" +} +- $preserve_keys = false - +array(4) { + [0]=> + string(1) "4" + [1]=> + string(1) "3" + [2]=> + string(1) "2" + [3]=> + string(1) "1" +} +-- Iteration 5 -- +- default argument - +array(4) { + ["pen +"]=> + int(33) + [" world"]=> + float(2.2) + ["re d"]=> + string(5) "color" + [" Hello"]=> + int(111) +} +- $preserve keys = true - +array(4) { + ["pen +"]=> + int(33) + [" world"]=> + float(2.2) + ["re d"]=> + string(5) "color" + [" Hello"]=> + int(111) +} +- $preserve_keys = false - +array(4) { + ["pen +"]=> + int(33) + [" world"]=> + float(2.2) + ["re d"]=> + string(5) "color" + [" Hello"]=> + int(111) +} +-- Iteration 6 -- +- default argument - +array(4) { + ["pen +"]=> + int(33) + [" world"]=> + float(2.2) + ["re d"]=> + string(5) "color" + [" Hello"]=> + int(111) +} +- $preserve keys = true - +array(4) { + ["pen +"]=> + int(33) + [" world"]=> + float(2.2) + ["re d"]=> + string(5) "color" + [" Hello"]=> + int(111) +} +- $preserve_keys = false - +array(4) { + ["pen +"]=> + int(33) + [" world"]=> + float(2.2) + ["re d"]=> + string(5) "color" + [" Hello"]=> + int(111) +} +-- Iteration 7 -- +- default argument - +array(2) { + ["Hello world"]=> + string(6) "string" + [0]=> + string(5) "hello" +} +- $preserve keys = true - +array(2) { + ["Hello world"]=> + string(6) "string" + [0]=> + string(5) "hello" +} +- $preserve_keys = false - +array(2) { + ["Hello world"]=> + string(6) "string" + [0]=> + string(5) "hello" +} +-- Iteration 8 -- +- default argument - +array(2) { + [0]=> + string(8) "resource" + [""]=> + string(5) "hello" +} +- $preserve keys = true - +array(2) { + [5]=> + string(8) "resource" + [""]=> + string(5) "hello" +} +- $preserve_keys = false - +array(2) { + [0]=> + string(8) "resource" + [""]=> + string(5) "hello" +} +-- Iteration 9 -- +- default argument - +array(6) { + ["Hello world"]=> + string(7) "heredoc" + [""]=> + string(5) "unset" + [0]=> + string(3) "int" + [1]=> + string(8) "resource" + ["fruit"]=> + float(2.2) + ["hello"]=> + int(1) +} +- $preserve keys = true - +array(6) { + ["Hello world"]=> + string(7) "heredoc" + [""]=> + string(5) "unset" + [133]=> + string(3) "int" + [5]=> + string(8) "resource" + ["fruit"]=> + float(2.2) + ["hello"]=> + int(1) +} +- $preserve_keys = false - +array(6) { + ["Hello world"]=> + string(7) "heredoc" + [""]=> + string(5) "unset" + [0]=> + string(3) "int" + [1]=> + string(8) "resource" + ["fruit"]=> + float(2.2) + ["hello"]=> + int(1) +} +Done diff --git a/tests/std/array/array_reverse_variation5.phpt b/tests/std/array/array_reverse_variation5.phpt new file mode 100644 index 00000000..25425e07 --- /dev/null +++ b/tests/std/array/array_reverse_variation5.phpt @@ -0,0 +1,389 @@ +--TEST-- +Test array_reverse() function : usage variations - assoc. array with diff. value for 'array' argument +--INI-- +precision=12 +--SKIPIF-- + +--FILE-- + 0), + array("1" => 1), + array("one" => 1, 'two' => 2, "three" => 3, 4 => 4), + // arrays with float values + /*5*/ + array("float" => 2.3333), + array("f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => 33333333.333333), + // arrays with string values + array(111 => "\tHello", "red" => "col\tor", 2 => "\v\fworld", 3 => "pen\n"), + /*8*/ + array(111 => '\tHello', "red" => 'col\tor', 2 => '\v\fworld', 3 => 'pen\n'), + array(1 => "hello", "heredoc" => $heredoc), + // array with object, unset variable and resource variable + array(11 => new classA(), "unset" => @$unset_var, "resource" => $fp), + // array with mixed values + /*11*/ + array(1 => 'hello', 2 => new classA(), 222 => "fruit", 'resource' => $fp, "int" => 133, "float" => 444.432, "unset" => @$unset_var, "heredoc" => $heredoc), + ); + // loop through the various elements of $arrays to test array_reverse() + $iterator = 1; + foreach ($arrays as $array) { + echo "-- Iteration {$iterator} --\n"; + // with default argument + echo "- default argument -\n"; + var_dump(array_reverse($array)); + // with $preserve_keys argument + echo "- \$preserve keys = true -\n"; + var_dump(array_reverse($array, true)); + echo "- \$preserve_keys = false -\n"; + var_dump(array_reverse($array, false)); + $iterator++; + } + // close the file resource used + fclose($fp); + echo "Done"; +} +?> +--EXPECTF-- +*** Testing array_reverse() : usage variations *** +-- Iteration 1 -- +- default argument - +array(0) { +} +- $preserve keys = true - +array(0) { +} +- $preserve_keys = false - +array(0) { +} +-- Iteration 2 -- +- default argument - +array(1) { + [0]=> + int(0) +} +- $preserve keys = true - +array(1) { + [0]=> + int(0) +} +- $preserve_keys = false - +array(1) { + [0]=> + int(0) +} +-- Iteration 3 -- +- default argument - +array(1) { + [0]=> + int(1) +} +- $preserve keys = true - +array(1) { + [1]=> + int(1) +} +- $preserve_keys = false - +array(1) { + [0]=> + int(1) +} +-- Iteration 4 -- +- default argument - +array(4) { + [0]=> + int(4) + ["three"]=> + int(3) + ["two"]=> + int(2) + ["one"]=> + int(1) +} +- $preserve keys = true - +array(4) { + [4]=> + int(4) + ["three"]=> + int(3) + ["two"]=> + int(2) + ["one"]=> + int(1) +} +- $preserve_keys = false - +array(4) { + [0]=> + int(4) + ["three"]=> + int(3) + ["two"]=> + int(2) + ["one"]=> + int(1) +} +-- Iteration 5 -- +- default argument - +array(1) { + ["float"]=> + float(2.3333) +} +- $preserve keys = true - +array(1) { + ["float"]=> + float(2.3333) +} +- $preserve_keys = false - +array(1) { + ["float"]=> + float(2.3333) +} +-- Iteration 6 -- +- default argument - +array(4) { + ["f4"]=> + float(33333333.333333) + [0]=> + float(4.89999922839999) + ["f2"]=> + float(3.33) + ["f1"]=> + float(1.2) +} +- $preserve keys = true - +array(4) { + ["f4"]=> + float(33333333.333333) + [3]=> + float(4.89999922839999) + ["f2"]=> + float(3.33) + ["f1"]=> + float(1.2) +} +- $preserve_keys = false - +array(4) { + ["f4"]=> + float(33333333.333333) + [0]=> + float(4.89999922839999) + ["f2"]=> + float(3.33) + ["f1"]=> + float(1.2) +} +-- Iteration 7 -- +- default argument - +array(4) { + [0]=> + string(4) "pen +" + [1]=> + string(7) " world" + ["red"]=> + string(6) "col or" + [2]=> + string(6) " Hello" +} +- $preserve keys = true - +array(4) { + [3]=> + string(4) "pen +" + [2]=> + string(7) " world" + ["red"]=> + string(6) "col or" + [111]=> + string(6) " Hello" +} +- $preserve_keys = false - +array(4) { + [0]=> + string(4) "pen +" + [1]=> + string(7) " world" + ["red"]=> + string(6) "col or" + [2]=> + string(6) " Hello" +} +-- Iteration 8 -- +- default argument - +array(4) { + [0]=> + string(5) "pen\n" + [1]=> + string(9) "\v\fworld" + ["red"]=> + string(7) "col\tor" + [2]=> + string(7) "\tHello" +} +- $preserve keys = true - +array(4) { + [3]=> + string(5) "pen\n" + [2]=> + string(9) "\v\fworld" + ["red"]=> + string(7) "col\tor" + [111]=> + string(7) "\tHello" +} +- $preserve_keys = false - +array(4) { + [0]=> + string(5) "pen\n" + [1]=> + string(9) "\v\fworld" + ["red"]=> + string(7) "col\tor" + [2]=> + string(7) "\tHello" +} +-- Iteration 9 -- +- default argument - +array(2) { + ["heredoc"]=> + string(11) "Hello world" + [0]=> + string(5) "hello" +} +- $preserve keys = true - +array(2) { + ["heredoc"]=> + string(11) "Hello world" + [1]=> + string(5) "hello" +} +- $preserve_keys = false - +array(2) { + ["heredoc"]=> + string(11) "Hello world" + [0]=> + string(5) "hello" +} +-- Iteration 10 -- +- default argument - +array(3) { + ["resource"]=> + resource(%d) of type (stream) + ["unset"]=> + NULL + [0]=> + object(classA)#%d (0) { + } +} +- $preserve keys = true - +array(3) { + ["resource"]=> + resource(%d) of type (stream) + ["unset"]=> + NULL + [11]=> + object(classA)#%d (0) { + } +} +- $preserve_keys = false - +array(3) { + ["resource"]=> + resource(%d) of type (stream) + ["unset"]=> + NULL + [0]=> + object(classA)#%d (0) { + } +} +-- Iteration 11 -- +- default argument - +array(8) { + ["heredoc"]=> + string(11) "Hello world" + ["unset"]=> + NULL + ["float"]=> + float(444.432) + ["int"]=> + int(133) + ["resource"]=> + resource(%d) of type (stream) + [0]=> + string(5) "fruit" + [1]=> + object(classA)#%d (0) { + } + [2]=> + string(5) "hello" +} +- $preserve keys = true - +array(8) { + ["heredoc"]=> + string(11) "Hello world" + ["unset"]=> + NULL + ["float"]=> + float(444.432) + ["int"]=> + int(133) + ["resource"]=> + resource(%d) of type (stream) + [222]=> + string(5) "fruit" + [2]=> + object(classA)#%d (0) { + } + [1]=> + string(5) "hello" +} +- $preserve_keys = false - +array(8) { + ["heredoc"]=> + string(11) "Hello world" + ["unset"]=> + NULL + ["float"]=> + float(444.432) + ["int"]=> + int(133) + ["resource"]=> + resource(%d) of type (stream) + [0]=> + string(5) "fruit" + [1]=> + object(classA)#%d (0) { + } + [2]=> + string(5) "hello" +} +Done diff --git a/tests/std/array/array_reverse_variation6.phpt b/tests/std/array/array_reverse_variation6.phpt new file mode 100644 index 00000000..8ad3451d --- /dev/null +++ b/tests/std/array/array_reverse_variation6.phpt @@ -0,0 +1,204 @@ +--TEST-- +Test array_reverse() function : usage variations - two dimensional arrays for 'array' argument +--FILE-- + 'red', 'item' => 'pen', 'place' => 'LA'), + + // numeric array + array(1, 2, 3, 4, 5), + + // combination of numeric and associative arrays + array('a' => 'green', 'red', 'brown', 33, 88, 'orange', 'item' => 'ball') +); + +// calling array_reverse() with various types of 2-d arrays +// with default arguments +echo "-- with default argument --\n"; +var_dump( array_reverse($two_dimensional_array) ); // whole array +var_dump( array_reverse($two_dimensional_array[1]) ); // sub array + +// with $preserve_keys argument +echo "-- with all possible arguments --\n"; +// whole array +var_dump( array_reverse($two_dimensional_array, true) ); +var_dump( array_reverse($two_dimensional_array, false) ); +// sub array +var_dump( array_reverse($two_dimensional_array[1], true) ); +var_dump( array_reverse($two_dimensional_array[1], false) ); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_reverse() : usage variations *** +-- with default argument -- +array(3) { + [0]=> + array(7) { + ["a"]=> + string(5) "green" + [0]=> + string(3) "red" + [1]=> + string(5) "brown" + [2]=> + int(33) + [3]=> + int(88) + [4]=> + string(6) "orange" + ["item"]=> + string(4) "ball" + } + [1]=> + array(5) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + } + [2]=> + array(3) { + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + ["place"]=> + string(2) "LA" + } +} +array(5) { + [0]=> + int(5) + [1]=> + int(4) + [2]=> + int(3) + [3]=> + int(2) + [4]=> + int(1) +} +-- with all possible arguments -- +array(3) { + [2]=> + array(7) { + ["a"]=> + string(5) "green" + [0]=> + string(3) "red" + [1]=> + string(5) "brown" + [2]=> + int(33) + [3]=> + int(88) + [4]=> + string(6) "orange" + ["item"]=> + string(4) "ball" + } + [1]=> + array(5) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + } + [0]=> + array(3) { + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + ["place"]=> + string(2) "LA" + } +} +array(3) { + [0]=> + array(7) { + ["a"]=> + string(5) "green" + [0]=> + string(3) "red" + [1]=> + string(5) "brown" + [2]=> + int(33) + [3]=> + int(88) + [4]=> + string(6) "orange" + ["item"]=> + string(4) "ball" + } + [1]=> + array(5) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + } + [2]=> + array(3) { + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + ["place"]=> + string(2) "LA" + } +} +array(5) { + [4]=> + int(5) + [3]=> + int(4) + [2]=> + int(3) + [1]=> + int(2) + [0]=> + int(1) +} +array(5) { + [0]=> + int(5) + [1]=> + int(4) + [2]=> + int(3) + [3]=> + int(2) + [4]=> + int(1) +} +Done diff --git a/tests/std/array/array_search.phpt b/tests/std/array/array_search.phpt new file mode 100644 index 00000000..6219efd3 --- /dev/null +++ b/tests/std/array/array_search.phpt @@ -0,0 +1,29 @@ +--TEST-- +Test array_search()/in_array() +--FILE-- +'d'); +$arr4 = array("a\0b"=>'e','key'=>'d', 'f'); + +var_dump(in_array(123, $arr2)); +var_dump(in_array(123, $arr1)); +var_dump(array_search(123, $arr1)); +var_dump(in_array('a', $arr1)); +var_dump(array_search('a', $arr1)); +var_dump(array_search('e', $arr4)); +var_dump(array_search('d', $arr4)); + +echo "Done\n"; +?> +--EXPECTF-- +bool(false) +bool(false) +bool(false) +bool(true) +int(0) +string(3) "a%0b" +string(3) "key" +Done diff --git a/tests/std/array/array_search1.phpt b/tests/std/array/array_search1.phpt new file mode 100644 index 00000000..33d9c75d --- /dev/null +++ b/tests/std/array/array_search1.phpt @@ -0,0 +1,28 @@ +--TEST-- +array_search() tests +--FILE-- +0, 2=>1, 4=>3, "a"=>"b", "c"=>"d"); + +var_dump(array_search("a",$a)); +var_dump(array_search("0",$a, true)); +var_dump(array_search("0",$a)); +var_dump(array_search(0,$a)); +var_dump(array_search(1,$a)); +var_dump(array_search("d",$a, true)); +var_dump(array_search("d",$a)); +var_dump(array_search(-1,$a, true)); + +echo "Done\n"; +?> +--EXPECT-- +bool(false) +bool(false) +int(1) +int(1) +int(2) +string(1) "c" +string(1) "c" +bool(false) +Done diff --git a/tests/std/array/array_search_variation1.phpt b/tests/std/array/array_search_variation1.phpt new file mode 100644 index 00000000..a2838810 --- /dev/null +++ b/tests/std/array/array_search_variation1.phpt @@ -0,0 +1,635 @@ +--TEST-- +Test array_search() function : usage variations - different needle values +--FILE-- + "A", 2 => "B", "C" => 3, 4 => 4, "one" => 1, "" => NULL, "b", "ab", "abcd"), + array(4, array(1, 2 => 3), "one" => 1, "5" => 5 ), + array(-1, -2, -3, -4, -2.989888, "-0.005" => "neg0.005", 2 => "float2", "-.9" => -.9), + array(TRUE, FALSE), + array("", array()), + array("abcd\x00abcd\x00abcd"), + array("abcd\tabcd\nabcd\rabcd\0abcdefghij") +); + +$array_compare = array ( + 4, + "4", + 4.00, + "b", + "5", + -2, + -2.0, + -2.98989, + "-.9", + "True", + "", + array(), + NULL, + "ab", + "abcd", + 0.0, + -0, + "abcd\x00abcd\x00abcd" +); +/* loop to check if elements in $array_compare exist in $arrays + using array_search() */ +$counter = 1; +foreach($arrays as $array) { + foreach($array_compare as $compare) { + echo "-- Iteration $counter --\n"; + //strict option OFF + var_dump(array_search($compare,$array)); + //strict option ON + var_dump(array_search($compare,$array,TRUE)); + //strict option OFF + var_dump(array_search($compare,$array,FALSE)); + $counter++; + } +} + +echo "Done\n"; +?> +--EXPECT-- +*** Testing array_search() with different needle values *** +-- Iteration 1 -- +bool(false) +bool(false) +bool(false) +-- Iteration 2 -- +bool(false) +bool(false) +bool(false) +-- Iteration 3 -- +bool(false) +bool(false) +bool(false) +-- Iteration 4 -- +bool(false) +bool(false) +bool(false) +-- Iteration 5 -- +bool(false) +bool(false) +bool(false) +-- Iteration 6 -- +bool(false) +bool(false) +bool(false) +-- Iteration 7 -- +bool(false) +bool(false) +bool(false) +-- Iteration 8 -- +bool(false) +bool(false) +bool(false) +-- Iteration 9 -- +bool(false) +bool(false) +bool(false) +-- Iteration 10 -- +bool(false) +bool(false) +bool(false) +-- Iteration 11 -- +bool(false) +bool(false) +bool(false) +-- Iteration 12 -- +bool(false) +bool(false) +bool(false) +-- Iteration 13 -- +int(0) +bool(false) +int(0) +-- Iteration 14 -- +bool(false) +bool(false) +bool(false) +-- Iteration 15 -- +bool(false) +bool(false) +bool(false) +-- Iteration 16 -- +int(0) +bool(false) +int(0) +-- Iteration 17 -- +int(0) +int(0) +int(0) +-- Iteration 18 -- +bool(false) +bool(false) +bool(false) +-- Iteration 19 -- +int(4) +int(4) +int(4) +-- Iteration 20 -- +int(4) +bool(false) +int(4) +-- Iteration 21 -- +int(4) +bool(false) +int(4) +-- Iteration 22 -- +int(5) +int(5) +int(5) +-- Iteration 23 -- +bool(false) +bool(false) +bool(false) +-- Iteration 24 -- +bool(false) +bool(false) +bool(false) +-- Iteration 25 -- +bool(false) +bool(false) +bool(false) +-- Iteration 26 -- +bool(false) +bool(false) +bool(false) +-- Iteration 27 -- +bool(false) +bool(false) +bool(false) +-- Iteration 28 -- +bool(false) +bool(false) +bool(false) +-- Iteration 29 -- +string(0) "" +bool(false) +string(0) "" +-- Iteration 30 -- +string(0) "" +bool(false) +string(0) "" +-- Iteration 31 -- +string(0) "" +string(0) "" +string(0) "" +-- Iteration 32 -- +int(6) +int(6) +int(6) +-- Iteration 33 -- +int(7) +int(7) +int(7) +-- Iteration 34 -- +string(0) "" +bool(false) +string(0) "" +-- Iteration 35 -- +string(0) "" +bool(false) +string(0) "" +-- Iteration 36 -- +bool(false) +bool(false) +bool(false) +-- Iteration 37 -- +int(0) +int(0) +int(0) +-- Iteration 38 -- +int(0) +bool(false) +int(0) +-- Iteration 39 -- +int(0) +bool(false) +int(0) +-- Iteration 40 -- +bool(false) +bool(false) +bool(false) +-- Iteration 41 -- +int(5) +bool(false) +int(5) +-- Iteration 42 -- +bool(false) +bool(false) +bool(false) +-- Iteration 43 -- +bool(false) +bool(false) +bool(false) +-- Iteration 44 -- +bool(false) +bool(false) +bool(false) +-- Iteration 45 -- +bool(false) +bool(false) +bool(false) +-- Iteration 46 -- +bool(false) +bool(false) +bool(false) +-- Iteration 47 -- +bool(false) +bool(false) +bool(false) +-- Iteration 48 -- +bool(false) +bool(false) +bool(false) +-- Iteration 49 -- +bool(false) +bool(false) +bool(false) +-- Iteration 50 -- +bool(false) +bool(false) +bool(false) +-- Iteration 51 -- +bool(false) +bool(false) +bool(false) +-- Iteration 52 -- +bool(false) +bool(false) +bool(false) +-- Iteration 53 -- +bool(false) +bool(false) +bool(false) +-- Iteration 54 -- +bool(false) +bool(false) +bool(false) +-- Iteration 55 -- +bool(false) +bool(false) +bool(false) +-- Iteration 56 -- +bool(false) +bool(false) +bool(false) +-- Iteration 57 -- +bool(false) +bool(false) +bool(false) +-- Iteration 58 -- +bool(false) +bool(false) +bool(false) +-- Iteration 59 -- +bool(false) +bool(false) +bool(false) +-- Iteration 60 -- +int(1) +int(1) +int(1) +-- Iteration 61 -- +int(1) +bool(false) +int(1) +-- Iteration 62 -- +bool(false) +bool(false) +bool(false) +-- Iteration 63 -- +string(3) "-.9" +bool(false) +string(3) "-.9" +-- Iteration 64 -- +bool(false) +bool(false) +bool(false) +-- Iteration 65 -- +bool(false) +bool(false) +bool(false) +-- Iteration 66 -- +bool(false) +bool(false) +bool(false) +-- Iteration 67 -- +bool(false) +bool(false) +bool(false) +-- Iteration 68 -- +bool(false) +bool(false) +bool(false) +-- Iteration 69 -- +bool(false) +bool(false) +bool(false) +-- Iteration 70 -- +bool(false) +bool(false) +bool(false) +-- Iteration 71 -- +bool(false) +bool(false) +bool(false) +-- Iteration 72 -- +bool(false) +bool(false) +bool(false) +-- Iteration 73 -- +int(0) +bool(false) +int(0) +-- Iteration 74 -- +int(0) +bool(false) +int(0) +-- Iteration 75 -- +int(0) +bool(false) +int(0) +-- Iteration 76 -- +int(0) +bool(false) +int(0) +-- Iteration 77 -- +int(0) +bool(false) +int(0) +-- Iteration 78 -- +int(0) +bool(false) +int(0) +-- Iteration 79 -- +int(0) +bool(false) +int(0) +-- Iteration 80 -- +int(0) +bool(false) +int(0) +-- Iteration 81 -- +int(0) +bool(false) +int(0) +-- Iteration 82 -- +int(0) +bool(false) +int(0) +-- Iteration 83 -- +int(1) +bool(false) +int(1) +-- Iteration 84 -- +int(1) +bool(false) +int(1) +-- Iteration 85 -- +int(1) +bool(false) +int(1) +-- Iteration 86 -- +int(0) +bool(false) +int(0) +-- Iteration 87 -- +int(0) +bool(false) +int(0) +-- Iteration 88 -- +int(1) +bool(false) +int(1) +-- Iteration 89 -- +int(1) +bool(false) +int(1) +-- Iteration 90 -- +int(0) +bool(false) +int(0) +-- Iteration 91 -- +bool(false) +bool(false) +bool(false) +-- Iteration 92 -- +bool(false) +bool(false) +bool(false) +-- Iteration 93 -- +bool(false) +bool(false) +bool(false) +-- Iteration 94 -- +bool(false) +bool(false) +bool(false) +-- Iteration 95 -- +bool(false) +bool(false) +bool(false) +-- Iteration 96 -- +bool(false) +bool(false) +bool(false) +-- Iteration 97 -- +bool(false) +bool(false) +bool(false) +-- Iteration 98 -- +bool(false) +bool(false) +bool(false) +-- Iteration 99 -- +bool(false) +bool(false) +bool(false) +-- Iteration 100 -- +bool(false) +bool(false) +bool(false) +-- Iteration 101 -- +int(0) +int(0) +int(0) +-- Iteration 102 -- +int(1) +int(1) +int(1) +-- Iteration 103 -- +int(0) +bool(false) +int(0) +-- Iteration 104 -- +bool(false) +bool(false) +bool(false) +-- Iteration 105 -- +bool(false) +bool(false) +bool(false) +-- Iteration 106 -- +bool(false) +bool(false) +bool(false) +-- Iteration 107 -- +bool(false) +bool(false) +bool(false) +-- Iteration 108 -- +bool(false) +bool(false) +bool(false) +-- Iteration 109 -- +bool(false) +bool(false) +bool(false) +-- Iteration 110 -- +bool(false) +bool(false) +bool(false) +-- Iteration 111 -- +bool(false) +bool(false) +bool(false) +-- Iteration 112 -- +bool(false) +bool(false) +bool(false) +-- Iteration 113 -- +bool(false) +bool(false) +bool(false) +-- Iteration 114 -- +bool(false) +bool(false) +bool(false) +-- Iteration 115 -- +bool(false) +bool(false) +bool(false) +-- Iteration 116 -- +bool(false) +bool(false) +bool(false) +-- Iteration 117 -- +bool(false) +bool(false) +bool(false) +-- Iteration 118 -- +bool(false) +bool(false) +bool(false) +-- Iteration 119 -- +bool(false) +bool(false) +bool(false) +-- Iteration 120 -- +bool(false) +bool(false) +bool(false) +-- Iteration 121 -- +bool(false) +bool(false) +bool(false) +-- Iteration 122 -- +bool(false) +bool(false) +bool(false) +-- Iteration 123 -- +bool(false) +bool(false) +bool(false) +-- Iteration 124 -- +bool(false) +bool(false) +bool(false) +-- Iteration 125 -- +bool(false) +bool(false) +bool(false) +-- Iteration 126 -- +int(0) +int(0) +int(0) +-- Iteration 127 -- +bool(false) +bool(false) +bool(false) +-- Iteration 128 -- +bool(false) +bool(false) +bool(false) +-- Iteration 129 -- +bool(false) +bool(false) +bool(false) +-- Iteration 130 -- +bool(false) +bool(false) +bool(false) +-- Iteration 131 -- +bool(false) +bool(false) +bool(false) +-- Iteration 132 -- +bool(false) +bool(false) +bool(false) +-- Iteration 133 -- +bool(false) +bool(false) +bool(false) +-- Iteration 134 -- +bool(false) +bool(false) +bool(false) +-- Iteration 135 -- +bool(false) +bool(false) +bool(false) +-- Iteration 136 -- +bool(false) +bool(false) +bool(false) +-- Iteration 137 -- +bool(false) +bool(false) +bool(false) +-- Iteration 138 -- +bool(false) +bool(false) +bool(false) +-- Iteration 139 -- +bool(false) +bool(false) +bool(false) +-- Iteration 140 -- +bool(false) +bool(false) +bool(false) +-- Iteration 141 -- +bool(false) +bool(false) +bool(false) +-- Iteration 142 -- +bool(false) +bool(false) +bool(false) +-- Iteration 143 -- +bool(false) +bool(false) +bool(false) +-- Iteration 144 -- +bool(false) +bool(false) +bool(false) +Done diff --git a/tests/std/array/array_search_variation2.phpt b/tests/std/array/array_search_variation2.phpt new file mode 100644 index 00000000..83c3a925 --- /dev/null +++ b/tests/std/array/array_search_variation2.phpt @@ -0,0 +1,98 @@ +--TEST-- +Test array_search() function : usage variations - different haystack values +--SKIPIF-- + +--FILE-- +'d', + 3, + ".001" =>-67, + "-.051" =>"k", + 0 =>"-.08", + "e" =>"5", + "y" =>NULL, + NULL =>"", + 0, + TRUE, + FALSE, + -27.39999999999, + " ", + "abcd\x00abcd\x00\abcd\x00abcdefghij", + "abcd\nabcd\tabcd\rabcd\0abcd" +); +$array_type = array(TRUE, FALSE, 1, 0, -1, "1", "0", "-1", NULL, array(), "PHP", ""); +/* loop to do loose and strict type check of elements in + $array_type on elements in $misc_array using array_search(); + checking PHP type comparison tables +*/ +$counter = 1; +foreach($array_type as $type) { + echo "-- Iteration $counter --\n"; + //loose type checking + var_dump( array_search($type,$misc_array ) ); + //strict type checking + var_dump( array_search($type,$misc_array,true) ); + //loose type checking + var_dump( array_search($type,$misc_array,false) ); + $counter++; +} + +echo "Done\n"; +?> +--EXPECT-- +*** Testing array_search() with different haystack values *** +-- Iteration 1 -- +int(0) +int(3) +int(0) +-- Iteration 2 -- +string(1) "y" +int(4) +string(1) "y" +-- Iteration 3 -- +int(3) +bool(false) +int(3) +-- Iteration 4 -- +string(1) "y" +int(2) +string(1) "y" +-- Iteration 5 -- +int(3) +bool(false) +int(3) +-- Iteration 6 -- +int(3) +bool(false) +int(3) +-- Iteration 7 -- +int(2) +bool(false) +int(2) +-- Iteration 8 -- +int(3) +bool(false) +int(3) +-- Iteration 9 -- +string(1) "y" +string(1) "y" +string(1) "y" +-- Iteration 10 -- +string(1) "y" +bool(false) +string(1) "y" +-- Iteration 11 -- +int(3) +bool(false) +int(3) +-- Iteration 12 -- +string(1) "y" +string(0) "" +string(1) "y" +Done diff --git a/tests/std/array/array_search_variation3.phpt b/tests/std/array/array_search_variation3.phpt new file mode 100644 index 00000000..674e9916 --- /dev/null +++ b/tests/std/array/array_search_variation3.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test array_search() function : usage variations - haystack as sub-array/object +--SKIPIF-- + +--FILE-- + "one", "two" => 2, 3 => 3); + public function foo() + { + echo "Public function\n"; + } +} +function main() +{ + /* checking for sub-arrays with array_search() */ + echo "*** Testing sub-arrays with array_search() ***\n"; + $sub_array = array("one", array(1, 2 => "two", "three" => 3), 4 => "four", "five" => 5, array('', 'i')); + var_dump(array_search("four", $sub_array)); + //checking for element in a sub-array + var_dump(array_search(3, $sub_array[1])); + var_dump(array_search(array('', 'i'), $sub_array)); + /* checking for objects in array_search() */ + echo "\n*** Testing objects with array_search() ***\n"; + $array_search_obj = new array_search_check(); + //creating new object + //error: as wrong datatype for second argument + try { + var_dump(array_search("array_var", $array_search_obj)); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + //error: as wrong datatype for second argument + try { + var_dump(array_search("foo", $array_search_obj)); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + //element found as "one" exists in array $array_var + var_dump(array_search("one", $array_search_obj->array_var)); + echo "Done\n"; +} +?> +--EXPECT-- +*** Testing sub-arrays with array_search() *** +int(4) +string(5) "three" +int(5) + +*** Testing objects with array_search() *** +array_search(): Argument #2 ($haystack) must be of type array, array_search_check given +array_search(): Argument #2 ($haystack) must be of type array, array_search_check given +int(1) +Done diff --git a/tests/std/array/array_search_variation4.phpt b/tests/std/array/array_search_variation4.phpt new file mode 100644 index 00000000..fa5cdf62 --- /dev/null +++ b/tests/std/array/array_search_variation4.phpt @@ -0,0 +1,68 @@ +--TEST-- +Test array_search() function : usage variations - haystack as resource/multi dimensional array +--FILE-- + TRUE, "b"=> TRUE, + array("c"=> TRUE, "d"=>TRUE) + ) + ) + ); + +//matching string having integer in beginning, result:true in loose type check +var_dump( array_search('123abc', array(123)) ); +var_dump( array_search('123abc', array(123), TRUE) ); // false in strict mode + +echo "Done\n"; +?> +--EXPECT-- +*** Testing resource type with array_search() *** +int(0) +bool(false) + +*** Testing miscelleneos inputs with array_search() *** +bool(false) +bool(false) +bool(false) +bool(false) +bool(true) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +Done diff --git a/tests/std/array/array_shift_basic.phpt b/tests/std/array/array_shift_basic.phpt new file mode 100644 index 00000000..ad0d70ea --- /dev/null +++ b/tests/std/array/array_shift_basic.phpt @@ -0,0 +1,49 @@ +--TEST-- +Test array_shift() function : basic functionality +--FILE-- + 'three', 'four' => 4); +echo "\n-- Before shift: --\n"; +var_dump($array); + +echo "\n-- After shift: --\n"; +echo "Returned value:\t"; +var_dump(array_shift($array)); +echo "New array:\n"; +var_dump($array); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_shift() : basic functionality *** + +-- Before shift: -- +array(4) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [3]=> + string(5) "three" + ["four"]=> + int(4) +} + +-- After shift: -- +Returned value: string(4) "zero" +New array: +array(3) { + [0]=> + string(3) "one" + [1]=> + string(5) "three" + ["four"]=> + int(4) +} +Done diff --git a/tests/std/array/array_shift_variation2.phpt b/tests/std/array/array_shift_variation2.phpt new file mode 100644 index 00000000..0ab7708b --- /dev/null +++ b/tests/std/array/array_shift_variation2.phpt @@ -0,0 +1,165 @@ +--TEST-- +Test array_shift() function : usage variations - Pass arrays of different data types +--SKIPIF-- + + +--FILE-- + array(0, 1, 12345, -2345), + // float data + /*2*/ + 'float' => array(10.5, -10.5, 123456789000.0, 1.23456789E-9, 0.5), + // null data + /*3*/ + 'null' => array(NULL, null), + // boolean data + /*4*/ + 'bool' => array(true, false, TRUE, FALSE), + // empty data + /*5*/ + 'empty string' => array("", ''), + /*6*/ + 'empty array' => array(), + // string data + /*7*/ + 'string' => array("string", 'string', $heredoc), + // object data + /*8*/ + 'object' => array(new classA()), + // undefined data + /*9*/ + 'undefined' => array(@$undefined_var), + // unset data + /*10*/ + 'unset' => array(@$unset_var), + // resource variable + /*11*/ + 'resource' => array($fp), + ); + // loop through each element of $inputs to check the behavior of array_shift + $iterator = 1; + foreach ($inputs as $key => $input) { + echo "\n-- Iteration {$iterator}: {$key} data --\n"; + var_dump(array_shift($input)); + var_dump($input); + $iterator++; + } + fclose($fp); + echo "Done"; +} +?> +--EXPECTF-- +*** Testing array_shift() : usage variations *** + +-- Iteration 1: int data -- +int(0) +array(3) { + [0]=> + int(1) + [1]=> + int(12345) + [2]=> + int(-2345) +} + +-- Iteration 2: float data -- +float(10.5) +array(4) { + [0]=> + float(-10.5) + [1]=> + float(123456789000) + [2]=> + float(1.23456789E-9) + [3]=> + float(0.5) +} + +-- Iteration 3: null data -- +NULL +array(1) { + [0]=> + NULL +} + +-- Iteration 4: bool data -- +bool(true) +array(3) { + [0]=> + bool(false) + [1]=> + bool(true) + [2]=> + bool(false) +} + +-- Iteration 5: empty string data -- +string(0) "" +array(1) { + [0]=> + string(0) "" +} + +-- Iteration 6: empty array data -- +NULL +array(0) { +} + +-- Iteration 7: string data -- +string(6) "string" +array(2) { + [0]=> + string(6) "string" + [1]=> + string(11) "hello world" +} + +-- Iteration 8: object data -- +object(classA)#%d (0) { +} +array(0) { +} + +-- Iteration 9: undefined data -- +NULL +array(0) { +} + +-- Iteration 10: unset data -- +NULL +array(0) { +} + +-- Iteration 11: resource data -- +resource(%d) of type (stream) +array(0) { +} +Done diff --git a/tests/std/array/array_shift_variation3.phpt b/tests/std/array/array_shift_variation3.phpt new file mode 100644 index 00000000..a33626b8 --- /dev/null +++ b/tests/std/array/array_shift_variation3.phpt @@ -0,0 +1,160 @@ +--TEST-- +Test array_shift() function : usage variations - Pass array with different data types as keys +--SKIPIF-- + + +--FILE-- + array( + 0 => 'zero', + 1 => 'one', + 12345 => 'positive', + -2345 => 'negative', + ), + + // null data +/*4*/ 'null uppercase' => array( + NULL => 'null 1', + ), + +/*5*/ 'null lowercase' => array( + null => 'null 2', + ), + + // boolean data +/*6*/ 'bool lowercase' => array( + true => 'lowert', + false => 'lowerf', + ), + +/*7*/ 'bool uppercase' => array( + TRUE => 'uppert', + FALSE => 'upperf', + ), + + // empty data +/*8*/ 'empty double quotes' => array( + "" => 'emptyd', + ), + +/*9*/ 'empty single quotes' => array( + '' => 'emptys', + ), + + // string data +/*10*/ 'string' => array( + "stringd" => 'stringd', + 'strings' => 'strings', + $heredoc => 'stringh', + ), + + // undefined data +/*11*/ 'undefined' => array( + @$undefined_var => 'undefined', + ), + + // unset data +/*12*/ 'unset' => array( + @$unset_var => 'unset', + ), +); + +// loop through each element of $inputs to check the behavior of array_shift() +$iterator = 1; +foreach($inputs as $key => $input) { + echo "\n-- Iteration $iterator : $key data --\n"; + var_dump( array_shift($input) ); + var_dump($input); + $iterator++; +}; + +echo "Done"; +?> +--EXPECT-- +*** Testing array_shift() : usage variations *** + +-- Iteration 1 : int data -- +string(4) "zero" +array(3) { + [0]=> + string(3) "one" + [1]=> + string(8) "positive" + [2]=> + string(8) "negative" +} + +-- Iteration 2 : null uppercase data -- +string(6) "null 1" +array(0) { +} + +-- Iteration 3 : null lowercase data -- +string(6) "null 2" +array(0) { +} + +-- Iteration 4 : bool lowercase data -- +string(6) "lowert" +array(1) { + [0]=> + string(6) "lowerf" +} + +-- Iteration 5 : bool uppercase data -- +string(6) "uppert" +array(1) { + [0]=> + string(6) "upperf" +} + +-- Iteration 6 : empty double quotes data -- +string(6) "emptyd" +array(0) { +} + +-- Iteration 7 : empty single quotes data -- +string(6) "emptys" +array(0) { +} + +-- Iteration 8 : string data -- +string(7) "stringd" +array(2) { + ["strings"]=> + string(7) "strings" + ["hello world"]=> + string(7) "stringh" +} + +-- Iteration 9 : undefined data -- +string(9) "undefined" +array(0) { +} + +-- Iteration 10 : unset data -- +string(5) "unset" +array(0) { +} +Done diff --git a/tests/std/array/array_shift_variation4.phpt b/tests/std/array/array_shift_variation4.phpt new file mode 100644 index 00000000..34c15055 --- /dev/null +++ b/tests/std/array/array_shift_variation4.phpt @@ -0,0 +1,104 @@ +--TEST-- +Test array_shift() function : usage variations - multi-dimensional arrays +--FILE-- + +--EXPECT-- +*** Testing array_shift() : usage variations *** + +-- Before shift: -- +---- $stack_first: +array(3) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + [1]=> + string(3) "one" + [2]=> + string(3) "two" +} +---- $stack_last: +array(3) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} + +-- After shift: -- +---- Pop array from array: +Returned value: array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +New array: +array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" +} +---- Pop element from array within array: +Returned value: int(1) +New array: +array(3) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + array(2) { + [0]=> + int(2) + [1]=> + int(3) + } +} +Done diff --git a/tests/std/array/array_shift_variation5.phpt b/tests/std/array/array_shift_variation5.phpt new file mode 100644 index 00000000..0ba29b62 --- /dev/null +++ b/tests/std/array/array_shift_variation5.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test array_shift() function : usage variations - call recursively +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +*** Testing array_shift() : usage variations *** + +-- Incorrect Method: -- + +Notice: Only variables should be passed by reference in %s on line %d + +Notice: Only variables should be passed by reference in %s on line %d +string(4) "zero" + +-- Correct Method: -- +string(4) "zero" +Done diff --git a/tests/std/array/array_shift_variation6.phpt b/tests/std/array/array_shift_variation6.phpt new file mode 100644 index 00000000..1f554887 --- /dev/null +++ b/tests/std/array/array_shift_variation6.phpt @@ -0,0 +1,80 @@ +--TEST-- +Test array_shift() function : usage variations - Referenced arrays +--SKIPIF-- + +--FILE-- + +--EXPECT-- +*** Testing array_shift() : usage variations *** + +-- Variable is referenced array -- +Result: string(4) "zero" + +$original_array: +array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" +} + +$copied_array: +array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" +} + +-- Element is referenced array -- +Result: string(3) "one" + +$new_array: +array(3) { + [0]=> + &array(1) { + [0]=> + string(3) "two" + } + [1]=> + int(1) + [2]=> + string(3) "two" +} + +$copied_array +array(1) { + [0]=> + string(3) "two" +} +Done diff --git a/tests/std/array/array_shift_variation7.phpt b/tests/std/array/array_shift_variation7.phpt new file mode 100644 index 00000000..257047be --- /dev/null +++ b/tests/std/array/array_shift_variation7.phpt @@ -0,0 +1,29 @@ +--TEST-- +Test array_shift() function : usage variations - position of internal pointer +--FILE-- + 'un', 'two' => 'deux'); + +echo "\n-- Call array_shift() --\n"; +var_dump($result = array_shift($stack)); + +echo "\n-- Position of Internal Pointer in Passed Array: --\n"; +echo key($stack) . " => " . current ($stack) . "\n"; + +echo "Done"; +?> +--EXPECT-- +*** Testing array_shift() : usage variations *** + +-- Call array_shift() -- +string(2) "un" + +-- Position of Internal Pointer in Passed Array: -- +two => deux +Done diff --git a/tests/std/array/array_shift_variation8.phpt b/tests/std/array/array_shift_variation8.phpt new file mode 100644 index 00000000..16bcecc1 --- /dev/null +++ b/tests/std/array/array_shift_variation8.phpt @@ -0,0 +1,50 @@ +--TEST-- +Test array_shift() function : usage variations - maintaining referenced elements +--SKIPIF-- + + +--FILE-- + +--EXPECTF-- +*** Testing array_shift() : usage variations *** + +-- Reference result of array_shift: -- + +Notice: Only variables should be assigned by reference in %s on line %d +a = 1, b = 2 + +-- Reference first element before array_shift: -- +a = 2, b = 2 +Done diff --git a/tests/std/array/array_shuffle_basic.phpt b/tests/std/array/array_shuffle_basic.phpt new file mode 100644 index 00000000..65d2f11d --- /dev/null +++ b/tests/std/array/array_shuffle_basic.phpt @@ -0,0 +1,98 @@ +--TEST-- +array_shuffle(): Test return type and value for expected input +--FILE-- + 1); +var_dump(shuffle($a)); +var_dump($a); +$a = array("a" => 1); +var_dump(shuffle($a)); +var_dump($a); +$a = array(array(1, 2, 3)); +var_dump(shuffle($a)); +var_dump($a); +$a = array(1, 1, 1, 1); +var_dump(shuffle($a)); +var_dump($a); +$arr1 = array(5 => 1, 6 => 2, 7 => 3, 8 => 9); +$arr2 = array(5 => 1, 6 => 2, 7 => 3, 8 => 9); +shuffle($arr1); +echo "this should be 0->...." . count(array_diff($arr1, $arr2)) . "\n"; +echo "this should be 4->...." . count(array_intersect($arr1, $arr2)) . "\n"; +$bigarray = range(1, 400); +shuffle($bigarray); +echo "this should be 400->...." . count($bigarray) . "\n"; +echo "*** testing pass by reference \n"; +$original = $bigarray; +shuffle($bigarray); +$diffarray = array_diff_assoc($original, $bigarray); +if (count($diffarray) < 350) { + // with 400 entries, the probability that 50 entries or more get the same + // key-> value association should be so close to zero it wont happen in the lifetime of the + // universe. + echo "shuffled array seems to be similar to original\n"; + var_dump($original); + var_dump($bigarray); +} else { + echo "test passed \n"; +} +?> +--EXPECT-- +*** testing array_shuffle +bool(true) +array(0) { +} +bool(true) +array(1) { + [0]=> + int(1) +} +bool(true) +array(1) { + [0]=> + int(1) +} +bool(true) +array(1) { + [0]=> + int(1) +} +bool(true) +array(1) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} +bool(true) +array(4) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + int(1) + [3]=> + int(1) +} +this should be 0->....0 +this should be 4->....4 +this should be 400->....400 +*** testing pass by reference +test passed diff --git a/tests/std/array/array_slice.phpt b/tests/std/array/array_slice.phpt new file mode 100644 index 00000000..f12f6d62 --- /dev/null +++ b/tests/std/array/array_slice.phpt @@ -0,0 +1,1419 @@ +--TEST-- +Testing array_slice() function +--FILE-- + "aaa", "A" => "AAA", "c" => "ccc", "d" => "ddd", "e" => "eee"), + array("1" => "one", "2" => "two", "3" => "three", "4" => "four", "5" => "five"), + array(1 => "one", 2 => "two", 3 => 7, 4 => "four", 5 => "five"), + array("f" => "fff", "1" => "one", 4 => 6, "" => "blank", 2 => "float", "F" => "FFF", + "blank" => "", 3 => 3.7, 5 => 7, 6 => 8.6, '5' => "Five"), + array(12, "name", 'age', '45'), + array( array("oNe", "tWo", 4), array(10, 20, 30, 40, 50), array()) + ); + +$num = 4; +$str = "john"; + +$counter = 1; +foreach ($var_array as $sub_array) +{ + /* variations with two arguments */ + /* offset values >, < and = 0 */ + + echo"\n*** Iteration ".$counter." ***\n"; + echo"\n*** Variation with first two Arguments ***\n"; + var_dump ( array_slice($sub_array, 1) ); + var_dump ( array_slice($sub_array, 0) ); + var_dump ( array_slice($sub_array, -2) ); + + /* variations with three arguments */ + /* offset value variations with length values */ + echo"\n*** Variation with first three Arguments ***\n"; + var_dump ( array_slice($sub_array, 1, 3) ); + var_dump ( array_slice($sub_array, 1, 0) ); + var_dump ( array_slice($sub_array, 1, -3) ); + var_dump ( array_slice($sub_array, 0, 3) ); + var_dump ( array_slice($sub_array, 0, 0) ); + var_dump ( array_slice($sub_array, 0, -3) ); + var_dump ( array_slice($sub_array, -2, 3) ); + var_dump ( array_slice($sub_array, -2, 0 ) ); + var_dump ( array_slice($sub_array, -2, -3) ); + + /* variations with four arguments */ + /* offset value, length value and preserve_key values variation */ + echo"\n*** Variation with first two arguments with preserve_key value TRUE ***\n"; + var_dump ( array_slice($sub_array, 1, 3, true) ); + var_dump ( array_slice($sub_array, 1, 0, true) ); + var_dump ( array_slice($sub_array, 1, -3, true) ); + var_dump ( array_slice($sub_array, 0, 3, true) ); + var_dump ( array_slice($sub_array, 0, 0, true) ); + var_dump ( array_slice($sub_array, 0, -3, true) ); + var_dump ( array_slice($sub_array, -2, 3, true) ); + var_dump ( array_slice($sub_array, -2, 0, true) ); + var_dump ( array_slice($sub_array, -2, -3, true) ); + $counter++; +} + + /* variation of offset and length to point to same element */ + echo"\n*** Typical Variation of offset and length Arguments ***\n"; + var_dump (array_slice($var_array[2], 1, -3, true) ); + var_dump (array_slice($var_array[2], 1, -3, false) ); + var_dump (array_slice($var_array[2], -3, -2, true) ); + var_dump (array_slice($var_array[2], -3, -2, false) ); + +?> +--EXPECT-- +*** Iteration 1 *** + +*** Variation with first two Arguments *** +array(0) { +} +array(0) { +} +array(0) { +} + +*** Variation with first three Arguments *** +array(0) { +} +array(0) { +} +array(0) { +} +array(0) { +} +array(0) { +} +array(0) { +} +array(0) { +} +array(0) { +} +array(0) { +} + +*** Variation with first two arguments with preserve_key value TRUE *** +array(0) { +} +array(0) { +} +array(0) { +} +array(0) { +} +array(0) { +} +array(0) { +} +array(0) { +} +array(0) { +} +array(0) { +} + +*** Iteration 2 *** + +*** Variation with first two Arguments *** +array(8) { + [0]=> + int(2) + [1]=> + int(3) + [2]=> + int(4) + [3]=> + int(5) + [4]=> + int(6) + [5]=> + int(7) + [6]=> + int(8) + [7]=> + int(9) +} +array(9) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + [6]=> + int(7) + [7]=> + int(8) + [8]=> + int(9) +} +array(2) { + [0]=> + int(8) + [1]=> + int(9) +} + +*** Variation with first three Arguments *** +array(3) { + [0]=> + int(2) + [1]=> + int(3) + [2]=> + int(4) +} +array(0) { +} +array(5) { + [0]=> + int(2) + [1]=> + int(3) + [2]=> + int(4) + [3]=> + int(5) + [4]=> + int(6) +} +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +array(0) { +} +array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) +} +array(2) { + [0]=> + int(8) + [1]=> + int(9) +} +array(0) { +} +array(0) { +} + +*** Variation with first two arguments with preserve_key value TRUE *** +array(3) { + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) +} +array(0) { +} +array(5) { + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) +} +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +array(0) { +} +array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) +} +array(2) { + [7]=> + int(8) + [8]=> + int(9) +} +array(0) { +} +array(0) { +} + +*** Iteration 3 *** + +*** Variation with first two Arguments *** +array(4) { + [0]=> + string(3) "Two" + [1]=> + string(5) "Three" + [2]=> + string(4) "Four" + [3]=> + string(4) "Five" +} +array(5) { + [0]=> + string(3) "One" + [1]=> + string(3) "Two" + [2]=> + string(5) "Three" + [3]=> + string(4) "Four" + [4]=> + string(4) "Five" +} +array(2) { + [0]=> + string(4) "Four" + [1]=> + string(4) "Five" +} + +*** Variation with first three Arguments *** +array(3) { + [0]=> + string(3) "Two" + [1]=> + string(5) "Three" + [2]=> + string(4) "Four" +} +array(0) { +} +array(1) { + [0]=> + string(3) "Two" +} +array(3) { + [0]=> + string(3) "One" + [1]=> + string(3) "Two" + [2]=> + string(5) "Three" +} +array(0) { +} +array(2) { + [0]=> + string(3) "One" + [1]=> + string(3) "Two" +} +array(2) { + [0]=> + string(4) "Four" + [1]=> + string(4) "Five" +} +array(0) { +} +array(0) { +} + +*** Variation with first two arguments with preserve_key value TRUE *** +array(3) { + [1]=> + string(3) "Two" + [2]=> + string(5) "Three" + [3]=> + string(4) "Four" +} +array(0) { +} +array(1) { + [1]=> + string(3) "Two" +} +array(3) { + [0]=> + string(3) "One" + [1]=> + string(3) "Two" + [2]=> + string(5) "Three" +} +array(0) { +} +array(2) { + [0]=> + string(3) "One" + [1]=> + string(3) "Two" +} +array(2) { + [3]=> + string(4) "Four" + [4]=> + string(4) "Five" +} +array(0) { +} +array(0) { +} + +*** Iteration 4 *** + +*** Variation with first two Arguments *** +array(7) { + [0]=> + string(3) "six" + [1]=> + int(7) + [2]=> + string(5) "seven" + [3]=> + int(8) + [4]=> + string(5) "eight" + [5]=> + int(9) + [6]=> + string(4) "nine" +} +array(8) { + [0]=> + int(6) + [1]=> + string(3) "six" + [2]=> + int(7) + [3]=> + string(5) "seven" + [4]=> + int(8) + [5]=> + string(5) "eight" + [6]=> + int(9) + [7]=> + string(4) "nine" +} +array(2) { + [0]=> + int(9) + [1]=> + string(4) "nine" +} + +*** Variation with first three Arguments *** +array(3) { + [0]=> + string(3) "six" + [1]=> + int(7) + [2]=> + string(5) "seven" +} +array(0) { +} +array(4) { + [0]=> + string(3) "six" + [1]=> + int(7) + [2]=> + string(5) "seven" + [3]=> + int(8) +} +array(3) { + [0]=> + int(6) + [1]=> + string(3) "six" + [2]=> + int(7) +} +array(0) { +} +array(5) { + [0]=> + int(6) + [1]=> + string(3) "six" + [2]=> + int(7) + [3]=> + string(5) "seven" + [4]=> + int(8) +} +array(2) { + [0]=> + int(9) + [1]=> + string(4) "nine" +} +array(0) { +} +array(0) { +} + +*** Variation with first two arguments with preserve_key value TRUE *** +array(3) { + [1]=> + string(3) "six" + [2]=> + int(7) + [3]=> + string(5) "seven" +} +array(0) { +} +array(4) { + [1]=> + string(3) "six" + [2]=> + int(7) + [3]=> + string(5) "seven" + [4]=> + int(8) +} +array(3) { + [0]=> + int(6) + [1]=> + string(3) "six" + [2]=> + int(7) +} +array(0) { +} +array(5) { + [0]=> + int(6) + [1]=> + string(3) "six" + [2]=> + int(7) + [3]=> + string(5) "seven" + [4]=> + int(8) +} +array(2) { + [6]=> + int(9) + [7]=> + string(4) "nine" +} +array(0) { +} +array(0) { +} + +*** Iteration 5 *** + +*** Variation with first two Arguments *** +array(4) { + ["A"]=> + string(3) "AAA" + ["c"]=> + string(3) "ccc" + ["d"]=> + string(3) "ddd" + ["e"]=> + string(3) "eee" +} +array(5) { + ["a"]=> + string(3) "aaa" + ["A"]=> + string(3) "AAA" + ["c"]=> + string(3) "ccc" + ["d"]=> + string(3) "ddd" + ["e"]=> + string(3) "eee" +} +array(2) { + ["d"]=> + string(3) "ddd" + ["e"]=> + string(3) "eee" +} + +*** Variation with first three Arguments *** +array(3) { + ["A"]=> + string(3) "AAA" + ["c"]=> + string(3) "ccc" + ["d"]=> + string(3) "ddd" +} +array(0) { +} +array(1) { + ["A"]=> + string(3) "AAA" +} +array(3) { + ["a"]=> + string(3) "aaa" + ["A"]=> + string(3) "AAA" + ["c"]=> + string(3) "ccc" +} +array(0) { +} +array(2) { + ["a"]=> + string(3) "aaa" + ["A"]=> + string(3) "AAA" +} +array(2) { + ["d"]=> + string(3) "ddd" + ["e"]=> + string(3) "eee" +} +array(0) { +} +array(0) { +} + +*** Variation with first two arguments with preserve_key value TRUE *** +array(3) { + ["A"]=> + string(3) "AAA" + ["c"]=> + string(3) "ccc" + ["d"]=> + string(3) "ddd" +} +array(0) { +} +array(1) { + ["A"]=> + string(3) "AAA" +} +array(3) { + ["a"]=> + string(3) "aaa" + ["A"]=> + string(3) "AAA" + ["c"]=> + string(3) "ccc" +} +array(0) { +} +array(2) { + ["a"]=> + string(3) "aaa" + ["A"]=> + string(3) "AAA" +} +array(2) { + ["d"]=> + string(3) "ddd" + ["e"]=> + string(3) "eee" +} +array(0) { +} +array(0) { +} + +*** Iteration 6 *** + +*** Variation with first two Arguments *** +array(4) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "four" + [3]=> + string(4) "five" +} +array(5) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + [2]=> + string(5) "three" + [3]=> + string(4) "four" + [4]=> + string(4) "five" +} +array(2) { + [0]=> + string(4) "four" + [1]=> + string(4) "five" +} + +*** Variation with first three Arguments *** +array(3) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "four" +} +array(0) { +} +array(1) { + [0]=> + string(3) "two" +} +array(3) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + [2]=> + string(5) "three" +} +array(0) { +} +array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" +} +array(2) { + [0]=> + string(4) "four" + [1]=> + string(4) "five" +} +array(0) { +} +array(0) { +} + +*** Variation with first two arguments with preserve_key value TRUE *** +array(3) { + [2]=> + string(3) "two" + [3]=> + string(5) "three" + [4]=> + string(4) "four" +} +array(0) { +} +array(1) { + [2]=> + string(3) "two" +} +array(3) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + string(5) "three" +} +array(0) { +} +array(2) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" +} +array(2) { + [4]=> + string(4) "four" + [5]=> + string(4) "five" +} +array(0) { +} +array(0) { +} + +*** Iteration 7 *** + +*** Variation with first two Arguments *** +array(4) { + [0]=> + string(3) "two" + [1]=> + int(7) + [2]=> + string(4) "four" + [3]=> + string(4) "five" +} +array(5) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + [2]=> + int(7) + [3]=> + string(4) "four" + [4]=> + string(4) "five" +} +array(2) { + [0]=> + string(4) "four" + [1]=> + string(4) "five" +} + +*** Variation with first three Arguments *** +array(3) { + [0]=> + string(3) "two" + [1]=> + int(7) + [2]=> + string(4) "four" +} +array(0) { +} +array(1) { + [0]=> + string(3) "two" +} +array(3) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + [2]=> + int(7) +} +array(0) { +} +array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" +} +array(2) { + [0]=> + string(4) "four" + [1]=> + string(4) "five" +} +array(0) { +} +array(0) { +} + +*** Variation with first two arguments with preserve_key value TRUE *** +array(3) { + [2]=> + string(3) "two" + [3]=> + int(7) + [4]=> + string(4) "four" +} +array(0) { +} +array(1) { + [2]=> + string(3) "two" +} +array(3) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + int(7) +} +array(0) { +} +array(2) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" +} +array(2) { + [4]=> + string(4) "four" + [5]=> + string(4) "five" +} +array(0) { +} +array(0) { +} + +*** Iteration 8 *** + +*** Variation with first two Arguments *** +array(9) { + [0]=> + string(3) "one" + [1]=> + int(6) + [""]=> + string(5) "blank" + [2]=> + string(5) "float" + ["F"]=> + string(3) "FFF" + ["blank"]=> + string(0) "" + [3]=> + float(3.7) + [4]=> + string(4) "Five" + [5]=> + float(8.6) +} +array(10) { + ["f"]=> + string(3) "fff" + [0]=> + string(3) "one" + [1]=> + int(6) + [""]=> + string(5) "blank" + [2]=> + string(5) "float" + ["F"]=> + string(3) "FFF" + ["blank"]=> + string(0) "" + [3]=> + float(3.7) + [4]=> + string(4) "Five" + [5]=> + float(8.6) +} +array(2) { + [0]=> + string(4) "Five" + [1]=> + float(8.6) +} + +*** Variation with first three Arguments *** +array(3) { + [0]=> + string(3) "one" + [1]=> + int(6) + [""]=> + string(5) "blank" +} +array(0) { +} +array(6) { + [0]=> + string(3) "one" + [1]=> + int(6) + [""]=> + string(5) "blank" + [2]=> + string(5) "float" + ["F"]=> + string(3) "FFF" + ["blank"]=> + string(0) "" +} +array(3) { + ["f"]=> + string(3) "fff" + [0]=> + string(3) "one" + [1]=> + int(6) +} +array(0) { +} +array(7) { + ["f"]=> + string(3) "fff" + [0]=> + string(3) "one" + [1]=> + int(6) + [""]=> + string(5) "blank" + [2]=> + string(5) "float" + ["F"]=> + string(3) "FFF" + ["blank"]=> + string(0) "" +} +array(2) { + [0]=> + string(4) "Five" + [1]=> + float(8.6) +} +array(0) { +} +array(0) { +} + +*** Variation with first two arguments with preserve_key value TRUE *** +array(3) { + [1]=> + string(3) "one" + [4]=> + int(6) + [""]=> + string(5) "blank" +} +array(0) { +} +array(6) { + [1]=> + string(3) "one" + [4]=> + int(6) + [""]=> + string(5) "blank" + [2]=> + string(5) "float" + ["F"]=> + string(3) "FFF" + ["blank"]=> + string(0) "" +} +array(3) { + ["f"]=> + string(3) "fff" + [1]=> + string(3) "one" + [4]=> + int(6) +} +array(0) { +} +array(7) { + ["f"]=> + string(3) "fff" + [1]=> + string(3) "one" + [4]=> + int(6) + [""]=> + string(5) "blank" + [2]=> + string(5) "float" + ["F"]=> + string(3) "FFF" + ["blank"]=> + string(0) "" +} +array(2) { + [5]=> + string(4) "Five" + [6]=> + float(8.6) +} +array(0) { +} +array(0) { +} + +*** Iteration 9 *** + +*** Variation with first two Arguments *** +array(3) { + [0]=> + string(4) "name" + [1]=> + string(3) "age" + [2]=> + string(2) "45" +} +array(4) { + [0]=> + int(12) + [1]=> + string(4) "name" + [2]=> + string(3) "age" + [3]=> + string(2) "45" +} +array(2) { + [0]=> + string(3) "age" + [1]=> + string(2) "45" +} + +*** Variation with first three Arguments *** +array(3) { + [0]=> + string(4) "name" + [1]=> + string(3) "age" + [2]=> + string(2) "45" +} +array(0) { +} +array(0) { +} +array(3) { + [0]=> + int(12) + [1]=> + string(4) "name" + [2]=> + string(3) "age" +} +array(0) { +} +array(1) { + [0]=> + int(12) +} +array(2) { + [0]=> + string(3) "age" + [1]=> + string(2) "45" +} +array(0) { +} +array(0) { +} + +*** Variation with first two arguments with preserve_key value TRUE *** +array(3) { + [1]=> + string(4) "name" + [2]=> + string(3) "age" + [3]=> + string(2) "45" +} +array(0) { +} +array(0) { +} +array(3) { + [0]=> + int(12) + [1]=> + string(4) "name" + [2]=> + string(3) "age" +} +array(0) { +} +array(1) { + [0]=> + int(12) +} +array(2) { + [2]=> + string(3) "age" + [3]=> + string(2) "45" +} +array(0) { +} +array(0) { +} + +*** Iteration 10 *** + +*** Variation with first two Arguments *** +array(2) { + [0]=> + array(5) { + [0]=> + int(10) + [1]=> + int(20) + [2]=> + int(30) + [3]=> + int(40) + [4]=> + int(50) + } + [1]=> + array(0) { + } +} +array(3) { + [0]=> + array(3) { + [0]=> + string(3) "oNe" + [1]=> + string(3) "tWo" + [2]=> + int(4) + } + [1]=> + array(5) { + [0]=> + int(10) + [1]=> + int(20) + [2]=> + int(30) + [3]=> + int(40) + [4]=> + int(50) + } + [2]=> + array(0) { + } +} +array(2) { + [0]=> + array(5) { + [0]=> + int(10) + [1]=> + int(20) + [2]=> + int(30) + [3]=> + int(40) + [4]=> + int(50) + } + [1]=> + array(0) { + } +} + +*** Variation with first three Arguments *** +array(2) { + [0]=> + array(5) { + [0]=> + int(10) + [1]=> + int(20) + [2]=> + int(30) + [3]=> + int(40) + [4]=> + int(50) + } + [1]=> + array(0) { + } +} +array(0) { +} +array(0) { +} +array(3) { + [0]=> + array(3) { + [0]=> + string(3) "oNe" + [1]=> + string(3) "tWo" + [2]=> + int(4) + } + [1]=> + array(5) { + [0]=> + int(10) + [1]=> + int(20) + [2]=> + int(30) + [3]=> + int(40) + [4]=> + int(50) + } + [2]=> + array(0) { + } +} +array(0) { +} +array(0) { +} +array(2) { + [0]=> + array(5) { + [0]=> + int(10) + [1]=> + int(20) + [2]=> + int(30) + [3]=> + int(40) + [4]=> + int(50) + } + [1]=> + array(0) { + } +} +array(0) { +} +array(0) { +} + +*** Variation with first two arguments with preserve_key value TRUE *** +array(2) { + [1]=> + array(5) { + [0]=> + int(10) + [1]=> + int(20) + [2]=> + int(30) + [3]=> + int(40) + [4]=> + int(50) + } + [2]=> + array(0) { + } +} +array(0) { +} +array(0) { +} +array(3) { + [0]=> + array(3) { + [0]=> + string(3) "oNe" + [1]=> + string(3) "tWo" + [2]=> + int(4) + } + [1]=> + array(5) { + [0]=> + int(10) + [1]=> + int(20) + [2]=> + int(30) + [3]=> + int(40) + [4]=> + int(50) + } + [2]=> + array(0) { + } +} +array(0) { +} +array(0) { +} +array(2) { + [1]=> + array(5) { + [0]=> + int(10) + [1]=> + int(20) + [2]=> + int(30) + [3]=> + int(40) + [4]=> + int(50) + } + [2]=> + array(0) { + } +} +array(0) { +} +array(0) { +} + +*** Typical Variation of offset and length Arguments *** +array(1) { + [1]=> + string(3) "Two" +} +array(1) { + [0]=> + string(3) "Two" +} +array(1) { + [2]=> + string(5) "Three" +} +array(1) { + [0]=> + string(5) "Three" +} diff --git a/tests/std/array/array_slice_basic.phpt b/tests/std/array/array_slice_basic.phpt new file mode 100644 index 00000000..b82e4cc4 --- /dev/null +++ b/tests/std/array/array_slice_basic.phpt @@ -0,0 +1,45 @@ +--TEST-- +Test array_slice() function : basic functionality +--FILE-- + 1, 'two' => 2, 3, 23 => 4); +$offset = 2; +$length = 2; +$preserve_keys = true; + +// Calling array_slice() with all possible arguments +echo "\n-- All arguments --\n"; +var_dump( array_slice($input, $offset, $length, $preserve_keys) ); + +// Calling array_slice() with mandatory arguments +echo "\n-- Mandatory arguments --\n"; +var_dump( array_slice($input, $offset) ); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_slice() : basic functionality *** + +-- All arguments -- +array(2) { + [0]=> + int(3) + [23]=> + int(4) +} + +-- Mandatory arguments -- +array(2) { + [0]=> + int(3) + [1]=> + int(4) +} +Done diff --git a/tests/std/array/array_slice_variation1.phpt b/tests/std/array/array_slice_variation1.phpt new file mode 100644 index 00000000..b1d80d3f --- /dev/null +++ b/tests/std/array/array_slice_variation1.phpt @@ -0,0 +1,66 @@ +--TEST-- +Test array_slice() - Third parameter (NULL vs 0) +--FILE-- +getMessage(), "\n"; +} +try { + var_dump(array_slice(range(1, 3), 0, $a)); +} catch (TypeError $e) { + echo $e->getMessage(), "\n"; +} +var_dump($a); + +?> +--EXPECT-- +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +array(0) { +} +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +array(0) { +} +array(0) { +} +array(0) { +} +array(1) { + [0]=> + int(3) +} +array(1) { + [2]=> + int(3) +} +array_slice(): Argument #3 ($length) must be of type ?int, string given +array_slice(): Argument #3 ($length) must be of type ?int, string given +string(3) "foo" diff --git a/tests/std/array/array_slice_variation10.phpt b/tests/std/array/array_slice_variation10.phpt new file mode 100644 index 00000000..66be016b --- /dev/null +++ b/tests/std/array/array_slice_variation10.phpt @@ -0,0 +1,38 @@ +--TEST-- +Test array_slice() function : usage variations - position of internal array pointer +--FILE-- + 'un', 'two' => 'deux', 23 => 'twenty-three', 'zero'); + +echo "\n-- Call array_slice() --\n"; +var_dump($result = array_slice($input, 2)); + +echo "-- Position of Internal Pointer in Result: --\n"; +echo key($result) . " => " . current($result) . "\n"; +echo "\n-- Position of Internal Pointer in Original Array: --\n"; +echo key($input) . " => " . current ($input) . "\n"; + +echo "Done"; +?> +--EXPECT-- +*** Testing array_slice() : usage variations *** + +-- Call array_slice() -- +array(2) { + [0]=> + string(12) "twenty-three" + [1]=> + string(4) "zero" +} +-- Position of Internal Pointer in Result: -- +0 => twenty-three + +-- Position of Internal Pointer in Original Array: -- +one => un +Done diff --git a/tests/std/array/array_slice_variation11.phpt b/tests/std/array/array_slice_variation11.phpt new file mode 100644 index 00000000..b69f0174 --- /dev/null +++ b/tests/std/array/array_slice_variation11.phpt @@ -0,0 +1,99 @@ +--TEST-- +Test array_slice() function : usage variations - array has holes in buckets +--FILE-- + 'un', 'two' => 'deux', 23 => 'twenty-three', 'zero']; + dump_slice($input, 'two', 0, 1); + dump_slice($input, 'two', 0, 2); + dump_slice($input, 'two', 0, 3); + dump_slice($input, 23, 1, 2); + echo "\n-- Call array_slice() on array with packed keys--\n"; + $input = [10, 11, 12, 'thirteen']; + dump_slice($input, 0, 0, 1); + dump_slice($input, 1, 0, 1); + dump_slice($input, 1, 0, 3); + dump_slice($input, 1, -1, 1); + dump_slice($input, 1, 0, 3); + dump_slice($input, 1, -3, 3); + echo "Done"; +} +?> +--EXPECT-- +*** Testing array_slice() : usage variations *** + +-- Call array_slice() on array with string keys-- +array(1) { + ["one"]=> + string(2) "un" +} +array(2) { + ["one"]=> + string(2) "un" + [0]=> + string(12) "twenty-three" +} +array(3) { + ["one"]=> + string(2) "un" + [0]=> + string(12) "twenty-three" + [1]=> + string(4) "zero" +} +array(2) { + ["two"]=> + string(4) "deux" + [0]=> + string(4) "zero" +} + +-- Call array_slice() on array with packed keys-- +array(1) { + [0]=> + int(11) +} +array(1) { + [0]=> + int(10) +} +array(3) { + [0]=> + int(10) + [1]=> + int(12) + [2]=> + string(8) "thirteen" +} +array(1) { + [0]=> + string(8) "thirteen" +} +array(3) { + [0]=> + int(10) + [1]=> + int(12) + [2]=> + string(8) "thirteen" +} +array(3) { + [0]=> + int(10) + [1]=> + int(12) + [2]=> + string(8) "thirteen" +} +Done diff --git a/tests/std/array/array_slice_variation5.phpt b/tests/std/array/array_slice_variation5.phpt new file mode 100644 index 00000000..e2340695 --- /dev/null +++ b/tests/std/array/array_slice_variation5.phpt @@ -0,0 +1,185 @@ +--TEST-- +Test array_slice() function : usage variations - Pass different integers as $offset argument +--FILE-- + 1, 2 => 'two', 'three', 9 => 'nine', 'ten' => 10); + +for ($i = -7; $i <= 7; $i++) { + echo "\n-- \$offset is $i --\n"; + var_dump(array_slice($input, $i)); +} +echo "\n-- \$offset is maximum integer value --\n"; +var_dump(array_slice($input, PHP_INT_MAX)); + +echo "\n-- \$offset is minimum integer value --\n"; +var_dump(array_slice($input, -PHP_INT_MAX)); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_slice() : usage variations *** + +-- $offset is -7 -- +array(5) { + ["one"]=> + int(1) + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $offset is -6 -- +array(5) { + ["one"]=> + int(1) + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $offset is -5 -- +array(5) { + ["one"]=> + int(1) + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $offset is -4 -- +array(4) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $offset is -3 -- +array(3) { + [0]=> + string(5) "three" + [1]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $offset is -2 -- +array(2) { + [0]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $offset is -1 -- +array(1) { + ["ten"]=> + int(10) +} + +-- $offset is 0 -- +array(5) { + ["one"]=> + int(1) + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $offset is 1 -- +array(4) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $offset is 2 -- +array(3) { + [0]=> + string(5) "three" + [1]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $offset is 3 -- +array(2) { + [0]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $offset is 4 -- +array(1) { + ["ten"]=> + int(10) +} + +-- $offset is 5 -- +array(0) { +} + +-- $offset is 6 -- +array(0) { +} + +-- $offset is 7 -- +array(0) { +} + +-- $offset is maximum integer value -- +array(0) { +} + +-- $offset is minimum integer value -- +array(5) { + ["one"]=> + int(1) + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} +Done diff --git a/tests/std/array/array_slice_variation6.phpt b/tests/std/array/array_slice_variation6.phpt new file mode 100644 index 00000000..f6099e68 --- /dev/null +++ b/tests/std/array/array_slice_variation6.phpt @@ -0,0 +1,144 @@ +--TEST-- +Test array_slice() function : usage variations - pass different int values as $length arg +--FILE-- + 1, 2 => 'two', 'three', 9 => 'nine', 'ten' => 10); +$offset = 1; + +for ($i = -6; $i <= 6; $i++) { + echo "\n-- \$length is $i --\n"; + var_dump(array_slice($input, $offset, $i)); +} +echo "\n-- \$length is maximum integer value --\n"; +var_dump(array_slice($input, $offset, PHP_INT_MAX)); + +echo "\n-- \$length is minimum integer value --\n"; +var_dump(array_slice($input, $offset, -PHP_INT_MAX)); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_slice() : usage variations *** + +-- $length is -6 -- +array(0) { +} + +-- $length is -5 -- +array(0) { +} + +-- $length is -4 -- +array(0) { +} + +-- $length is -3 -- +array(1) { + [0]=> + string(3) "two" +} + +-- $length is -2 -- +array(2) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" +} + +-- $length is -1 -- +array(3) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" +} + +-- $length is 0 -- +array(0) { +} + +-- $length is 1 -- +array(1) { + [0]=> + string(3) "two" +} + +-- $length is 2 -- +array(2) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" +} + +-- $length is 3 -- +array(3) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" +} + +-- $length is 4 -- +array(4) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $length is 5 -- +array(4) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $length is 6 -- +array(4) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $length is maximum integer value -- +array(4) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $length is minimum integer value -- +array(0) { +} +Done diff --git a/tests/std/array/array_slice_variation7.phpt b/tests/std/array/array_slice_variation7.phpt new file mode 100644 index 00000000..58788bd9 --- /dev/null +++ b/tests/std/array/array_slice_variation7.phpt @@ -0,0 +1,251 @@ +--TEST-- +Test array_slice() function : usage variations - different data types as keys in an array +--SKIPIF-- + + +--FILE-- + array( + 0 => 'zero', + 1 => 'one', + 12345 => 'positive', + -2345 => 'negative', + ), + + // null data +/*4*/ 'null uppercase' => array( + NULL => 'null 1', + ), + +/*5*/ 'null lowercase' => array( + null => 'null 2', + ), + + // boolean data +/*6*/ 'bool lowercase' => array( + true => 'lowert', + false => 'lowerf', + ), + +/*7*/ 'bool uppercase' => array( + TRUE => 'uppert', + FALSE => 'upperf', + ), + + // empty data +/*8*/ 'empty double quotes' => array( + "" => 'emptyd', + ), + +/*9*/ 'empty single quotes' => array( + '' => 'emptys', + ), + + // string data +/*10*/ 'string' => array( + "stringd" => 'stringd', + 'strings' => 'strings', + $heredoc => 'stringh', + ), + + // undefined data +/*11*/ 'undefined' => array( + @$undefined_var => 'undefined', + ), + + // unset data +/*12*/ 'unset' => array( + @$unset_var => 'unset', + ), +); + +// loop through each element of $inputs to check the behavior of array_slice() +$iterator = 1; +foreach($inputs as $type => $input) { + echo "\n-- Iteration $iterator : key type is $type --\n"; + echo "\$preserve_keys = TRUE\n"; + var_dump( array_slice($input, $offset, $length, true) ); + echo "\$preserve_keys = FALSE\n"; + var_dump( array_slice($input, $offset, $length, false) ); + $iterator++; +}; + +echo "Done"; +?> +--EXPECT-- +*** Testing array_slice() : usage variations *** + +-- Iteration 1 : key type is int -- +$preserve_keys = TRUE +array(4) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [12345]=> + string(8) "positive" + [-2345]=> + string(8) "negative" +} +$preserve_keys = FALSE +array(4) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + string(8) "positive" + [3]=> + string(8) "negative" +} + +-- Iteration 2 : key type is null uppercase -- +$preserve_keys = TRUE +array(1) { + [0]=> + string(6) "null 1" +} +$preserve_keys = FALSE +array(1) { + [0]=> + string(6) "null 1" +} + +-- Iteration 3 : key type is null lowercase -- +$preserve_keys = TRUE +array(1) { + [0]=> + string(6) "null 2" +} +$preserve_keys = FALSE +array(1) { + [0]=> + string(6) "null 2" +} + +-- Iteration 4 : key type is bool lowercase -- +$preserve_keys = TRUE +array(2) { + [1]=> + string(6) "lowert" + [0]=> + string(6) "lowerf" +} +$preserve_keys = FALSE +array(2) { + [0]=> + string(6) "lowert" + [1]=> + string(6) "lowerf" +} + +-- Iteration 5 : key type is bool uppercase -- +$preserve_keys = TRUE +array(2) { + [1]=> + string(6) "uppert" + [0]=> + string(6) "upperf" +} +$preserve_keys = FALSE +array(2) { + [0]=> + string(6) "uppert" + [1]=> + string(6) "upperf" +} + +-- Iteration 6 : key type is empty double quotes -- +$preserve_keys = TRUE +array(1) { + [""]=> + string(6) "emptyd" +} +$preserve_keys = FALSE +array(1) { + [""]=> + string(6) "emptyd" +} + +-- Iteration 7 : key type is empty single quotes -- +$preserve_keys = TRUE +array(1) { + [""]=> + string(6) "emptys" +} +$preserve_keys = FALSE +array(1) { + [""]=> + string(6) "emptys" +} + +-- Iteration 8 : key type is string -- +$preserve_keys = TRUE +array(3) { + ["stringd"]=> + string(7) "stringd" + ["strings"]=> + string(7) "strings" + ["hello world"]=> + string(7) "stringh" +} +$preserve_keys = FALSE +array(3) { + ["stringd"]=> + string(7) "stringd" + ["strings"]=> + string(7) "strings" + ["hello world"]=> + string(7) "stringh" +} + +-- Iteration 9 : key type is undefined -- +$preserve_keys = TRUE +array(1) { + [0]=> + string(9) "undefined" +} +$preserve_keys = FALSE +array(1) { + [0]=> + string(9) "undefined" +} + +-- Iteration 10 : key type is unset -- +$preserve_keys = TRUE +array(1) { + [""]=> + string(5) "unset" +} +$preserve_keys = FALSE +array(1) { + [""]=> + string(5) "unset" +} +Done diff --git a/tests/std/array/array_slice_variation8.phpt b/tests/std/array/array_slice_variation8.phpt new file mode 100644 index 00000000..6e0e8f00 --- /dev/null +++ b/tests/std/array/array_slice_variation8.phpt @@ -0,0 +1,50 @@ +--TEST-- +Test array_slice() function : usage variations - multidimensional arrays +--FILE-- + 'nine'); + +echo "\n-- Slice a two-dimensional array --\n"; +var_dump(array_slice($input, 1, 3)); + +echo "\n-- \$input is a sub-array --\n"; +var_dump(array_slice($input[2], 1, 2)); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_slice() : usage variations *** + +-- Slice a two-dimensional array -- +array(3) { + [0]=> + string(3) "one" + [1]=> + array(3) { + [0]=> + string(4) "zero" + [1]=> + string(2) "un" + [2]=> + string(4) "deux" + } + [2]=> + string(4) "nine" +} + +-- $input is a sub-array -- +array(2) { + [0]=> + string(2) "un" + [1]=> + string(4) "deux" +} +Done diff --git a/tests/std/array/array_slice_variation9.phpt b/tests/std/array/array_slice_variation9.phpt new file mode 100644 index 00000000..436ee467 --- /dev/null +++ b/tests/std/array/array_slice_variation9.phpt @@ -0,0 +1,46 @@ +--TEST-- +Test array_slice() function : usage variations - referenced variables +--SKIPIF-- + +--FILE-- + &$val1, 2 => &$val2, 1 => &$val3); +var_dump(array_slice($input, 1, 2)); + +echo "-- Change \$val2 (\$preserve_keys = TRUE) --\n"; +$val2 = 'hello, world'; +var_dump(array_slice($input, 1, 2, true)); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_slice() : usage variations *** + +-- Array of referenced variables ($preserve_keys = default) -- +array(2) { + [0]=> + &string(3) "two" + [1]=> + &string(5) "three" +} +-- Change $val2 ($preserve_keys = TRUE) -- +array(2) { + [2]=> + &string(12) "hello, world" + [1]=> + &string(5) "three" +} +Done diff --git a/tests/std/array/array_splice_basic.phpt b/tests/std/array/array_splice_basic.phpt new file mode 100644 index 00000000..6396ca75 --- /dev/null +++ b/tests/std/array/array_splice_basic.phpt @@ -0,0 +1,135 @@ +--TEST-- +Test array_splice(): basic functionality +--FILE-- + +--EXPECT-- +*** Testing array_splice() basic operations *** +test truncation +array(2) { + [0]=> + string(4) "blue" + [1]=> + string(6) "yellow" +} +array(2) { + [0]=> + string(3) "red" + [1]=> + string(5) "green" +} +test truncation with null length +array(2) { + [0]=> + string(4) "blue" + [1]=> + string(6) "yellow" +} +array(2) { + [0]=> + string(3) "red" + [1]=> + string(5) "green" +} +test removing entries from the middle +array(2) { + [0]=> + string(5) "green" + [1]=> + string(4) "blue" +} +array(2) { + [0]=> + string(3) "red" + [1]=> + string(6) "yellow" +} +test substitution at end +array(3) { + [0]=> + string(5) "green" + [1]=> + string(4) "blue" + [2]=> + string(6) "yellow" +} +array(2) { + [0]=> + string(3) "red" + [1]=> + string(6) "orange" +} +array(1) { + [0]=> + string(6) "yellow" +} +array(5) { + [0]=> + string(3) "red" + [1]=> + string(5) "green" + [2]=> + string(4) "blue" + [3]=> + string(5) "black" + [4]=> + string(6) "maroon" +} +test insertion +array(0) { +} +array(5) { + [0]=> + string(3) "red" + [1]=> + string(5) "green" + [2]=> + string(4) "blue" + [3]=> + string(6) "purple" + [4]=> + string(6) "yellow" +} diff --git a/tests/std/array/array_splice_variation1.phpt b/tests/std/array/array_splice_variation1.phpt new file mode 100644 index 00000000..ab13d75e --- /dev/null +++ b/tests/std/array/array_splice_variation1.phpt @@ -0,0 +1,113 @@ +--TEST-- +Test array_splice() function : usage variations - references +--SKIPIF-- + + +--FILE-- +&$numbers[3],4,&$numbers[5],"six"=>&$numbers[6],7,&$numbers[8],"nine"=>&$numbers[9]); +var_dump (array_splice ($input_array,4,3)); +var_dump ($input_array); + +echo "Test behaviour of replacement array containing references \n"; + +$three=3; +$four=4; +$input_array=array (0,1,2); +$b=array(&$three,"fourkey"=>&$four); +array_splice ($input_array,-1,1,$b); +var_dump ($input_array); + +echo "Test behaviour of replacement which is part of reference set \n"; + +$int=3; +$input_array=array (1,2); +$b=&$int; + +array_splice ($input_array,-1,1,$b); +var_dump ($input_array); +echo "Done\n"; +?> +--EXPECT-- +test behaviour when input array is in a reference set +array(1) { + [0]=> + int(2) +} +array(2) { + [0]=> + &array(1) { + [0]=> + int(1) + } + [1]=> + &array(1) { + [0]=> + int(1) + } +} +Test behaviour of input arrays containing references +array(3) { + [0]=> + int(4) + [1]=> + &int(5) + ["six"]=> + &int(6) +} +array(7) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + &int(2) + ["three"]=> + &int(3) + [3]=> + int(7) + [4]=> + &int(8) + ["nine"]=> + &int(9) +} +Test behaviour of replacement array containing references +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + &int(3) + [3]=> + &int(4) +} +Test behaviour of replacement which is part of reference set +array(2) { + [0]=> + int(1) + [1]=> + int(3) +} +Done diff --git a/tests/std/array/array_splice_variation3.phpt b/tests/std/array/array_splice_variation3.phpt new file mode 100644 index 00000000..d456cdb5 --- /dev/null +++ b/tests/std/array/array_splice_variation3.phpt @@ -0,0 +1,844 @@ +--TEST-- +Test array_splice() function : usage variations - lengths and offsets +--FILE-- + +--EXPECT-- +*** array_splice() function : usage variations - lengths and offsets +absolute offset - absolute length - cut from beginning + - No replacement +array(2) { + [0]=> + int(0) + [1]=> + int(1) +} +array(4) { + [0]=> + int(2) + [1]=> + int(3) + [2]=> + int(4) + [3]=> + int(5) +} + - With replacement +array(2) { + [0]=> + int(0) + [1]=> + int(1) +} +array(7) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + [2]=> + string(1) "C" + [3]=> + int(2) + [4]=> + int(3) + [5]=> + int(4) + [6]=> + int(5) +} +absolute offset - absolute length - cut from middle + - No replacement +array(2) { + [0]=> + int(2) + [1]=> + int(3) +} +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(4) + [3]=> + int(5) +} + - With replacement +array(2) { + [0]=> + int(2) + [1]=> + int(3) +} +array(7) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + string(1) "A" + [3]=> + string(1) "B" + [4]=> + string(1) "C" + [5]=> + int(4) + [6]=> + int(5) +} +absolute offset - absolute length - cut from end + - No replacement +array(2) { + [0]=> + int(4) + [1]=> + int(5) +} +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) +} + - With replacement +array(2) { + [0]=> + int(4) + [1]=> + int(5) +} +array(7) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + string(1) "A" + [5]=> + string(1) "B" + [6]=> + string(1) "C" +} +absolute offset - absolute length - attempt to cut past end + - No replacement +array(2) { + [0]=> + int(4) + [1]=> + int(5) +} +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) +} + - With replacement +array(2) { + [0]=> + int(4) + [1]=> + int(5) +} +array(7) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + string(1) "A" + [5]=> + string(1) "B" + [6]=> + string(1) "C" +} +absolute offset - absolute length - cut everything + - No replacement +array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) +} +array(0) { +} + - With replacement +array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) +} +array(3) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + [2]=> + string(1) "C" +} +absolute offset - absolute length - cut nothing + - No replacement +array(0) { +} +array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) +} + - With replacement +array(0) { +} +array(9) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + string(1) "A" + [4]=> + string(1) "B" + [5]=> + string(1) "C" + [6]=> + int(3) + [7]=> + int(4) + [8]=> + int(5) +} +absolute offset - relative length - cut from beginning + - No replacement +array(2) { + [0]=> + int(0) + [1]=> + int(1) +} +array(4) { + [0]=> + int(2) + [1]=> + int(3) + [2]=> + int(4) + [3]=> + int(5) +} + - With replacement +array(2) { + [0]=> + int(0) + [1]=> + int(1) +} +array(7) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + [2]=> + string(1) "C" + [3]=> + int(2) + [4]=> + int(3) + [5]=> + int(4) + [6]=> + int(5) +} +absolute offset - relative length - cut from middle + - No replacement +array(2) { + [0]=> + int(2) + [1]=> + int(3) +} +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(4) + [3]=> + int(5) +} + - With replacement +array(2) { + [0]=> + int(2) + [1]=> + int(3) +} +array(7) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + string(1) "A" + [3]=> + string(1) "B" + [4]=> + string(1) "C" + [5]=> + int(4) + [6]=> + int(5) +} +absolute offset - relative length - attempt to cut form before beginning + - No replacement +array(0) { +} +array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) +} + - With replacement +array(0) { +} +array(9) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + [2]=> + string(1) "C" + [3]=> + int(0) + [4]=> + int(1) + [5]=> + int(2) + [6]=> + int(3) + [7]=> + int(4) + [8]=> + int(5) +} +absolute offset - relative length - cut nothing + - No replacement +array(0) { +} +array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) +} + - With replacement +array(0) { +} +array(9) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + string(1) "A" + [3]=> + string(1) "B" + [4]=> + string(1) "C" + [5]=> + int(2) + [6]=> + int(3) + [7]=> + int(4) + [8]=> + int(5) +} +relative offset - absolute length - cut from beginning + - No replacement +array(2) { + [0]=> + int(0) + [1]=> + int(1) +} +array(4) { + [0]=> + int(2) + [1]=> + int(3) + [2]=> + int(4) + [3]=> + int(5) +} + - With replacement +array(2) { + [0]=> + int(0) + [1]=> + int(1) +} +array(7) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + [2]=> + string(1) "C" + [3]=> + int(2) + [4]=> + int(3) + [5]=> + int(4) + [6]=> + int(5) +} +relative offset - absolute length - cut from middle + - No replacement +array(2) { + [0]=> + int(2) + [1]=> + int(3) +} +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(4) + [3]=> + int(5) +} + - With replacement +array(2) { + [0]=> + int(2) + [1]=> + int(3) +} +array(7) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + string(1) "A" + [3]=> + string(1) "B" + [4]=> + string(1) "C" + [5]=> + int(4) + [6]=> + int(5) +} +relative offset - absolute length - cut from end + - No replacement +array(2) { + [0]=> + int(4) + [1]=> + int(5) +} +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) +} + - With replacement +array(2) { + [0]=> + int(4) + [1]=> + int(5) +} +array(7) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + string(1) "A" + [5]=> + string(1) "B" + [6]=> + string(1) "C" +} +relative offset - absolute length - attempt to cut past end + - No replacement +array(2) { + [0]=> + int(4) + [1]=> + int(5) +} +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) +} + - With replacement +array(2) { + [0]=> + int(4) + [1]=> + int(5) +} +array(7) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + string(1) "A" + [5]=> + string(1) "B" + [6]=> + string(1) "C" +} +relative offset - absolute length - cut everything + - No replacement +array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) +} +array(0) { +} + - With replacement +array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) +} +array(3) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + [2]=> + string(1) "C" +} +relative offset - absolute length - cut nothing + - No replacement +array(0) { +} +array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) +} + - With replacement +array(0) { +} +array(9) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + [2]=> + string(1) "C" + [3]=> + int(0) + [4]=> + int(1) + [5]=> + int(2) + [6]=> + int(3) + [7]=> + int(4) + [8]=> + int(5) +} +relative offset - relative length - cut from beginning + - No replacement +array(2) { + [0]=> + int(0) + [1]=> + int(1) +} +array(4) { + [0]=> + int(2) + [1]=> + int(3) + [2]=> + int(4) + [3]=> + int(5) +} + - With replacement +array(2) { + [0]=> + int(0) + [1]=> + int(1) +} +array(7) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + [2]=> + string(1) "C" + [3]=> + int(2) + [4]=> + int(3) + [5]=> + int(4) + [6]=> + int(5) +} +relative offset - relative length - cut from middle + - No replacement +array(2) { + [0]=> + int(2) + [1]=> + int(3) +} +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(4) + [3]=> + int(5) +} + - With replacement +array(2) { + [0]=> + int(2) + [1]=> + int(3) +} +array(7) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + string(1) "A" + [3]=> + string(1) "B" + [4]=> + string(1) "C" + [5]=> + int(4) + [6]=> + int(5) +} +relative offset - relative length - cut nothing + - No replacement +array(0) { +} +array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) +} + - With replacement +array(0) { +} +array(9) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + string(1) "A" + [3]=> + string(1) "B" + [4]=> + string(1) "C" + [5]=> + int(2) + [6]=> + int(3) + [7]=> + int(4) + [8]=> + int(5) +} +Done diff --git a/tests/std/array/array_splice_variation4.phpt b/tests/std/array/array_splice_variation4.phpt new file mode 100644 index 00000000..6742b2ff --- /dev/null +++ b/tests/std/array/array_splice_variation4.phpt @@ -0,0 +1,66 @@ +--TEST-- +Test array_splice() function : usage variations - non array replacement values +--FILE-- + +--EXPECTF-- +array(0) { +} +array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) +} +array(0) { +} +array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + float(2.1) +} +array(0) { +} +array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + bool(true) +} +array(0) { +} +array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + resource(%d) of type (stream) +} +Done diff --git a/tests/std/array/array_sum.phpt b/tests/std/array/array_sum.phpt new file mode 100644 index 00000000..9ba80beb --- /dev/null +++ b/tests/std/array/array_sum.phpt @@ -0,0 +1,30 @@ +--TEST-- +Test array_sum() +--INI-- +precision=14 +memory_limit=128M +--FILE-- + +--EXPECTF-- +int(500500) +int(500500) +%st(5000050000) +%st(5000050000) diff --git a/tests/std/array/array_sum_basic.phpt b/tests/std/array/array_sum_basic.phpt new file mode 100644 index 00000000..7a7b13e9 --- /dev/null +++ b/tests/std/array/array_sum_basic.phpt @@ -0,0 +1,32 @@ +--TEST-- +Test array_sum() function : basic functionality +--FILE-- + +--EXPECT-- +*** Testing array_sum() : basic functionality *** +-- array_sum() with integer array entries -- +int(15) +-- array_sum() with float array entries -- +float(11.2) +-- array_sum() with integer/float array entries -- +float(17.9) +Done diff --git a/tests/std/array/array_sum_empty_array.phpt b/tests/std/array/array_sum_empty_array.phpt new file mode 100644 index 00000000..17c80ce4 --- /dev/null +++ b/tests/std/array/array_sum_empty_array.phpt @@ -0,0 +1,17 @@ +--TEST-- +Test array_sum() function with empty array +--FILE-- + $carry + $value, 0)); +?> +--EXPECT-- +array_sum() version: +int(0) +array_reduce() version: +int(0) diff --git a/tests/std/array/array_sum_objects_operation_no_cast.phpt b/tests/std/array/array_sum_objects_operation_no_cast.phpt new file mode 100644 index 00000000..d89b44ae --- /dev/null +++ b/tests/std/array/array_sum_objects_operation_no_cast.phpt @@ -0,0 +1,26 @@ +--TEST-- +Test array_sum() function with objects that implement addition but not castable to numeric type +--EXTENSIONS-- +zend_test +--FILE-- + $carry + $value, 0)); +?> +--EXPECTF-- +array_sum() version: + +Warning: array_sum(): Addition is not supported on type DoOperationNoCast in %s on line %d + +Warning: array_sum(): Addition is not supported on type DoOperationNoCast in %s on line %d +int(0) +array_reduce() version: +object(DoOperationNoCast)#5 (1) { + ["val":"DoOperationNoCast":private]=> + int(31) +} diff --git a/tests/std/array/array_sum_objects_operation_no_cast_FFI.phpt b/tests/std/array/array_sum_objects_operation_no_cast_FFI.phpt new file mode 100644 index 00000000..a43f27b1 --- /dev/null +++ b/tests/std/array/array_sum_objects_operation_no_cast_FFI.phpt @@ -0,0 +1,29 @@ +--TEST-- +Test array_sum() function with objects that implement addition but not castable to numeric type +--EXTENSIONS-- +ffi +--FILE-- +new("int[2]"); +$x[0] = 10; +$x[1] = 25; + +$input = [$x, 1]; + +echo "array_sum() version:\n"; +var_dump(array_sum($input)); + +echo "array_reduce() version:\n"; +var_dump(array_reduce($input, fn($carry, $value) => $carry + $value, 0)); +?> +--EXPECTF-- +array_sum() version: + +Warning: array_sum(): Addition is not supported on type FFI\CData in %s on line %d +int(1) +array_reduce() version: +object(FFI\CData:int32_t*)#4 (1) { + [0]=> + int(25) +} diff --git a/tests/std/array/array_sum_on_reference.phpt b/tests/std/array/array_sum_on_reference.phpt new file mode 100644 index 00000000..a11da5fd --- /dev/null +++ b/tests/std/array/array_sum_on_reference.phpt @@ -0,0 +1,15 @@ +--TEST-- +array_sum() on array with references +--FILE-- + +--EXPECT-- +int(200) +string(3) "100" diff --git a/tests/std/array/array_sum_variation2.phpt b/tests/std/array/array_sum_variation2.phpt new file mode 100644 index 00000000..a4cf7d74 --- /dev/null +++ b/tests/std/array/array_sum_variation2.phpt @@ -0,0 +1,44 @@ +--TEST-- +Test array_sum() function : usage variations - array with different integer value +--FILE-- + +--EXPECT-- +*** Testing array_sum() : different integer array *** +-- Sum of Integer array -- +int(-573) +-- Sum of Octal array -- +int(35) +-- Sum of Hex array -- +int(-198) +-- Sum of mixed integer values -- +int(58) +Done diff --git a/tests/std/array/array_sum_variation3.phpt b/tests/std/array/array_sum_variation3.phpt new file mode 100644 index 00000000..3cb8bc7d --- /dev/null +++ b/tests/std/array/array_sum_variation3.phpt @@ -0,0 +1,49 @@ +--TEST-- +Test array_sum() function : usage variations - array with different float values +--FILE-- + +--EXPECT-- +*** Testing array_sum() : array with different float values *** +-- simple float array -- +float(1.3) +-- float array with scientific notations e and E -- +float(23630.021) +float(23630.021) +-- Mixed float array -- +float(6531.5458) +Done diff --git a/tests/std/array/array_sum_variation4.phpt b/tests/std/array/array_sum_variation4.phpt new file mode 100644 index 00000000..22c72ad1 --- /dev/null +++ b/tests/std/array/array_sum_variation4.phpt @@ -0,0 +1,29 @@ +--TEST-- +Test array_sum() function : usage variations - array with duplicate values +--FILE-- + +--EXPECT-- +*** Testing array_sum() : array with duplicate values *** +-- With integer array -- +int(117) +-- With float array -- +float(2.5) +Done diff --git a/tests/std/array/array_sum_variation5.phpt b/tests/std/array/array_sum_variation5.phpt new file mode 100644 index 00000000..f38f4507 --- /dev/null +++ b/tests/std/array/array_sum_variation5.phpt @@ -0,0 +1,32 @@ +--TEST-- +Test array_sum() function : usage variations - array with reference variables as elements +--FILE-- + 10, + 1 => &$value4, + 2 => &$value2, + 3 => 200, + 4 => &$value3, +); + +var_dump( array_sum($input) ); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_sum() : array with elements as reference *** +int(305) +Done diff --git a/tests/std/array/array_sum_variation6.phpt b/tests/std/array/array_sum_variation6.phpt new file mode 100644 index 00000000..e0739ec1 --- /dev/null +++ b/tests/std/array/array_sum_variation6.phpt @@ -0,0 +1,28 @@ +--TEST-- +Test array_sum() function : usage variations - associative array +--FILE-- + 1, 1 => 10, 2 => 0, 3 => -2, 4 => 23.56); +echo "-- with numeric keys --\n"; +var_dump( array_sum($input) ); + +// array with string keys +$input = array('a' => 20, "b" => 50, 'c' => 0, 'd' => -30, "e" => 100); +echo "-- with string keys --\n"; +var_dump( array_sum($input) ); +echo "Done"; +?> +--EXPECT-- +*** Testing array_sum() : with associative array *** +-- with numeric keys -- +float(32.56) +-- with string keys -- +int(140) +Done diff --git a/tests/std/array/array_sum_variation7.phpt b/tests/std/array/array_sum_variation7.phpt new file mode 100644 index 00000000..224d0d0a --- /dev/null +++ b/tests/std/array/array_sum_variation7.phpt @@ -0,0 +1,110 @@ +--TEST-- +Test array_sum() function : usage variations - 'input' array with unexpected values as array element +--SKIPIF-- + +--FILE-- +value = $value; + } +} + +function main() { +echo "*** Testing array_sum() : array with unexpected entries ***\n"; + +// string array +$input = array('Apple', 'Banana', 'Carrot', 'Mango', 'Orange'); +echo "-- array with string values --\n"; +var_dump( array_sum($input) ); + +// bool array +$input = array( true, true, false, true, false); +echo "-- array with bool values --\n"; +var_dump( array_sum($input) ); + +// array with null entry +$input = array(null, NULL); +echo "-- array with null values --\n"; +var_dump( array_sum($input) ); + +// array with subarray +$input = array( + array(1, 2), + array(), + array(0) +); +echo "-- array with subarrays --\n"; +var_dump( array_sum($input) ); + +// array of objects +$input = array( + new MyClass(2), + new MyClass(5), + new MyClass(10), + new MyClass(0) +); +echo "-- array with object values --\n"; +var_dump( array_sum($input) ); + +// Mixed values +$input = array( 5, -8, 7.2, -1.2, "10", "apple", 'Mango', true, false, null, NULL, array( array(1,2), array(0), array())); +echo "-- array with mixed values --\n"; +var_dump( array_sum($input) ); +echo "Done"; +} +?> +--EXPECTF-- +*** Testing array_sum() : array with unexpected entries *** +-- array with string values -- + +%s: Addition is not supported on type string in %s on line %d + +%s: Addition is not supported on type string in %s on line %d + +%s: Addition is not supported on type string in %s on line %d + +%s: Addition is not supported on type string in %s on line %d + +%s: Addition is not supported on type string in %s on line %d +int(0) +-- array with bool values -- +int(3) +-- array with null values -- +int(0) +-- array with subarrays -- + +%s: Addition is not supported on type array in %s on line %d + +%s: Addition is not supported on type array in %s on line %d + +%s: Addition is not supported on type array in %s on line %d +int(0) +-- array with object values -- + +%s: Addition is not supported on type MyClass in %s on line %d + +%s: Addition is not supported on type MyClass in %s on line %d + +%s: Addition is not supported on type MyClass in %s on line %d + +%s: Addition is not supported on type MyClass in %s on line %d +int(0) +-- array with mixed values -- + +%s: Addition is not supported on type string in %s on line %d + +%s: Addition is not supported on type string in %s on line %d + +%s: Addition is not supported on type array in %s on line %d +float(14) +Done diff --git a/tests/std/array/array_sum_variation8.phpt b/tests/std/array/array_sum_variation8.phpt new file mode 100644 index 00000000..21ff8fcf --- /dev/null +++ b/tests/std/array/array_sum_variation8.phpt @@ -0,0 +1,24 @@ +--TEST-- +Test array_sum() function: resources in array +--FILE-- + $carry + $value, 0)); +} catch (TypeError $e) { + echo $e->getMessage(); +} +?> +--EXPECTF-- +array_sum() version: + +Warning:%S Addition is not supported on type resource in %s on line %d +int(13) +array_reduce() version: +Unsupported operand types: int + resource%S +%a diff --git a/tests/std/array/array_sum_variation9.phpt b/tests/std/array/array_sum_variation9.phpt new file mode 100644 index 00000000..61af56b2 --- /dev/null +++ b/tests/std/array/array_sum_variation9.phpt @@ -0,0 +1,22 @@ +--TEST-- +Test array_sum() function with objects castable to numeric type +--EXTENSIONS-- +gmp +--FILE-- + $carry + $value, 0)); +?> +--EXPECT-- +array_sum() version: +int(31) +array_reduce() version: +object(GMP)#5 (1) { + ["num"]=> + string(2) "31" +} diff --git a/tests/std/array/array_udiff_assoc_basic.phpt b/tests/std/array/array_udiff_assoc_basic.phpt new file mode 100644 index 00000000..293ff402 --- /dev/null +++ b/tests/std/array/array_udiff_assoc_basic.phpt @@ -0,0 +1,48 @@ +--TEST-- +array_udiff_assoc(): Test return type and value for expected input +--FILE-- +priv_member = $val; + } + static function comp_func_cr($a, $b) + { + if ($a->priv_member === $b->priv_member) { + return 0; + } + return $a->priv_member > $b->priv_member ? 1 : -1; + } +} +function main() +{ + $a = array("0.1" => new cr(9), "0.5" => new cr(12), 0 => new cr(23), 1 => new cr(4), 2 => new cr(-15)); + $b = array("0.2" => new cr(9), "0.5" => new cr(22), 0 => new cr(3), 1 => new cr(4), 2 => new cr(-15)); + $result = array_udiff_assoc($a, $b, array("cr", "comp_func_cr")); + var_dump($result); +} +?> +--EXPECTF-- +array(3) { + ["0.1"]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(9) + } + ["0.5"]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(12) + } + [0]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(23) + } +} diff --git a/tests/std/array/array_udiff_assoc_variation.phpt b/tests/std/array/array_udiff_assoc_variation.phpt new file mode 100644 index 00000000..02afa572 --- /dev/null +++ b/tests/std/array/array_udiff_assoc_variation.phpt @@ -0,0 +1,29 @@ +--TEST-- +Test array_udiff_assoc() function : variation +--SKIPIF-- +--FILE-- + "one", "02" => "two", '3' => "three", "four", "0.5" => 5, 6 => 6, "seven" => "07"); +$arr2 = array("one" => "one", "02" => "two", '3' => "three"); +$arr3 = array("four", "0.5" => "five", 6 => 6, "seven" => 7); +$arr4 = array("four", "0.5" => "five", 6 => 6, "seven" => 7); + + +var_dump( array_udiff_assoc($arr1, $arr2, $arr3, $arr4, $key_compare_function) ); + + +?> +--EXPECT-- +*** Testing array_udiff_assoc() : variation - testing with multiple array arguments *** +array(2) { + [4]=> + string(4) "four" + ["0.5"]=> + int(5) +} diff --git a/tests/std/array/array_udiff_assoc_variation1.phpt b/tests/std/array/array_udiff_assoc_variation1.phpt new file mode 100644 index 00000000..1fd8eabb --- /dev/null +++ b/tests/std/array/array_udiff_assoc_variation1.phpt @@ -0,0 +1,161 @@ +--TEST-- +Test array_udiff_assoc() function : usage variation +--SKIPIF-- + + +--FILE-- + 1, 'two' => 2); + //array of values to iterate over + $inputs = array( + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 123456789000.0, + 'float -12.3456789000e10' => -123456789000.0, + 'float .5' => 0.5, + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + // boolean data + 'lowercase true' => true, + 'lowercase false' => false, + 'uppercase TRUE' => TRUE, + 'uppercase FALSE' => FALSE, + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + // undefined data + 'undefined var' => @$undefined_var, + // unset data + 'unset var' => @$unset_var, + ); + // loop through each element of the array for array1 + foreach ($inputs as $key => $value) { + echo "\n--{$key}--\n"; + try { + var_dump(array_udiff_assoc($value, $array2, $key_comp_func)); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + } +} +?> +--EXPECT-- +*** Testing array_udiff_assoc() : usage variation *** + +--int 0-- +array_udiff_assoc(): Argument #1 ($array) must be of type array, int given + +--int 1-- +array_udiff_assoc(): Argument #1 ($array) must be of type array, int given + +--int 12345-- +array_udiff_assoc(): Argument #1 ($array) must be of type array, int given + +--int -12345-- +array_udiff_assoc(): Argument #1 ($array) must be of type array, int given + +--float 10.5-- +array_udiff_assoc(): Argument #1 ($array) must be of type array, float given + +--float -10.5-- +array_udiff_assoc(): Argument #1 ($array) must be of type array, float given + +--float 12.3456789000e10-- +array_udiff_assoc(): Argument #1 ($array) must be of type array, float given + +--float -12.3456789000e10-- +array_udiff_assoc(): Argument #1 ($array) must be of type array, float given + +--float .5-- +array_udiff_assoc(): Argument #1 ($array) must be of type array, float given + +--uppercase NULL-- +array_udiff_assoc(): Argument #1 ($array) must be of type array, null given + +--lowercase null-- +array_udiff_assoc(): Argument #1 ($array) must be of type array, null given + +--lowercase true-- +array_udiff_assoc(): Argument #1 ($array) must be of type array, true given + +--lowercase false-- +array_udiff_assoc(): Argument #1 ($array) must be of type array, false given + +--uppercase TRUE-- +array_udiff_assoc(): Argument #1 ($array) must be of type array, true given + +--uppercase FALSE-- +array_udiff_assoc(): Argument #1 ($array) must be of type array, false given + +--empty string DQ-- +array_udiff_assoc(): Argument #1 ($array) must be of type array, string given + +--empty string SQ-- +array_udiff_assoc(): Argument #1 ($array) must be of type array, string given + +--string DQ-- +array_udiff_assoc(): Argument #1 ($array) must be of type array, string given + +--string SQ-- +array_udiff_assoc(): Argument #1 ($array) must be of type array, string given + +--mixed case string-- +array_udiff_assoc(): Argument #1 ($array) must be of type array, string given + +--heredoc-- +array_udiff_assoc(): Argument #1 ($array) must be of type array, string given + +--instance of classWithToString-- +array_udiff_assoc(): Argument #1 ($array) must be of type array, classWithToString given + +--instance of classWithoutToString-- +array_udiff_assoc(): Argument #1 ($array) must be of type array, classWithoutToString given + +--undefined var-- +array_udiff_assoc(): Argument #1 ($array) must be of type array, null given + +--unset var-- +array_udiff_assoc(): Argument #1 ($array) must be of type array, null given diff --git a/tests/std/array/array_udiff_assoc_variation2.phpt b/tests/std/array/array_udiff_assoc_variation2.phpt new file mode 100644 index 00000000..b155ff4a --- /dev/null +++ b/tests/std/array/array_udiff_assoc_variation2.phpt @@ -0,0 +1,161 @@ +--TEST-- +Test array_udiff_assoc() function : usage variation +--SKIPIF-- + + +--FILE-- + 1, 'two' => 2); + //array of values to iterate over + $inputs = array( + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 123456789000.0, + 'float -12.3456789000e10' => -123456789000.0, + 'float .5' => 0.5, + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + // boolean data + 'lowercase true' => true, + 'lowercase false' => false, + 'uppercase TRUE' => TRUE, + 'uppercase FALSE' => FALSE, + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + // undefined data + 'undefined var' => @$undefined_var, + // unset data + 'unset var' => @$unset_var, + ); + // loop through each element of the array for array2 + foreach ($inputs as $key => $value) { + echo "\n--{$key}--\n"; + try { + var_dump(array_udiff_assoc($array1, $value, $key_comp_func)); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + } +} +?> +--EXPECT-- +*** Testing array_udiff_assoc() : usage variation *** + +--int 0-- +array_udiff_assoc(): Argument #2 must be of type array, int given + +--int 1-- +array_udiff_assoc(): Argument #2 must be of type array, int given + +--int 12345-- +array_udiff_assoc(): Argument #2 must be of type array, int given + +--int -12345-- +array_udiff_assoc(): Argument #2 must be of type array, int given + +--float 10.5-- +array_udiff_assoc(): Argument #2 must be of type array, float given + +--float -10.5-- +array_udiff_assoc(): Argument #2 must be of type array, float given + +--float 12.3456789000e10-- +array_udiff_assoc(): Argument #2 must be of type array, float given + +--float -12.3456789000e10-- +array_udiff_assoc(): Argument #2 must be of type array, float given + +--float .5-- +array_udiff_assoc(): Argument #2 must be of type array, float given + +--uppercase NULL-- +array_udiff_assoc(): Argument #2 must be of type array, null given + +--lowercase null-- +array_udiff_assoc(): Argument #2 must be of type array, null given + +--lowercase true-- +array_udiff_assoc(): Argument #2 must be of type array, true given + +--lowercase false-- +array_udiff_assoc(): Argument #2 must be of type array, false given + +--uppercase TRUE-- +array_udiff_assoc(): Argument #2 must be of type array, true given + +--uppercase FALSE-- +array_udiff_assoc(): Argument #2 must be of type array, false given + +--empty string DQ-- +array_udiff_assoc(): Argument #2 must be of type array, string given + +--empty string SQ-- +array_udiff_assoc(): Argument #2 must be of type array, string given + +--string DQ-- +array_udiff_assoc(): Argument #2 must be of type array, string given + +--string SQ-- +array_udiff_assoc(): Argument #2 must be of type array, string given + +--mixed case string-- +array_udiff_assoc(): Argument #2 must be of type array, string given + +--heredoc-- +array_udiff_assoc(): Argument #2 must be of type array, string given + +--instance of classWithToString-- +array_udiff_assoc(): Argument #2 must be of type array, classWithToString given + +--instance of classWithoutToString-- +array_udiff_assoc(): Argument #2 must be of type array, classWithoutToString given + +--undefined var-- +array_udiff_assoc(): Argument #2 must be of type array, null given + +--unset var-- +array_udiff_assoc(): Argument #2 must be of type array, null given diff --git a/tests/std/array/array_udiff_assoc_variation5.phpt b/tests/std/array/array_udiff_assoc_variation5.phpt new file mode 100644 index 00000000..3ce2c6cf --- /dev/null +++ b/tests/std/array/array_udiff_assoc_variation5.phpt @@ -0,0 +1,56 @@ +--TEST-- +Test array_udiff_assoc() function : usage variation - incorrect comparison functions +--SKIPIF-- + + +--FILE-- +getMessage() . "\n"; + } + echo "\n-- comparison function taking too few parameters --\n"; + var_dump(array_udiff_assoc($arr1, $arr2, 'too_few_parameters')); +} +?> +--EXPECT-- +*** Testing array_udiff_assoc() : usage variation - differing comparison functions*** + +-- comparison function with an incorrect return value -- +array(1) { + [0]=> + int(1) +} + +-- comparison function taking too many parameters -- +array(1) { + [0]=> + int(1) +} + +-- comparison function taking too few parameters -- +array(1) { + [0]=> + int(1) +} diff --git a/tests/std/array/array_udiff_basic.phpt b/tests/std/array/array_udiff_basic.phpt new file mode 100644 index 00000000..cbac87a8 --- /dev/null +++ b/tests/std/array/array_udiff_basic.phpt @@ -0,0 +1,43 @@ +--TEST-- +array_udiff():Test return type and value for expected input +--FILE-- +priv_member = $val; + } + static function comp_func_cr($a, $b) + { + if ($a->priv_member === $b->priv_member) { + return 0; + } + return $a->priv_member > $b->priv_member ? 1 : -1; + } +} +function main() +{ + $a = array("0.1" => new cr(9), "0.5" => new cr(12), 0 => new cr(23), 1 => new cr(4), 2 => new cr(-15)); + $b = array("0.2" => new cr(9), "0.5" => new cr(22), 0 => new cr(3), 1 => new cr(4), 2 => new cr(-15)); + $result = array_udiff($a, $b, array("cr", "comp_func_cr")); + var_dump($result); +} +?> +--EXPECTF-- +array(2) { + ["0.5"]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(12) + } + [0]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(23) + } +} diff --git a/tests/std/array/array_udiff_uassoc_basic.phpt b/tests/std/array/array_udiff_uassoc_basic.phpt new file mode 100644 index 00000000..cbe99767 --- /dev/null +++ b/tests/std/array/array_udiff_uassoc_basic.phpt @@ -0,0 +1,55 @@ +--TEST-- +array_udiff_uassoc(): Test return type and value for expected input +--FILE-- +priv_member = $val; + } + static function comp_func_cr($a, $b) + { + if ($a->priv_member === $b->priv_member) { + return 0; + } + return $a->priv_member > $b->priv_member ? 1 : -1; + } + static function comp_func_key($a, $b) + { + if ($a === $b) { + return 0; + } + return $a > $b ? 1 : -1; + } +} +function main() +{ + $a = array("0.1" => new cr(9), "0.5" => new cr(12), 0 => new cr(23), 1 => new cr(4), 2 => new cr(-15)); + $b = array("0.2" => new cr(9), "0.5" => new cr(22), 0 => new cr(3), 1 => new cr(4), 2 => new cr(-15)); + $result = array_udiff_uassoc($a, $b, array("cr", "comp_func_cr"), array("cr", "comp_func_key")); + var_dump($result); +} +?> +--EXPECTF-- +array(3) { + ["0.1"]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(9) + } + ["0.5"]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(12) + } + [0]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(23) + } +} diff --git a/tests/std/array/array_udiff_uassoc_variation1.phpt b/tests/std/array/array_udiff_uassoc_variation1.phpt new file mode 100644 index 00000000..15436670 --- /dev/null +++ b/tests/std/array/array_udiff_uassoc_variation1.phpt @@ -0,0 +1,160 @@ +--TEST-- +Test array_udiff_uassoc() function : usage variation +--SKIPIF-- + + +--FILE-- + 1, 'two' => 2); + //array of values to iterate over + $inputs = array( + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 123456789000.0, + 'float -12.3456789000e10' => -123456789000.0, + 'float .5' => 0.5, + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + // boolean data + 'lowercase true' => true, + 'lowercase false' => false, + 'uppercase TRUE' => TRUE, + 'uppercase FALSE' => FALSE, + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + // undefined data + 'undefined var' => $undefined_var, + // unset data + 'unset var' => $unset_var, + ); + // loop through each element of the array for array1 + foreach ($inputs as $key => $value) { + echo "\n--{$key}--\n"; + try { + var_dump(array_udiff_uassoc($value, $array2, $data_comp_func, $key_comp_func)); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + } +} +?> +--EXPECT-- +*** Testing array_udiff_uassoc() : usage variation *** + +--int 0-- +array_udiff_uassoc(): Argument #1 ($array) must be of type array, int given + +--int 1-- +array_udiff_uassoc(): Argument #1 ($array) must be of type array, int given + +--int 12345-- +array_udiff_uassoc(): Argument #1 ($array) must be of type array, int given + +--int -12345-- +array_udiff_uassoc(): Argument #1 ($array) must be of type array, int given + +--float 10.5-- +array_udiff_uassoc(): Argument #1 ($array) must be of type array, float given + +--float -10.5-- +array_udiff_uassoc(): Argument #1 ($array) must be of type array, float given + +--float 12.3456789000e10-- +array_udiff_uassoc(): Argument #1 ($array) must be of type array, float given + +--float -12.3456789000e10-- +array_udiff_uassoc(): Argument #1 ($array) must be of type array, float given + +--float .5-- +array_udiff_uassoc(): Argument #1 ($array) must be of type array, float given + +--uppercase NULL-- +array_udiff_uassoc(): Argument #1 ($array) must be of type array, null given + +--lowercase null-- +array_udiff_uassoc(): Argument #1 ($array) must be of type array, null given + +--lowercase true-- +array_udiff_uassoc(): Argument #1 ($array) must be of type array, true given + +--lowercase false-- +array_udiff_uassoc(): Argument #1 ($array) must be of type array, false given + +--uppercase TRUE-- +array_udiff_uassoc(): Argument #1 ($array) must be of type array, true given + +--uppercase FALSE-- +array_udiff_uassoc(): Argument #1 ($array) must be of type array, false given + +--empty string DQ-- +array_udiff_uassoc(): Argument #1 ($array) must be of type array, string given + +--empty string SQ-- +array_udiff_uassoc(): Argument #1 ($array) must be of type array, string given + +--string DQ-- +array_udiff_uassoc(): Argument #1 ($array) must be of type array, string given + +--string SQ-- +array_udiff_uassoc(): Argument #1 ($array) must be of type array, string given + +--mixed case string-- +array_udiff_uassoc(): Argument #1 ($array) must be of type array, string given + +--heredoc-- +array_udiff_uassoc(): Argument #1 ($array) must be of type array, string given + +--instance of classWithToString-- +array_udiff_uassoc(): Argument #1 ($array) must be of type array, classWithToString given + +--instance of classWithoutToString-- +array_udiff_uassoc(): Argument #1 ($array) must be of type array, classWithoutToString given + +--undefined var-- +array_udiff_uassoc(): Argument #1 ($array) must be of type array, null given + diff --git a/tests/std/array/array_udiff_uassoc_variation2.phpt b/tests/std/array/array_udiff_uassoc_variation2.phpt new file mode 100644 index 00000000..4aa546e9 --- /dev/null +++ b/tests/std/array/array_udiff_uassoc_variation2.phpt @@ -0,0 +1,162 @@ +--TEST-- +Test array_udiff_uassoc() function : usage variation +--SKIPIF-- + + +--FILE-- + 1, 'two' => 2); + //array of values to iterate over + $inputs = array( + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 123456789000.0, + 'float -12.3456789000e10' => -123456789000.0, + 'float .5' => 0.5, + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + // boolean data + 'lowercase true' => true, + 'lowercase false' => false, + 'uppercase TRUE' => TRUE, + 'uppercase FALSE' => FALSE, + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + // undefined data + 'undefined var' => @$undefined_var, + // unset data + 'unset var' => @$unset_var, + ); + // loop through each element of the array for array2 + foreach ($inputs as $key => $value) { + echo "\n--{$key}--\n"; + try { + var_dump(array_udiff_uassoc($array1, $value, $data_comp_func, $key_comp_func)); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + } +} +?> +--EXPECT-- +*** Testing array_udiff_uassoc() : usage variation *** + +--int 0-- +array_udiff_uassoc(): Argument #2 must be of type array, int given + +--int 1-- +array_udiff_uassoc(): Argument #2 must be of type array, int given + +--int 12345-- +array_udiff_uassoc(): Argument #2 must be of type array, int given + +--int -12345-- +array_udiff_uassoc(): Argument #2 must be of type array, int given + +--float 10.5-- +array_udiff_uassoc(): Argument #2 must be of type array, float given + +--float -10.5-- +array_udiff_uassoc(): Argument #2 must be of type array, float given + +--float 12.3456789000e10-- +array_udiff_uassoc(): Argument #2 must be of type array, float given + +--float -12.3456789000e10-- +array_udiff_uassoc(): Argument #2 must be of type array, float given + +--float .5-- +array_udiff_uassoc(): Argument #2 must be of type array, float given + +--uppercase NULL-- +array_udiff_uassoc(): Argument #2 must be of type array, null given + +--lowercase null-- +array_udiff_uassoc(): Argument #2 must be of type array, null given + +--lowercase true-- +array_udiff_uassoc(): Argument #2 must be of type array, true given + +--lowercase false-- +array_udiff_uassoc(): Argument #2 must be of type array, false given + +--uppercase TRUE-- +array_udiff_uassoc(): Argument #2 must be of type array, true given + +--uppercase FALSE-- +array_udiff_uassoc(): Argument #2 must be of type array, false given + +--empty string DQ-- +array_udiff_uassoc(): Argument #2 must be of type array, string given + +--empty string SQ-- +array_udiff_uassoc(): Argument #2 must be of type array, string given + +--string DQ-- +array_udiff_uassoc(): Argument #2 must be of type array, string given + +--string SQ-- +array_udiff_uassoc(): Argument #2 must be of type array, string given + +--mixed case string-- +array_udiff_uassoc(): Argument #2 must be of type array, string given + +--heredoc-- +array_udiff_uassoc(): Argument #2 must be of type array, string given + +--instance of classWithToString-- +array_udiff_uassoc(): Argument #2 must be of type array, classWithToString given + +--instance of classWithoutToString-- +array_udiff_uassoc(): Argument #2 must be of type array, classWithoutToString given + +--undefined var-- +array_udiff_uassoc(): Argument #2 must be of type array, null given + +--unset var-- +array_udiff_uassoc(): Argument #2 must be of type array, null given diff --git a/tests/std/array/array_udiff_uassoc_variation6.phpt b/tests/std/array/array_udiff_uassoc_variation6.phpt new file mode 100644 index 00000000..38a26896 --- /dev/null +++ b/tests/std/array/array_udiff_uassoc_variation6.phpt @@ -0,0 +1,56 @@ +--TEST-- +Test array_udiff_uassoc() function : usage variation +--SKIPIF-- + + +--FILE-- +getMessage() . "\n"; + } + echo "\n-- comparison function taking too few parameters --\n"; + var_dump(array_udiff_uassoc($arr1, $arr2, 'too_few_parameters', 'too_few_parameters')); +} +?> +--EXPECT-- +*** Testing array_udiff_uassoc() : usage variation - differing comparison functions*** + +-- comparison function with an incorrect return value -- +array(1) { + [0]=> + int(1) +} + +-- comparison function taking too many parameters -- +array(1) { + [0]=> + int(1) +} + +-- comparison function taking too few parameters -- +array(1) { + [0]=> + int(1) +} diff --git a/tests/std/array/array_udiff_variation1.phpt b/tests/std/array/array_udiff_variation1.phpt new file mode 100644 index 00000000..927d5200 --- /dev/null +++ b/tests/std/array/array_udiff_variation1.phpt @@ -0,0 +1,161 @@ +--TEST-- +Test array_udiff() function : usage variation +--SKIPIF-- + + +--FILE-- + 1, 'two' => 2); + //array of values to iterate over + $inputs = array( + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 123456789000.0, + 'float -12.3456789000e10' => -123456789000.0, + 'float .5' => 0.5, + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + // boolean data + 'lowercase true' => true, + 'lowercase false' => false, + 'uppercase TRUE' => TRUE, + 'uppercase FALSE' => FALSE, + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + // undefined data + 'undefined var' => @$undefined_var, + // unset data + 'unset var' => @$unset_var, + ); + // loop through each element of the array for array1 + foreach ($inputs as $key => $value) { + echo "\n--{$key}--\n"; + try { + var_dump(array_udiff($value, $array2, $data_comp_func)); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + } +} +?> +--EXPECT-- +*** Testing array_udiff() : usage variation *** + +--int 0-- +array_udiff(): Argument #1 ($array) must be of type array, int given + +--int 1-- +array_udiff(): Argument #1 ($array) must be of type array, int given + +--int 12345-- +array_udiff(): Argument #1 ($array) must be of type array, int given + +--int -12345-- +array_udiff(): Argument #1 ($array) must be of type array, int given + +--float 10.5-- +array_udiff(): Argument #1 ($array) must be of type array, float given + +--float -10.5-- +array_udiff(): Argument #1 ($array) must be of type array, float given + +--float 12.3456789000e10-- +array_udiff(): Argument #1 ($array) must be of type array, float given + +--float -12.3456789000e10-- +array_udiff(): Argument #1 ($array) must be of type array, float given + +--float .5-- +array_udiff(): Argument #1 ($array) must be of type array, float given + +--uppercase NULL-- +array_udiff(): Argument #1 ($array) must be of type array, null given + +--lowercase null-- +array_udiff(): Argument #1 ($array) must be of type array, null given + +--lowercase true-- +array_udiff(): Argument #1 ($array) must be of type array, true given + +--lowercase false-- +array_udiff(): Argument #1 ($array) must be of type array, false given + +--uppercase TRUE-- +array_udiff(): Argument #1 ($array) must be of type array, true given + +--uppercase FALSE-- +array_udiff(): Argument #1 ($array) must be of type array, false given + +--empty string DQ-- +array_udiff(): Argument #1 ($array) must be of type array, string given + +--empty string SQ-- +array_udiff(): Argument #1 ($array) must be of type array, string given + +--string DQ-- +array_udiff(): Argument #1 ($array) must be of type array, string given + +--string SQ-- +array_udiff(): Argument #1 ($array) must be of type array, string given + +--mixed case string-- +array_udiff(): Argument #1 ($array) must be of type array, string given + +--heredoc-- +array_udiff(): Argument #1 ($array) must be of type array, string given + +--instance of classWithToString-- +array_udiff(): Argument #1 ($array) must be of type array, classWithToString given + +--instance of classWithoutToString-- +array_udiff(): Argument #1 ($array) must be of type array, classWithoutToString given + +--undefined var-- +array_udiff(): Argument #1 ($array) must be of type array, null given + +--unset var-- +array_udiff(): Argument #1 ($array) must be of type array, null given diff --git a/tests/std/array/array_udiff_variation2.phpt b/tests/std/array/array_udiff_variation2.phpt new file mode 100644 index 00000000..0035949f --- /dev/null +++ b/tests/std/array/array_udiff_variation2.phpt @@ -0,0 +1,161 @@ +--TEST-- +Test array_udiff() function : usage variation +--SKIPIF-- + + +--FILE-- + 1, 'two' => 2); + //array of values to iterate over + $inputs = array( + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 123456789000.0, + 'float -12.3456789000e10' => -123456789000.0, + 'float .5' => 0.5, + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + // boolean data + 'lowercase true' => true, + 'lowercase false' => false, + 'uppercase TRUE' => TRUE, + 'uppercase FALSE' => FALSE, + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + // undefined data + 'undefined var' => @$undefined_var, + // unset data + 'unset var' => @$unset_var, + ); + // loop through each element of the array for array2 + foreach ($inputs as $key => $value) { + echo "\n--{$key}--\n"; + try { + var_dump(array_udiff($array1, $value, $data_comp_func)); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + } +} +?> +--EXPECT-- +*** Testing array_udiff() : usage variation *** + +--int 0-- +array_udiff(): Argument #2 must be of type array, int given + +--int 1-- +array_udiff(): Argument #2 must be of type array, int given + +--int 12345-- +array_udiff(): Argument #2 must be of type array, int given + +--int -12345-- +array_udiff(): Argument #2 must be of type array, int given + +--float 10.5-- +array_udiff(): Argument #2 must be of type array, float given + +--float -10.5-- +array_udiff(): Argument #2 must be of type array, float given + +--float 12.3456789000e10-- +array_udiff(): Argument #2 must be of type array, float given + +--float -12.3456789000e10-- +array_udiff(): Argument #2 must be of type array, float given + +--float .5-- +array_udiff(): Argument #2 must be of type array, float given + +--uppercase NULL-- +array_udiff(): Argument #2 must be of type array, null given + +--lowercase null-- +array_udiff(): Argument #2 must be of type array, null given + +--lowercase true-- +array_udiff(): Argument #2 must be of type array, true given + +--lowercase false-- +array_udiff(): Argument #2 must be of type array, false given + +--uppercase TRUE-- +array_udiff(): Argument #2 must be of type array, true given + +--uppercase FALSE-- +array_udiff(): Argument #2 must be of type array, false given + +--empty string DQ-- +array_udiff(): Argument #2 must be of type array, string given + +--empty string SQ-- +array_udiff(): Argument #2 must be of type array, string given + +--string DQ-- +array_udiff(): Argument #2 must be of type array, string given + +--string SQ-- +array_udiff(): Argument #2 must be of type array, string given + +--mixed case string-- +array_udiff(): Argument #2 must be of type array, string given + +--heredoc-- +array_udiff(): Argument #2 must be of type array, string given + +--instance of classWithToString-- +array_udiff(): Argument #2 must be of type array, classWithToString given + +--instance of classWithoutToString-- +array_udiff(): Argument #2 must be of type array, classWithoutToString given + +--undefined var-- +array_udiff(): Argument #2 must be of type array, null given + +--unset var-- +array_udiff(): Argument #2 must be of type array, null given diff --git a/tests/std/array/array_udiff_variation5.phpt b/tests/std/array/array_udiff_variation5.phpt new file mode 100644 index 00000000..21a58df8 --- /dev/null +++ b/tests/std/array/array_udiff_variation5.phpt @@ -0,0 +1,53 @@ +--TEST-- +Test array_udiff() function : usage variation +--SKIPIF-- + + +--FILE-- +getMessage() . "\n"; + } + echo "\n-- comparison function taking too few parameters --\n"; + var_dump(array_udiff($arr1, $arr2, 'too_few_parameters')); +} +?> +--EXPECT-- +*** Testing array_udiff() : usage variation *** + +-- comparison function with an incorrect return value -- +array(1) { + [0]=> + int(1) +} + +-- comparison function taking too many parameters -- +array(0) { +} + +-- comparison function taking too few parameters -- +array(0) { +} diff --git a/tests/std/array/array_uintersect_assoc_basic.phpt b/tests/std/array/array_uintersect_assoc_basic.phpt new file mode 100644 index 00000000..0b8e6b5f --- /dev/null +++ b/tests/std/array/array_uintersect_assoc_basic.phpt @@ -0,0 +1,43 @@ +--TEST-- +array_uintersect_assoc(): Test return type and value for expected input +--FILE-- +priv_member = $val; + } + static function comp_func_cr($a, $b) + { + if ($a->priv_member === $b->priv_member) { + return 0; + } + return $a->priv_member > $b->priv_member ? 1 : -1; + } +} +function main() +{ + $a = array("0.1" => new cr(9), "0.5" => new cr(12), 0 => new cr(23), 1 => new cr(4), 2 => new cr(-15)); + $b = array("0.2" => new cr(9), "0.5" => new cr(22), 0 => new cr(3), 1 => new cr(4), 2 => new cr(-15)); + $result = array_uintersect_assoc($a, $b, array("cr", "comp_func_cr")); + var_dump($result); +} +?> +--EXPECTF-- +array(2) { + [1]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(4) + } + [2]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(-15) + } +} diff --git a/tests/std/array/array_uintersect_assoc_basic2.phpt b/tests/std/array/array_uintersect_assoc_basic2.phpt new file mode 100644 index 00000000..47bb916e --- /dev/null +++ b/tests/std/array/array_uintersect_assoc_basic2.phpt @@ -0,0 +1,29 @@ +--TEST-- +Test array_uintersect_assoc() function : basic functionality - testing with multiple array arguments +--SKIPIF-- +--FILE-- + "one", "02" => "two", '3' => "three", "four", "0.5" => 5, 0 => 6, "0x7" => "seven"); +$arr2 = array("one" => "one", "02" => "two", '3' => "three"); +$arr3 = array("one" => "one", '3' => "three", "0.5" => 5); +$arr4 = array("one" => "one", '3' => "three", "0.5" => 5); + + +var_dump( array_uintersect_assoc($arr1, $arr2, $arr3, $arr4, $data_compare_function) ); + + +?> +--EXPECT-- +*** Testing array_uintersect_assoc() : basic functionality - testing with multiple array arguments *** +array(2) { + ["one"]=> + string(3) "one" + [3]=> + string(5) "three" +} diff --git a/tests/std/array/array_uintersect_assoc_variation1.phpt b/tests/std/array/array_uintersect_assoc_variation1.phpt new file mode 100644 index 00000000..1f70e037 --- /dev/null +++ b/tests/std/array/array_uintersect_assoc_variation1.phpt @@ -0,0 +1,161 @@ +--TEST-- +Test array_uintersect_assoc() function : usage variation +--SKIPIF-- + + +--FILE-- + 1, 'two' => 2); + //array of values to iterate over + $inputs = array( + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 123456789000.0, + 'float -12.3456789000e10' => -123456789000.0, + 'float .5' => 0.5, + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + // boolean data + 'lowercase true' => true, + 'lowercase false' => false, + 'uppercase TRUE' => TRUE, + 'uppercase FALSE' => FALSE, + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + // undefined data + 'undefined var' => @$undefined_var, + // unset data + 'unset var' => @$unset_var, + ); + // loop through each element of the array for array1 + foreach ($inputs as $key => $value) { + echo "\n--{$key}--\n"; + try { + var_dump(array_uintersect_assoc($value, $array2, $data_compare_function)); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + } +} +?> +--EXPECT-- +*** Testing array_uintersect_assoc() : usage variation *** + +--int 0-- +array_uintersect_assoc(): Argument #1 ($array) must be of type array, int given + +--int 1-- +array_uintersect_assoc(): Argument #1 ($array) must be of type array, int given + +--int 12345-- +array_uintersect_assoc(): Argument #1 ($array) must be of type array, int given + +--int -12345-- +array_uintersect_assoc(): Argument #1 ($array) must be of type array, int given + +--float 10.5-- +array_uintersect_assoc(): Argument #1 ($array) must be of type array, float given + +--float -10.5-- +array_uintersect_assoc(): Argument #1 ($array) must be of type array, float given + +--float 12.3456789000e10-- +array_uintersect_assoc(): Argument #1 ($array) must be of type array, float given + +--float -12.3456789000e10-- +array_uintersect_assoc(): Argument #1 ($array) must be of type array, float given + +--float .5-- +array_uintersect_assoc(): Argument #1 ($array) must be of type array, float given + +--uppercase NULL-- +array_uintersect_assoc(): Argument #1 ($array) must be of type array, null given + +--lowercase null-- +array_uintersect_assoc(): Argument #1 ($array) must be of type array, null given + +--lowercase true-- +array_uintersect_assoc(): Argument #1 ($array) must be of type array, true given + +--lowercase false-- +array_uintersect_assoc(): Argument #1 ($array) must be of type array, false given + +--uppercase TRUE-- +array_uintersect_assoc(): Argument #1 ($array) must be of type array, true given + +--uppercase FALSE-- +array_uintersect_assoc(): Argument #1 ($array) must be of type array, false given + +--empty string DQ-- +array_uintersect_assoc(): Argument #1 ($array) must be of type array, string given + +--empty string SQ-- +array_uintersect_assoc(): Argument #1 ($array) must be of type array, string given + +--string DQ-- +array_uintersect_assoc(): Argument #1 ($array) must be of type array, string given + +--string SQ-- +array_uintersect_assoc(): Argument #1 ($array) must be of type array, string given + +--mixed case string-- +array_uintersect_assoc(): Argument #1 ($array) must be of type array, string given + +--heredoc-- +array_uintersect_assoc(): Argument #1 ($array) must be of type array, string given + +--instance of classWithToString-- +array_uintersect_assoc(): Argument #1 ($array) must be of type array, classWithToString given + +--instance of classWithoutToString-- +array_uintersect_assoc(): Argument #1 ($array) must be of type array, classWithoutToString given + +--undefined var-- +array_uintersect_assoc(): Argument #1 ($array) must be of type array, null given + +--unset var-- +array_uintersect_assoc(): Argument #1 ($array) must be of type array, null given diff --git a/tests/std/array/array_uintersect_assoc_variation2.phpt b/tests/std/array/array_uintersect_assoc_variation2.phpt new file mode 100644 index 00000000..ccef8840 --- /dev/null +++ b/tests/std/array/array_uintersect_assoc_variation2.phpt @@ -0,0 +1,161 @@ +--TEST-- +Test array_uintersect_assoc() function : usage variation +--SKIPIF-- + + +--FILE-- + 1, 'two' => 2); + //array of values to iterate over + $inputs = array( + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 123456789000.0, + 'float -12.3456789000e10' => -123456789000.0, + 'float .5' => 0.5, + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + // boolean data + 'lowercase true' => true, + 'lowercase false' => false, + 'uppercase TRUE' => TRUE, + 'uppercase FALSE' => FALSE, + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + // undefined data + 'undefined var' => @$undefined_var, + // unset data + 'unset var' => @$unset_var, + ); + // loop through each element of the array for array2 + foreach ($inputs as $key => $value) { + echo "\n--{$key}--\n"; + try { + var_dump(array_uintersect_assoc($array1, $value, $data_compare_function)); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + } +} +?> +--EXPECT-- +*** Testing array_uintersect_assoc() : usage variation *** + +--int 0-- +array_uintersect_assoc(): Argument #2 must be of type array, int given + +--int 1-- +array_uintersect_assoc(): Argument #2 must be of type array, int given + +--int 12345-- +array_uintersect_assoc(): Argument #2 must be of type array, int given + +--int -12345-- +array_uintersect_assoc(): Argument #2 must be of type array, int given + +--float 10.5-- +array_uintersect_assoc(): Argument #2 must be of type array, float given + +--float -10.5-- +array_uintersect_assoc(): Argument #2 must be of type array, float given + +--float 12.3456789000e10-- +array_uintersect_assoc(): Argument #2 must be of type array, float given + +--float -12.3456789000e10-- +array_uintersect_assoc(): Argument #2 must be of type array, float given + +--float .5-- +array_uintersect_assoc(): Argument #2 must be of type array, float given + +--uppercase NULL-- +array_uintersect_assoc(): Argument #2 must be of type array, null given + +--lowercase null-- +array_uintersect_assoc(): Argument #2 must be of type array, null given + +--lowercase true-- +array_uintersect_assoc(): Argument #2 must be of type array, true given + +--lowercase false-- +array_uintersect_assoc(): Argument #2 must be of type array, false given + +--uppercase TRUE-- +array_uintersect_assoc(): Argument #2 must be of type array, true given + +--uppercase FALSE-- +array_uintersect_assoc(): Argument #2 must be of type array, false given + +--empty string DQ-- +array_uintersect_assoc(): Argument #2 must be of type array, string given + +--empty string SQ-- +array_uintersect_assoc(): Argument #2 must be of type array, string given + +--string DQ-- +array_uintersect_assoc(): Argument #2 must be of type array, string given + +--string SQ-- +array_uintersect_assoc(): Argument #2 must be of type array, string given + +--mixed case string-- +array_uintersect_assoc(): Argument #2 must be of type array, string given + +--heredoc-- +array_uintersect_assoc(): Argument #2 must be of type array, string given + +--instance of classWithToString-- +array_uintersect_assoc(): Argument #2 must be of type array, classWithToString given + +--instance of classWithoutToString-- +array_uintersect_assoc(): Argument #2 must be of type array, classWithoutToString given + +--undefined var-- +array_uintersect_assoc(): Argument #2 must be of type array, null given + +--unset var-- +array_uintersect_assoc(): Argument #2 must be of type array, null given diff --git a/tests/std/array/array_uintersect_assoc_variation5.phpt b/tests/std/array/array_uintersect_assoc_variation5.phpt new file mode 100644 index 00000000..94fefc47 --- /dev/null +++ b/tests/std/array/array_uintersect_assoc_variation5.phpt @@ -0,0 +1,51 @@ +--TEST-- +Test array_uintersect_assoc() function : usage variation - differing comparison functions +--SKIPIF-- + + +--FILE-- +getMessage() . "\n"; + } + echo "\n-- comparison function taking too few parameters --\n"; + var_dump(array_uintersect_assoc($arr1, $arr2, 'too_few_parameters')); +} +?> +--EXPECT-- +*** Testing array_uintersect_assoc() : usage variation - differing comparison functions*** + +-- comparison function with an incorrect return value -- +array(0) { +} + +-- comparison function taking too many parameters -- +array(0) { +} + +-- comparison function taking too few parameters -- +array(0) { +} + diff --git a/tests/std/array/array_uintersect_basic.phpt b/tests/std/array/array_uintersect_basic.phpt new file mode 100644 index 00000000..7444cc07 --- /dev/null +++ b/tests/std/array/array_uintersect_basic.phpt @@ -0,0 +1,48 @@ +--TEST-- +array_uintersect(): Test return type and value for expected input +--FILE-- +priv_member = $val; + } + static function comp_func_cr($a, $b) + { + if ($a->priv_member === $b->priv_member) { + return 0; + } + return $a->priv_member > $b->priv_member ? 1 : -1; + } +} +function main() +{ + $a = array("0.1" => new cr(9), "0.5" => new cr(12), 0 => new cr(23), 1 => new cr(4), 2 => new cr(-15)); + $b = array("0.2" => new cr(9), "0.5" => new cr(22), 0 => new cr(3), 1 => new cr(4), 2 => new cr(-15)); + $result = array_uintersect($a, $b, array("cr", "comp_func_cr")); + var_dump($result); +} +?> +--EXPECTF-- +array(3) { + ["0.1"]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(9) + } + [1]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(4) + } + [2]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(-15) + } +} diff --git a/tests/std/array/array_uintersect_uassoc_basic.phpt b/tests/std/array/array_uintersect_uassoc_basic.phpt new file mode 100644 index 00000000..8f4e3afd --- /dev/null +++ b/tests/std/array/array_uintersect_uassoc_basic.phpt @@ -0,0 +1,50 @@ +--TEST-- +array_uintersect_uassoc(): Test return type and value for expected input +--FILE-- +priv_member = $val; + } + static function comp_func_cr($a, $b) + { + if ($a->priv_member === $b->priv_member) { + return 0; + } + return $a->priv_member > $b->priv_member ? 1 : -1; + } + static function comp_func_key($a, $b) + { + if ($a === $b) { + return 0; + } + return $a > $b ? 1 : -1; + } +} +function main() +{ + $a = array("0.1" => new cr(9), "0.5" => new cr(12), 0 => new cr(23), 1 => new cr(4), 2 => new cr(-15)); + $b = array("0.2" => new cr(9), "0.5" => new cr(22), 0 => new cr(3), 1 => new cr(4), 2 => new cr(-15)); + $result = array_uintersect_uassoc($a, $b, array("cr", "comp_func_cr"), array("cr", "comp_func_key")); + var_dump($result); +} +?> +--EXPECTF-- +array(2) { + [1]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(4) + } + [2]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(-15) + } +} diff --git a/tests/std/array/array_uintersect_uassoc_variation1.phpt b/tests/std/array/array_uintersect_uassoc_variation1.phpt new file mode 100644 index 00000000..9478f908 --- /dev/null +++ b/tests/std/array/array_uintersect_uassoc_variation1.phpt @@ -0,0 +1,162 @@ +--TEST-- +Test array_uintersect_uassoc() function : usage variation +--SKIPIF-- + + +--FILE-- + 1, 'two' => 2); + //array of values to iterate over + $inputs = array( + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 123456789000.0, + 'float -12.3456789000e10' => -123456789000.0, + 'float .5' => 0.5, + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + // boolean data + 'lowercase true' => true, + 'lowercase false' => false, + 'uppercase TRUE' => TRUE, + 'uppercase FALSE' => FALSE, + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + // undefined data + 'undefined var' => @$undefined_var, + // unset data + 'unset var' => @$unset_var, + ); + // loop through each element of the array for array1 + foreach ($inputs as $key => $value) { + echo "\n--{$key}--\n"; + try { + var_dump(array_uintersect_uassoc($value, $array2, $data_compare_func, $key_compare_func)); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + } +} +?> +--EXPECT-- +*** Testing array_uintersect_uassoc() : usage variation *** + +--int 0-- +array_uintersect_uassoc(): Argument #1 ($array) must be of type array, int given + +--int 1-- +array_uintersect_uassoc(): Argument #1 ($array) must be of type array, int given + +--int 12345-- +array_uintersect_uassoc(): Argument #1 ($array) must be of type array, int given + +--int -12345-- +array_uintersect_uassoc(): Argument #1 ($array) must be of type array, int given + +--float 10.5-- +array_uintersect_uassoc(): Argument #1 ($array) must be of type array, float given + +--float -10.5-- +array_uintersect_uassoc(): Argument #1 ($array) must be of type array, float given + +--float 12.3456789000e10-- +array_uintersect_uassoc(): Argument #1 ($array) must be of type array, float given + +--float -12.3456789000e10-- +array_uintersect_uassoc(): Argument #1 ($array) must be of type array, float given + +--float .5-- +array_uintersect_uassoc(): Argument #1 ($array) must be of type array, float given + +--uppercase NULL-- +array_uintersect_uassoc(): Argument #1 ($array) must be of type array, null given + +--lowercase null-- +array_uintersect_uassoc(): Argument #1 ($array) must be of type array, null given + +--lowercase true-- +array_uintersect_uassoc(): Argument #1 ($array) must be of type array, true given + +--lowercase false-- +array_uintersect_uassoc(): Argument #1 ($array) must be of type array, false given + +--uppercase TRUE-- +array_uintersect_uassoc(): Argument #1 ($array) must be of type array, true given + +--uppercase FALSE-- +array_uintersect_uassoc(): Argument #1 ($array) must be of type array, false given + +--empty string DQ-- +array_uintersect_uassoc(): Argument #1 ($array) must be of type array, string given + +--empty string SQ-- +array_uintersect_uassoc(): Argument #1 ($array) must be of type array, string given + +--string DQ-- +array_uintersect_uassoc(): Argument #1 ($array) must be of type array, string given + +--string SQ-- +array_uintersect_uassoc(): Argument #1 ($array) must be of type array, string given + +--mixed case string-- +array_uintersect_uassoc(): Argument #1 ($array) must be of type array, string given + +--heredoc-- +array_uintersect_uassoc(): Argument #1 ($array) must be of type array, string given + +--instance of classWithToString-- +array_uintersect_uassoc(): Argument #1 ($array) must be of type array, classWithToString given + +--instance of classWithoutToString-- +array_uintersect_uassoc(): Argument #1 ($array) must be of type array, classWithoutToString given + +--undefined var-- +array_uintersect_uassoc(): Argument #1 ($array) must be of type array, null given + +--unset var-- +array_uintersect_uassoc(): Argument #1 ($array) must be of type array, null given diff --git a/tests/std/array/array_uintersect_uassoc_variation2.phpt b/tests/std/array/array_uintersect_uassoc_variation2.phpt new file mode 100644 index 00000000..85793cd1 --- /dev/null +++ b/tests/std/array/array_uintersect_uassoc_variation2.phpt @@ -0,0 +1,162 @@ +--TEST-- +Test array_uintersect_uassoc() function : usage variation +--SKIPIF-- + + +--FILE-- + 1, 'two' => 2); + //array of values to iterate over + $inputs = array( + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 123456789000.0, + 'float -12.3456789000e10' => -123456789000.0, + 'float .5' => 0.5, + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + // boolean data + 'lowercase true' => true, + 'lowercase false' => false, + 'uppercase TRUE' => TRUE, + 'uppercase FALSE' => FALSE, + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + // undefined data + 'undefined var' => @$undefined_var, + // unset data + 'unset var' => @$unset_var, + ); + // loop through each element of the array for array2 + foreach ($inputs as $key => $value) { + echo "\n--{$key}--\n"; + try { + var_dump(array_uintersect_uassoc($array1, $value, $data_compare_func, $key_compare_func)); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + } +} +?> +--EXPECT-- +*** Testing array_uintersect_uassoc() : usage variation *** + +--int 0-- +array_uintersect_uassoc(): Argument #2 must be of type array, int given + +--int 1-- +array_uintersect_uassoc(): Argument #2 must be of type array, int given + +--int 12345-- +array_uintersect_uassoc(): Argument #2 must be of type array, int given + +--int -12345-- +array_uintersect_uassoc(): Argument #2 must be of type array, int given + +--float 10.5-- +array_uintersect_uassoc(): Argument #2 must be of type array, float given + +--float -10.5-- +array_uintersect_uassoc(): Argument #2 must be of type array, float given + +--float 12.3456789000e10-- +array_uintersect_uassoc(): Argument #2 must be of type array, float given + +--float -12.3456789000e10-- +array_uintersect_uassoc(): Argument #2 must be of type array, float given + +--float .5-- +array_uintersect_uassoc(): Argument #2 must be of type array, float given + +--uppercase NULL-- +array_uintersect_uassoc(): Argument #2 must be of type array, null given + +--lowercase null-- +array_uintersect_uassoc(): Argument #2 must be of type array, null given + +--lowercase true-- +array_uintersect_uassoc(): Argument #2 must be of type array, true given + +--lowercase false-- +array_uintersect_uassoc(): Argument #2 must be of type array, false given + +--uppercase TRUE-- +array_uintersect_uassoc(): Argument #2 must be of type array, true given + +--uppercase FALSE-- +array_uintersect_uassoc(): Argument #2 must be of type array, false given + +--empty string DQ-- +array_uintersect_uassoc(): Argument #2 must be of type array, string given + +--empty string SQ-- +array_uintersect_uassoc(): Argument #2 must be of type array, string given + +--string DQ-- +array_uintersect_uassoc(): Argument #2 must be of type array, string given + +--string SQ-- +array_uintersect_uassoc(): Argument #2 must be of type array, string given + +--mixed case string-- +array_uintersect_uassoc(): Argument #2 must be of type array, string given + +--heredoc-- +array_uintersect_uassoc(): Argument #2 must be of type array, string given + +--instance of classWithToString-- +array_uintersect_uassoc(): Argument #2 must be of type array, classWithToString given + +--instance of classWithoutToString-- +array_uintersect_uassoc(): Argument #2 must be of type array, classWithoutToString given + +--undefined var-- +array_uintersect_uassoc(): Argument #2 must be of type array, null given + +--unset var-- +array_uintersect_uassoc(): Argument #2 must be of type array, null given diff --git a/tests/std/array/array_uintersect_uassoc_variation6.phpt b/tests/std/array/array_uintersect_uassoc_variation6.phpt new file mode 100644 index 00000000..54d4ecfb --- /dev/null +++ b/tests/std/array/array_uintersect_uassoc_variation6.phpt @@ -0,0 +1,50 @@ +--TEST-- +Test array_uintersect_uassoc() function : usage variation - incorrect callbacks +--SKIPIF-- + + +--FILE-- +getMessage() . "\n"; + } + echo "\n-- comparison function taking too few parameters --\n"; + var_dump(array_uintersect_uassoc($arr1, $arr2, 'too_few_parameters', 'too_few_parameters')); +} +?> +--EXPECT-- +*** Testing array_uintersect_uassoc() : usage variation - incorrect callbacks *** + +-- comparison function with an incorrect return value -- +array(0) { +} + +-- comparison function taking too many parameters -- +array(0) { +} + +-- comparison function taking too few parameters -- +array(0) { +} diff --git a/tests/std/array/array_uintersect_variation1.phpt b/tests/std/array/array_uintersect_variation1.phpt new file mode 100644 index 00000000..f482c7a9 --- /dev/null +++ b/tests/std/array/array_uintersect_variation1.phpt @@ -0,0 +1,161 @@ +--TEST-- +Test array_uintersect() function : usage variation +--SKIPIF-- + + +--FILE-- + 1, 'two' => 2); + //array of values to iterate over + $inputs = array( + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 123456789000.0, + 'float -12.3456789000e10' => -123456789000.0, + 'float .5' => 0.5, + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + // boolean data + 'lowercase true' => true, + 'lowercase false' => false, + 'uppercase TRUE' => TRUE, + 'uppercase FALSE' => FALSE, + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + // undefined data + 'undefined var' => @$undefined_var, + // unset data + 'unset var' => @$unset_var, + ); + // loop through each element of the array for array1 + foreach ($inputs as $key => $value) { + echo "\n--{$key}--\n"; + try { + var_dump(array_uintersect($value, $array2, $data_compare_function)); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + } +} +?> +--EXPECT-- +*** Testing array_uintersect() : usage variation *** + +--int 0-- +array_uintersect(): Argument #1 ($array) must be of type array, int given + +--int 1-- +array_uintersect(): Argument #1 ($array) must be of type array, int given + +--int 12345-- +array_uintersect(): Argument #1 ($array) must be of type array, int given + +--int -12345-- +array_uintersect(): Argument #1 ($array) must be of type array, int given + +--float 10.5-- +array_uintersect(): Argument #1 ($array) must be of type array, float given + +--float -10.5-- +array_uintersect(): Argument #1 ($array) must be of type array, float given + +--float 12.3456789000e10-- +array_uintersect(): Argument #1 ($array) must be of type array, float given + +--float -12.3456789000e10-- +array_uintersect(): Argument #1 ($array) must be of type array, float given + +--float .5-- +array_uintersect(): Argument #1 ($array) must be of type array, float given + +--uppercase NULL-- +array_uintersect(): Argument #1 ($array) must be of type array, null given + +--lowercase null-- +array_uintersect(): Argument #1 ($array) must be of type array, null given + +--lowercase true-- +array_uintersect(): Argument #1 ($array) must be of type array, true given + +--lowercase false-- +array_uintersect(): Argument #1 ($array) must be of type array, false given + +--uppercase TRUE-- +array_uintersect(): Argument #1 ($array) must be of type array, true given + +--uppercase FALSE-- +array_uintersect(): Argument #1 ($array) must be of type array, false given + +--empty string DQ-- +array_uintersect(): Argument #1 ($array) must be of type array, string given + +--empty string SQ-- +array_uintersect(): Argument #1 ($array) must be of type array, string given + +--string DQ-- +array_uintersect(): Argument #1 ($array) must be of type array, string given + +--string SQ-- +array_uintersect(): Argument #1 ($array) must be of type array, string given + +--mixed case string-- +array_uintersect(): Argument #1 ($array) must be of type array, string given + +--heredoc-- +array_uintersect(): Argument #1 ($array) must be of type array, string given + +--instance of classWithToString-- +array_uintersect(): Argument #1 ($array) must be of type array, classWithToString given + +--instance of classWithoutToString-- +array_uintersect(): Argument #1 ($array) must be of type array, classWithoutToString given + +--undefined var-- +array_uintersect(): Argument #1 ($array) must be of type array, null given + +--unset var-- +array_uintersect(): Argument #1 ($array) must be of type array, null given diff --git a/tests/std/array/array_uintersect_variation2.phpt b/tests/std/array/array_uintersect_variation2.phpt new file mode 100644 index 00000000..6076204d --- /dev/null +++ b/tests/std/array/array_uintersect_variation2.phpt @@ -0,0 +1,161 @@ +--TEST-- +Test array_uintersect() function : usage variation +--SKIPIF-- + + +--FILE-- + 1, 'two' => 2); + //array of values to iterate over + $inputs = array( + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 123456789000.0, + 'float -12.3456789000e10' => -123456789000.0, + 'float .5' => 0.5, + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + // boolean data + 'lowercase true' => true, + 'lowercase false' => false, + 'uppercase TRUE' => TRUE, + 'uppercase FALSE' => FALSE, + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + // undefined data + 'undefined var' => @$undefined_var, + // unset data + 'unset var' => @$unset_var, + ); + // loop through each element of the array for array2 + foreach ($inputs as $key => $value) { + echo "\n--{$key}--\n"; + try { + var_dump(array_uintersect($array1, $value, $data_compare_function)); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + } +} +?> +--EXPECT-- +*** Testing array_uintersect() : usage variation *** + +--int 0-- +array_uintersect(): Argument #2 must be of type array, int given + +--int 1-- +array_uintersect(): Argument #2 must be of type array, int given + +--int 12345-- +array_uintersect(): Argument #2 must be of type array, int given + +--int -12345-- +array_uintersect(): Argument #2 must be of type array, int given + +--float 10.5-- +array_uintersect(): Argument #2 must be of type array, float given + +--float -10.5-- +array_uintersect(): Argument #2 must be of type array, float given + +--float 12.3456789000e10-- +array_uintersect(): Argument #2 must be of type array, float given + +--float -12.3456789000e10-- +array_uintersect(): Argument #2 must be of type array, float given + +--float .5-- +array_uintersect(): Argument #2 must be of type array, float given + +--uppercase NULL-- +array_uintersect(): Argument #2 must be of type array, null given + +--lowercase null-- +array_uintersect(): Argument #2 must be of type array, null given + +--lowercase true-- +array_uintersect(): Argument #2 must be of type array, true given + +--lowercase false-- +array_uintersect(): Argument #2 must be of type array, false given + +--uppercase TRUE-- +array_uintersect(): Argument #2 must be of type array, true given + +--uppercase FALSE-- +array_uintersect(): Argument #2 must be of type array, false given + +--empty string DQ-- +array_uintersect(): Argument #2 must be of type array, string given + +--empty string SQ-- +array_uintersect(): Argument #2 must be of type array, string given + +--string DQ-- +array_uintersect(): Argument #2 must be of type array, string given + +--string SQ-- +array_uintersect(): Argument #2 must be of type array, string given + +--mixed case string-- +array_uintersect(): Argument #2 must be of type array, string given + +--heredoc-- +array_uintersect(): Argument #2 must be of type array, string given + +--instance of classWithToString-- +array_uintersect(): Argument #2 must be of type array, classWithToString given + +--instance of classWithoutToString-- +array_uintersect(): Argument #2 must be of type array, classWithoutToString given + +--undefined var-- +array_uintersect(): Argument #2 must be of type array, null given + +--unset var-- +array_uintersect(): Argument #2 must be of type array, null given diff --git a/tests/std/array/array_uintersect_variation5.phpt b/tests/std/array/array_uintersect_variation5.phpt new file mode 100644 index 00000000..e3ad1e5a --- /dev/null +++ b/tests/std/array/array_uintersect_variation5.phpt @@ -0,0 +1,51 @@ +--TEST-- +Test array_uintersect() function : usage variation - differing comparison functions +--SKIPIF-- + + +--FILE-- +getMessage() . "\n"; + } + echo "\n-- comparison function taking too few parameters --\n"; + var_dump(array_uintersect($arr1, $arr2, 'too_few_parameters')); +} +?> +--EXPECT-- +*** Testing array_uintersect() : usage variation - differing comparison functions*** + +-- comparison function with an incorrect return value -- +array(0) { +} + +-- comparison function taking too many parameters -- +array(0) { +} + +-- comparison function taking too few parameters -- +array(0) { +} + diff --git a/tests/std/array/array_unique_basic.phpt b/tests/std/array/array_unique_basic.phpt new file mode 100644 index 00000000..d76c2e34 --- /dev/null +++ b/tests/std/array/array_unique_basic.phpt @@ -0,0 +1,43 @@ +--TEST-- +Test array_unique() function : basic functionality +--FILE-- + "one", 1 => "one", 2 => "two", '2' => "two"); +var_dump( array_unique($input) ); + +// mixed array +$input = array("1" => "one", "two", "one", 2 => "two", "three"); +var_dump( array_unique($input) ); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_unique() : basic functionality *** +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +array(2) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" +} +array(3) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [4]=> + string(5) "three" +} +Done diff --git a/tests/std/array/array_unique_variation2.phpt b/tests/std/array/array_unique_variation2.phpt new file mode 100644 index 00000000..736aefdb --- /dev/null +++ b/tests/std/array/array_unique_variation2.phpt @@ -0,0 +1,229 @@ +--TEST-- +Test array_unique() function : usage variations - different arrays for 'input' argument +--SKIPIF-- + +--FILE-- +22 +'single quoted string' +"double quoted string" +2222 != 1111.\t 0000 = 0000\n +EOT; + +// arrays passed to $input argument +$inputs = array ( +/*1*/ array(1, 2, 2, 1), // with default keys and numeric values + array(1.1, 2.2, 1.1), // with default keys & float values + array(false, true, false), // with default keys and boolean values + array(), // empty array +/*5*/ array(NULL, null), // with NULL + array("a\v\f", "aaaa\r", "b", "aaaa\r", "\[\]\!\@\#\$\%\^\&\*\(\)\{\}"), // with double quoted strings + array('a\v\f', 'aaaa\r', 'b', 'aaaa\r', '\[\]\!\@\#\$\%\^\&\*\(\)\{\}'), // with single quoted strings + array("h1" => $blank_line, "h2" => $multiline_string, "h3" => $diff_whitespaces, $blank_line), // with heredocs + + // associative arrays +/*9*/ array(1 => "one", 2 => "two", 2 => "two"), // explicit numeric keys, string values + array("one" => 1, "two" => 2, "1" => 1 ), // string keys & numeric values + array( 1 => 10, 2 => 20, 4 => 40, 5 => 10), // explicit numeric keys and numeric values + array( "one" => "ten", "two" => "twenty", "10" => "ten"), // string key/value + array("one" => 1, 2 => "two", 4 => "four"), //mixed + + // associative array, containing null/empty/boolean values as key/value +/*14*/ array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null), + array(true => "true", false => "false", "false" => false, "true" => true), + array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''), + array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true), +/*18*/ array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6), +); + +// loop through each sub-array of $inputs to check the behavior of array_unique() +$iterator = 1; +foreach($inputs as $input) { + echo "-- Iteration $iterator --\n"; + var_dump( array_unique($input, SORT_STRING) ); + $iterator++; +} + +echo "Done"; +?> +--EXPECT-- +*** Testing array_unique() : Passing different arrays to $input argument *** +-- Iteration 1 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 2 -- +array(2) { + [0]=> + float(1.1) + [1]=> + float(2.2) +} +-- Iteration 3 -- +array(2) { + [0]=> + bool(false) + [1]=> + bool(true) +} +-- Iteration 4 -- +array(0) { +} +-- Iteration 5 -- +array(1) { + [0]=> + NULL +} +-- Iteration 6 -- +array(4) { + [0]=> + string(3) "a " + [1]=> + string(5) "aaaa " + [2]=> + string(1) "b" + [4]=> + string(27) "\[\]\!\@\#$\%\^\&\*\(\)\{\}" +} +-- Iteration 7 -- +array(4) { + [0]=> + string(5) "a\v\f" + [1]=> + string(6) "aaaa\r" + [2]=> + string(1) "b" + [4]=> + string(28) "\[\]\!\@\#\$\%\^\&\*\(\)\{\}" +} +-- Iteration 8 -- +array(3) { + ["h1"]=> + string(1) " +" + ["h2"]=> + string(88) "hello world +The quick brown fox jumped over; +the lazy dog +This is a double quoted string" + ["h3"]=> + string(88) "hello world +1111 != 2222 +heredoc +double quoted string. with different white spaces" +} +-- Iteration 9 -- +array(2) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" +} +-- Iteration 10 -- +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +-- Iteration 11 -- +array(3) { + [1]=> + int(10) + [2]=> + int(20) + [4]=> + int(40) +} +-- Iteration 12 -- +array(2) { + ["one"]=> + string(3) "ten" + ["two"]=> + string(6) "twenty" +} +-- Iteration 13 -- +array(3) { + ["one"]=> + int(1) + [2]=> + string(3) "two" + [4]=> + string(4) "four" +} +-- Iteration 14 -- +array(2) { + [""]=> + string(4) "null" + ["NULL"]=> + NULL +} +-- Iteration 15 -- +array(4) { + [1]=> + string(4) "true" + [0]=> + string(5) "false" + ["false"]=> + bool(false) + ["true"]=> + bool(true) +} +-- Iteration 16 -- +array(2) { + [""]=> + string(6) "emptys" + ["emptyd"]=> + string(0) "" +} +-- Iteration 17 -- +array(2) { + [1]=> + string(0) "" + [6]=> + bool(true) +} +-- Iteration 18 -- +array(3) { + [""]=> + int(4) + [0]=> + int(5) + [1]=> + int(6) +} +Done diff --git a/tests/std/array/array_unique_variation3.phpt b/tests/std/array/array_unique_variation3.phpt new file mode 100644 index 00000000..015f42d3 --- /dev/null +++ b/tests/std/array/array_unique_variation3.phpt @@ -0,0 +1,109 @@ +--TEST-- +Test array_unique() function : usage variations - associative array with different keys +--SKIPIF-- + +--FILE-- + "0", 1 => "0"), + array(1 => "1", 2 => "2", 3 => 1, 4 => "4"), + // arrays with string keys + /*5*/ + array('\tHello' => 111, 're\td' => "color", '\v\fworld' => 2.2, 'pen\n' => 111), + array("\tHello" => 111, "re\td" => "color", "\v\fworld" => 2.2, "pen\n" => 111), + array("hello", $heredoc => "string", "string"), + // array with object, unset variable and resource variable + /*8*/ + array(@$unset_var => "hello", $fp => 'resource', 11, "hello"), + ); + // loop through each sub-array of $inputs to check the behavior of array_unique() + $iterator = 1; + foreach ($inputs as $input) { + echo "-- Iteration {$iterator} --\n"; + var_dump(array_unique($input)); + $iterator++; + } + fclose($fp); + echo "Done"; +} +?> +--EXPECTF-- +*** Testing array_unique() : assoc. array with diff. keys passed to $input argument *** + +Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d +-- Iteration 1 -- +array(1) { + [0]=> + string(1) "0" +} +-- Iteration 2 -- +array(3) { + [1]=> + string(1) "1" + [2]=> + string(1) "2" + [4]=> + string(1) "4" +} +-- Iteration 3 -- +array(3) { + ["\tHello"]=> + int(111) + ["re\td"]=> + string(5) "color" + ["\v\fworld"]=> + float(2.2) +} +-- Iteration 4 -- +array(3) { + [" Hello"]=> + int(111) + ["re d"]=> + string(5) "color" + [" world"]=> + float(2.2) +} +-- Iteration 5 -- +array(2) { + [0]=> + string(5) "hello" + ["Hello world"]=> + string(6) "string" +} +-- Iteration 6 -- +array(3) { + [""]=> + string(5) "hello" + [5]=> + string(8) "resource" + [6]=> + int(11) +} +Done diff --git a/tests/std/array/array_unique_variation4.phpt b/tests/std/array/array_unique_variation4.phpt new file mode 100644 index 00000000..92ed76e6 --- /dev/null +++ b/tests/std/array/array_unique_variation4.phpt @@ -0,0 +1,106 @@ +--TEST-- +Test array_unique() function : usage variations - associative array with different values +--SKIPIF-- + +--FILE-- + 0, '1' => 0), + array("one" => 1, 'two' => 2, "three" => 1, 4 => 1), + // arrays with string values + /*5*/ + array(111 => "\tHello", "red" => "col\tor", 2 => "\v\fworld", 3 => "\tHello"), + array(111 => '\tHello', "red" => 'col\tor', 2 => '\v\fworld', 3 => '\tHello'), + array(1 => "hello", "heredoc" => $heredoc, $heredoc), + // array with object, unset variable and resource variable + /*8*/ + array(11 => new classA(), "unset" => @$unset_var, "resource" => $fp, new classA(), $fp), + ); + // loop through each sub-array of $inputs to check the behavior of array_unique() + $iterator = 1; + foreach ($inputs as $input) { + echo "-- Iteration {$iterator} --\n"; + var_dump(array_unique($input)); + $iterator++; + } + fclose($fp); + echo "Done"; +} +?> +--EXPECTF-- +*** Testing array_unique() : assoc. array with diff. values to $input argument *** +-- Iteration 1 -- +array(1) { + [0]=> + int(0) +} +-- Iteration 2 -- +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +-- Iteration 3 -- +array(3) { + [111]=> + string(6) " Hello" + ["red"]=> + string(6) "col or" + [2]=> + string(7) " world" +} +-- Iteration 4 -- +array(3) { + [111]=> + string(7) "\tHello" + ["red"]=> + string(7) "col\tor" + [2]=> + string(9) "\v\fworld" +} +-- Iteration 5 -- +array(2) { + [1]=> + string(5) "hello" + ["heredoc"]=> + string(11) "Hello world" +} +-- Iteration 6 -- +array(3) { + [11]=> + object(classA)#%d (0) { + } + ["unset"]=> + NULL + ["resource"]=> + resource(%d) of type (stream) +} +Done diff --git a/tests/std/array/array_unique_variation5.phpt b/tests/std/array/array_unique_variation5.phpt new file mode 100644 index 00000000..8a2df526 --- /dev/null +++ b/tests/std/array/array_unique_variation5.phpt @@ -0,0 +1,28 @@ +--TEST-- +Test array_unique() function : usage variations - array with duplicate keys +--FILE-- + "one", 2 => "two", 2 => "2", 3 => "three", 1 => "1", "1", "2"); +var_dump( array_unique($input) ); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_unique() : array with duplicate keys for $input argument *** +array(3) { + [1]=> + string(1) "1" + [2]=> + string(1) "2" + [3]=> + string(5) "three" +} +Done diff --git a/tests/std/array/array_unique_variation6.phpt b/tests/std/array/array_unique_variation6.phpt new file mode 100644 index 00000000..f1a888d0 --- /dev/null +++ b/tests/std/array/array_unique_variation6.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test array_unique() function : usage variations - array with reference variables +--SKIPIF-- + +--FILE-- + 0, + 1 => &$value4, + 2 => &$value2, + 3 => "hello", + 4 => &$value3, + 5 => $value4 +); + +var_dump( array_unique($input, SORT_STRING) ); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_unique() : array with reference variables for $input argument *** +array(2) { + [0]=> + int(0) + [1]=> + &string(5) "hello" +} +Done diff --git a/tests/std/array/array_unique_variation7.phpt b/tests/std/array/array_unique_variation7.phpt new file mode 100644 index 00000000..e5a7542b --- /dev/null +++ b/tests/std/array/array_unique_variation7.phpt @@ -0,0 +1,28 @@ +--TEST-- +Test array_unique() function : usage variations - binary safe checking +--FILE-- + "hello", "str2" => "world"); + +var_dump( array_unique($input) ); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_unique() : array with binary data for $input argument *** +array(3) { + [0]=> + string(1) "1" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" +} +Done diff --git a/tests/std/array/array_unique_variation8.phpt b/tests/std/array/array_unique_variation8.phpt new file mode 100644 index 00000000..ae9faffc --- /dev/null +++ b/tests/std/array/array_unique_variation8.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test array_unique() function : usage variations - two dimensional arrays +--FILE-- + "hello", "str2" => 'world'), + array(1 => "one", 2 => "two", "one", 'two'), + array(1, 2, 3, 1) +); + +var_dump( array_unique($input, SORT_STRING) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unique() : two dimensional array for $input argument *** + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d + +Warning: Array to string conversion in %s on line %d +array(1) { + [0]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(1) + } +} +Done diff --git a/tests/std/array/array_unique_variation9.phpt b/tests/std/array/array_unique_variation9.phpt new file mode 100644 index 00000000..aa083010 --- /dev/null +++ b/tests/std/array/array_unique_variation9.phpt @@ -0,0 +1,109 @@ +--TEST-- +Test array_unique() function : usage variations - more than 16 elements +--CREDITS-- +Matteo Beccati +--FILE-- + 'acls_channel', + 1 => 'acls_channel', + 2 => 'ad_zone_assoc', + 3 => 'ad_zone_assoc', + 4 => 'ad_zone_assoc', + 5 => 'affiliates', + 6 => 'affiliates', + 7 => 'affiliates', + 8 => 'banners', + 9 => 'banners', + 10 => 'banners', + 11 => 'campaigns', + 12 => 'campaigns', + 13 => 'campaigns', + 14 => 'campaigns_trackers', + 15 => 'campaigns_trackers', + 16 => 'campaigns_trackers', + 17 => 'clients', + 18 => 'clients', + 19 => 'clients', + 20 => 'data_intermediate_ad', + 21 => 'data_intermediate_ad', + 22 => 'data_summary_ad_hourly', + 23 => 'data_summary_ad_hourly', + 24 => 'data_summary_zone_country_daily', + 25 => 'data_summary_zone_country_daily', + 26 => 'data_summary_zone_country_daily', + 27 => 'data_summary_zone_country_forecast', + 28 => 'data_summary_zone_country_forecast', + 29 => 'data_summary_zone_country_forecast', + 30 => 'data_summary_zone_country_monthly', + 31 => 'data_summary_zone_country_monthly', + 32 => 'data_summary_zone_country_monthly', + 33 => 'data_summary_zone_domain_page_daily', + 34 => 'data_summary_zone_domain_page_daily', + 35 => 'data_summary_zone_domain_page_daily', + 36 => 'data_summary_zone_domain_page_forecast', + 37 => 'data_summary_zone_domain_page_forecast', + 38 => 'data_summary_zone_domain_page_forecast', + 39 => 'data_summary_zone_domain_page_monthly', + 40 => 'data_summary_zone_domain_page_monthly', + 41 => 'data_summary_zone_domain_page_monthly', + 42 => 'data_summary_zone_site_keyword_daily', + 43 => 'data_summary_zone_site_keyword_daily', + 44 => 'data_summary_zone_site_keyword_daily', + 45 => 'data_summary_zone_site_keyword_forecast', + 46 => 'data_summary_zone_site_keyword_forecast', + 47 => 'data_summary_zone_site_keyword_forecast', + 48 => 'data_summary_zone_site_keyword_monthly', + 49 => 'data_summary_zone_site_keyword_monthly', + 50 => 'data_summary_zone_site_keyword_monthly', + 51 => 'data_summary_zone_source_daily', + 52 => 'data_summary_zone_source_daily', + 53 => 'data_summary_zone_source_daily', + 54 => 'data_summary_zone_source_forecast', + 55 => 'data_summary_zone_source_forecast', + 56 => 'data_summary_zone_source_forecast', + 57 => 'data_summary_zone_source_monthly', + 58 => 'data_summary_zone_source_monthly', + 59 => 'data_summary_zone_source_monthly', + 60 => 'placement_zone_assoc', + 61 => 'placement_zone_assoc', + 62 => 'placement_zone_assoc', + 63 => 'trackers', + 64 => 'trackers', + 65 => 'trackers', + 66 => 'variables', + 67 => 'variables', + 68 => 'variables', +); + +print_r(array_unique($a)); +?> +--EXPECT-- +Array +( + [0] => acls_channel + [2] => ad_zone_assoc + [5] => affiliates + [8] => banners + [11] => campaigns + [14] => campaigns_trackers + [17] => clients + [20] => data_intermediate_ad + [22] => data_summary_ad_hourly + [24] => data_summary_zone_country_daily + [27] => data_summary_zone_country_forecast + [30] => data_summary_zone_country_monthly + [33] => data_summary_zone_domain_page_daily + [36] => data_summary_zone_domain_page_forecast + [39] => data_summary_zone_domain_page_monthly + [42] => data_summary_zone_site_keyword_daily + [45] => data_summary_zone_site_keyword_forecast + [48] => data_summary_zone_site_keyword_monthly + [51] => data_summary_zone_source_daily + [54] => data_summary_zone_source_forecast + [57] => data_summary_zone_source_monthly + [60] => placement_zone_assoc + [63] => trackers + [66] => variables +) diff --git a/tests/std/array/array_unshift.phpt b/tests/std/array/array_unshift.phpt new file mode 100644 index 00000000..265de4e8 --- /dev/null +++ b/tests/std/array/array_unshift.phpt @@ -0,0 +1,31 @@ +--TEST-- +array_unshift() tests +--FILE-- + +--EXPECT-- +int(1) +array(1) { + [0]=> + string(0) "" +} +int(2) +array(2) { + [0]=> + array(1) { + [0]=> + string(0) "" + } + [1]=> + string(0) "" +} +Done diff --git a/tests/std/array/array_unshift_basic1.phpt b/tests/std/array/array_unshift_basic1.phpt new file mode 100644 index 00000000..ef0de5e7 --- /dev/null +++ b/tests/std/array/array_unshift_basic1.phpt @@ -0,0 +1,58 @@ +--TEST-- +Test array_unshift() function : basic functionality - array with default keys for 'array' argument +--FILE-- + +--EXPECT-- +*** Testing array_unshift() : basic functionality with default key array *** +int(3) +array(3) { + [0]=> + int(10) + [1]=> + int(1) + [2]=> + int(2) +} +int(5) +array(5) { + [0]=> + int(222) + [1]=> + string(5) "hello" + [2]=> + float(12.33) + [3]=> + int(1) + [4]=> + int(2) +} +Done diff --git a/tests/std/array/array_unshift_basic2.phpt b/tests/std/array/array_unshift_basic2.phpt new file mode 100644 index 00000000..7c19dcda --- /dev/null +++ b/tests/std/array/array_unshift_basic2.phpt @@ -0,0 +1,66 @@ +--TEST-- +Test array_unshift() function : basic functionality - associative arrays for 'array' argument +--FILE-- + "first", "s" => 'second', 1 => "one", 2 => 'two'); + +// Calling array_unshift() with default argument +$temp_array = $array; +// returns element count in the resulting array after arguments are pushed to +// beginning of the given array +var_dump( array_unshift($temp_array, 10) ); + +// dump the resulting array +var_dump($temp_array); + +// Calling array_unshift() with optional arguments +$temp_array = $array; +// returns element count in the resulting array after arguments are pushed to +// beginning of the given array +var_dump( array_unshift($temp_array, 222, "hello", 12.33) ); + +// dump the resulting array +var_dump($temp_array); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_unshift() : basic functionality with associative array *** +int(5) +array(5) { + [0]=> + int(10) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + string(3) "one" + [2]=> + string(3) "two" +} +int(7) +array(7) { + [0]=> + int(222) + [1]=> + string(5) "hello" + [2]=> + float(12.33) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + string(3) "one" + [4]=> + string(3) "two" +} +Done diff --git a/tests/std/array/array_unshift_empty.phpt b/tests/std/array/array_unshift_empty.phpt new file mode 100644 index 00000000..43bad5b3 --- /dev/null +++ b/tests/std/array/array_unshift_empty.phpt @@ -0,0 +1,25 @@ +--TEST-- +Test array_unshift() function : prepend array with empty set +--FILE-- + +--EXPECT-- +int(3) +int(3) +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +Done diff --git a/tests/std/array/array_unshift_object.phpt b/tests/std/array/array_unshift_object.phpt new file mode 100644 index 00000000..a7deb4b8 --- /dev/null +++ b/tests/std/array/array_unshift_object.phpt @@ -0,0 +1,273 @@ +--TEST-- +Test array_unshift() function : passing object for 'var' argument +--SKIPIF-- + + +--FILE-- + "first", "s" => 'second', 1, 2.222); + // array containing different types of objects as elements + $vars = array(new SimpleClass(), new EmptyClass(), new ChildClass(), new FinalClass(), new StaticClass()); + // loop through the various elements of $arrays to check the functionality of array_unshift + $iterator = 1; + foreach ($vars as $var) { + echo "-- Iteration {$iterator} --\n"; + /* with default argument */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + $temp_array = $array; + var_dump(array_unshift($temp_array, $var)); + // dump the resulting array + var_dump($temp_array); + /* with optional arguments */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + $temp_array = $array; + var_dump(array_unshift($temp_array, $var, "hello", 'world')); + // dump the resulting array + var_dump($temp_array); + $iterator++; + } + echo "Done"; +} +?> +--EXPECTF-- +*** Testing array_unshift() : Passing object to $var argument *** +-- Iteration 1 -- +int(5) +array(5) { + [0]=> + object(SimpleClass)#%d (1) { + ["var1"]=> + int(1) + } + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + object(SimpleClass)#%d (1) { + ["var1"]=> + int(1) + } + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 2 -- +int(5) +array(5) { + [0]=> + object(EmptyClass)#%d (0) { + } + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + object(EmptyClass)#%d (0) { + } + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 3 -- +int(5) +array(5) { + [0]=> + object(ChildClass)#%d (2) { + ["var2":protected]=> + int(5) + ["var3":"ChildClass":private]=> + NULL + } + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + object(ChildClass)#%d (2) { + ["var2":protected]=> + int(5) + ["var3":"ChildClass":private]=> + NULL + } + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 4 -- +int(5) +array(5) { + [0]=> + object(FinalClass)#%d (1) { + ["var4":"FinalClass":private]=> + NULL + } + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + object(FinalClass)#%d (1) { + ["var4":"FinalClass":private]=> + NULL + } + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 5 -- +int(5) +array(5) { + [0]=> + object(StaticClass)#%d (0) { + } + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + object(StaticClass)#%d (0) { + } + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +Done diff --git a/tests/std/array/array_unshift_variation2.phpt b/tests/std/array/array_unshift_variation2.phpt new file mode 100644 index 00000000..b23b151f --- /dev/null +++ b/tests/std/array/array_unshift_variation2.phpt @@ -0,0 +1,1048 @@ +--TEST-- +Test array_unshift() function : usage variations - all possible values for 'var' argument +--SKIPIF-- + + +--FILE-- + "first", "s" => 'second', 1, 2.222); + // get a resource variable + $fp = fopen(__FILE__, "r"); + // heredoc string + $heredoc = << 'red', 'item' => 'pen'), + // null data + /*15*/ + NULL, + null, + // boolean data + /*17*/ + true, + false, + TRUE, + FALSE, + // empty data + /*21*/ + "", + '', + // string data + /*23*/ + "string", + 'string', + $heredoc, + // object data + /*26*/ + new classA(), + // undefined data + @$undefined_var, + // unset data + @$unset_var, + // resource variable + /*29*/ + $fp, + ); + // loop through each element of $vars to check the functionality of array_unshift() + $iterator = 1; + foreach ($vars as $var) { + echo "-- Iteration {$iterator} --\n"; + $temp_array = $array; + /* with default argument */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + var_dump(array_unshift($temp_array, $var)); + // dump the resulting array + var_dump($temp_array); + /* with optional arguments */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + $temp_array = $array; + var_dump(array_unshift($temp_array, $var, "hello", 'world')); + // dump the resulting array + var_dump($temp_array); + $iterator++; + } + // close the file resource used + fclose($fp); + echo "Done"; +} +?> +--EXPECTF-- +*** Testing array_unshift() : all possible values for $var argument *** +-- Iteration 1 -- +int(5) +array(5) { + [0]=> + int(0) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + int(0) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 2 -- +int(5) +array(5) { + [0]=> + int(1) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + int(1) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 3 -- +int(5) +array(5) { + [0]=> + int(12345) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + int(12345) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 4 -- +int(5) +array(5) { + [0]=> + int(-2345) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + int(-2345) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 5 -- +int(5) +array(5) { + [0]=> + float(10.5) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + float(10.5) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 6 -- +int(5) +array(5) { + [0]=> + float(-10.5) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + float(-10.5) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 7 -- +int(5) +array(5) { + [0]=> + float(123456789000) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + float(123456789000) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 8 -- +int(5) +array(5) { + [0]=> + float(1.23456789E-9) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + float(1.23456789E-9) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 9 -- +int(5) +array(5) { + [0]=> + float(0.5) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + float(0.5) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 10 -- +int(5) +array(5) { + [0]=> + array(0) { + } + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + array(0) { + } + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 11 -- +int(5) +array(5) { + [0]=> + array(1) { + [0]=> + int(0) + } + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 12 -- +int(5) +array(5) { + [0]=> + array(1) { + [0]=> + int(1) + } + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 13 -- +int(5) +array(5) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 14 -- +int(5) +array(5) { + [0]=> + array(2) { + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + } + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + array(2) { + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + } + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 15 -- +int(5) +array(5) { + [0]=> + NULL + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + NULL + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 16 -- +int(5) +array(5) { + [0]=> + NULL + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + NULL + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 17 -- +int(5) +array(5) { + [0]=> + bool(true) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + bool(true) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 18 -- +int(5) +array(5) { + [0]=> + bool(false) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + bool(false) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 19 -- +int(5) +array(5) { + [0]=> + bool(true) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + bool(true) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 20 -- +int(5) +array(5) { + [0]=> + bool(false) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + bool(false) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 21 -- +int(5) +array(5) { + [0]=> + string(0) "" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(0) "" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 22 -- +int(5) +array(5) { + [0]=> + string(0) "" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(0) "" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 23 -- +int(5) +array(5) { + [0]=> + string(6) "string" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(6) "string" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 24 -- +int(5) +array(5) { + [0]=> + string(6) "string" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(6) "string" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 25 -- +int(5) +array(5) { + [0]=> + string(11) "hello world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(11) "hello world" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 26 -- +int(5) +array(5) { + [0]=> + object(classA)#%d (0) { + } + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + object(classA)#%d (0) { + } + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 27 -- +int(5) +array(5) { + [0]=> + NULL + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + NULL + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 28 -- +int(5) +array(5) { + [0]=> + NULL + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + NULL + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 29 -- +int(5) +array(5) { + [0]=> + resource(%d) of type (stream) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + resource(%d) of type (stream) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +Done diff --git a/tests/std/array/array_unshift_variation3.phpt b/tests/std/array/array_unshift_variation3.phpt new file mode 100644 index 00000000..6ed96472 --- /dev/null +++ b/tests/std/array/array_unshift_variation3.phpt @@ -0,0 +1,568 @@ +--TEST-- +Test array_unshift() function : usage variations - different array values for 'array' argument +--SKIPIF-- + +--FILE-- + "one", 2 => "two", 3 => "three"), // explicit numeric keys, string values + array("one" => 1, "two" => 2, "three" => 3 ), // string keys & numeric values + array( 1 => 10, 2 => 20, 4 => 40, 3 => 30), // explicit numeric keys and numeric values + array( "one" => "ten", "two" => "twenty", "three" => "thirty"), // string key/value + array("one" => 1, 2 => "two", 4 => "four"), //mixed + + // associative array, containing null/empty/boolean values as key/value +/*13*/ array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null), + array(true => "true", false => "false", "false" => false, "true" => true), + array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''), + array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true), + array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6), + + // array with repetitive keys +/*18*/ array("One" => 1, "two" => 2, "One" => 10, "two" => 20, "three" => 3) +); + +// loop through the various elements of $arrays to test array_unshift() +$iterator = 1; +foreach($arrays as $array) { + echo "-- Iteration $iterator --\n"; + + /* with default argument */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + $temp_array = $array; + var_dump( array_unshift($temp_array, $var) ); + + // dump the resulting array + var_dump($temp_array); + + /* with optional arguments */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + $temp_array = $array; + var_dump( array_unshift($temp_array, $var, "hello", 'world') ); + + // dump the resulting array + var_dump($temp_array); + $iterator++; +} + +echo "Done"; +?> +--EXPECT-- +*** Testing array_unshift() : different arrays for $array argument *** +-- Iteration 1 -- +int(3) +array(3) { + [0]=> + int(10) + [1]=> + int(1) + [2]=> + int(2) +} +int(5) +array(5) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + int(1) + [4]=> + int(2) +} +-- Iteration 2 -- +int(3) +array(3) { + [0]=> + int(10) + [1]=> + float(1.1) + [2]=> + float(2.2) +} +int(5) +array(5) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + float(1.1) + [4]=> + float(2.2) +} +-- Iteration 3 -- +int(3) +array(3) { + [0]=> + int(10) + [1]=> + array(1) { + [0]=> + int(2) + } + [2]=> + array(1) { + [0]=> + int(1) + } +} +int(5) +array(5) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + array(1) { + [0]=> + int(2) + } + [4]=> + array(1) { + [0]=> + int(1) + } +} +-- Iteration 4 -- +int(3) +array(3) { + [0]=> + int(10) + [1]=> + bool(false) + [2]=> + bool(true) +} +int(5) +array(5) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + bool(false) + [4]=> + bool(true) +} +-- Iteration 5 -- +int(1) +array(1) { + [0]=> + int(10) +} +int(3) +array(3) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" +} +-- Iteration 6 -- +int(2) +array(2) { + [0]=> + int(10) + [1]=> + NULL +} +int(4) +array(4) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + NULL +} +-- Iteration 7 -- +int(7) +array(7) { + [0]=> + int(10) + [1]=> + string(1) "a" + [2]=> + string(4) "aaaa" + [3]=> + string(1) "b" + [4]=> + string(4) "bbbb" + [5]=> + string(1) "c" + [6]=> + string(5) "ccccc" +} +int(9) +array(9) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + string(1) "a" + [4]=> + string(4) "aaaa" + [5]=> + string(1) "b" + [6]=> + string(4) "bbbb" + [7]=> + string(1) "c" + [8]=> + string(5) "ccccc" +} +-- Iteration 8 -- +int(4) +array(4) { + [0]=> + int(10) + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + string(5) "three" +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + string(3) "one" + [4]=> + string(3) "two" + [5]=> + string(5) "three" +} +-- Iteration 9 -- +int(4) +array(4) { + [0]=> + int(10) + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} +-- Iteration 10 -- +int(5) +array(5) { + [0]=> + int(10) + [1]=> + int(10) + [2]=> + int(20) + [3]=> + int(40) + [4]=> + int(30) +} +int(7) +array(7) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + int(10) + [4]=> + int(20) + [5]=> + int(40) + [6]=> + int(30) +} +-- Iteration 11 -- +int(4) +array(4) { + [0]=> + int(10) + ["one"]=> + string(3) "ten" + ["two"]=> + string(6) "twenty" + ["three"]=> + string(6) "thirty" +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["one"]=> + string(3) "ten" + ["two"]=> + string(6) "twenty" + ["three"]=> + string(6) "thirty" +} +-- Iteration 12 -- +int(4) +array(4) { + [0]=> + int(10) + ["one"]=> + int(1) + [1]=> + string(3) "two" + [2]=> + string(4) "four" +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["one"]=> + int(1) + [3]=> + string(3) "two" + [4]=> + string(4) "four" +} +-- Iteration 13 -- +int(4) +array(4) { + [0]=> + int(10) + [""]=> + string(4) "null" + ["NULL"]=> + NULL + ["null"]=> + NULL +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [""]=> + string(4) "null" + ["NULL"]=> + NULL + ["null"]=> + NULL +} +-- Iteration 14 -- +int(5) +array(5) { + [0]=> + int(10) + [1]=> + string(4) "true" + [2]=> + string(5) "false" + ["false"]=> + bool(false) + ["true"]=> + bool(true) +} +int(7) +array(7) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + string(4) "true" + [4]=> + string(5) "false" + ["false"]=> + bool(false) + ["true"]=> + bool(true) +} +-- Iteration 15 -- +int(4) +array(4) { + [0]=> + int(10) + [""]=> + string(6) "emptys" + ["emptyd"]=> + string(0) "" + ["emptys"]=> + string(0) "" +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [""]=> + string(6) "emptys" + ["emptyd"]=> + string(0) "" + ["emptys"]=> + string(0) "" +} +-- Iteration 16 -- +int(7) +array(7) { + [0]=> + int(10) + [1]=> + string(0) "" + [2]=> + string(0) "" + [3]=> + NULL + [4]=> + NULL + [5]=> + bool(false) + [6]=> + bool(true) +} +int(9) +array(9) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + string(0) "" + [4]=> + string(0) "" + [5]=> + NULL + [6]=> + NULL + [7]=> + bool(false) + [8]=> + bool(true) +} +-- Iteration 17 -- +int(4) +array(4) { + [0]=> + int(10) + [""]=> + int(4) + [1]=> + int(5) + [2]=> + int(6) +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [""]=> + int(4) + [3]=> + int(5) + [4]=> + int(6) +} +-- Iteration 18 -- +int(4) +array(4) { + [0]=> + int(10) + ["One"]=> + int(10) + ["two"]=> + int(20) + ["three"]=> + int(3) +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["One"]=> + int(10) + ["two"]=> + int(20) + ["three"]=> + int(3) +} +Done diff --git a/tests/std/array/array_unshift_variation4.phpt b/tests/std/array/array_unshift_variation4.phpt new file mode 100644 index 00000000..908557fc --- /dev/null +++ b/tests/std/array/array_unshift_variation4.phpt @@ -0,0 +1,316 @@ +--TEST-- +Test array_unshift() function : usage variations - assoc. array with diff. keys for 'array' argument +--SKIPIF-- + +--FILE-- + "0"), + array(1 => "1"), + array(1 => "1", 2 => "2", 3 => "3", 4 => "4"), + // arrays with string keys + /*7*/ + array('\tHello' => 111, 're\td' => "color", '\v\fworld' => 2.2, 'pen\n' => 33), + array("\tHello" => 111, "re\td" => "color", "\v\fworld" => 2.2, "pen\n" => 33), + array("hello", $heredoc => "string"), + // heredoc + // array with object, unset variable and resource variable + array(@$unset_var => "hello", $fp => 'resource'), + // array with mixed keys + /*11*/ + array('hello' => 1, "fruit" => 2.2, $fp => 'resource', 133 => "int", @$unset_var => "unset", $heredoc => "heredoc"), + ); + // loop through the various elements of $arrays to test array_unshift() + $iterator = 1; + foreach ($arrays as $array) { + echo "-- Iteration {$iterator} --\n"; + /* with default argument */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + $temp_array = $array; + var_dump(array_unshift($temp_array, $var)); + // dump the resulting array + var_dump($temp_array); + /* with optional arguments */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + $temp_array = $array; + var_dump(array_unshift($temp_array, $var, "hello", 'world')); + // dump the resulting array + var_dump($temp_array); + $iterator++; + } + echo "Done"; +} +?> +--EXPECTF-- +*** Testing array_unshift() : associative array with different keys *** + +Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d + +Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d +-- Iteration 1 -- +int(1) +array(1) { + [0]=> + int(10) +} +int(3) +array(3) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" +} +-- Iteration 2 -- +int(2) +array(2) { + [0]=> + int(10) + [1]=> + string(1) "0" +} +int(4) +array(4) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + string(1) "0" +} +-- Iteration 3 -- +int(2) +array(2) { + [0]=> + int(10) + [1]=> + string(1) "1" +} +int(4) +array(4) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + string(1) "1" +} +-- Iteration 4 -- +int(5) +array(5) { + [0]=> + int(10) + [1]=> + string(1) "1" + [2]=> + string(1) "2" + [3]=> + string(1) "3" + [4]=> + string(1) "4" +} +int(7) +array(7) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + string(1) "1" + [4]=> + string(1) "2" + [5]=> + string(1) "3" + [6]=> + string(1) "4" +} +-- Iteration 5 -- +int(5) +array(5) { + [0]=> + int(10) + ["\tHello"]=> + int(111) + ["re\td"]=> + string(5) "color" + ["\v\fworld"]=> + float(2.2) + ["pen\n"]=> + int(33) +} +int(7) +array(7) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["\tHello"]=> + int(111) + ["re\td"]=> + string(5) "color" + ["\v\fworld"]=> + float(2.2) + ["pen\n"]=> + int(33) +} +-- Iteration 6 -- +int(5) +array(5) { + [0]=> + int(10) + [" Hello"]=> + int(111) + ["re d"]=> + string(5) "color" + [" world"]=> + float(2.2) + ["pen +"]=> + int(33) +} +int(7) +array(7) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [" Hello"]=> + int(111) + ["re d"]=> + string(5) "color" + [" world"]=> + float(2.2) + ["pen +"]=> + int(33) +} +-- Iteration 7 -- +int(3) +array(3) { + [0]=> + int(10) + [1]=> + string(5) "hello" + ["Hello world"]=> + string(6) "string" +} +int(5) +array(5) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + string(5) "hello" + ["Hello world"]=> + string(6) "string" +} +-- Iteration 8 -- +int(3) +array(3) { + [0]=> + int(10) + [""]=> + string(5) "hello" + [1]=> + string(8) "resource" +} +int(5) +array(5) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [""]=> + string(5) "hello" + [3]=> + string(8) "resource" +} +-- Iteration 9 -- +int(7) +array(7) { + [0]=> + int(10) + ["hello"]=> + int(1) + ["fruit"]=> + float(2.2) + [1]=> + string(8) "resource" + [2]=> + string(3) "int" + [""]=> + string(5) "unset" + ["Hello world"]=> + string(7) "heredoc" +} +int(9) +array(9) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["hello"]=> + int(1) + ["fruit"]=> + float(2.2) + [3]=> + string(8) "resource" + [4]=> + string(3) "int" + [""]=> + string(5) "unset" + ["Hello world"]=> + string(7) "heredoc" +} +Done diff --git a/tests/std/array/array_unshift_variation5.phpt b/tests/std/array/array_unshift_variation5.phpt new file mode 100644 index 00000000..303971f6 --- /dev/null +++ b/tests/std/array/array_unshift_variation5.phpt @@ -0,0 +1,383 @@ +--TEST-- +Test array_unshift() function : usage variations - assoc. array with diff values for 'array' argument +--INI-- +precision=12 +--SKIPIF-- + +--FILE-- + 0), + array("1" => 1), + array("one" => 1, 'two' => 2, "three" => 3, 4 => 4), + // arrays with float values + /*5*/ + array("float" => 2.3333), + array("f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => 33333333.333333), + // arrays with string values + /*7*/ + array(111 => "\tHello", "red" => "col\tor", 2 => "\v\fworld", 3 => "pen\n"), + array(111 => '\tHello', "red" => 'col\tor', 2 => '\v\fworld', 3 => 'pen\n'), + array(1 => "hello", "heredoc" => $heredoc), + // array with object, unset variable and resource variable + array(11 => new classA(), "unset" => @$unset_var, "resource" => $fp), + // array with mixed values + /*11*/ + array(1 => 'hello', 2 => new classA(), 222 => "fruit", 'resource' => $fp, "int" => 133, "float" => 444.432, "unset" => @$unset_var, "heredoc" => $heredoc), + ); + // loop through the various elements of $arrays to test array_unshift() + $iterator = 1; + foreach ($arrays as $array) { + echo "-- Iteration {$iterator} --\n"; + /* with default argument */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + $temp_array = $array; + var_dump(array_unshift($temp_array, $var)); + // dump the resulting array + var_dump($temp_array); + /* with optional arguments */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + $temp_array = $array; + var_dump(array_unshift($temp_array, $var, "hello", 'world')); + // dump the resulting array + var_dump($temp_array); + $iterator++; + } + echo "Done"; +} +?> +--EXPECTF-- +*** Testing array_unshift() : associative array with different values *** +-- Iteration 1 -- +int(1) +array(1) { + [0]=> + int(10) +} +int(3) +array(3) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" +} +-- Iteration 2 -- +int(2) +array(2) { + [0]=> + int(10) + [1]=> + int(0) +} +int(4) +array(4) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + int(0) +} +-- Iteration 3 -- +int(2) +array(2) { + [0]=> + int(10) + [1]=> + int(1) +} +int(4) +array(4) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + int(1) +} +-- Iteration 4 -- +int(5) +array(5) { + [0]=> + int(10) + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} +int(7) +array(7) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) + [3]=> + int(4) +} +-- Iteration 5 -- +int(2) +array(2) { + [0]=> + int(10) + ["float"]=> + float(2.3333) +} +int(4) +array(4) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["float"]=> + float(2.3333) +} +-- Iteration 6 -- +int(5) +array(5) { + [0]=> + int(10) + ["f1"]=> + float(1.2) + ["f2"]=> + float(3.33) + [1]=> + float(4.89999922839999) + ["f4"]=> + float(33333333.333333) +} +int(7) +array(7) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f1"]=> + float(1.2) + ["f2"]=> + float(3.33) + [3]=> + float(4.89999922839999) + ["f4"]=> + float(33333333.333333) +} +-- Iteration 7 -- +int(5) +array(5) { + [0]=> + int(10) + [1]=> + string(6) " Hello" + ["red"]=> + string(6) "col or" + [2]=> + string(7) " world" + [3]=> + string(4) "pen +" +} +int(7) +array(7) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + string(6) " Hello" + ["red"]=> + string(6) "col or" + [4]=> + string(7) " world" + [5]=> + string(4) "pen +" +} +-- Iteration 8 -- +int(5) +array(5) { + [0]=> + int(10) + [1]=> + string(7) "\tHello" + ["red"]=> + string(7) "col\tor" + [2]=> + string(9) "\v\fworld" + [3]=> + string(5) "pen\n" +} +int(7) +array(7) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + string(7) "\tHello" + ["red"]=> + string(7) "col\tor" + [4]=> + string(9) "\v\fworld" + [5]=> + string(5) "pen\n" +} +-- Iteration 9 -- +int(3) +array(3) { + [0]=> + int(10) + [1]=> + string(5) "hello" + ["heredoc"]=> + string(11) "Hello world" +} +int(5) +array(5) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + string(5) "hello" + ["heredoc"]=> + string(11) "Hello world" +} +-- Iteration 10 -- +int(4) +array(4) { + [0]=> + int(10) + [1]=> + object(classA)#%d (0) { + } + ["unset"]=> + NULL + ["resource"]=> + resource(%d) of type (stream) +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + object(classA)#%d (0) { + } + ["unset"]=> + NULL + ["resource"]=> + resource(%d) of type (stream) +} +-- Iteration 11 -- +int(9) +array(9) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + object(classA)#%d (0) { + } + [3]=> + string(5) "fruit" + ["resource"]=> + resource(%d) of type (stream) + ["int"]=> + int(133) + ["float"]=> + float(444.432) + ["unset"]=> + NULL + ["heredoc"]=> + string(11) "Hello world" +} +int(11) +array(11) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + string(5) "hello" + [4]=> + object(classA)#%d (0) { + } + [5]=> + string(5) "fruit" + ["resource"]=> + resource(%d) of type (stream) + ["int"]=> + int(133) + ["float"]=> + float(444.432) + ["unset"]=> + NULL + ["heredoc"]=> + string(11) "Hello world" +} +Done diff --git a/tests/std/array/array_unshift_variation6.phpt b/tests/std/array/array_unshift_variation6.phpt new file mode 100644 index 00000000..89f7e228 --- /dev/null +++ b/tests/std/array/array_unshift_variation6.phpt @@ -0,0 +1,191 @@ +--TEST-- +Test array_unshift() function : usage variations - two dimensional arrays for 'array' argument +--FILE-- + 'red', 'item' => 'pen', 'place' => 'LA'), + + // numeric array + array(1, 2, 3, 4, 5), + + // combination of numeric and associative arrays + array('a' => 'green', 'red', 'brown', 33, 88, 'orange', 'item' => 'ball') +); + +/* Passing the entire $two_dimensional_array to $array */ + +/* With default argument */ +// returns element count in the resulting array after arguments are pushed to +// beginning of the given array +$temp_array = $two_dimensional_array; +var_dump( array_unshift($temp_array, $var) ); // whole 2-d array + +// dumps the resulting array +var_dump($temp_array); + +/* With optional arguments */ +// returns element count in the resulting array after arguments are pushed to +// beginning of the given array +$temp_array = $two_dimensional_array; +var_dump( array_unshift($temp_array, $var, "hello", 'world') ); // whole 2-d array + +// dumps the resulting array +var_dump($temp_array); + +/* Passing the sub-array within the $two_dimensional_array to $array argument */ + +/* With default argument */ +// returns element count in the resulting array after arguments are pushed to +// beginning of the given array +$temp_array = $two_dimensional_array[0]; +var_dump( array_unshift($temp_array, $var) ); // sub array + +// dumps the resulting array +var_dump($temp_array); + +/* With optional arguments */ +// returns element count in the resulting array after arguments are pushed to +// beginning of the given array +$temp_array = $two_dimensional_array[0]; +var_dump( array_unshift($temp_array, $var, "hello", 'world') ); // sub array + +// dumps the resulting array +var_dump($temp_array); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_unshift() : two dimensional arrays for $array argument *** +int(4) +array(4) { + [0]=> + int(10) + [1]=> + array(3) { + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + ["place"]=> + string(2) "LA" + } + [2]=> + array(5) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + } + [3]=> + array(7) { + ["a"]=> + string(5) "green" + [0]=> + string(3) "red" + [1]=> + string(5) "brown" + [2]=> + int(33) + [3]=> + int(88) + [4]=> + string(6) "orange" + ["item"]=> + string(4) "ball" + } +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + array(3) { + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + ["place"]=> + string(2) "LA" + } + [4]=> + array(5) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + } + [5]=> + array(7) { + ["a"]=> + string(5) "green" + [0]=> + string(3) "red" + [1]=> + string(5) "brown" + [2]=> + int(33) + [3]=> + int(88) + [4]=> + string(6) "orange" + ["item"]=> + string(4) "ball" + } +} +int(4) +array(4) { + [0]=> + int(10) + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + ["place"]=> + string(2) "LA" +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + ["place"]=> + string(2) "LA" +} +Done diff --git a/tests/std/array/array_unshift_variation7.phpt b/tests/std/array/array_unshift_variation7.phpt new file mode 100644 index 00000000..f42ac1cf --- /dev/null +++ b/tests/std/array/array_unshift_variation7.phpt @@ -0,0 +1,211 @@ +--TEST-- +Test array_unshift() function : usage variations - double quoted strings for 'var' argument +--FILE-- + "first", "s" => 'second', 1, 2.222); + +// different variations of double quoted strings to be passed to $var argument +$vars = array ( + "\$ -> This represents the dollar sign. hello dollar!!!", + "\t\r\v The quick brown fo\fx jumped over the lazy dog", + "This is a text with special chars: \!\@\#\$\%\^\&\*\(\)\\", + "hello world\\t", + "This is \ta text in bold letters\r\s\malong with slashes\n : HELLO WORLD\t" +); + +// loop through the various elements of $arrays to test array_unshift() +$iterator = 1; +foreach($vars as $var) { + echo "-- Iteration $iterator --\n"; + $temp_array = $array; // assign $array to another temporary $temp_array + + /* with default argument */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + var_dump( array_unshift($temp_array, $var) ); + +// dump the resulting array + var_dump($temp_array); + + /* with optional arguments */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + $temp_array = $array; + var_dump( array_unshift($temp_array, $var, "hello", 'world') ); + + // dump the resulting array + var_dump($temp_array); + $iterator++; +} + +echo "Done"; +?> +--EXPECT-- +*** Testing array_unshift() : double quoted strings for $var argument *** +-- Iteration 1 -- +int(5) +array(5) { + [0]=> + string(53) "$ -> This represents the dollar sign. hello dollar!!!" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(53) "$ -> This represents the dollar sign. hello dollar!!!" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 2 -- +int(5) +array(5) { + [0]=> + string(49) " The quick brown fo x jumped over the lazy dog" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(49) " The quick brown fo x jumped over the lazy dog" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 3 -- +int(5) +array(5) { + [0]=> + string(55) "This is a text with special chars: \!\@\#$\%\^\&\*\(\)\" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(55) "This is a text with special chars: \!\@\#$\%\^\&\*\(\)\" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 4 -- +int(5) +array(5) { + [0]=> + string(13) "hello world\t" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(13) "hello world\t" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 5 -- +int(5) +array(5) { + [0]=> + string(70) "This is a text in bold letters \s\malong with slashes + : HELLO WORLD " + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(70) "This is a text in bold letters \s\malong with slashes + : HELLO WORLD " + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +Done diff --git a/tests/std/array/array_unshift_variation8.phpt b/tests/std/array/array_unshift_variation8.phpt new file mode 100644 index 00000000..ff87f370 --- /dev/null +++ b/tests/std/array/array_unshift_variation8.phpt @@ -0,0 +1,209 @@ +--TEST-- +Test array_unshift() function : usage variations - single quoted strings for 'var' argument +--FILE-- + "first", "s" => 'second', 1, 2.222); + +// different variations of single quoted strings to be passed to $var argument +$vars = array ( + '\$ -> This represents the dollar sign. hello dollar!!!', + '\t\r\v The quick brown fo\fx jumped over the lazy dog', + 'This is a text with special chars: \!\@\#\$\%\^\&\*\(\)\\', + 'hello world\\t', + 'This is \ta text in bold letters\r\s\malong with slashes\n : HELLO WORLD\t' +); + +// loop through the various elements of $arrays to test array_unshift() +$iterator = 1; +foreach($vars as $var) { + echo "-- Iteration $iterator --\n"; + $temp_array = $array; // assign $array to another temporary $temp_array + + /* with default argument */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + var_dump( array_unshift($temp_array, $var) ); + + // dump the resulting array + var_dump($temp_array); + + /* with optional arguments */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + $temp_array = $array; + var_dump( array_unshift($temp_array, $var, "hello", 'world') ); + + // dump the resulting array + var_dump($temp_array); + $iterator++; +} + +echo "Done"; +?> +--EXPECT-- +*** Testing array_unshift() : single quoted strings for $var argument *** +-- Iteration 1 -- +int(5) +array(5) { + [0]=> + string(54) "\$ -> This represents the dollar sign. hello dollar!!!" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(54) "\$ -> This represents the dollar sign. hello dollar!!!" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 2 -- +int(5) +array(5) { + [0]=> + string(53) "\t\r\v The quick brown fo\fx jumped over the lazy dog" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(53) "\t\r\v The quick brown fo\fx jumped over the lazy dog" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 3 -- +int(5) +array(5) { + [0]=> + string(56) "This is a text with special chars: \!\@\#\$\%\^\&\*\(\)\" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(56) "This is a text with special chars: \!\@\#\$\%\^\&\*\(\)\" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 4 -- +int(5) +array(5) { + [0]=> + string(13) "hello world\t" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(13) "hello world\t" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 5 -- +int(5) +array(5) { + [0]=> + string(74) "This is \ta text in bold letters\r\s\malong with slashes\n : HELLO WORLD\t" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(74) "This is \ta text in bold letters\r\s\malong with slashes\n : HELLO WORLD\t" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +Done diff --git a/tests/std/array/array_unshift_variation9.phpt b/tests/std/array/array_unshift_variation9.phpt new file mode 100644 index 00000000..133f8f91 --- /dev/null +++ b/tests/std/array/array_unshift_variation9.phpt @@ -0,0 +1,304 @@ +--TEST-- +Test array_unshift() function : usage variations - heredoc strings for 'var' argument +--FILE-- +22 +2222 != 1111.\t 0000 = 0000\n +EOT; + +// heredoc with quote chars & slash +$quote_char_string = << "first", "s" => 'second', 1, 2.222); + +// different heredoc strings to be passed to $var argument +$vars = array( + $empty_string, + $blank_line, + $multiline_string, + $diff_whitespaces, + $numeric_string, + $quote_char_string +); + +// loop through the various elements of $arrays to test array_unshift() +$iterator = 1; +foreach($vars as $var) { + echo "-- Iteration $iterator --\n"; + $temp_array = $array; // assign $array to another temporary $temp_array + + /* with default argument */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + var_dump( array_unshift($temp_array, $var) ); + + // dump the resulting array + var_dump($temp_array); + + /* with all possible arguments */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + $temp_array = $array; + var_dump( array_unshift($temp_array, $var, "hello", 'world') ); + + // dump the resulting array + var_dump($temp_array); + $iterator++; +} + +echo "Done"; +?> +--EXPECT-- +*** Testing array_unshift() : heredoc strings for $var argument *** +-- Iteration 1 -- +int(5) +array(5) { + [0]=> + string(0) "" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(0) "" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 2 -- +int(5) +array(5) { + [0]=> + string(1) " +" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(1) " +" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 3 -- +int(5) +array(5) { + [0]=> + string(86) "hello world +The big brown fox jumped over; +the lazy dog +This is a double quoted string" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(86) "hello world +The big brown fox jumped over; +the lazy dog +This is a double quoted string" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 4 -- +int(5) +array(5) { + [0]=> + string(88) "hello world +1111 != 2222 +heredoc +double quoted string. with different white spaces" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(88) "hello world +1111 != 2222 +heredoc +double quoted string. with different white spaces" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 5 -- +int(5) +array(5) { + [0]=> + string(44) "11 < 12. 123 >22 +2222 != 1111. 0000 = 0000 +" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(44) "11 < 12. 123 >22 +2222 != 1111. 0000 = 0000 +" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 6 -- +int(5) +array(5) { + [0]=> + string(123) "This's a string with quotes: +"strings in double quote"; +'strings in single quote'; +this\line is single quoted /with\slashes" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(123) "This's a string with quotes: +"strings in double quote"; +'strings in single quote'; +this\line is single quoted /with\slashes" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +Done diff --git a/tests/std/array/array_user_key_compare.phpt b/tests/std/array/array_user_key_compare.phpt new file mode 100644 index 00000000..3bb02c10 --- /dev/null +++ b/tests/std/array/array_user_key_compare.phpt @@ -0,0 +1,27 @@ +--TEST-- +Fix UMR in array_user_key_compare (MOPB24) +--SKIPIF-- + + +--FILE-- + 1, "B" => 1); + uksort($arr, "array_compare"); + var_dump($a); +} +?> +--EXPECTF-- +Warning: array_compare(): Argument #1 ($key1) must be passed by reference, value given in %s on line %d + +Warning: array_compare(): Argument #2 ($key2) must be passed by reference, value given in %s on line %d +string(1) "B" diff --git a/tests/std/array/array_values.phpt b/tests/std/array/array_values.phpt new file mode 100644 index 00000000..443a4676 --- /dev/null +++ b/tests/std/array/array_values.phpt @@ -0,0 +1,233 @@ +--TEST-- +Test array_values() function +--INI-- +precision=14 +--FILE-- + 1, "b" => 2, "c" =>3), + array(0 => 0, 1 => 1, 2 => 2), + array(TRUE, FALSE, NULL, true, false, null, "TRUE", "FALSE", + "NULL", "\x000", "\000"), + array("Hi" => 1, "Hello" => 2, "World" => 3), + array("a" => "abcd", "a" => "", "ab" => -6, "cd" => -0.5 ), + array(0 => array(), 1=> array(0), 2 => array(1), ""=> array(), ""=>"" ) +); + +$i = 0; +/* loop through to test array_values() with different arrays given above */ +foreach ($arrays as $array) { + echo "\n-- Iteration $i --\n"; + var_dump( array_values($array) ); + $i++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing array_values() on basic array *** +array(5) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + float(2) + [3]=> + string(6) "asdasd" + [4]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} + +*** Testing array_values() on various arrays *** +-- Iteration 0 -- +array(0) { +} + +-- Iteration 1 -- +array(1) { + [0]=> + int(0) +} + +-- Iteration 2 -- +array(1) { + [0]=> + int(-1) +} + +-- Iteration 3 -- +array(1) { + [0]=> + array(0) { + } +} + +-- Iteration 4 -- +array(1) { + [0]=> + string(5) "Hello" +} + +-- Iteration 5 -- +array(1) { + [0]=> + string(0) "" +} + +-- Iteration 6 -- +array(2) { + [0]=> + string(0) "" + [1]=> + array(0) { + } +} + +-- Iteration 7 -- +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} + +-- Iteration 8 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + array(0) { + } +} + +-- Iteration 9 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + array(2) { + [0]=> + int(4) + [1]=> + int(6) + } +} + +-- Iteration 10 -- +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} + +-- Iteration 11 -- +array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) +} + +-- Iteration 12 -- +array(11) { + [0]=> + bool(true) + [1]=> + bool(false) + [2]=> + NULL + [3]=> + bool(true) + [4]=> + bool(false) + [5]=> + NULL + [6]=> + string(4) "TRUE" + [7]=> + string(5) "FALSE" + [8]=> + string(4) "NULL" + [9]=> + string(2) "%00" + [10]=> + string(1) "%0" +} + +-- Iteration 13 -- +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} + +-- Iteration 14 -- +array(3) { + [0]=> + string(0) "" + [1]=> + int(-6) + [2]=> + float(-0.5) +} + +-- Iteration 15 -- +array(4) { + [0]=> + array(0) { + } + [1]=> + array(1) { + [0]=> + int(0) + } + [2]=> + array(1) { + [0]=> + int(1) + } + [3]=> + string(0) "" +} +Done diff --git a/tests/std/array/array_values_basic.phpt b/tests/std/array/array_values_basic.phpt new file mode 100644 index 00000000..f7434ad6 --- /dev/null +++ b/tests/std/array/array_values_basic.phpt @@ -0,0 +1,34 @@ +--TEST-- +Test array_values() function : basic functionality +--FILE-- + 3, 10 => 'ten'); + +// Calling array_values() with all possible arguments +var_dump( array_values($input) ); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_values() : basic functionality *** +array(5) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + int(3) + [4]=> + string(3) "ten" +} +Done diff --git a/tests/std/array/array_values_variation.phpt b/tests/std/array/array_values_variation.phpt new file mode 100644 index 00000000..15eb77da --- /dev/null +++ b/tests/std/array/array_values_variation.phpt @@ -0,0 +1,76 @@ +--TEST-- +Test array_values() function (variation) +--SKIPIF-- + +--INI-- +precision=14 +--FILE-- + $resource1, "b" => $resource2); +var_dump( array_values($arr_resource) ); + +echo "\n*** Testing array_values() with range checking ***\n"; +$arr_range = array( + 2147483647, + 2147483648, + -2147483647, + -2147483648, + -0, + 0, + -2147483649 +); +var_dump( array_values($arr_range) ); + +echo "\n*** Testing array_values() on an array created on the fly ***\n"; +var_dump( array_values(array(1,2,3)) ); +var_dump( array_values(array()) ); // null array + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing array_values() with resource type *** +array(2) { + [0]=> + resource(%d) of type (stream) + [1]=> + resource(%d) of type (stream) +} + +*** Testing array_values() with range checking *** +array(7) { + [0]=> + int(2147483647) + [1]=> + float(2147483648) + [2]=> + int(-2147483647) + [3]=> + float(-2147483648) + [4]=> + int(0) + [5]=> + int(0) + [6]=> + float(-2147483649) +} + +*** Testing array_values() on an array created on the fly *** +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +array(0) { +} +Done diff --git a/tests/std/array/array_values_variation2.phpt b/tests/std/array/array_values_variation2.phpt new file mode 100644 index 00000000..c4efdb92 --- /dev/null +++ b/tests/std/array/array_values_variation2.phpt @@ -0,0 +1,173 @@ +--TEST-- +Test array_values() function : usage variations - arrays of different data types +--SKIPIF-- + + +--FILE-- + array(0, 1, 12345, -2345), + // float data + /*2*/ + 'float' => array(10.5, -10.5, 123456789000.0, 1.23456789E-9, 0.5), + // null data + /*3*/ + 'null' => array(NULL, null), + // boolean data + /*4*/ + 'bool' => array(true, false, TRUE, FALSE), + // empty data + /*5*/ + 'empty string' => array("", ''), + /*6*/ + 'empty array' => array(), + // string data + /*7*/ + 'string' => array("string", 'string', $heredoc), + // object data + /*8*/ + 'object' => array(new classA()), + // undefined data + /*9*/ + 'undefined' => array(@$undefined_var), + // unset data + /*10*/ + 'unset' => array(@$unset_var), + // resource variable + /*11*/ + 'resource' => array($fp), + ); + // loop through each element of $inputs to check the behavior of array_values() + $iterator = 1; + foreach ($inputs as $key => $input) { + echo "\n-- Iteration {$iterator}: {$key} data --\n"; + var_dump(array_values($input)); + $iterator++; + } + fclose($fp); + echo "Done"; +} +?> +--EXPECTF-- +*** Testing array_values() : usage variations *** + +-- Iteration 1: int data -- +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(12345) + [3]=> + int(-2345) +} + +-- Iteration 2: float data -- +array(5) { + [0]=> + float(10.5) + [1]=> + float(-10.5) + [2]=> + float(123456789000) + [3]=> + float(1.23456789E-9) + [4]=> + float(0.5) +} + +-- Iteration 3: null data -- +array(2) { + [0]=> + NULL + [1]=> + NULL +} + +-- Iteration 4: bool data -- +array(4) { + [0]=> + bool(true) + [1]=> + bool(false) + [2]=> + bool(true) + [3]=> + bool(false) +} + +-- Iteration 5: empty string data -- +array(2) { + [0]=> + string(0) "" + [1]=> + string(0) "" +} + +-- Iteration 6: empty array data -- +array(0) { +} + +-- Iteration 7: string data -- +array(3) { + [0]=> + string(6) "string" + [1]=> + string(6) "string" + [2]=> + string(11) "hello world" +} + +-- Iteration 8: object data -- +array(1) { + [0]=> + object(classA)#%d (0) { + } +} + +-- Iteration 9: undefined data -- +array(1) { + [0]=> + NULL +} + +-- Iteration 10: unset data -- +array(1) { + [0]=> + NULL +} + +-- Iteration 11: resource data -- +array(1) { + [0]=> + resource(%d) of type (stream) +} +Done diff --git a/tests/std/array/array_values_variation3.phpt b/tests/std/array/array_values_variation3.phpt new file mode 100644 index 00000000..43efed83 --- /dev/null +++ b/tests/std/array/array_values_variation3.phpt @@ -0,0 +1,169 @@ +--TEST-- +Test array_values() function : usage variations - array keys different data types +--SKIPIF-- + + +--FILE-- + array( + 0 => 'zero', + 1 => 'one', + 12345 => 'positive', + -2345 => 'negative', + ), + + // null data +/*4*/ 'null uppercase' => array( + NULL => 'null 1', + ), + +/*5*/ 'null lowercase' => array( + null => 'null 2', + ), + + // boolean data +/*6*/ 'bool lowercase' => array( + true => 'lowert', + false => 'lowerf', + ), + +/*7*/ 'bool uppercase' => array( + TRUE => 'uppert', + FALSE => 'upperf', + ), + + // empty data +/*8*/ 'empty double quotes' => array( + "" => 'emptyd', + ), + +/*9*/ 'empty single quotes' => array( + '' => 'emptys', + ), + + // string data +/*10*/ 'string' => array( + "stringd" => 'stringd', + 'strings' => 'strings', + $heredoc => 'stringh', + ), + + // undefined data +/*11*/ 'undefined' => array( + @$undefined_var => 'undefined', + ), + + // unset data +/*12*/ 'unset' => array( + @$unset_var => 'unset', + ), +); + +// loop through each element of $inputs to check the behavior of array_values() +$iterator = 1; +foreach($inputs as $key => $input) { + echo "\n-- Iteration $iterator: $key data --\n"; + var_dump( array_values($input) ); + $iterator++; +}; +echo "Done"; +?> +--EXPECT-- +*** Testing array_values() : usage variations *** + +-- Iteration 1: int data -- +array(4) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + string(8) "positive" + [3]=> + string(8) "negative" +} + +-- Iteration 2: null uppercase data -- +array(1) { + [0]=> + string(6) "null 1" +} + +-- Iteration 3: null lowercase data -- +array(1) { + [0]=> + string(6) "null 2" +} + +-- Iteration 4: bool lowercase data -- +array(2) { + [0]=> + string(6) "lowert" + [1]=> + string(6) "lowerf" +} + +-- Iteration 5: bool uppercase data -- +array(2) { + [0]=> + string(6) "uppert" + [1]=> + string(6) "upperf" +} + +-- Iteration 6: empty double quotes data -- +array(1) { + [0]=> + string(6) "emptyd" +} + +-- Iteration 7: empty single quotes data -- +array(1) { + [0]=> + string(6) "emptys" +} + +-- Iteration 8: string data -- +array(3) { + [0]=> + string(7) "stringd" + [1]=> + string(7) "strings" + [2]=> + string(7) "stringh" +} + +-- Iteration 9: undefined data -- +array(1) { + [0]=> + string(9) "undefined" +} + +-- Iteration 10: unset data -- +array(1) { + [0]=> + string(5) "unset" +} +Done diff --git a/tests/std/array/array_values_variation4.phpt b/tests/std/array/array_values_variation4.phpt new file mode 100644 index 00000000..17e7bdd4 --- /dev/null +++ b/tests/std/array/array_values_variation4.phpt @@ -0,0 +1,93 @@ +--TEST-- +Test array_values() function : usage variations - multi-dimensional arrays +--FILE-- + 'zero', 'un' => 'one', 'sub' => array (1, 2, 3)); + +echo "\n-- Array values of a two-dimensional array --\n"; +var_dump(array_values($input)); + +echo "\n-- Array values of a sub-array --\n"; +var_dump(array_values($input['sub'])); + +// get an infinitely recursive array +$input[] = &$input; +echo "\n-- Array values of an infinitely recursive array --\n"; +var_dump(array_values($input)); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_values() : usage variations *** + +-- Array values of a two-dimensional array -- +array(3) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} + +-- Array values of a sub-array -- +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} + +-- Array values of an infinitely recursive array -- +array(4) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + [3]=> + &array(4) { + ["zero"]=> + string(4) "zero" + ["un"]=> + string(3) "one" + ["sub"]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + [0]=> + *RECURSION* + } +} +Done diff --git a/tests/std/array/array_values_variation5.phpt b/tests/std/array/array_values_variation5.phpt new file mode 100644 index 00000000..8dbd7ca3 --- /dev/null +++ b/tests/std/array/array_values_variation5.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test array_values() function : usage variations - internal array pointer +--FILE-- + 'un', 'two' => 'deux', 'three' => 'trois'); + +echo "\n-- Call array_values() --\n"; +var_dump($result = array_values($input)); + +echo "-- Position of Internal Pointer in Result: --\n"; +echo key($result) . " => " . current($result) . "\n"; +echo "\n-- Position of Internal Pointer in Original Array: --\n"; +echo key($input) . " => " . current ($input) . "\n"; + +echo "Done"; +?> +--EXPECT-- +*** Testing array_values() : usage variations *** + +-- Call array_values() -- +array(3) { + [0]=> + string(2) "un" + [1]=> + string(4) "deux" + [2]=> + string(5) "trois" +} +-- Position of Internal Pointer in Result: -- +0 => un + +-- Position of Internal Pointer in Original Array: -- +one => un +Done diff --git a/tests/std/array/array_values_variation6.phpt b/tests/std/array/array_values_variation6.phpt new file mode 100644 index 00000000..b4c953c4 --- /dev/null +++ b/tests/std/array/array_values_variation6.phpt @@ -0,0 +1,50 @@ +--TEST-- +Test array_values() function : usage variations - Referenced variables +--SKIPIF-- + +--FILE-- + +--EXPECT-- +*** Testing array_values() : usage variations *** + +-- $input is an array made up of referenced variables: -- +array(3) { + [0]=> + &string(3) "one" + [1]=> + &string(3) "two" + [2]=> + &string(5) "three" +} +Change $val2 and check result of array_values(): +array(3) { + [0]=> + &string(3) "one" + [1]=> + &string(4) "deux" + [2]=> + &string(5) "three" +} +Done diff --git a/tests/std/array/array_values_variation7.phpt b/tests/std/array/array_values_variation7.phpt new file mode 100644 index 00000000..b17451ed --- /dev/null +++ b/tests/std/array/array_values_variation7.phpt @@ -0,0 +1,49 @@ +--TEST-- +Test array_values() function : usage variations - Internal order check +--FILE-- + 'three', 2 => 'two', 1 => 'one', 0 => 'zero'); + +echo "\n-- \$input argument: --\n"; +var_dump($input); + +echo "\n-- Result of array_values() --\n"; +var_dump(array_values($input)); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_values() : usage variations *** + +-- $input argument: -- +array(4) { + [3]=> + string(5) "three" + [2]=> + string(3) "two" + [1]=> + string(3) "one" + [0]=> + string(4) "zero" +} + +-- Result of array_values() -- +array(4) { + [0]=> + string(5) "three" + [1]=> + string(3) "two" + [2]=> + string(3) "one" + [3]=> + string(4) "zero" +} +Done diff --git a/tests/std/array/array_values_variation_64bit.phpt b/tests/std/array/array_values_variation_64bit.phpt new file mode 100644 index 00000000..066d35da --- /dev/null +++ b/tests/std/array/array_values_variation_64bit.phpt @@ -0,0 +1,74 @@ +--TEST-- +Test array_values() function +--SKIPIF-- + +--INI-- +precision=14 +--FILE-- + $resource1, "b" => $resource2); +var_dump( array_values($arr_resource) ); + +echo "\n*** Testing array_values() with range checking ***\n"; +$arr_range = array( + 2147483647, + 2147483648, + -2147483647, + -2147483648, + -0, + 0, + -2147483649 +); +var_dump( array_values($arr_range) ); + +echo "\n*** Testing array_values() on an array created on the fly ***\n"; +var_dump( array_values(array(1,2,3)) ); +var_dump( array_values(array()) ); // null array + +?> +--EXPECTF-- +*** Testing array_values() with resource type *** +array(2) { + [0]=> + resource(%d) of type (stream) + [1]=> + resource(%d) of type (stream) +} + +*** Testing array_values() with range checking *** +array(7) { + [0]=> + int(2147483647) + [1]=> + int(2147483648) + [2]=> + int(-2147483647) + [3]=> + int(-2147483648) + [4]=> + int(0) + [5]=> + int(0) + [6]=> + int(-2147483649) +} + +*** Testing array_values() on an array created on the fly *** +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +array(0) { +} diff --git a/tests/std/array/array_walk.phpt b/tests/std/array/array_walk.phpt new file mode 100644 index 00000000..db454a5a --- /dev/null +++ b/tests/std/array/array_walk.phpt @@ -0,0 +1,38 @@ +--TEST-- +array_walk() tests +--SKIPIF-- + +--FILE-- +getMessage()); + } + echo "Done\n"; +} +?> +--EXPECT-- +int(1) +int(0) +string(4) "data" +int(2) +int(1) +string(4) "data" +bool(true) +string(4) "data" +Done diff --git a/tests/std/array/array_walk_basic1.phpt b/tests/std/array/array_walk_basic1.phpt new file mode 100644 index 00000000..f4db6f29 --- /dev/null +++ b/tests/std/array/array_walk_basic1.phpt @@ -0,0 +1,75 @@ +--TEST-- +Test array_walk() function : basic functionality - regular array +--FILE-- + +--EXPECT-- +*** Testing array_walk() : basic functionality *** +-- Using array_walk() with default parameters to show array contents -- +string(5) "lemon" +int(0) + +string(6) "orange" +int(1) + +string(6) "banana" +int(2) + +string(5) "apple" +int(3) + +bool(true) +-- Using array_walk() with all parameters -- +string(5) "lemon" +int(0) +string(5) "Added" + +string(6) "orange" +int(1) +string(5) "Added" + +string(6) "banana" +int(2) +string(5) "Added" + +string(5) "apple" +int(3) +string(5) "Added" + +bool(true) +Done diff --git a/tests/std/array/array_walk_basic2.phpt b/tests/std/array/array_walk_basic2.phpt new file mode 100644 index 00000000..42df9939 --- /dev/null +++ b/tests/std/array/array_walk_basic2.phpt @@ -0,0 +1,91 @@ +--TEST-- +Test array_walk() function : basic functionality - associative array +--FILE-- + "lemon", "a" => "orange", "b" => "banana", "c" => "apple"); + echo "-- Using array_walk with default parameters to show array contents --\n"; + var_dump(array_walk($fruits, 'test_print')); + echo "-- Using array_walk with one optional parameter to modify contents --\n"; + var_dump(array_walk($fruits, 'test_alter', 'fruit')); + echo "-- Using array_walk with default parameters to show modified array contents --\n"; + var_dump(array_walk($fruits, 'test_print')); + echo "Done"; +} +?> +--EXPECT-- +*** Testing array_walk() : basic functionality *** +-- Using array_walk with default parameters to show array contents -- +string(5) "lemon" +string(1) "d" + +string(6) "orange" +string(1) "a" + +string(6) "banana" +string(1) "b" + +string(5) "apple" +string(1) "c" + +bool(true) +-- Using array_walk with one optional parameter to modify contents -- +string(5) "lemon" +string(1) "d" +string(5) "fruit" + +string(6) "orange" +string(1) "a" +string(5) "fruit" + +string(6) "banana" +string(1) "b" +string(5) "fruit" + +string(5) "apple" +string(1) "c" +string(5) "fruit" + +bool(true) +-- Using array_walk with default parameters to show modified array contents -- +string(5) "lemon" +string(1) "d" + +string(6) "orange" +string(1) "a" + +string(6) "banana" +string(1) "b" + +string(5) "apple" +string(1) "c" + +bool(true) +Done diff --git a/tests/std/array/array_walk_closure.phpt b/tests/std/array/array_walk_closure.phpt new file mode 100644 index 00000000..e7ddf112 --- /dev/null +++ b/tests/std/array/array_walk_closure.phpt @@ -0,0 +1,247 @@ +--TEST-- +array_walk() closure tests +--SKIPIF-- + + +--FILE-- +sum += $value; +} +function sum_it_up_array($value, $key, $udata) +{ + var_dump($udata); + $udata['sum'] += $value; +} +function main() +{ + $ar = ["one" => 1, "two" => 2, "three" => 3]; + var_dump(array_walk($ar, function () { + var_dump(func_get_args()); + })); + echo "\nclosure with array\n"; + $ar = ["one" => 1, "two" => 2, "three" => 3]; + $user_data = ["sum" => 42]; + $func = function ($value, $key, &$udata) { + var_dump($udata); + $udata["sum"] += $value; + }; + var_dump(array_walk($ar, $func, $user_data)); + echo "End result:"; + var_dump($user_data["sum"]); + echo "\nclosure with use\n"; + $ar = ["one" => 1, "two" => 2, "three" => 3]; + $user_data = ["sum" => 42]; + $func = function ($value, $key) use (&$user_data) { + var_dump($user_data); + $user_data["sum"] += $value; + }; + var_dump(array_walk($ar, $func, $user_data)); + echo "End result:"; + var_dump($user_data["sum"]); + echo "\nclosure with object\n"; + $ar = ["one" => 1, "two" => 2, "three" => 3]; + $user_data = (object) ["sum" => 42]; + $func = function ($value, $key, &$udata) { + var_dump($udata); + $udata->sum += $value; + }; + var_dump(array_walk($ar, $func, $user_data)); + echo "End result:"; + var_dump($user_data->sum); + echo "\nfunction with object\n"; + $ar = ["one" => 1, "two" => 2, "three" => 3]; + $user_data = (object) ["sum" => 42]; + var_dump(array_walk($ar, "sum_it_up_object", $user_data)); + echo "End result:"; + var_dump($user_data->sum); + echo "\nfunction with array\n"; + $ar = ["one" => 1, "two" => 2, "three" => 3]; + $user_data = ["sum" => 42]; + var_dump(array_walk($ar, "sum_it_up_array", $user_data)); + echo "End result:"; + var_dump($user_data['sum']); + echo "\nclosure and exception\n"; + $ar = ["one" => 1, "two" => 2, "three" => 3]; + try { + var_dump(array_walk($ar, function ($v, $k) { + if ($v == 2) { + throw new Exception(); + } + })); + } catch (Exception $e) { + var_dump($e->getTrace()); + } + echo "Done\n"; +} +?> +--EXPECTF-- +array(2) { + [0]=> + int(1) + [1]=> + string(3) "one" +} +array(2) { + [0]=> + int(2) + [1]=> + string(3) "two" +} +array(2) { + [0]=> + int(3) + [1]=> + string(5) "three" +} +bool(true) + +closure with array + +Warning: {closure:%s:%d}(): Argument #3 ($udata) must be passed by reference, value given in %s on line %d +array(1) { + ["sum"]=> + int(42) +} + +Warning: {closure:%s:%d}(): Argument #3 ($udata) must be passed by reference, value given in %s on line %d +array(1) { + ["sum"]=> + int(42) +} + +Warning: {closure:%s:%d}(): Argument #3 ($udata) must be passed by reference, value given in %s on line %d +array(1) { + ["sum"]=> + int(42) +} +bool(true) +End result:int(42) + +closure with use +array(1) { + ["sum"]=> + int(42) +} +array(1) { + ["sum"]=> + int(43) +} +array(1) { + ["sum"]=> + int(45) +} +bool(true) +End result:int(48) + +closure with object + +Warning: {closure:%s:%d}(): Argument #3 ($udata) must be passed by reference, value given in %s on line %d +object(stdClass)#1 (1) { + ["sum"]=> + int(42) +} + +Warning: {closure:%s:%d}(): Argument #3 ($udata) must be passed by reference, value given in %s on line %d +object(stdClass)#1 (1) { + ["sum"]=> + int(43) +} + +Warning: {closure:%s:%d}(): Argument #3 ($udata) must be passed by reference, value given in %s on line %d +object(stdClass)#1 (1) { + ["sum"]=> + int(45) +} +bool(true) +End result:int(48) + +function with object +object(stdClass)#2 (1) { + ["sum"]=> + int(42) +} +object(stdClass)#2 (1) { + ["sum"]=> + int(43) +} +object(stdClass)#2 (1) { + ["sum"]=> + int(45) +} +bool(true) +End result:int(48) + +function with array +array(1) { + ["sum"]=> + int(42) +} +array(1) { + ["sum"]=> + int(42) +} +array(1) { + ["sum"]=> + int(42) +} +bool(true) +End result:int(42) + +closure and exception +array(2) { + [0]=> + array(2) { + ["function"]=> + string(%d) "{closure:%s:%d}" + ["args"]=> + array(2) { + [0]=> + int(2) + [1]=> + string(3) "two" + } + } + [1]=> + array(4) { + ["file"]=> + string(%d) "%s" + ["line"]=> + int(%d) + ["function"]=> + string(10) "array_walk" + ["args"]=> + array(2) { + [0]=> + array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) + } + [1]=> + object(Closure)#%d (4) { + ["name"]=> + string(%d) "{closure:%s:%d}" + ["file"]=> + string(%d) "%s" + ["line"]=> + int(%d) + ["parameter"]=> + array(2) { + ["$v"]=> + string(10) "" + ["$k"]=> + string(10) "" + } + } + } + } +} +Done diff --git a/tests/std/array/array_walk_error2.phpt b/tests/std/array/array_walk_error2.phpt new file mode 100644 index 00000000..7ab3b22a --- /dev/null +++ b/tests/std/array/array_walk_error2.phpt @@ -0,0 +1,64 @@ +--TEST-- +Test array_walk() function : error conditions - callback parameters +--SKIPIF-- + + +--FILE-- +getMessage() . "\n"; + } + try { + var_dump(array_walk($input, "callback2", 4)); + } catch (Throwable $e) { + echo "Exception: " . $e->getMessage() . "\n"; + } + // expected: Warning is suppressed + try { + var_dump(@array_walk($input, "callback1")); + } catch (Throwable $e) { + echo "Exception: " . $e->getMessage() . "\n"; + } + try { + var_dump(@array_walk($input, "callback2", 4)); + } catch (Throwable $e) { + echo "Exception: " . $e->getMessage() . "\n"; + } + echo "-- Testing array_walk() function with too many callback parameters --\n"; + try { + var_dump(array_walk($input, "callback1", 20, 10)); + } catch (Throwable $e) { + echo "Exception: " . $e->getMessage() . "\n"; + } + echo "Done"; +} +?> +--EXPECT-- +*** Testing array_walk() : error conditions - callback parameters *** +Exception: Too few arguments to function callback1(), 2 passed and exactly 3 expected +Exception: Too few arguments to function callback2(), 3 passed and exactly 4 expected +Exception: Too few arguments to function callback1(), 2 passed and exactly 3 expected +Exception: Too few arguments to function callback2(), 3 passed and exactly 4 expected +-- Testing array_walk() function with too many callback parameters -- +Exception: array_walk() expects at most 3 arguments, 4 given +Done diff --git a/tests/std/array/array_walk_object1.phpt b/tests/std/array/array_walk_object1.phpt new file mode 100644 index 00000000..9c241124 --- /dev/null +++ b/tests/std/array/array_walk_object1.phpt @@ -0,0 +1,56 @@ +--TEST-- +Test array_walk() function : object functionality +--FILE-- +pri_value = $setVal; + $this->pub_value = $setVal; + $this->pro_value = $setVal; + } +}; + +function main() { +echo "*** Testing array_walk() : object functionality ***\n"; + +// object for 'input' argument +$input = new MyClass(10); + +var_dump( array_walk($input, "callback", 1)); + +echo "Done"; +} +?> +--EXPECTF-- +*** Testing array_walk() : object functionality *** +string(18) "%r\0%rMyClass%r\0%rpri_value" +int(10) +int(1) + +string(9) "pub_value" +int(10) +int(1) + +string(12) "%r\0%r*%r\0%rpro_value" +int(10) +int(1) + +bool(true) +Done diff --git a/tests/std/array/array_walk_object2.phpt b/tests/std/array/array_walk_object2.phpt new file mode 100644 index 00000000..f49be31a --- /dev/null +++ b/tests/std/array/array_walk_object2.phpt @@ -0,0 +1,94 @@ +--TEST-- +Test array_walk() function : object functionality - array of objects +--FILE-- +getValue()); + echo "key : "; + var_dump($key); +} + +function callback_public($value, $key) +{ + echo "value : "; + var_dump($value->pub_value); +} +function callback_protected($value, $key) +{ + echo "value : "; + var_dump($value->get_pro_value()); +} + +class MyClass +{ + private $pri_value; + public $pub_value; + protected $pro_value; + public function __construct($setVal) + { + $this->pri_value = $setVal; + $this->pub_value = $setVal; + $this->pro_value = $setVal; + } + public function getValue() + { + return $this->pri_value; + } + public function get_pro_value() + { + return $this->pro_value; + } +}; + +function main() { +echo "*** Testing array_walk() : array of objects ***\n"; + +// array containing objects of MyClass +$input = array ( + new MyClass(3), + new MyClass(10), + new MyClass(20), + new MyClass(-10) +); + +echo "-- For private member --\n"; +var_dump( array_walk($input, "callback_private", 1)); +echo "-- For public member --\n"; +var_dump( array_walk($input, "callback_public")); +echo "-- For protected member --\n"; +var_dump( array_walk($input, "callback_protected")); + +echo "Done"; +} +?> +--EXPECT-- +*** Testing array_walk() : array of objects *** +-- For private member -- +value : int(3) +key : int(0) +value : int(10) +key : int(1) +value : int(20) +key : int(2) +value : int(-10) +key : int(3) +bool(true) +-- For public member -- +value : int(3) +value : int(10) +value : int(20) +value : int(-10) +bool(true) +-- For protected member -- +value : int(3) +value : int(10) +value : int(20) +value : int(-10) +bool(true) +Done diff --git a/tests/std/array/array_walk_objects.phpt b/tests/std/array/array_walk_objects.phpt new file mode 100644 index 00000000..a481d3c5 --- /dev/null +++ b/tests/std/array/array_walk_objects.phpt @@ -0,0 +1,46 @@ +--TEST-- +array_walk() and objects +--FILE-- +foo = "foo"; + $stdclass->bar = "bar"; + array_walk($stdclass, "walk"); + $t = new test(); + array_walk($t, "walk"); + $var = array(); + array_walk($var, "walk"); + $var_str = ""; + try { + array_walk($var_str, "walk"); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + echo "Done\n"; +} +?> +--EXPECTF-- +string(3) "foo" +string(3) "foo" +string(3) "bar" +string(3) "bar" +string(13) "%r\0%rtest%r\0%rvar_pri" +string(12) "test_private" +string(10) "%r\0%r*%r\0%rvar_pro" +string(14) "test_protected" +string(7) "var_pub" +string(11) "test_public" +array_walk(): Argument #1 ($array) must be of type array, string given +Done diff --git a/tests/std/array/array_walk_rec_objects.phpt b/tests/std/array/array_walk_rec_objects.phpt new file mode 100644 index 00000000..a26e8989 --- /dev/null +++ b/tests/std/array/array_walk_rec_objects.phpt @@ -0,0 +1,46 @@ +--TEST-- +array_walk_recursive() and objects +--FILE-- +foo = "foo"; + $stdclass->bar = "bar"; + array_walk_recursive($stdclass, "walk"); + $t = new test(); + array_walk_recursive($t, "walk"); + $var = array(); + array_walk_recursive($var, "walk"); + $var_str = ""; + try { + array_walk_recursive($var_str, "walk"); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + echo "Done\n"; +} +?> +--EXPECTF-- +string(3) "foo" +string(3) "foo" +string(3) "bar" +string(3) "bar" +string(13) "%0test%0var_pri" +string(12) "test_private" +string(10) "%0*%0var_pro" +string(14) "test_protected" +string(7) "var_pub" +string(11) "test_public" +array_walk_recursive(): Argument #1 ($array) must be of type array, string given +Done diff --git a/tests/std/array/array_walk_recursive.phpt b/tests/std/array/array_walk_recursive.phpt new file mode 100644 index 00000000..3c331cfb --- /dev/null +++ b/tests/std/array/array_walk_recursive.phpt @@ -0,0 +1,29 @@ +--TEST-- +Test array_walk_recursive() +--SKIPIF-- +--FILE-- + +--EXPECT-- +1 foo +2 foo +3 foo +bool(true) +1 bar +2 bar +3 bar +bool(true) diff --git a/tests/std/array/array_walk_recursive1.phpt b/tests/std/array/array_walk_recursive1.phpt new file mode 100644 index 00000000..cd57bc5a --- /dev/null +++ b/tests/std/array/array_walk_recursive1.phpt @@ -0,0 +1,44 @@ +--TEST-- +array_walk_recursive() tests +--SKIPIF-- + +--FILE-- +getMessage()); + } + echo "Done\n"; +} +?> +--EXPECT-- +int(1) +int(0) +string(4) "data" +int(2) +int(1) +string(4) "data" +int(2) +int(0) +string(4) "data" +int(3) +int(1) +string(4) "data" +bool(true) +string(4) "data" +Done diff --git a/tests/std/array/array_walk_recursive_basic1.phpt b/tests/std/array/array_walk_recursive_basic1.phpt new file mode 100644 index 00000000..fbdbd52c --- /dev/null +++ b/tests/std/array/array_walk_recursive_basic1.phpt @@ -0,0 +1,75 @@ +--TEST-- +Test array_walk_recursive() function : basic functionality - regular array +--FILE-- + +--EXPECT-- +*** Testing array_walk_recursive() : basic functionality *** +-- Using array_walk_recursive() with default parameters to show array contents -- +string(5) "lemon" +int(0) + +string(6) "orange" +int(0) + +string(6) "banana" +int(1) + +string(5) "apple" +int(0) + +bool(true) +-- Using array_walk_recursive() with all parameters -- +string(5) "lemon" +int(0) +string(5) "Added" + +string(6) "orange" +int(0) +string(5) "Added" + +string(6) "banana" +int(1) +string(5) "Added" + +string(5) "apple" +int(0) +string(5) "Added" + +bool(true) +Done diff --git a/tests/std/array/array_walk_recursive_basic2.phpt b/tests/std/array/array_walk_recursive_basic2.phpt new file mode 100644 index 00000000..9664cb92 --- /dev/null +++ b/tests/std/array/array_walk_recursive_basic2.phpt @@ -0,0 +1,91 @@ +--TEST-- +Test array_walk_recursive() function : basic functionality - associative array +--FILE-- + "lemon", "b" => array("c" => "orange", "d" => "banana"), "e" => array("f" => "apple")); + echo "-- Using array_walk_recursive with default parameters to show array contents --\n"; + var_dump(array_walk_recursive($fruits, 'test_print')); + echo "-- Using array_walk_recursive with one optional parameter to modify contents --\n"; + var_dump(array_walk_recursive($fruits, 'test_alter', 'fruit')); + echo "-- Using array_walk_recursive with default parameters to show modified array contents --\n"; + var_dump(array_walk_recursive($fruits, 'test_print')); + echo "Done"; +} +?> +--EXPECT-- +*** Testing array_walk_recursive() : basic functionality *** +-- Using array_walk_recursive with default parameters to show array contents -- +string(5) "lemon" +string(1) "a" + +string(6) "orange" +string(1) "c" + +string(6) "banana" +string(1) "d" + +string(5) "apple" +string(1) "f" + +bool(true) +-- Using array_walk_recursive with one optional parameter to modify contents -- +string(5) "lemon" +string(1) "a" +string(5) "fruit" + +string(6) "orange" +string(1) "c" +string(5) "fruit" + +string(6) "banana" +string(1) "d" +string(5) "fruit" + +string(5) "apple" +string(1) "f" +string(5) "fruit" + +bool(true) +-- Using array_walk_recursive with default parameters to show modified array contents -- +string(5) "lemon" +string(1) "a" + +string(6) "orange" +string(1) "c" + +string(6) "banana" +string(1) "d" + +string(5) "apple" +string(1) "f" + +bool(true) +Done diff --git a/tests/std/array/array_walk_recursive_error2.phpt b/tests/std/array/array_walk_recursive_error2.phpt new file mode 100644 index 00000000..e3b9514f --- /dev/null +++ b/tests/std/array/array_walk_recursive_error2.phpt @@ -0,0 +1,64 @@ +--TEST-- +Test array_walk_recursive() function : error conditions - callback parameters +--SKIPIF-- + + +--FILE-- +getMessage() . "\n"; + } + try { + var_dump(array_walk_recursive($input, "callback2", 4)); + } catch (Throwable $e) { + echo "Exception: " . $e->getMessage() . "\n"; + } + // expected: Warning is suppressed + try { + var_dump(@array_walk_recursive($input, "callback1")); + } catch (Throwable $e) { + echo "Exception: " . $e->getMessage() . "\n"; + } + try { + var_dump(@array_walk_recursive($input, "callback2", 4)); + } catch (Throwable $e) { + echo "Exception: " . $e->getMessage() . "\n"; + } + echo "-- Testing array_walk_recursive() function with too many callback parameters --\n"; + try { + var_dump(array_walk_recursive($input, "callback1", 20, 10)); + } catch (Throwable $e) { + echo "Exception: " . $e->getMessage() . "\n"; + } + echo "Done"; +} +?> +--EXPECT-- +*** Testing array_walk_recursive() : error conditions - callback parameters *** +Exception: Too few arguments to function callback1(), 2 passed and exactly 3 expected +Exception: Too few arguments to function callback2(), 3 passed and exactly 4 expected +Exception: Too few arguments to function callback1(), 2 passed and exactly 3 expected +Exception: Too few arguments to function callback2(), 3 passed and exactly 4 expected +-- Testing array_walk_recursive() function with too many callback parameters -- +Exception: array_walk_recursive() expects at most 3 arguments, 4 given +Done diff --git a/tests/std/array/array_walk_recursive_object1.phpt b/tests/std/array/array_walk_recursive_object1.phpt new file mode 100644 index 00000000..cefcff95 --- /dev/null +++ b/tests/std/array/array_walk_recursive_object1.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test array_walk_recursive() function : object functionality +--FILE-- +pri_value = $setVal; + $this->pub_value = $setVal; + $this->pro_value = $setVal; + } +}; + +function main() { +echo "*** Testing array_walk_recursive() : object functionality ***\n"; + +// object for 'input' argument +$input = new MyClass(10); + +var_dump( array_walk_recursive($input, "callback", 1)); + +echo "Done"; +} +?> +--EXPECTF-- +*** Testing array_walk_recursive() : object functionality *** +string(18) "%r\0%rMyClass%r\0%rpri_value" +int(10) +int(1) + +string(9) "pub_value" +int(10) +int(1) + +string(12) "%r\0%r*%r\0%rpro_value" +int(10) +int(1) + +bool(true) +Done diff --git a/tests/std/array/array_walk_recursive_object2.phpt b/tests/std/array/array_walk_recursive_object2.phpt new file mode 100644 index 00000000..faa3a78a --- /dev/null +++ b/tests/std/array/array_walk_recursive_object2.phpt @@ -0,0 +1,96 @@ +--TEST-- +Test array_walk_recursive() function : object functionality - array of objects +--FILE-- +getValue()); + echo "key : "; + var_dump($key); +} + +function callback_public($value, $key) +{ + echo "value : "; + var_dump($value->pub_value); +} +function callback_protected($value, $key) +{ + echo "value : "; + var_dump($value->get_pro_value()); +} + +class MyClass +{ + private $pri_value; + public $pub_value; + protected $pro_value; + public function __construct($setVal) + { + $this->pri_value = $setVal; + $this->pub_value = $setVal; + $this->pro_value = $setVal; + } + public function getValue() + { + return $this->pri_value; + } + public function get_pro_value() + { + return $this->pro_value; + } +}; + +function main() { +echo "*** Testing array_walk_recursive() : array of objects ***\n"; + +// array containing objects of MyClass +$input = array ( + array( + new MyClass(3), + new MyClass(10), + ), + new MyClass(20), + array(new MyClass(-10)) +); + +echo "-- For private member --\n"; +var_dump( array_walk_recursive($input, "callback_private", 1)); +echo "-- For public member --\n"; +var_dump( array_walk_recursive($input, "callback_public")); +echo "-- For protected member --\n"; +var_dump( array_walk_recursive($input, "callback_protected")); + +echo "Done"; +} +?> +--EXPECT-- +*** Testing array_walk_recursive() : array of objects *** +-- For private member -- +value : int(3) +key : int(0) +value : int(10) +key : int(1) +value : int(20) +key : int(1) +value : int(-10) +key : int(0) +bool(true) +-- For public member -- +value : int(3) +value : int(10) +value : int(20) +value : int(-10) +bool(true) +-- For protected member -- +value : int(3) +value : int(10) +value : int(20) +value : int(-10) +bool(true) +Done diff --git a/tests/std/array/array_walk_recursive_variation3.phpt b/tests/std/array/array_walk_recursive_variation3.phpt new file mode 100644 index 00000000..c887d86e --- /dev/null +++ b/tests/std/array/array_walk_recursive_variation3.phpt @@ -0,0 +1,116 @@ +--TEST-- +Test array_walk_recursive() function : usage variations - 'input' array with different values +--SKIPIF-- + +--FILE-- + +--EXPECT-- +*** Testing array_walk_recursive() : 'input' array with different values*** + +-- Iteration 1 -- +1 : 0 1 +1 : 1 0 +1 : 2 -10 +1 : 0 19 +1 : 1 -33 +1 : 0 90 +1 : 1 31 +1 : 2 -110 +bool(true) + +-- Iteration 2 -- +2 : 0 3.4 +2 : 1 0.8 +2 : 2 -2.9 +2 : 0 625 +2 : 1 0.0082 +bool(true) + +-- Iteration 3 -- +3 : 0 Mango +3 : 0 Apple +3 : 1 Orange +3 : 2 Lemon +bool(true) + +-- Iteration 4 -- +4 : 0 1 +4 : 1 +4 : 0 1 +4 : 1 +bool(true) + +-- Iteration 5 -- +5 : 0 +5 : 0 +bool(true) + +-- Iteration 6 -- +bool(true) + +-- Iteration 7 -- +7 : 0 binary +bool(true) + +-- Iteration 8 -- +8 : 0 16 +8 : 1 8.345 +8 : 0 Fruits +8 : 0 1 +8 : 1 +8 : 0 +8 : 0 -98 +8 : 1 0.005 +8 : 2 banana +bool(true) +Done diff --git a/tests/std/array/array_walk_recursive_variation4.phpt b/tests/std/array/array_walk_recursive_variation4.phpt new file mode 100644 index 00000000..a40644ce --- /dev/null +++ b/tests/std/array/array_walk_recursive_variation4.phpt @@ -0,0 +1,67 @@ +--TEST-- +Test array_walk_recursive() function : usage variations - 'input' array with subarray +--FILE-- + +--EXPECT-- +*** Testing array_walk_recursive() : array with subarray *** +int(0) +int(1) + +int(0) +int(1) + +int(1) +int(2) + +int(2) +int(3) + +int(0) +string(5) "Mango" + +int(1) +string(6) "Orange" + +int(0) +int(1) + +int(1) +int(2) + +int(2) +int(3) + +int(0) +int(1) + +bool(true) +Done diff --git a/tests/std/array/array_walk_recursive_variation5.phpt b/tests/std/array/array_walk_recursive_variation5.phpt new file mode 100644 index 00000000..55bc642e --- /dev/null +++ b/tests/std/array/array_walk_recursive_variation5.phpt @@ -0,0 +1,59 @@ +--TEST-- +Test array_walk_recursive() function : usage variations - 'input' argument containing reference variables +--SKIPIF-- + +--FILE-- + +--EXPECT-- +*** Testing array_walk_recursive() : array with references *** +int(0) +int(10) + +int(0) +int(-20) + +int(1) +int(-35) + +int(0) +int(10) + +int(1) +int(0) + +int(0) +int(50) + +bool(true) +Done diff --git a/tests/std/array/array_walk_recursive_variation6.phpt b/tests/std/array/array_walk_recursive_variation6.phpt new file mode 100644 index 00000000..78926a6d --- /dev/null +++ b/tests/std/array/array_walk_recursive_variation6.phpt @@ -0,0 +1,127 @@ +--TEST-- +Test array_walk_recursive() function : usage variations - 'input' argument as diff. associative arrays +--FILE-- + array(1 => 25, 5 => 12, 0 => -80), 1 => array(-2 => 100, 5 => 30)); +echo "-- Associative array with numeric keys --\n"; +var_dump( array_walk_recursive($input, "for_numeric", 10)); + +// String keys +$input = array( "a" => "Apple", 'z' => array('b' => 'Bananna', "c" => "carrot"), 'x' => array('o' => "Orange")); +echo "-- Associative array with string keys --\n"; +var_dump( array_walk_recursive($input, "for_string")); + +// binary key +$input = array( b"a" => "Apple", b"b" => "Banana"); +echo "-- Associative array with binary keys --\n"; +var_dump( array_walk_recursive($input, "for_string")); + +// Mixed keys - numeric/string +$input = array( 0 => array(0 => 1, 1 => 2), "x" => array("a" => "Apple", "b" => "Banana"), 2 =>3); +echo "-- Associative array with numeric/string keys --\n"; +var_dump( array_walk_recursive($input, "for_mixed")); + +echo "Done"; +} +?> +--EXPECT-- +*** Testing array_walk_recursive() : 'input' as an associative array *** +-- Associative array with numeric keys -- +int(1) +int(25) +int(10) + +int(5) +int(12) +int(10) + +int(0) +int(-80) +int(10) + +int(-2) +int(100) +int(10) + +int(5) +int(30) +int(10) + +bool(true) +-- Associative array with string keys -- +string(1) "a" +string(5) "Apple" + +string(1) "b" +string(7) "Bananna" + +string(1) "c" +string(6) "carrot" + +string(1) "o" +string(6) "Orange" + +bool(true) +-- Associative array with binary keys -- +string(1) "a" +string(5) "Apple" + +string(1) "b" +string(6) "Banana" + +bool(true) +-- Associative array with numeric/string keys -- +int(0) +int(1) + +int(1) +int(2) + +string(1) "a" +string(5) "Apple" + +string(1) "b" +string(6) "Banana" + +int(2) +int(3) + +bool(true) +Done diff --git a/tests/std/array/array_walk_recursive_variation7.phpt b/tests/std/array/array_walk_recursive_variation7.phpt new file mode 100644 index 00000000..012e05b2 --- /dev/null +++ b/tests/std/array/array_walk_recursive_variation7.phpt @@ -0,0 +1,81 @@ +--TEST-- +Test array_walk_recursive() function : usage variations - anonymous callback function +--FILE-- + +--EXPECT-- +*** Testing array_walk_recursive() : anonymous function as callback *** +-- Anonymous function with one argument -- +int(2) + +int(5) + +int(10) + +int(0) + +bool(true) +-- Anonymous function with two arguments -- +int(0) +int(2) + +int(1) +int(5) + +int(0) +int(10) + +int(1) +int(0) + +bool(true) +-- Anonymous function with three arguments -- +int(0) +int(2) +int(10) + +int(1) +int(5) +int(10) + +int(0) +int(10) +int(10) + +int(1) +int(0) +int(10) + +bool(true) +-- Anonymous function with null argument -- +1 +1 +1 +1 +bool(true) +Done diff --git a/tests/std/array/array_walk_recursive_variation8.phpt b/tests/std/array/array_walk_recursive_variation8.phpt new file mode 100644 index 00000000..c3cd3454 --- /dev/null +++ b/tests/std/array/array_walk_recursive_variation8.phpt @@ -0,0 +1,39 @@ +--TEST-- +Test array_walk_recursive() function : usage variations - buit-in function as callback +--FILE-- + 1, 65), array(98, 100), array(6 => -4)); + +echo "-- With 'pow' built-in function --\n"; +var_dump( array_walk_recursive($input, 'pow')); + +echo "-- With 'min' built-in function --\n"; +var_dump( array_walk_recursive($input, "min")); + +echo "-- With 'echo' language construct --\n"; +try { + var_dump( array_walk_recursive($input, "echo")); +} catch (TypeError $e) { + echo $e->getMessage(), "\n"; +} + +echo "Done"; +?> +--EXPECT-- +*** Testing array_walk_recursive() : built-in function as callback *** +-- With 'pow' built-in function -- +bool(true) +-- With 'min' built-in function -- +bool(true) +-- With 'echo' language construct -- +array_walk_recursive(): Argument #2 ($callback) must be a valid callback, function "echo" not found or invalid function name +Done diff --git a/tests/std/array/array_walk_recursive_variation9.phpt b/tests/std/array/array_walk_recursive_variation9.phpt new file mode 100644 index 00000000..58847eb9 --- /dev/null +++ b/tests/std/array/array_walk_recursive_variation9.phpt @@ -0,0 +1,101 @@ +--TEST-- +Test array_walk_recursive() function : usage variations - different callback functions +--SKIPIF-- + +--FILE-- + +--EXPECT-- +*** Testing array_walk_recursive() : callback function variation *** +-- callback function with both parameters -- +int(0) +string(5) "Apple" + +int(1) +string(6) "Banana" + +int(1) +string(5) "Mango" + +int(0) +string(6) "Orange" + +bool(true) +-- callback function with only one parameter -- +string(5) "Apple" + +string(6) "Banana" + +string(5) "Mango" + +string(6) "Orange" + +bool(true) +-- callback function without parameters -- +callback3() called +callback3() called +callback3() called +callback3() called +bool(true) +-- passing one more parameter to function with two parameters -- +int(0) +string(5) "Apple" + +int(1) +string(6) "Banana" + +int(1) +string(5) "Mango" + +int(0) +string(6) "Orange" + +bool(true) +Done diff --git a/tests/std/array/array_walk_variation3.phpt b/tests/std/array/array_walk_variation3.phpt new file mode 100644 index 00000000..840cbf19 --- /dev/null +++ b/tests/std/array/array_walk_variation3.phpt @@ -0,0 +1,116 @@ +--TEST-- +Test array_walk() function : usage variations - 'input' array with different values +--SKIPIF-- + +--FILE-- + +--EXPECT-- +*** Testing array_walk() : 'input' array with different values*** + +-- Iteration 1 -- +1 : 0 1 +1 : 1 0 +1 : 2 -10 +1 : 3 19 +1 : 4 -33 +1 : 5 90 +1 : 6 31 +1 : 7 -110 +bool(true) + +-- Iteration 2 -- +2 : 0 3.4 +2 : 1 0.8 +2 : 2 -2.9 +2 : 3 625 +2 : 4 0.0082 +bool(true) + +-- Iteration 3 -- +3 : 0 Mango +3 : 1 Apple +3 : 2 Orange +3 : 3 Lemon +bool(true) + +-- Iteration 4 -- +4 : 0 1 +4 : 1 +4 : 2 1 +4 : 3 +bool(true) + +-- Iteration 5 -- +5 : 0 +5 : 1 +bool(true) + +-- Iteration 6 -- +bool(true) + +-- Iteration 7 -- +7 : 0 binary +bool(true) + +-- Iteration 8 -- +8 : 0 16 +8 : 1 8.345 +8 : 2 Fruits +8 : 3 1 +8 : 4 +8 : 5 +8 : 6 -98 +8 : 7 0.005 +8 : 8 banana +bool(true) +Done diff --git a/tests/std/array/array_walk_variation4.phpt b/tests/std/array/array_walk_variation4.phpt new file mode 100644 index 00000000..46958129 --- /dev/null +++ b/tests/std/array/array_walk_variation4.phpt @@ -0,0 +1,78 @@ +--TEST-- +Test array_walk() function : usage variations - 'input' array with subarray +--FILE-- + +--EXPECT-- +*** Testing array_walk() : array with subarray *** +int(0) +array(0) { +} + +int(1) +array(1) { + [0]=> + int(1) +} + +int(2) +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} + +int(3) +array(2) { + [0]=> + string(5) "Mango" + [1]=> + string(6) "Orange" +} + +int(4) +array(1) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} + +bool(true) +Done diff --git a/tests/std/array/array_walk_variation5.phpt b/tests/std/array/array_walk_variation5.phpt new file mode 100644 index 00000000..f41fe67e --- /dev/null +++ b/tests/std/array/array_walk_variation5.phpt @@ -0,0 +1,59 @@ +--TEST-- +Test array_walk() function : usage variations - 'input' argument containing reference variables +--SKIPIF-- + +--FILE-- + +--EXPECT-- +*** Testing array_walk() : array with references *** +int(0) +int(10) + +int(1) +int(-20) + +int(2) +int(-35) + +int(3) +int(10) + +int(4) +int(0) + +int(5) +int(50) + +bool(true) +Done diff --git a/tests/std/array/array_walk_variation6.phpt b/tests/std/array/array_walk_variation6.phpt new file mode 100644 index 00000000..600f67c5 --- /dev/null +++ b/tests/std/array/array_walk_variation6.phpt @@ -0,0 +1,123 @@ +--TEST-- +Test array_walk() function : usage variations - 'input' argument as diff. associative arrays +--FILE-- + 25, 5 => 12, 0 => -80, -2 => 100, 5 => 30); +echo "-- Associative array with numeric keys --\n"; +var_dump( array_walk($input, "for_numeric", 10)); + +// String keys +$input = array( "a" => "Apple", 'b' => 'Bananna', "c" => "carrot", 'o' => "Orange"); +echo "-- Associative array with string keys --\n"; +var_dump( array_walk($input, "for_string")); + +// binary keys +$input = array( b"a" => "Apple", b"b" => "Banana"); +echo "-- Associative array with binary keys --\n"; +var_dump( array_walk($input, "for_string")); + +// Mixed keys - numeric/string +$input = array( 0 => 1, 1 => 2, "a" => "Apple", "b" => "Banana", 2 =>3); +echo "-- Associative array with numeric/string keys --\n"; +var_dump( array_walk($input, "for_mixed")); + +echo "Done"; +} +?> +--EXPECT-- +*** Testing array_walk() : 'input' as an associative array *** +-- Associative array with numeric keys -- +int(1) +int(25) +int(10) + +int(5) +int(30) +int(10) + +int(0) +int(-80) +int(10) + +int(-2) +int(100) +int(10) + +bool(true) +-- Associative array with string keys -- +string(1) "a" +string(5) "Apple" + +string(1) "b" +string(7) "Bananna" + +string(1) "c" +string(6) "carrot" + +string(1) "o" +string(6) "Orange" + +bool(true) +-- Associative array with binary keys -- +string(1) "a" +string(5) "Apple" + +string(1) "b" +string(6) "Banana" + +bool(true) +-- Associative array with numeric/string keys -- +int(0) +int(1) + +int(1) +int(2) + +string(1) "a" +string(5) "Apple" + +string(1) "b" +string(6) "Banana" + +int(2) +int(3) + +bool(true) +Done diff --git a/tests/std/array/array_walk_variation7.phpt b/tests/std/array/array_walk_variation7.phpt new file mode 100644 index 00000000..e5b80ba8 --- /dev/null +++ b/tests/std/array/array_walk_variation7.phpt @@ -0,0 +1,81 @@ +--TEST-- +Test array_walk() function : usage variations - anonymous callback function +--FILE-- + +--EXPECT-- +*** Testing array_walk() : anonymous function as callback *** +-- Anonymous function with one argument -- +int(2) + +int(5) + +int(10) + +int(0) + +bool(true) +-- Anonymous function with two arguments -- +int(0) +int(2) + +int(1) +int(5) + +int(2) +int(10) + +int(3) +int(0) + +bool(true) +-- Anonymous function with three arguments -- +int(0) +int(2) +int(10) + +int(1) +int(5) +int(10) + +int(2) +int(10) +int(10) + +int(3) +int(0) +int(10) + +bool(true) +-- Anonymous function with null argument -- +1 +1 +1 +1 +bool(true) +Done diff --git a/tests/std/array/array_walk_variation8.phpt b/tests/std/array/array_walk_variation8.phpt new file mode 100644 index 00000000..0ba4fe9f --- /dev/null +++ b/tests/std/array/array_walk_variation8.phpt @@ -0,0 +1,39 @@ +--TEST-- +Test array_walk() function : usage variations - buit-in function as callback +--FILE-- + 1, 65, 98, 100, 6 => -4); + +echo "-- With 'pow' built-in function --\n"; +var_dump( array_walk($input, 'pow')); + +echo "-- With 'min' built-in function --\n"; +var_dump( array_walk($input, "min")); + +echo "-- With 'echo' language construct --\n"; +try { + var_dump( array_walk($input, "echo")); +} catch (TypeError $e) { + echo $e->getMessage(), "\n"; +} + +echo "Done"; +?> +--EXPECT-- +*** Testing array_walk() : built-in function as callback *** +-- With 'pow' built-in function -- +bool(true) +-- With 'min' built-in function -- +bool(true) +-- With 'echo' language construct -- +array_walk(): Argument #2 ($callback) must be a valid callback, function "echo" not found or invalid function name +Done diff --git a/tests/std/array/array_walk_variation9.phpt b/tests/std/array/array_walk_variation9.phpt new file mode 100644 index 00000000..434264de --- /dev/null +++ b/tests/std/array/array_walk_variation9.phpt @@ -0,0 +1,101 @@ +--TEST-- +Test array_walk() function : usage variations - different callback functions +--SKIPIF-- + +--FILE-- + +--EXPECT-- +*** Testing array_walk() : callback function variation *** +-- callback function with both parameters -- +int(0) +string(5) "Apple" + +int(1) +string(6) "Banana" + +int(2) +string(5) "Mango" + +int(3) +string(6) "Orange" + +bool(true) +-- callback function with only one parameter -- +string(5) "Apple" + +string(6) "Banana" + +string(5) "Mango" + +string(6) "Orange" + +bool(true) +-- callback function without parameters -- +callback3() called +callback3() called +callback3() called +callback3() called +bool(true) +-- passing one more parameter to function with two parameters -- +int(0) +string(5) "Apple" + +int(1) +string(6) "Banana" + +int(2) +string(5) "Mango" + +int(3) +string(6) "Orange" + +bool(true) +Done diff --git a/tests/std/array/arsort_basic.phpt b/tests/std/array/arsort_basic.phpt new file mode 100644 index 00000000..c636a627 --- /dev/null +++ b/tests/std/array/arsort_basic.phpt @@ -0,0 +1,239 @@ +--TEST-- +Test arsort() function : basic functionality +--FILE-- + "lemon", "o" => "orange", + "O" => "Orange", "O1" => "Orange1", "o2" => "orange2", "O3" => "Orange3", "o20" => "orange20", + "b" => "banana", +); +// an array containing unsorted numeric values with indices +$unsorted_numerics = array( 1 => 100, 2 => 33, 3 => 555, 4 => 22 ); + +echo "\n-- Testing arsort() by supplying string array, 'flag' value is default --\n"; +$temp_array = $unsorted_strings; +var_dump( arsort($temp_array) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing arsort() by supplying numeric array, 'flag' value is default --\n"; +$temp_array = $unsorted_numerics; +var_dump( arsort($temp_array) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing arsort() by supplying string array, 'flag' = SORT_REGULAR --\n"; +$temp_array = $unsorted_strings; +var_dump( arsort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing arsort() by supplying numeric array, 'flag' = SORT_REGULAR --\n"; +$temp_array = $unsorted_numerics; +var_dump( arsort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing arsort() by supplying string array, 'flag' = SORT_STRING --\n"; +$temp_array = $unsorted_strings; +var_dump( arsort($temp_array, SORT_STRING) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing arsort() by supplying string array (case insensitive), 'flag' = SORT_STRING|SORT_FLAG_CASE --\n"; +$temp_array = $unsorted_strings; +var_dump( arsort($temp_array, SORT_STRING|SORT_FLAG_CASE) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing arsort() by supplying string array (natural), 'flag' = SORT_NATURAL --\n"; +$temp_array = $unsorted_strings; +var_dump( arsort($temp_array, SORT_NATURAL) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing arsort() by supplying string array (natural, case insensitive), 'flag' = SORT_NATURAL|SORT_FLAG_CASE --\n"; +$temp_array = $unsorted_strings; +var_dump( arsort($temp_array, SORT_NATURAL|SORT_FLAG_CASE) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing arsort() by supplying numeric array, 'flag' = SORT_NUMERIC --\n"; +$temp_array = $unsorted_numerics; +var_dump( arsort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "Done\n"; +?> +--EXPECT-- +*** Testing arsort() : basic functionality *** + +-- Testing arsort() by supplying string array, 'flag' value is default -- +bool(true) +array(8) { + ["o20"]=> + string(8) "orange20" + ["o2"]=> + string(7) "orange2" + ["o"]=> + string(6) "orange" + ["l"]=> + string(5) "lemon" + ["b"]=> + string(6) "banana" + ["O3"]=> + string(7) "Orange3" + ["O1"]=> + string(7) "Orange1" + ["O"]=> + string(6) "Orange" +} + +-- Testing arsort() by supplying numeric array, 'flag' value is default -- +bool(true) +array(4) { + [3]=> + int(555) + [1]=> + int(100) + [2]=> + int(33) + [4]=> + int(22) +} + +-- Testing arsort() by supplying string array, 'flag' = SORT_REGULAR -- +bool(true) +array(8) { + ["o20"]=> + string(8) "orange20" + ["o2"]=> + string(7) "orange2" + ["o"]=> + string(6) "orange" + ["l"]=> + string(5) "lemon" + ["b"]=> + string(6) "banana" + ["O3"]=> + string(7) "Orange3" + ["O1"]=> + string(7) "Orange1" + ["O"]=> + string(6) "Orange" +} + +-- Testing arsort() by supplying numeric array, 'flag' = SORT_REGULAR -- +bool(true) +array(4) { + [3]=> + int(555) + [1]=> + int(100) + [2]=> + int(33) + [4]=> + int(22) +} + +-- Testing arsort() by supplying string array, 'flag' = SORT_STRING -- +bool(true) +array(8) { + ["o20"]=> + string(8) "orange20" + ["o2"]=> + string(7) "orange2" + ["o"]=> + string(6) "orange" + ["l"]=> + string(5) "lemon" + ["b"]=> + string(6) "banana" + ["O3"]=> + string(7) "Orange3" + ["O1"]=> + string(7) "Orange1" + ["O"]=> + string(6) "Orange" +} + +-- Testing arsort() by supplying string array (case insensitive), 'flag' = SORT_STRING|SORT_FLAG_CASE -- +bool(true) +array(8) { + ["O3"]=> + string(7) "Orange3" + ["o20"]=> + string(8) "orange20" + ["o2"]=> + string(7) "orange2" + ["O1"]=> + string(7) "Orange1" + ["o"]=> + string(6) "orange" + ["O"]=> + string(6) "Orange" + ["l"]=> + string(5) "lemon" + ["b"]=> + string(6) "banana" +} + +-- Testing arsort() by supplying string array (natural), 'flag' = SORT_NATURAL -- +bool(true) +array(8) { + ["o20"]=> + string(8) "orange20" + ["o2"]=> + string(7) "orange2" + ["o"]=> + string(6) "orange" + ["l"]=> + string(5) "lemon" + ["b"]=> + string(6) "banana" + ["O3"]=> + string(7) "Orange3" + ["O1"]=> + string(7) "Orange1" + ["O"]=> + string(6) "Orange" +} + +-- Testing arsort() by supplying string array (natural, case insensitive), 'flag' = SORT_NATURAL|SORT_FLAG_CASE -- +bool(true) +array(8) { + ["o20"]=> + string(8) "orange20" + ["O3"]=> + string(7) "Orange3" + ["o2"]=> + string(7) "orange2" + ["O1"]=> + string(7) "Orange1" + ["o"]=> + string(6) "orange" + ["O"]=> + string(6) "Orange" + ["l"]=> + string(5) "lemon" + ["b"]=> + string(6) "banana" +} + +-- Testing arsort() by supplying numeric array, 'flag' = SORT_NUMERIC -- +bool(true) +array(4) { + [3]=> + int(555) + [1]=> + int(100) + [2]=> + int(33) + [4]=> + int(22) +} +Done diff --git a/tests/std/array/arsort_object1.phpt b/tests/std/array/arsort_object1.phpt new file mode 100644 index 00000000..edefd9f1 --- /dev/null +++ b/tests/std/array/arsort_object1.phpt @@ -0,0 +1,220 @@ +--TEST-- +Test arsort() function : object functionality - sort objects +--FILE-- +class_value = $value; + } +} +// class declaration for string objects +class for_string_arsort +{ + public $class_value; + // initializing object member value + function __construct($value) + { + $this->class_value = $value; + } + // return string value + function __tostring(): string { + return (string) $this->value; + } +} +function main() +{ + /* + * testing arsort() by providing integer/string object arrays with following flag values + * 1. Default flag value + * 2. SORT_REGULAR - compare items normally + */ + echo "*** Testing arsort() : object functionality ***\n"; + // array of integer objects + $unsorted_int_obj = array(1 => new for_integer_arsort(11), 2 => new for_integer_arsort(66), 3 => new for_integer_arsort(23), 4 => new for_integer_arsort(-5), 5 => new for_integer_arsort(0.001), 6 => new for_integer_arsort(0)); + // array of string objects + $unsorted_str_obj = array("a" => new for_string_arsort("axx"), "b" => new for_string_arsort("t"), "c" => new for_string_arsort("w"), "d" => new for_string_arsort("py"), "e" => new for_string_arsort("apple"), "f" => new for_string_arsort("Orange"), "g" => new for_string_arsort("Lemon"), "h" => new for_string_arsort("aPPle")); + echo "\n-- Testing arsort() by supplying various object arrays, 'flag' value is default --\n"; + // testing arsort() function by supplying integer object array, flag value is default + $temp_array = $unsorted_int_obj; + var_dump(arsort($temp_array)); + var_dump($temp_array); + // testing arsort() function by supplying string object array, flag value is default + $temp_array = $unsorted_str_obj; + var_dump(arsort($temp_array)); + var_dump($temp_array); + echo "\n-- Testing arsort() by supplying various object arrays, 'flag' value is SORT_REGULAR --\n"; + // testing arsort() function by supplying integer object array, flag value = SORT_REGULAR + $temp_array = $unsorted_int_obj; + var_dump(arsort($temp_array, SORT_REGULAR)); + var_dump($temp_array); + // testing arsort() function by supplying string object array, flag value = SORT_REGULAR + $temp_array = $unsorted_str_obj; + var_dump(arsort($temp_array, SORT_REGULAR)); + var_dump($temp_array); + echo "Done\n"; +} +?> +--EXPECT-- +*** Testing arsort() : object functionality *** + +-- Testing arsort() by supplying various object arrays, 'flag' value is default -- +bool(true) +array(6) { + [2]=> + object(for_integer_arsort)#2 (1) { + ["class_value"]=> + int(66) + } + [3]=> + object(for_integer_arsort)#3 (1) { + ["class_value"]=> + int(23) + } + [1]=> + object(for_integer_arsort)#1 (1) { + ["class_value"]=> + int(11) + } + [5]=> + object(for_integer_arsort)#5 (1) { + ["class_value"]=> + float(0.001) + } + [6]=> + object(for_integer_arsort)#6 (1) { + ["class_value"]=> + int(0) + } + [4]=> + object(for_integer_arsort)#4 (1) { + ["class_value"]=> + int(-5) + } +} +bool(true) +array(8) { + ["c"]=> + object(for_string_arsort)#9 (1) { + ["class_value"]=> + string(1) "w" + } + ["b"]=> + object(for_string_arsort)#8 (1) { + ["class_value"]=> + string(1) "t" + } + ["d"]=> + object(for_string_arsort)#10 (1) { + ["class_value"]=> + string(2) "py" + } + ["a"]=> + object(for_string_arsort)#7 (1) { + ["class_value"]=> + string(3) "axx" + } + ["e"]=> + object(for_string_arsort)#11 (1) { + ["class_value"]=> + string(5) "apple" + } + ["h"]=> + object(for_string_arsort)#14 (1) { + ["class_value"]=> + string(5) "aPPle" + } + ["f"]=> + object(for_string_arsort)#12 (1) { + ["class_value"]=> + string(6) "Orange" + } + ["g"]=> + object(for_string_arsort)#13 (1) { + ["class_value"]=> + string(5) "Lemon" + } +} + +-- Testing arsort() by supplying various object arrays, 'flag' value is SORT_REGULAR -- +bool(true) +array(6) { + [2]=> + object(for_integer_arsort)#2 (1) { + ["class_value"]=> + int(66) + } + [3]=> + object(for_integer_arsort)#3 (1) { + ["class_value"]=> + int(23) + } + [1]=> + object(for_integer_arsort)#1 (1) { + ["class_value"]=> + int(11) + } + [5]=> + object(for_integer_arsort)#5 (1) { + ["class_value"]=> + float(0.001) + } + [6]=> + object(for_integer_arsort)#6 (1) { + ["class_value"]=> + int(0) + } + [4]=> + object(for_integer_arsort)#4 (1) { + ["class_value"]=> + int(-5) + } +} +bool(true) +array(8) { + ["c"]=> + object(for_string_arsort)#9 (1) { + ["class_value"]=> + string(1) "w" + } + ["b"]=> + object(for_string_arsort)#8 (1) { + ["class_value"]=> + string(1) "t" + } + ["d"]=> + object(for_string_arsort)#10 (1) { + ["class_value"]=> + string(2) "py" + } + ["a"]=> + object(for_string_arsort)#7 (1) { + ["class_value"]=> + string(3) "axx" + } + ["e"]=> + object(for_string_arsort)#11 (1) { + ["class_value"]=> + string(5) "apple" + } + ["h"]=> + object(for_string_arsort)#14 (1) { + ["class_value"]=> + string(5) "aPPle" + } + ["f"]=> + object(for_string_arsort)#12 (1) { + ["class_value"]=> + string(6) "Orange" + } + ["g"]=> + object(for_string_arsort)#13 (1) { + ["class_value"]=> + string(5) "Lemon" + } +} +Done diff --git a/tests/std/array/arsort_object2.phpt b/tests/std/array/arsort_object2.phpt new file mode 100644 index 00000000..3db1891a --- /dev/null +++ b/tests/std/array/arsort_object2.phpt @@ -0,0 +1,232 @@ +--TEST-- +Test arsort() function : object functionality - sorting objects with diff. accessibility of member vars +--FILE-- +public_class_value = $value1; + $this->private_class_value = $value2; + $this->protected_class_value = $value3; + } +} +// class declaration for string objects +class for_string_arsort +{ + public $public_class_value; + private $private_class_value; + protected $protected_class_value; + // initializing object member value + function __construct($value1, $value2, $value3) + { + $this->public_class_value = $value1; + $this->private_class_value = $value2; + $this->protected_class_value = $value3; + } + // return string value + function __tostring(): string { + return (string) $this->value; + } +} +function main() +{ + /* + * testing arsort() by providing integer/string object arrays with following flag values + * 1. Default flag value + 2. SORT_REGULAR - compare items normally + */ + echo "*** Testing arsort() : object functionality ***\n"; + // array of integer objects + $unsorted_int_obj = array(1 => new for_integer_arsort(11, 33, 2), 2 => new for_integer_arsort(44, 66, 3), 3 => new for_integer_arsort(23, 32, 6), 4 => new for_integer_arsort(-88, -5, -4)); + // array of string objects + $unsorted_str_obj = array("a" => new for_string_arsort("axx", "AXX", "d"), "b" => new for_string_arsort("T", "t", "q"), "c" => new for_string_arsort("w", "W", "c"), "d" => new for_string_arsort("PY", "py", "s")); + echo "\n-- Testing arsort() by supplying various object arrays, 'flag' value is default --\n"; + // testing arsort() function by supplying integer object array, flag value is default + $temp_array = $unsorted_int_obj; + var_dump(arsort($temp_array)); + var_dump($temp_array); + // testing arsort() function by supplying string object array, flag value is default + $temp_array = $unsorted_str_obj; + var_dump(arsort($temp_array)); + var_dump($temp_array); + echo "\n-- Testing arsort() by supplying various object arrays, 'flag' value is SORT_REGULAR --\n"; + // testing arsort() function by supplying integer object array, flag value = SORT_REGULAR + $temp_array = $unsorted_int_obj; + var_dump(arsort($temp_array, SORT_REGULAR)); + var_dump($temp_array); + // testing arsort() function by supplying string object array, flag value = SORT_REGULAR + $temp_array = $unsorted_str_obj; + var_dump(arsort($temp_array, SORT_REGULAR)); + var_dump($temp_array); + echo "Done\n"; +} +?> +--EXPECT-- +*** Testing arsort() : object functionality *** + +-- Testing arsort() by supplying various object arrays, 'flag' value is default -- +bool(true) +array(4) { + [2]=> + object(for_integer_arsort)#2 (3) { + ["public_class_value"]=> + int(44) + ["private_class_value":"for_integer_arsort":private]=> + int(66) + ["protected_class_value":protected]=> + int(3) + } + [3]=> + object(for_integer_arsort)#3 (3) { + ["public_class_value"]=> + int(23) + ["private_class_value":"for_integer_arsort":private]=> + int(32) + ["protected_class_value":protected]=> + int(6) + } + [1]=> + object(for_integer_arsort)#1 (3) { + ["public_class_value"]=> + int(11) + ["private_class_value":"for_integer_arsort":private]=> + int(33) + ["protected_class_value":protected]=> + int(2) + } + [4]=> + object(for_integer_arsort)#4 (3) { + ["public_class_value"]=> + int(-88) + ["private_class_value":"for_integer_arsort":private]=> + int(-5) + ["protected_class_value":protected]=> + int(-4) + } +} +bool(true) +array(4) { + ["c"]=> + object(for_string_arsort)#7 (3) { + ["public_class_value"]=> + string(1) "w" + ["private_class_value":"for_string_arsort":private]=> + string(1) "W" + ["protected_class_value":protected]=> + string(1) "c" + } + ["a"]=> + object(for_string_arsort)#5 (3) { + ["public_class_value"]=> + string(3) "axx" + ["private_class_value":"for_string_arsort":private]=> + string(3) "AXX" + ["protected_class_value":protected]=> + string(1) "d" + } + ["b"]=> + object(for_string_arsort)#6 (3) { + ["public_class_value"]=> + string(1) "T" + ["private_class_value":"for_string_arsort":private]=> + string(1) "t" + ["protected_class_value":protected]=> + string(1) "q" + } + ["d"]=> + object(for_string_arsort)#8 (3) { + ["public_class_value"]=> + string(2) "PY" + ["private_class_value":"for_string_arsort":private]=> + string(2) "py" + ["protected_class_value":protected]=> + string(1) "s" + } +} + +-- Testing arsort() by supplying various object arrays, 'flag' value is SORT_REGULAR -- +bool(true) +array(4) { + [2]=> + object(for_integer_arsort)#2 (3) { + ["public_class_value"]=> + int(44) + ["private_class_value":"for_integer_arsort":private]=> + int(66) + ["protected_class_value":protected]=> + int(3) + } + [3]=> + object(for_integer_arsort)#3 (3) { + ["public_class_value"]=> + int(23) + ["private_class_value":"for_integer_arsort":private]=> + int(32) + ["protected_class_value":protected]=> + int(6) + } + [1]=> + object(for_integer_arsort)#1 (3) { + ["public_class_value"]=> + int(11) + ["private_class_value":"for_integer_arsort":private]=> + int(33) + ["protected_class_value":protected]=> + int(2) + } + [4]=> + object(for_integer_arsort)#4 (3) { + ["public_class_value"]=> + int(-88) + ["private_class_value":"for_integer_arsort":private]=> + int(-5) + ["protected_class_value":protected]=> + int(-4) + } +} +bool(true) +array(4) { + ["c"]=> + object(for_string_arsort)#7 (3) { + ["public_class_value"]=> + string(1) "w" + ["private_class_value":"for_string_arsort":private]=> + string(1) "W" + ["protected_class_value":protected]=> + string(1) "c" + } + ["a"]=> + object(for_string_arsort)#5 (3) { + ["public_class_value"]=> + string(3) "axx" + ["private_class_value":"for_string_arsort":private]=> + string(3) "AXX" + ["protected_class_value":protected]=> + string(1) "d" + } + ["b"]=> + object(for_string_arsort)#6 (3) { + ["public_class_value"]=> + string(1) "T" + ["private_class_value":"for_string_arsort":private]=> + string(1) "t" + ["protected_class_value":protected]=> + string(1) "q" + } + ["d"]=> + object(for_string_arsort)#8 (3) { + ["public_class_value"]=> + string(2) "PY" + ["private_class_value":"for_string_arsort":private]=> + string(2) "py" + ["protected_class_value":protected]=> + string(1) "s" + } +} +Done diff --git a/tests/std/array/arsort_variation10.phpt b/tests/std/array/arsort_variation10.phpt new file mode 100644 index 00000000..30127b84 --- /dev/null +++ b/tests/std/array/arsort_variation10.phpt @@ -0,0 +1,108 @@ +--TEST-- +Test arsort() function : usage variations - sort octal values +--FILE-- + 01235, 0321 => 0321, 0345 => 0345, 066 => 066, 0772 => 0772, + 077 => 077, -066 => -066, -0345 => -0345, 0 => 0 +); + +echo "\n-- Testing arsort() by supplying octal value array, 'flag' value is default --\n"; +$temp_array = $unsorted_oct_array; +var_dump( arsort($temp_array) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing arsort() by supplying octal value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $unsorted_oct_array; +var_dump( arsort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing arsort() by supplying octal value array, 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $unsorted_oct_array; +var_dump( arsort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECT-- +*** Testing arsort() : usage variations *** + +-- Testing arsort() by supplying octal value array, 'flag' value is default -- +bool(true) +array(9) { + [669]=> + int(669) + [506]=> + int(506) + [229]=> + int(229) + [209]=> + int(209) + [63]=> + int(63) + [54]=> + int(54) + [0]=> + int(0) + [-54]=> + int(-54) + [-229]=> + int(-229) +} + +-- Testing arsort() by supplying octal value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(9) { + [669]=> + int(669) + [506]=> + int(506) + [229]=> + int(229) + [209]=> + int(209) + [63]=> + int(63) + [54]=> + int(54) + [0]=> + int(0) + [-54]=> + int(-54) + [-229]=> + int(-229) +} + +-- Testing arsort() by supplying octal value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(9) { + [669]=> + int(669) + [506]=> + int(506) + [229]=> + int(229) + [209]=> + int(209) + [63]=> + int(63) + [54]=> + int(54) + [0]=> + int(0) + [-54]=> + int(-54) + [-229]=> + int(-229) +} +Done diff --git a/tests/std/array/arsort_variation11.phpt b/tests/std/array/arsort_variation11.phpt new file mode 100644 index 00000000..8d0f99a2 --- /dev/null +++ b/tests/std/array/arsort_variation11.phpt @@ -0,0 +1,155 @@ +--TEST-- +Test arsort() function : usage variations - sort mixed values, 'sort_flags' as default/SORT_REGULAR (OK to fail as result is unpredectable) +--SKIPIF-- + +--FILE-- + array(), + "array2" => array ( "sub_array[2,1]" => array(33,-5,6), "sub_array[2,2]" => array(11), + "sub_array[2,3]" => array(22,-55), "sub_array[2,4]" => array() + ), + 4 => 4, "4" => "4", 4 => 4.01, "b" => "b", "5" => "5", -2 => -2, -2 => -2.01, + -2 => -2.98989, "-.9" => "-.9", "True" => "True", "" => "", NULL => NULL, + "ab" => "ab", "abcd" => "abcd", 0 => 0.01, -0 => -0, '' => '' , + "abcd\x00abcd\x00abcd" => "abcd\x00abcd\x00abcd", 0 => 0.001 +); + +echo "\n-- Testing arsort() by supplying mixed value array, 'flag' value is default --\n"; +$temp_array = $mixed_values; +var_dump( arsort($temp_array) ); +var_dump($temp_array); + +echo "\n-- Testing arsort() by supplying mixed value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $mixed_values; +var_dump( arsort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing arsort() : usage variations *** + +-- Testing arsort() by supplying mixed value array, 'flag' value is default -- +bool(true) +array(13) { + ["array2"]=> + array(4) { + ["sub_array[2,1]"]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } + ["sub_array[2,2]"]=> + array(1) { + [0]=> + int(11) + } + ["sub_array[2,3]"]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + ["sub_array[2,4]"]=> + array(0) { + } + } + ["array1"]=> + array(0) { + } + ["b"]=> + string(1) "b" + ["abcd%0abcd%0abcd"]=> + string(14) "abcd%0abcd%0abcd" + ["abcd"]=> + string(4) "abcd" + ["ab"]=> + string(2) "ab" + ["True"]=> + string(4) "True" + [5]=> + string(1) "5" + [4]=> + float(4.01) + [0]=> + float(0.001) + ["-.9"]=> + string(3) "-.9" + [-2]=> + float(-2.98989) + [""]=> + string(0) "" +} + +-- Testing arsort() by supplying mixed value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(13) { + ["array2"]=> + array(4) { + ["sub_array[2,1]"]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } + ["sub_array[2,2]"]=> + array(1) { + [0]=> + int(11) + } + ["sub_array[2,3]"]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + ["sub_array[2,4]"]=> + array(0) { + } + } + ["array1"]=> + array(0) { + } + ["b"]=> + string(1) "b" + ["abcd%0abcd%0abcd"]=> + string(14) "abcd%0abcd%0abcd" + ["abcd"]=> + string(4) "abcd" + ["ab"]=> + string(2) "ab" + ["True"]=> + string(4) "True" + [5]=> + string(1) "5" + [4]=> + float(4.01) + [0]=> + float(0.001) + ["-.9"]=> + string(3) "-.9" + [-2]=> + float(-2.98989) + [""]=> + string(0) "" +} +Done diff --git a/tests/std/array/arsort_variation3.phpt b/tests/std/array/arsort_variation3.phpt new file mode 100644 index 00000000..e54d9c3b --- /dev/null +++ b/tests/std/array/arsort_variation3.phpt @@ -0,0 +1,320 @@ +--TEST-- +Test arsort() function : usage variations - sort integer/float values +--FILE-- + 11, 2 => -11, 3 => 21, 4 => -21, 5 => 31, 6 => -31, 7 => 0, 8 => 41, 10 =>-41), + + // float value array + array(1 => 10.5, 2 => -10.5, 3 => 10.5e2, 4 => 10.6E-2, 5 => .5, 6 => .0001, 7 => -.1), + + // mixed value array + array(1 => .0001, 2 => .0021, 3 => -.01, 4 => -1, 5 => 0, 6 => .09, 7 => 2, 8 => -.9, 9 => 10.6E-2, 10 => -10.6E-2, 11 => 33), + + // array values contains minimum and maximum ranges + array(1 => 2147483647, 2 => 2147483648, 3 => -2147483647, 4 => -2147483648, 5 => -0, 6 => 0, 7 => -2147483649) +); + +// set of possible flag values +$flag_value = array("SORT_REGULAR" => SORT_REGULAR, "SORT_NUMERIC" => SORT_NUMERIC); + +$count = 1; +echo "\n-- Testing arsort() by supplying various integer/float arrays --\n"; + +// loop through to test arsort() with different arrays +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With default sort_flag -\n"; + $temp_array = $array; + var_dump(arsort($temp_array) ); + var_dump($temp_array); + + // loop through $flag_value array and setting all possible flag values + foreach($flag_value as $key => $flag){ + echo "- Sort_flag = $key -\n"; + $temp_array = $array; + var_dump(arsort($temp_array, $flag) ); + var_dump($temp_array); + } + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing arsort() : usage variations *** + +-- Testing arsort() by supplying various integer/float arrays -- + +-- Iteration 1 -- +- With default sort_flag - +bool(true) +array(9) { + [8]=> + int(41) + [5]=> + int(31) + [3]=> + int(21) + [1]=> + int(11) + [7]=> + int(0) + [2]=> + int(-11) + [4]=> + int(-21) + [6]=> + int(-31) + [10]=> + int(-41) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(9) { + [8]=> + int(41) + [5]=> + int(31) + [3]=> + int(21) + [1]=> + int(11) + [7]=> + int(0) + [2]=> + int(-11) + [4]=> + int(-21) + [6]=> + int(-31) + [10]=> + int(-41) +} +- Sort_flag = SORT_NUMERIC - +bool(true) +array(9) { + [8]=> + int(41) + [5]=> + int(31) + [3]=> + int(21) + [1]=> + int(11) + [7]=> + int(0) + [2]=> + int(-11) + [4]=> + int(-21) + [6]=> + int(-31) + [10]=> + int(-41) +} + +-- Iteration 2 -- +- With default sort_flag - +bool(true) +array(7) { + [3]=> + float(1050) + [1]=> + float(10.5) + [5]=> + float(0.5) + [4]=> + float(0.106) + [6]=> + float(0.0001) + [7]=> + float(-0.1) + [2]=> + float(-10.5) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(7) { + [3]=> + float(1050) + [1]=> + float(10.5) + [5]=> + float(0.5) + [4]=> + float(0.106) + [6]=> + float(0.0001) + [7]=> + float(-0.1) + [2]=> + float(-10.5) +} +- Sort_flag = SORT_NUMERIC - +bool(true) +array(7) { + [3]=> + float(1050) + [1]=> + float(10.5) + [5]=> + float(0.5) + [4]=> + float(0.106) + [6]=> + float(0.0001) + [7]=> + float(-0.1) + [2]=> + float(-10.5) +} + +-- Iteration 3 -- +- With default sort_flag - +bool(true) +array(11) { + [11]=> + int(33) + [7]=> + int(2) + [9]=> + float(0.106) + [6]=> + float(0.09) + [2]=> + float(0.0021) + [1]=> + float(0.0001) + [5]=> + int(0) + [3]=> + float(-0.01) + [10]=> + float(-0.106) + [8]=> + float(-0.9) + [4]=> + int(-1) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(11) { + [11]=> + int(33) + [7]=> + int(2) + [9]=> + float(0.106) + [6]=> + float(0.09) + [2]=> + float(0.0021) + [1]=> + float(0.0001) + [5]=> + int(0) + [3]=> + float(-0.01) + [10]=> + float(-0.106) + [8]=> + float(-0.9) + [4]=> + int(-1) +} +- Sort_flag = SORT_NUMERIC - +bool(true) +array(11) { + [11]=> + int(33) + [7]=> + int(2) + [9]=> + float(0.106) + [6]=> + float(0.09) + [2]=> + float(0.0021) + [1]=> + float(0.0001) + [5]=> + int(0) + [3]=> + float(-0.01) + [10]=> + float(-0.106) + [8]=> + float(-0.9) + [4]=> + int(-1) +} + +-- Iteration 4 -- +- With default sort_flag - +bool(true) +array(7) { + [2]=> + %s(2147483648) + [1]=> + int(2147483647) + [5]=> + int(0) + [6]=> + int(0) + [3]=> + int(-2147483647) + [4]=> + %s(-2147483648) + [7]=> + %s(-2147483649) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(7) { + [2]=> + %s(2147483648) + [1]=> + int(2147483647) + [5]=> + int(0) + [6]=> + int(0) + [3]=> + int(-2147483647) + [4]=> + %s(-2147483648) + [7]=> + %s(-2147483649) +} +- Sort_flag = SORT_NUMERIC - +bool(true) +array(7) { + [2]=> + %s(2147483648) + [1]=> + int(2147483647) + [5]=> + int(0) + [6]=> + int(0) + [3]=> + int(-2147483647) + [4]=> + %s(-2147483648) + [7]=> + %s(-2147483649) +} +Done diff --git a/tests/std/array/arsort_variation4.phpt b/tests/std/array/arsort_variation4.phpt new file mode 100644 index 00000000..5e0bd2cd --- /dev/null +++ b/tests/std/array/arsort_variation4.phpt @@ -0,0 +1,78 @@ +--TEST-- +Test arsort() function : usage variations - sort reference variables +--SKIPIF-- + + +--FILE-- + &$value1 , 2 => &$value2, 3 => &$value3); + +echo "\n-- Testing arsort() by supplying reference variable array, 'flag' value is default --\n"; +$temp_array = $unsorted_numerics; +var_dump( arsort($temp_array) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing arsort() by supplying reference variable array, 'flag' = SORT_REGULAR --\n"; +$temp_array = &$unsorted_numerics; +var_dump( arsort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing arsort() by supplying reference variable array, 'flag' = SORT_NUMERIC --\n"; +$temp_array = &$unsorted_numerics; +var_dump( arsort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "Done\n"; +?> +--EXPECT-- +*** Testing arsort() :usage variations *** + +-- Testing arsort() by supplying reference variable array, 'flag' value is default -- +bool(true) +array(3) { + [3]=> + &int(555) + [1]=> + &int(100) + [2]=> + &int(33) +} + +-- Testing arsort() by supplying reference variable array, 'flag' = SORT_REGULAR -- +bool(true) +array(3) { + [3]=> + &int(555) + [1]=> + &int(100) + [2]=> + &int(33) +} + +-- Testing arsort() by supplying reference variable array, 'flag' = SORT_NUMERIC -- +bool(true) +array(3) { + [3]=> + &int(555) + [1]=> + &int(100) + [2]=> + &int(33) +} +Done diff --git a/tests/std/array/arsort_variation5.phpt b/tests/std/array/arsort_variation5.phpt new file mode 100644 index 00000000..eb3f2f95 --- /dev/null +++ b/tests/std/array/arsort_variation5.phpt @@ -0,0 +1,236 @@ +--TEST-- +Test arsort() function : usage variations - sort strings +--FILE-- + null, "NULL" => NULL, "\a" => "\a", "\cx" => "\cx", "\e" => "\e", + "\f" => "\f", "\n" =>"\n", "\r" => "\r", "\t" => "\t", "\xhh" => "\xhh", + "\ddd" => "\ddd", "\v" => "\v" + ), + + // array contains combination of capital/small letters + array ('l' => "lemoN", 'O' => "Orange", 'b' => "banana", 'a' => "apple", 'Te' => "Test", + 'T' => "TTTT", 't' => "ttt", 'w' => "ww", 'x' => "x", 'X' => "X", 'o' => "oraNGe", + 'B' => "BANANA" + ) +); + +$flags = array("SORT_REGULAR" => SORT_REGULAR, "SORT_STRING" => SORT_STRING); + +$count = 1; +echo "\n-- Testing arsort() by supplying various string arrays --\n"; + +// loop through to test arsort() with different arrays +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With default sort_flag -\n"; + $temp_array = $array; + var_dump(arsort($temp_array) ); // expecting : bool(true) + var_dump($temp_array); + + // loop through $flags array and setting all possible flag values + foreach($flags as $key => $flag){ + echo "- Sort_flag = $key -\n"; + $temp_array = $array; + var_dump(arsort($temp_array, $flag) ); // expecting : bool(true) + var_dump($temp_array); + } + $count++; +} + +echo "Done\n"; +?> +--EXPECT-- +*** Testing arsort() : usage variations *** + +-- Testing arsort() by supplying various string arrays -- + +-- Iteration 1 -- +- With default sort_flag - +bool(true) +array(12) { + ["\xhh"]=> + string(4) "\xhh" + ["\ddd"]=> + string(4) "\ddd" + ["\cx"]=> + string(3) "\cx" + ["\a"]=> + string(2) "\a" + [""]=> + string(1) "" + [" "]=> + string(1) " " + [" "]=> + string(1) " " + [" "]=> + string(1) " " + [" +"]=> + string(1) " +" + [" "]=> + string(1) " " + ["null"]=> + NULL + ["NULL"]=> + NULL +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(12) { + ["\xhh"]=> + string(4) "\xhh" + ["\ddd"]=> + string(4) "\ddd" + ["\cx"]=> + string(3) "\cx" + ["\a"]=> + string(2) "\a" + [""]=> + string(1) "" + [" "]=> + string(1) " " + [" "]=> + string(1) " " + [" "]=> + string(1) " " + [" +"]=> + string(1) " +" + [" "]=> + string(1) " " + ["null"]=> + NULL + ["NULL"]=> + NULL +} +- Sort_flag = SORT_STRING - +bool(true) +array(12) { + ["\xhh"]=> + string(4) "\xhh" + ["\ddd"]=> + string(4) "\ddd" + ["\cx"]=> + string(3) "\cx" + ["\a"]=> + string(2) "\a" + [""]=> + string(1) "" + [" "]=> + string(1) " " + [" "]=> + string(1) " " + [" "]=> + string(1) " " + [" +"]=> + string(1) " +" + [" "]=> + string(1) " " + ["null"]=> + NULL + ["NULL"]=> + NULL +} + +-- Iteration 2 -- +- With default sort_flag - +bool(true) +array(12) { + ["x"]=> + string(1) "x" + ["w"]=> + string(2) "ww" + ["t"]=> + string(3) "ttt" + ["o"]=> + string(6) "oraNGe" + ["l"]=> + string(5) "lemoN" + ["b"]=> + string(6) "banana" + ["a"]=> + string(5) "apple" + ["X"]=> + string(1) "X" + ["Te"]=> + string(4) "Test" + ["T"]=> + string(4) "TTTT" + ["O"]=> + string(6) "Orange" + ["B"]=> + string(6) "BANANA" +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(12) { + ["x"]=> + string(1) "x" + ["w"]=> + string(2) "ww" + ["t"]=> + string(3) "ttt" + ["o"]=> + string(6) "oraNGe" + ["l"]=> + string(5) "lemoN" + ["b"]=> + string(6) "banana" + ["a"]=> + string(5) "apple" + ["X"]=> + string(1) "X" + ["Te"]=> + string(4) "Test" + ["T"]=> + string(4) "TTTT" + ["O"]=> + string(6) "Orange" + ["B"]=> + string(6) "BANANA" +} +- Sort_flag = SORT_STRING - +bool(true) +array(12) { + ["x"]=> + string(1) "x" + ["w"]=> + string(2) "ww" + ["t"]=> + string(3) "ttt" + ["o"]=> + string(6) "oraNGe" + ["l"]=> + string(5) "lemoN" + ["b"]=> + string(6) "banana" + ["a"]=> + string(5) "apple" + ["X"]=> + string(1) "X" + ["Te"]=> + string(4) "Test" + ["T"]=> + string(4) "TTTT" + ["O"]=> + string(6) "Orange" + ["B"]=> + string(6) "BANANA" +} +Done diff --git a/tests/std/array/arsort_variation6.phpt b/tests/std/array/arsort_variation6.phpt new file mode 100644 index 00000000..1cf1bb5f --- /dev/null +++ b/tests/std/array/arsort_variation6.phpt @@ -0,0 +1,108 @@ +--TEST-- +Test arsort() function : usage variations - sort hexadecimal values +--FILE-- + 0x1AB, 0xFFF => 0xFFF, 0xF => 0xF, 0xFF => 0xFF, 0x2AA => 0x2AA, 0xBB => 0xBB, + 0x1ab => 0x1ab, 0xff => 0xff, -0xff => -0xFF, 0 => 0, -0x2aa => -0x2aa + ); + +echo "\n-- Testing arsort() by supplying hexadecimal value array, 'flag' value is default --\n"; +$temp_array = $unsorted_hex_array; +var_dump(arsort($temp_array) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing arsort() by supplying hexadecimal value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $unsorted_hex_array; +var_dump(arsort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing arsort() by supplying hexadecimal value array, 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $unsorted_hex_array; +var_dump(arsort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECT-- +*** Testing arsort() : usage variations *** + +-- Testing arsort() by supplying hexadecimal value array, 'flag' value is default -- +bool(true) +array(9) { + [4095]=> + int(4095) + [682]=> + int(682) + [427]=> + int(427) + [255]=> + int(255) + [187]=> + int(187) + [15]=> + int(15) + [0]=> + int(0) + [-255]=> + int(-255) + [-682]=> + int(-682) +} + +-- Testing arsort() by supplying hexadecimal value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(9) { + [4095]=> + int(4095) + [682]=> + int(682) + [427]=> + int(427) + [255]=> + int(255) + [187]=> + int(187) + [15]=> + int(15) + [0]=> + int(0) + [-255]=> + int(-255) + [-682]=> + int(-682) +} + +-- Testing arsort() by supplying hexadecimal value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(9) { + [4095]=> + int(4095) + [682]=> + int(682) + [427]=> + int(427) + [255]=> + int(255) + [187]=> + int(187) + [15]=> + int(15) + [0]=> + int(0) + [-255]=> + int(-255) + [-682]=> + int(-682) +} +Done diff --git a/tests/std/array/arsort_variation7.phpt b/tests/std/array/arsort_variation7.phpt new file mode 100644 index 00000000..ecd2afc4 --- /dev/null +++ b/tests/std/array/arsort_variation7.phpt @@ -0,0 +1,92 @@ +--TEST-- +Test arsort() function : usage variations - sort bool values +--FILE-- + true, 2 => false, 3 => TRUE, 4 => FALSE); + +echo "\n-- Testing arsort() by supplying bool value array, 'flag' value is default --\n"; +$temp_array = $bool_values; +var_dump(arsort($temp_array) ); +var_dump($temp_array); + +echo "\n-- Testing arsort() by supplying bool value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $bool_values; +var_dump(arsort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +echo "\n-- Testing arsort() by supplying bool value array, 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $bool_values; +var_dump(arsort($temp_array, SORT_NUMERIC) ); +var_dump($temp_array); + +echo "\n-- Testing arsort() by supplying bool value array, 'flag' value is SORT_STRING --\n"; +$temp_array = $bool_values; +var_dump(arsort($temp_array, SORT_STRING) ); +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECT-- +*** Testing arsort() : usage variations *** + +-- Testing arsort() by supplying bool value array, 'flag' value is default -- +bool(true) +array(4) { + [1]=> + bool(true) + [3]=> + bool(true) + [2]=> + bool(false) + [4]=> + bool(false) +} + +-- Testing arsort() by supplying bool value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(4) { + [1]=> + bool(true) + [3]=> + bool(true) + [2]=> + bool(false) + [4]=> + bool(false) +} + +-- Testing arsort() by supplying bool value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(4) { + [1]=> + bool(true) + [3]=> + bool(true) + [2]=> + bool(false) + [4]=> + bool(false) +} + +-- Testing arsort() by supplying bool value array, 'flag' value is SORT_STRING -- +bool(true) +array(4) { + [1]=> + bool(true) + [3]=> + bool(true) + [2]=> + bool(false) + [4]=> + bool(false) +} +Done diff --git a/tests/std/array/arsort_variation8.phpt b/tests/std/array/arsort_variation8.phpt new file mode 100644 index 00000000..267f8ddc --- /dev/null +++ b/tests/std/array/arsort_variation8.phpt @@ -0,0 +1,174 @@ +--TEST-- +Test arsort() function : usage variations - sort array with diff. sub arrays, 'sort_flags' as default/SORT_REGULAR +--FILE-- + array(), + + // array contains null sub array + "array[1]" => array( "sub_array[1][0]" => array() ), + + // array of arrays along with some values + "array[2]" => array("data[2,0]" => 44, "data[2,1]" => 11, "sub_array[2][0] " => array(64,61) ), + + // array contains sub arrays + "array[3]" => array ( "sub_array[3][0]" => array(33,-5,6), "sub_array[3][1]" => array(11), + "sub_array[3][2]" => array(22,-55), "sub_array[3][3]" => array() ) +); + + +$count = 1; +echo "\n-- Testing arsort() by supplying various arrays containing sub arrays --\n"; + +// loop through to test arsort() with different arrays +foreach ($various_arrays as $array) { + + echo "\n-- Iteration $count --\n"; + // testing arsort() function by supplying different arrays, flag value is default + echo "- With default sort_flag -\n"; + $temp_array = $array; + var_dump(arsort($temp_array) ); + var_dump($temp_array); + + // testing arsort() function by supplying different arrays, flag value = SORT_REGULAR + echo "- Sort_flag = SORT_REGULAR -\n"; + $temp_array = $array; + var_dump(arsort($temp_array, SORT_REGULAR) ); + var_dump($temp_array); + $count++; +} + +echo "Done\n"; +?> +--EXPECT-- +*** Testing arsort() : usage variations *** + +-- Testing arsort() by supplying various arrays containing sub arrays -- + +-- Iteration 1 -- +- With default sort_flag - +bool(true) +array(0) { +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(0) { +} + +-- Iteration 2 -- +- With default sort_flag - +bool(true) +array(1) { + ["sub_array[1][0]"]=> + array(0) { + } +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(1) { + ["sub_array[1][0]"]=> + array(0) { + } +} + +-- Iteration 3 -- +- With default sort_flag - +bool(true) +array(3) { + ["sub_array[2][0] "]=> + array(2) { + [0]=> + int(64) + [1]=> + int(61) + } + ["data[2,0]"]=> + int(44) + ["data[2,1]"]=> + int(11) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(3) { + ["sub_array[2][0] "]=> + array(2) { + [0]=> + int(64) + [1]=> + int(61) + } + ["data[2,0]"]=> + int(44) + ["data[2,1]"]=> + int(11) +} + +-- Iteration 4 -- +- With default sort_flag - +bool(true) +array(4) { + ["sub_array[3][0]"]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } + ["sub_array[3][2]"]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + ["sub_array[3][1]"]=> + array(1) { + [0]=> + int(11) + } + ["sub_array[3][3]"]=> + array(0) { + } +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(4) { + ["sub_array[3][0]"]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } + ["sub_array[3][2]"]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + ["sub_array[3][1]"]=> + array(1) { + [0]=> + int(11) + } + ["sub_array[3][3]"]=> + array(0) { + } +} +Done diff --git a/tests/std/array/arsort_variation9.phpt b/tests/std/array/arsort_variation9.phpt new file mode 100644 index 00000000..cfad3b44 --- /dev/null +++ b/tests/std/array/arsort_variation9.phpt @@ -0,0 +1,252 @@ +--TEST-- +Test arsort() function : usage variations - sorting arrays with/without keys, 'sort_flags' as default/SORT_REGULAR +--FILE-- + 55, 66, 22, 33, 11), + array ("a" => "orange", "banana", "c" => "apple"), + array(1, 2, 3, 4, 5, 6), + array("first", 5 => "second", "third"), + array(1, 1, 8 => 1, 4 => 1, 19, 3 => 13), + array('bar' => 'baz', "foo" => 1), + array('a'=>1,'b'=>array('e'=>2,'f'=>3),'c'=>array('g'=>4),'d'=>5), +); + +$count = 1; +echo "\n-- Testing arsort() by supplying various arrays with key values --\n"; + +// loop through to test arsort() with different arrays, +// to test the new keys for the elements in the sorted array +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With default sort_flag -\n"; + $temp_array = $array; + var_dump(arsort($temp_array) ); + var_dump($temp_array); + + echo "- Sort_flag = SORT_REGULAR -\n"; + $temp_array = $array; + var_dump(arsort($temp_array, SORT_REGULAR) ); + var_dump($temp_array); + $count++; +} + +echo "Done\n"; +?> +--EXPECT-- +*** Testing arsort() : usage variations *** + +-- Testing arsort() by supplying various arrays with key values -- + +-- Iteration 1 -- +- With default sort_flag - +bool(true) +array(5) { + [6]=> + int(66) + [5]=> + int(55) + [8]=> + int(33) + [7]=> + int(22) + [9]=> + int(11) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(5) { + [6]=> + int(66) + [5]=> + int(55) + [8]=> + int(33) + [7]=> + int(22) + [9]=> + int(11) +} + +-- Iteration 2 -- +- With default sort_flag - +bool(true) +array(3) { + ["a"]=> + string(6) "orange" + [0]=> + string(6) "banana" + ["c"]=> + string(5) "apple" +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(3) { + ["a"]=> + string(6) "orange" + [0]=> + string(6) "banana" + ["c"]=> + string(5) "apple" +} + +-- Iteration 3 -- +- With default sort_flag - +bool(true) +array(6) { + [5]=> + int(6) + [4]=> + int(5) + [3]=> + int(4) + [2]=> + int(3) + [1]=> + int(2) + [0]=> + int(1) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(6) { + [5]=> + int(6) + [4]=> + int(5) + [3]=> + int(4) + [2]=> + int(3) + [1]=> + int(2) + [0]=> + int(1) +} + +-- Iteration 4 -- +- With default sort_flag - +bool(true) +array(3) { + [6]=> + string(5) "third" + [5]=> + string(6) "second" + [0]=> + string(5) "first" +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(3) { + [6]=> + string(5) "third" + [5]=> + string(6) "second" + [0]=> + string(5) "first" +} + +-- Iteration 5 -- +- With default sort_flag - +bool(true) +array(6) { + [9]=> + int(19) + [3]=> + int(13) + [0]=> + int(1) + [1]=> + int(1) + [8]=> + int(1) + [4]=> + int(1) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(6) { + [9]=> + int(19) + [3]=> + int(13) + [0]=> + int(1) + [1]=> + int(1) + [8]=> + int(1) + [4]=> + int(1) +} + +-- Iteration 6 -- +- With default sort_flag - +bool(true) +array(2) { + ["bar"]=> + string(3) "baz" + ["foo"]=> + int(1) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(2) { + ["bar"]=> + string(3) "baz" + ["foo"]=> + int(1) +} + +-- Iteration 7 -- +- With default sort_flag - +bool(true) +array(4) { + ["b"]=> + array(2) { + ["e"]=> + int(2) + ["f"]=> + int(3) + } + ["c"]=> + array(1) { + ["g"]=> + int(4) + } + ["d"]=> + int(5) + ["a"]=> + int(1) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(4) { + ["b"]=> + array(2) { + ["e"]=> + int(2) + ["f"]=> + int(3) + } + ["c"]=> + array(1) { + ["g"]=> + int(4) + } + ["d"]=> + int(5) + ["a"]=> + int(1) +} +Done diff --git a/tests/std/array/asort_basic.phpt b/tests/std/array/asort_basic.phpt new file mode 100644 index 00000000..13f03a92 --- /dev/null +++ b/tests/std/array/asort_basic.phpt @@ -0,0 +1,239 @@ +--TEST-- +Test asort() function : basic functionality +--FILE-- + "lemon", "o" => "orange", + "O" => "Orange", "O1" => "Orange1", "o2" => "orange2", "O3" => "Orange3", "o20" => "orange20", + "b" => "banana", +); +// an array containing unsorted numeric values with indices +$unsorted_numerics = array( 1 => 100, 2 => 33, 3 => 555, 4 => 22 ); + +echo "\n-- Testing asort() by supplying string array, 'flag' value is default --\n"; +$temp_array = $unsorted_strings; +var_dump( asort($temp_array) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing asort() by supplying numeric array, 'flag' value is default --\n"; +$temp_array = $unsorted_numerics; +var_dump( asort($temp_array) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing asort() by supplying string array, 'flag' = SORT_REGULAR --\n"; +$temp_array = $unsorted_strings; +var_dump( asort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing asort() by supplying numeric array, 'flag' = SORT_REGULAR --\n"; +$temp_array = $unsorted_numerics; +var_dump( asort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing asort() by supplying string array, 'flag' = SORT_STRING --\n"; +$temp_array = $unsorted_strings; +var_dump( asort($temp_array, SORT_STRING) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing asort() by supplying string array (case insensitive), 'flag' = SORT_STRING|SORT_FLAG_CASE --\n"; +$temp_array = $unsorted_strings; +var_dump( asort($temp_array, SORT_STRING|SORT_FLAG_CASE) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing asort() by supplying string array (natural), 'flag' = SORT_NATURAL --\n"; +$temp_array = $unsorted_strings; +var_dump( asort($temp_array, SORT_NATURAL) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing asort() by supplying string array (natural, case insensitive), 'flag' = SORT_NATURAL|SORT_FLAG_CASE --\n"; +$temp_array = $unsorted_strings; +var_dump( asort($temp_array, SORT_NATURAL|SORT_FLAG_CASE) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing asort() by supplying numeric array, 'flag' = SORT_NUMERIC --\n"; +$temp_array = $unsorted_numerics; +var_dump( asort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "Done\n"; +?> +--EXPECT-- +*** Testing asort() : basic functionality *** + +-- Testing asort() by supplying string array, 'flag' value is default -- +bool(true) +array(8) { + ["O"]=> + string(6) "Orange" + ["O1"]=> + string(7) "Orange1" + ["O3"]=> + string(7) "Orange3" + ["b"]=> + string(6) "banana" + ["l"]=> + string(5) "lemon" + ["o"]=> + string(6) "orange" + ["o2"]=> + string(7) "orange2" + ["o20"]=> + string(8) "orange20" +} + +-- Testing asort() by supplying numeric array, 'flag' value is default -- +bool(true) +array(4) { + [4]=> + int(22) + [2]=> + int(33) + [1]=> + int(100) + [3]=> + int(555) +} + +-- Testing asort() by supplying string array, 'flag' = SORT_REGULAR -- +bool(true) +array(8) { + ["O"]=> + string(6) "Orange" + ["O1"]=> + string(7) "Orange1" + ["O3"]=> + string(7) "Orange3" + ["b"]=> + string(6) "banana" + ["l"]=> + string(5) "lemon" + ["o"]=> + string(6) "orange" + ["o2"]=> + string(7) "orange2" + ["o20"]=> + string(8) "orange20" +} + +-- Testing asort() by supplying numeric array, 'flag' = SORT_REGULAR -- +bool(true) +array(4) { + [4]=> + int(22) + [2]=> + int(33) + [1]=> + int(100) + [3]=> + int(555) +} + +-- Testing asort() by supplying string array, 'flag' = SORT_STRING -- +bool(true) +array(8) { + ["O"]=> + string(6) "Orange" + ["O1"]=> + string(7) "Orange1" + ["O3"]=> + string(7) "Orange3" + ["b"]=> + string(6) "banana" + ["l"]=> + string(5) "lemon" + ["o"]=> + string(6) "orange" + ["o2"]=> + string(7) "orange2" + ["o20"]=> + string(8) "orange20" +} + +-- Testing asort() by supplying string array (case insensitive), 'flag' = SORT_STRING|SORT_FLAG_CASE -- +bool(true) +array(8) { + ["b"]=> + string(6) "banana" + ["l"]=> + string(5) "lemon" + ["o"]=> + string(6) "orange" + ["O"]=> + string(6) "Orange" + ["O1"]=> + string(7) "Orange1" + ["o2"]=> + string(7) "orange2" + ["o20"]=> + string(8) "orange20" + ["O3"]=> + string(7) "Orange3" +} + +-- Testing asort() by supplying string array (natural), 'flag' = SORT_NATURAL -- +bool(true) +array(8) { + ["O"]=> + string(6) "Orange" + ["O1"]=> + string(7) "Orange1" + ["O3"]=> + string(7) "Orange3" + ["b"]=> + string(6) "banana" + ["l"]=> + string(5) "lemon" + ["o"]=> + string(6) "orange" + ["o2"]=> + string(7) "orange2" + ["o20"]=> + string(8) "orange20" +} + +-- Testing asort() by supplying string array (natural, case insensitive), 'flag' = SORT_NATURAL|SORT_FLAG_CASE -- +bool(true) +array(8) { + ["b"]=> + string(6) "banana" + ["l"]=> + string(5) "lemon" + ["o"]=> + string(6) "orange" + ["O"]=> + string(6) "Orange" + ["O1"]=> + string(7) "Orange1" + ["o2"]=> + string(7) "orange2" + ["O3"]=> + string(7) "Orange3" + ["o20"]=> + string(8) "orange20" +} + +-- Testing asort() by supplying numeric array, 'flag' = SORT_NUMERIC -- +bool(true) +array(4) { + [4]=> + int(22) + [2]=> + int(33) + [1]=> + int(100) + [3]=> + int(555) +} +Done diff --git a/tests/std/array/asort_object1.phpt b/tests/std/array/asort_object1.phpt new file mode 100644 index 00000000..a4c68a40 --- /dev/null +++ b/tests/std/array/asort_object1.phpt @@ -0,0 +1,220 @@ +--TEST-- +Test asort() function : object functionality - sort objects +--FILE-- +class_value = $value; + } +} +// class declaration for string objects +class for_string_asort +{ + public $class_value; + // initializing object member value + function __construct($value) + { + $this->class_value = $value; + } + // return string value + function __tostring(): string { + return (string) $this->value; + } +} +function main() +{ + /* + * testing asort() by providing integer/string object arrays with following flag values + * 1. Default flag value + * 2. SORT_REGULAR - compare items normally + */ + echo "*** Testing asort() : object functionality ***\n"; + // array of integer objects + $unsorted_int_obj = array(1 => new for_integer_asort(11), 2 => new for_integer_asort(66), 3 => new for_integer_asort(23), 4 => new for_integer_asort(-5), 5 => new for_integer_asort(0.001), 6 => new for_integer_asort(0)); + // array of string objects + $unsorted_str_obj = array("a" => new for_string_asort("axx"), "b" => new for_string_asort("t"), "c" => new for_string_asort("w"), "d" => new for_string_asort("py"), "e" => new for_string_asort("apple"), "f" => new for_string_asort("Orange"), "g" => new for_string_asort("Lemon"), "h" => new for_string_asort("aPPle")); + echo "\n-- Testing asort() by supplying various object arrays, 'flag' value is default --\n"; + // testing asort() function by supplying integer object array, flag value is default + $temp_array = $unsorted_int_obj; + var_dump(asort($temp_array)); + var_dump($temp_array); + // testing asort() function by supplying string object array, flag value is default + $temp_array = $unsorted_str_obj; + var_dump(asort($temp_array)); + var_dump($temp_array); + echo "\n-- Testing asort() by supplying various object arrays, 'flag' value is SORT_REGULAR --\n"; + // testing asort() function by supplying integer object array, flag value = SORT_REGULAR + $temp_array = $unsorted_int_obj; + var_dump(asort($temp_array, SORT_REGULAR)); + var_dump($temp_array); + // testing asort() function by supplying string object array, flag value = SORT_REGULAR + $temp_array = $unsorted_str_obj; + var_dump(asort($temp_array, SORT_REGULAR)); + var_dump($temp_array); + echo "Done\n"; +} +?> +--EXPECTF-- +*** Testing asort() : object functionality *** + +-- Testing asort() by supplying various object arrays, 'flag' value is default -- +bool(true) +array(6) { + [4]=> + object(for_integer_asort)#%d (1) { + ["class_value"]=> + int(-5) + } + [6]=> + object(for_integer_asort)#%d (1) { + ["class_value"]=> + int(0) + } + [5]=> + object(for_integer_asort)#%d (1) { + ["class_value"]=> + float(0.001) + } + [1]=> + object(for_integer_asort)#%d (1) { + ["class_value"]=> + int(11) + } + [3]=> + object(for_integer_asort)#%d (1) { + ["class_value"]=> + int(23) + } + [2]=> + object(for_integer_asort)#%d (1) { + ["class_value"]=> + int(66) + } +} +bool(true) +array(8) { + ["g"]=> + object(for_string_asort)#%d (1) { + ["class_value"]=> + string(5) "Lemon" + } + ["f"]=> + object(for_string_asort)#%d (1) { + ["class_value"]=> + string(6) "Orange" + } + ["h"]=> + object(for_string_asort)#%d (1) { + ["class_value"]=> + string(5) "aPPle" + } + ["e"]=> + object(for_string_asort)#%d (1) { + ["class_value"]=> + string(5) "apple" + } + ["a"]=> + object(for_string_asort)#%d (1) { + ["class_value"]=> + string(3) "axx" + } + ["d"]=> + object(for_string_asort)#%d (1) { + ["class_value"]=> + string(2) "py" + } + ["b"]=> + object(for_string_asort)#%d (1) { + ["class_value"]=> + string(1) "t" + } + ["c"]=> + object(for_string_asort)#%d (1) { + ["class_value"]=> + string(1) "w" + } +} + +-- Testing asort() by supplying various object arrays, 'flag' value is SORT_REGULAR -- +bool(true) +array(6) { + [4]=> + object(for_integer_asort)#%d (1) { + ["class_value"]=> + int(-5) + } + [6]=> + object(for_integer_asort)#%d (1) { + ["class_value"]=> + int(0) + } + [5]=> + object(for_integer_asort)#%d (1) { + ["class_value"]=> + float(0.001) + } + [1]=> + object(for_integer_asort)#%d (1) { + ["class_value"]=> + int(11) + } + [3]=> + object(for_integer_asort)#%d (1) { + ["class_value"]=> + int(23) + } + [2]=> + object(for_integer_asort)#%d (1) { + ["class_value"]=> + int(66) + } +} +bool(true) +array(8) { + ["g"]=> + object(for_string_asort)#%d (1) { + ["class_value"]=> + string(5) "Lemon" + } + ["f"]=> + object(for_string_asort)#%d (1) { + ["class_value"]=> + string(6) "Orange" + } + ["h"]=> + object(for_string_asort)#%d (1) { + ["class_value"]=> + string(5) "aPPle" + } + ["e"]=> + object(for_string_asort)#%d (1) { + ["class_value"]=> + string(5) "apple" + } + ["a"]=> + object(for_string_asort)#%d (1) { + ["class_value"]=> + string(3) "axx" + } + ["d"]=> + object(for_string_asort)#%d (1) { + ["class_value"]=> + string(2) "py" + } + ["b"]=> + object(for_string_asort)#%d (1) { + ["class_value"]=> + string(1) "t" + } + ["c"]=> + object(for_string_asort)#%d (1) { + ["class_value"]=> + string(1) "w" + } +} +Done diff --git a/tests/std/array/asort_object2.phpt b/tests/std/array/asort_object2.phpt new file mode 100644 index 00000000..ca2f1538 --- /dev/null +++ b/tests/std/array/asort_object2.phpt @@ -0,0 +1,232 @@ +--TEST-- +Test asort() function : object functionality - sorting objects with diff. accessibility of member vars +--FILE-- +public_class_value = $value1; + $this->private_class_value = $value2; + $this->protected_class_value = $value3; + } +} +// class declaration for string objects +class for_string_asort +{ + public $public_class_value; + private $private_class_value; + protected $protected_class_value; + // initializing object member value + function __construct($value1, $value2, $value3) + { + $this->public_class_value = $value1; + $this->private_class_value = $value2; + $this->protected_class_value = $value3; + } + // return string value + function __tostring(): string { + return (string) $this->value; + } +} +function main() +{ + /* + * testing asort() by providing integer/string object arrays with following flag values + * 1. Default flag value + 2. SORT_REGULAR - compare items normally + */ + echo "*** Testing asort() : object functionality ***\n"; + // array of integer objects + $unsorted_int_obj = array(1 => new for_integer_asort(11, 33, 2), 2 => new for_integer_asort(44, 66, 3), 3 => new for_integer_asort(23, 32, 6), 4 => new for_integer_asort(-88, -5, -4)); + // array of string objects + $unsorted_str_obj = array("a" => new for_string_asort("axx", "AXX", "d"), "b" => new for_string_asort("T", "t", "q"), "c" => new for_string_asort("w", "W", "c"), "d" => new for_string_asort("PY", "py", "s")); + echo "\n-- Testing asort() by supplying various object arrays, 'flag' value is default --\n"; + // testing asort() function by supplying integer object array, flag value is default + $temp_array = $unsorted_int_obj; + var_dump(asort($temp_array)); + var_dump($temp_array); + // testing asort() function by supplying string object array, flag value is default + $temp_array = $unsorted_str_obj; + var_dump(asort($temp_array)); + var_dump($temp_array); + echo "\n-- Testing asort() by supplying various object arrays, 'flag' value is SORT_REGULAR --\n"; + // testing asort() function by supplying integer object array, flag value = SORT_REGULAR + $temp_array = $unsorted_int_obj; + var_dump(asort($temp_array, SORT_REGULAR)); + var_dump($temp_array); + // testing asort() function by supplying string object array, flag value = SORT_REGULAR + $temp_array = $unsorted_str_obj; + var_dump(asort($temp_array, SORT_REGULAR)); + var_dump($temp_array); + echo "Done\n"; +} +?> +--EXPECTF-- +*** Testing asort() : object functionality *** + +-- Testing asort() by supplying various object arrays, 'flag' value is default -- +bool(true) +array(4) { + [4]=> + object(for_integer_asort)#%d (3) { + ["public_class_value"]=> + int(-88) + ["private_class_value":"for_integer_asort":private]=> + int(-5) + ["protected_class_value":protected]=> + int(-4) + } + [1]=> + object(for_integer_asort)#%d (3) { + ["public_class_value"]=> + int(11) + ["private_class_value":"for_integer_asort":private]=> + int(33) + ["protected_class_value":protected]=> + int(2) + } + [3]=> + object(for_integer_asort)#%d (3) { + ["public_class_value"]=> + int(23) + ["private_class_value":"for_integer_asort":private]=> + int(32) + ["protected_class_value":protected]=> + int(6) + } + [2]=> + object(for_integer_asort)#%d (3) { + ["public_class_value"]=> + int(44) + ["private_class_value":"for_integer_asort":private]=> + int(66) + ["protected_class_value":protected]=> + int(3) + } +} +bool(true) +array(4) { + ["d"]=> + object(for_string_asort)#%d (3) { + ["public_class_value"]=> + string(2) "PY" + ["private_class_value":"for_string_asort":private]=> + string(2) "py" + ["protected_class_value":protected]=> + string(1) "s" + } + ["b"]=> + object(for_string_asort)#%d (3) { + ["public_class_value"]=> + string(1) "T" + ["private_class_value":"for_string_asort":private]=> + string(1) "t" + ["protected_class_value":protected]=> + string(1) "q" + } + ["a"]=> + object(for_string_asort)#%d (3) { + ["public_class_value"]=> + string(3) "axx" + ["private_class_value":"for_string_asort":private]=> + string(3) "AXX" + ["protected_class_value":protected]=> + string(1) "d" + } + ["c"]=> + object(for_string_asort)#%d (3) { + ["public_class_value"]=> + string(1) "w" + ["private_class_value":"for_string_asort":private]=> + string(1) "W" + ["protected_class_value":protected]=> + string(1) "c" + } +} + +-- Testing asort() by supplying various object arrays, 'flag' value is SORT_REGULAR -- +bool(true) +array(4) { + [4]=> + object(for_integer_asort)#%d (3) { + ["public_class_value"]=> + int(-88) + ["private_class_value":"for_integer_asort":private]=> + int(-5) + ["protected_class_value":protected]=> + int(-4) + } + [1]=> + object(for_integer_asort)#%d (3) { + ["public_class_value"]=> + int(11) + ["private_class_value":"for_integer_asort":private]=> + int(33) + ["protected_class_value":protected]=> + int(2) + } + [3]=> + object(for_integer_asort)#%d (3) { + ["public_class_value"]=> + int(23) + ["private_class_value":"for_integer_asort":private]=> + int(32) + ["protected_class_value":protected]=> + int(6) + } + [2]=> + object(for_integer_asort)#%d (3) { + ["public_class_value"]=> + int(44) + ["private_class_value":"for_integer_asort":private]=> + int(66) + ["protected_class_value":protected]=> + int(3) + } +} +bool(true) +array(4) { + ["d"]=> + object(for_string_asort)#%d (3) { + ["public_class_value"]=> + string(2) "PY" + ["private_class_value":"for_string_asort":private]=> + string(2) "py" + ["protected_class_value":protected]=> + string(1) "s" + } + ["b"]=> + object(for_string_asort)#%d (3) { + ["public_class_value"]=> + string(1) "T" + ["private_class_value":"for_string_asort":private]=> + string(1) "t" + ["protected_class_value":protected]=> + string(1) "q" + } + ["a"]=> + object(for_string_asort)#%d (3) { + ["public_class_value"]=> + string(3) "axx" + ["private_class_value":"for_string_asort":private]=> + string(3) "AXX" + ["protected_class_value":protected]=> + string(1) "d" + } + ["c"]=> + object(for_string_asort)#%d (3) { + ["public_class_value"]=> + string(1) "w" + ["private_class_value":"for_string_asort":private]=> + string(1) "W" + ["protected_class_value":protected]=> + string(1) "c" + } +} +Done diff --git a/tests/std/array/asort_stability.phpt b/tests/std/array/asort_stability.phpt new file mode 100644 index 00000000..aeb3b9c1 --- /dev/null +++ b/tests/std/array/asort_stability.phpt @@ -0,0 +1,12 @@ +--TEST-- +asort() is stable +--FILE-- + +--EXPECT-- +bool(true) diff --git a/tests/std/array/asort_variation10.phpt b/tests/std/array/asort_variation10.phpt new file mode 100644 index 00000000..5c8d9041 --- /dev/null +++ b/tests/std/array/asort_variation10.phpt @@ -0,0 +1,108 @@ +--TEST-- +Test asort() function : usage variations - sort octal values +--FILE-- + 01235, 0321 => 0321, 0345 => 0345, 066 => 066, 0772 => 0772, + 077 => 077, -066 => -066, -0345 => -0345, 0 => 0 +); + +echo "\n-- Testing asort() by supplying octal value array, 'flag' value is default --\n"; +$temp_array = $unsorted_oct_array; +var_dump( asort($temp_array) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing asort() by supplying octal value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $unsorted_oct_array; +var_dump( asort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing asort() by supplying octal value array, 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $unsorted_oct_array; +var_dump( asort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECT-- +*** Testing asort() : usage variations *** + +-- Testing asort() by supplying octal value array, 'flag' value is default -- +bool(true) +array(9) { + [-229]=> + int(-229) + [-54]=> + int(-54) + [0]=> + int(0) + [54]=> + int(54) + [63]=> + int(63) + [209]=> + int(209) + [229]=> + int(229) + [506]=> + int(506) + [669]=> + int(669) +} + +-- Testing asort() by supplying octal value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(9) { + [-229]=> + int(-229) + [-54]=> + int(-54) + [0]=> + int(0) + [54]=> + int(54) + [63]=> + int(63) + [209]=> + int(209) + [229]=> + int(229) + [506]=> + int(506) + [669]=> + int(669) +} + +-- Testing asort() by supplying octal value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(9) { + [-229]=> + int(-229) + [-54]=> + int(-54) + [0]=> + int(0) + [54]=> + int(54) + [63]=> + int(63) + [209]=> + int(209) + [229]=> + int(229) + [506]=> + int(506) + [669]=> + int(669) +} +Done diff --git a/tests/std/array/asort_variation11.phpt b/tests/std/array/asort_variation11.phpt new file mode 100644 index 00000000..ef1938b6 --- /dev/null +++ b/tests/std/array/asort_variation11.phpt @@ -0,0 +1,155 @@ +--TEST-- +Test asort() function : usage variations - sort mixed values, 'sort_flags' as default/SORT_REGULAR (OK to fail as result is unpredectable) +--SKIPIF-- + +--FILE-- + array(), + "array2" => array ( "sub_array[2,1]" => array(33,-5,6), "sub_array[2,2]" => array(11), + "sub_array[2,3]" => array(22,-55), "sub_array[2,4]" => array() + ), + 4 => 4, "4" => "4", 4 => 4.01, "b" => "b", "5" => "5", -2 => -2, -2 => -2.01, + -2 => -2.98989, "-.9" => "-.9", "True" => "True", "" => "", NULL => NULL, + "ab" => "ab", "abcd" => "abcd", 0 => 0.01, -0 => -0, '' => '' , + "abcd\x00abcd\x00abcd" => "abcd\x00abcd\x00abcd", 0 => 0.001 +); + +echo "\n-- Testing asort() by supplying mixed value array, 'flag' value is default --\n"; +$temp_array = $mixed_values; +var_dump( asort($temp_array) ); +var_dump($temp_array); + +echo "\n-- Testing asort() by supplying mixed value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $mixed_values; +var_dump( asort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing asort() : usage variations *** + +-- Testing asort() by supplying mixed value array, 'flag' value is default -- +bool(true) +array(13) { + [""]=> + string(0) "" + [-2]=> + float(-2.98989) + ["-.9"]=> + string(3) "-.9" + [0]=> + float(0.001) + [4]=> + float(4.01) + [5]=> + string(1) "5" + ["True"]=> + string(4) "True" + ["ab"]=> + string(2) "ab" + ["abcd"]=> + string(4) "abcd" + ["abcd%0abcd%0abcd"]=> + string(14) "abcd%0abcd%0abcd" + ["b"]=> + string(1) "b" + ["array1"]=> + array(0) { + } + ["array2"]=> + array(4) { + ["sub_array[2,1]"]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } + ["sub_array[2,2]"]=> + array(1) { + [0]=> + int(11) + } + ["sub_array[2,3]"]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + ["sub_array[2,4]"]=> + array(0) { + } + } +} + +-- Testing asort() by supplying mixed value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(13) { + [""]=> + string(0) "" + [-2]=> + float(-2.98989) + ["-.9"]=> + string(3) "-.9" + [0]=> + float(0.001) + [4]=> + float(4.01) + [5]=> + string(1) "5" + ["True"]=> + string(4) "True" + ["ab"]=> + string(2) "ab" + ["abcd"]=> + string(4) "abcd" + ["abcd%0abcd%0abcd"]=> + string(14) "abcd%0abcd%0abcd" + ["b"]=> + string(1) "b" + ["array1"]=> + array(0) { + } + ["array2"]=> + array(4) { + ["sub_array[2,1]"]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } + ["sub_array[2,2]"]=> + array(1) { + [0]=> + int(11) + } + ["sub_array[2,3]"]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + ["sub_array[2,4]"]=> + array(0) { + } + } +} +Done diff --git a/tests/std/array/asort_variation3.phpt b/tests/std/array/asort_variation3.phpt new file mode 100644 index 00000000..7736c727 --- /dev/null +++ b/tests/std/array/asort_variation3.phpt @@ -0,0 +1,320 @@ +--TEST-- +Test asort() function : usage variations - sort integer/float values +--FILE-- + 11, 2 => -11, 3 => 21, 4 => -21, 5 => 31, 6 => -31, 7 => 0, 8 => 41, 10 =>-41), + + // float value array + array(1 => 10.5, 2 => -10.5, 3 => 10.5e2, 4 => 10.6E-2, 5 => .5, 6 => .0001, 7 => -.1), + + // mixed value array + array(1 => .0001, 2 => .0021, 3 => -.01, 4 => -1, 5 => 0, 6 => .09, 7 => 2, 8 => -.9, 9 => 10.6E-2, 10 => -10.6E-2, 11 => 33), + + // array values contains minimum and maximum ranges + array(1 => 2147483647, 2 => 2147483648, 3 => -2147483647, 4 => -2147483648, 5 => -0, 6 => 0, 7 => -2147483649) +); + +// set of possible flag values +$flag_value = array("SORT_REGULAR" => SORT_REGULAR, "SORT_NUMERIC" => SORT_NUMERIC); + +$count = 1; +echo "\n-- Testing asort() by supplying various integer/float arrays --\n"; + +// loop through to test asort() with different arrays +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With default sort_flag -\n"; + $temp_array = $array; + var_dump(asort($temp_array) ); + var_dump($temp_array); + + // loop through $flag_value array and setting all possible flag values + foreach($flag_value as $key => $flag){ + echo "- Sort_flag = $key -\n"; + $temp_array = $array; + var_dump(asort($temp_array, $flag) ); + var_dump($temp_array); + } + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing asort() : usage variations *** + +-- Testing asort() by supplying various integer/float arrays -- + +-- Iteration 1 -- +- With default sort_flag - +bool(true) +array(9) { + [10]=> + int(-41) + [6]=> + int(-31) + [4]=> + int(-21) + [2]=> + int(-11) + [7]=> + int(0) + [1]=> + int(11) + [3]=> + int(21) + [5]=> + int(31) + [8]=> + int(41) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(9) { + [10]=> + int(-41) + [6]=> + int(-31) + [4]=> + int(-21) + [2]=> + int(-11) + [7]=> + int(0) + [1]=> + int(11) + [3]=> + int(21) + [5]=> + int(31) + [8]=> + int(41) +} +- Sort_flag = SORT_NUMERIC - +bool(true) +array(9) { + [10]=> + int(-41) + [6]=> + int(-31) + [4]=> + int(-21) + [2]=> + int(-11) + [7]=> + int(0) + [1]=> + int(11) + [3]=> + int(21) + [5]=> + int(31) + [8]=> + int(41) +} + +-- Iteration 2 -- +- With default sort_flag - +bool(true) +array(7) { + [2]=> + float(-10.5) + [7]=> + float(-0.1) + [6]=> + float(0.0001) + [4]=> + float(0.106) + [5]=> + float(0.5) + [1]=> + float(10.5) + [3]=> + float(1050) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(7) { + [2]=> + float(-10.5) + [7]=> + float(-0.1) + [6]=> + float(0.0001) + [4]=> + float(0.106) + [5]=> + float(0.5) + [1]=> + float(10.5) + [3]=> + float(1050) +} +- Sort_flag = SORT_NUMERIC - +bool(true) +array(7) { + [2]=> + float(-10.5) + [7]=> + float(-0.1) + [6]=> + float(0.0001) + [4]=> + float(0.106) + [5]=> + float(0.5) + [1]=> + float(10.5) + [3]=> + float(1050) +} + +-- Iteration 3 -- +- With default sort_flag - +bool(true) +array(11) { + [4]=> + int(-1) + [8]=> + float(-0.9) + [10]=> + float(-0.106) + [3]=> + float(-0.01) + [5]=> + int(0) + [1]=> + float(0.0001) + [2]=> + float(0.0021) + [6]=> + float(0.09) + [9]=> + float(0.106) + [7]=> + int(2) + [11]=> + int(33) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(11) { + [4]=> + int(-1) + [8]=> + float(-0.9) + [10]=> + float(-0.106) + [3]=> + float(-0.01) + [5]=> + int(0) + [1]=> + float(0.0001) + [2]=> + float(0.0021) + [6]=> + float(0.09) + [9]=> + float(0.106) + [7]=> + int(2) + [11]=> + int(33) +} +- Sort_flag = SORT_NUMERIC - +bool(true) +array(11) { + [4]=> + int(-1) + [8]=> + float(-0.9) + [10]=> + float(-0.106) + [3]=> + float(-0.01) + [5]=> + int(0) + [1]=> + float(0.0001) + [2]=> + float(0.0021) + [6]=> + float(0.09) + [9]=> + float(0.106) + [7]=> + int(2) + [11]=> + int(33) +} + +-- Iteration 4 -- +- With default sort_flag - +bool(true) +array(7) { + [7]=> + %s(-2147483649) + [4]=> + %s(-2147483648) + [3]=> + int(-2147483647) + [5]=> + int(0) + [6]=> + int(0) + [1]=> + int(2147483647) + [2]=> + %s(2147483648) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(7) { + [7]=> + %s(-2147483649) + [4]=> + %s(-2147483648) + [3]=> + int(-2147483647) + [5]=> + int(0) + [6]=> + int(0) + [1]=> + int(2147483647) + [2]=> + %s(2147483648) +} +- Sort_flag = SORT_NUMERIC - +bool(true) +array(7) { + [7]=> + %s(-2147483649) + [4]=> + %s(-2147483648) + [3]=> + int(-2147483647) + [5]=> + int(0) + [6]=> + int(0) + [1]=> + int(2147483647) + [2]=> + %s(2147483648) +} +Done diff --git a/tests/std/array/asort_variation4.phpt b/tests/std/array/asort_variation4.phpt new file mode 100644 index 00000000..3621e0cc --- /dev/null +++ b/tests/std/array/asort_variation4.phpt @@ -0,0 +1,78 @@ +--TEST-- +Test asort() function : usage variations - sort reference variables +--SKIPIF-- + + +--FILE-- + &$value1 , 2 => &$value2, 3 => &$value3); + +echo "\n-- Testing asort() by supplying reference variable array, 'flag' value is default --\n"; +$temp_array = $unsorted_numerics; +var_dump( asort($temp_array) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing asort() by supplying reference variable array, 'flag' = SORT_REGULAR --\n"; +$temp_array = &$unsorted_numerics; +var_dump( asort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing asort() by supplying reference variable array, 'flag' = SORT_NUMERIC --\n"; +$temp_array = &$unsorted_numerics; +var_dump( asort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "Done\n"; +?> +--EXPECT-- +*** Testing asort() :usage variations *** + +-- Testing asort() by supplying reference variable array, 'flag' value is default -- +bool(true) +array(3) { + [2]=> + &int(33) + [1]=> + &int(100) + [3]=> + &int(555) +} + +-- Testing asort() by supplying reference variable array, 'flag' = SORT_REGULAR -- +bool(true) +array(3) { + [2]=> + &int(33) + [1]=> + &int(100) + [3]=> + &int(555) +} + +-- Testing asort() by supplying reference variable array, 'flag' = SORT_NUMERIC -- +bool(true) +array(3) { + [2]=> + &int(33) + [1]=> + &int(100) + [3]=> + &int(555) +} +Done diff --git a/tests/std/array/asort_variation5.phpt b/tests/std/array/asort_variation5.phpt new file mode 100644 index 00000000..f39c4829 --- /dev/null +++ b/tests/std/array/asort_variation5.phpt @@ -0,0 +1,236 @@ +--TEST-- +Test asort() function : usage variations - sort strings +--FILE-- + null, "NULL" => NULL, "\a" => "\a", "\cx" => "\cx", "\e" => "\e", + "\f" => "\f", "\n" =>"\n", "\r" => "\r", "\t" => "\t", "\xhh" => "\xhh", + "\ddd" => "\ddd", "\v" => "\v" + ), + + // array contains combination of capital/small letters + array ('l' => "lemoN", 'O' => "Orange", 'b' => "banana", 'a' => "apple", 'Te' => "Test", + 'T' => "TTTT", 't' => "ttt", 'w' => "ww", 'x' => "x", 'X' => "X", 'o' => "oraNGe", + 'B' => "BANANA" + ) +); + +$flags = array("SORT_REGULAR" => SORT_REGULAR, "SORT_STRING" => SORT_STRING); + +$count = 1; +echo "\n-- Testing asort() by supplying various string arrays --\n"; + +// loop through to test asort() with different arrays +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With default sort_flag -\n"; + $temp_array = $array; + var_dump(asort($temp_array) ); // expecting : bool(true) + var_dump($temp_array); + + // loop through $flags array and setting all possible flag values + foreach($flags as $key => $flag){ + echo "- Sort_flag = $key -\n"; + $temp_array = $array; + var_dump(asort($temp_array, $flag) ); // expecting : bool(true) + var_dump($temp_array); + } + $count++; +} + +echo "Done\n"; +?> +--EXPECT-- +*** Testing asort() : usage variations *** + +-- Testing asort() by supplying various string arrays -- + +-- Iteration 1 -- +- With default sort_flag - +bool(true) +array(12) { + ["null"]=> + NULL + ["NULL"]=> + NULL + [" "]=> + string(1) " " + [" +"]=> + string(1) " +" + [" "]=> + string(1) " " + [" "]=> + string(1) " " + [" "]=> + string(1) " " + [""]=> + string(1) "" + ["\a"]=> + string(2) "\a" + ["\cx"]=> + string(3) "\cx" + ["\ddd"]=> + string(4) "\ddd" + ["\xhh"]=> + string(4) "\xhh" +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(12) { + ["null"]=> + NULL + ["NULL"]=> + NULL + [" "]=> + string(1) " " + [" +"]=> + string(1) " +" + [" "]=> + string(1) " " + [" "]=> + string(1) " " + [" "]=> + string(1) " " + [""]=> + string(1) "" + ["\a"]=> + string(2) "\a" + ["\cx"]=> + string(3) "\cx" + ["\ddd"]=> + string(4) "\ddd" + ["\xhh"]=> + string(4) "\xhh" +} +- Sort_flag = SORT_STRING - +bool(true) +array(12) { + ["null"]=> + NULL + ["NULL"]=> + NULL + [" "]=> + string(1) " " + [" +"]=> + string(1) " +" + [" "]=> + string(1) " " + [" "]=> + string(1) " " + [" "]=> + string(1) " " + [""]=> + string(1) "" + ["\a"]=> + string(2) "\a" + ["\cx"]=> + string(3) "\cx" + ["\ddd"]=> + string(4) "\ddd" + ["\xhh"]=> + string(4) "\xhh" +} + +-- Iteration 2 -- +- With default sort_flag - +bool(true) +array(12) { + ["B"]=> + string(6) "BANANA" + ["O"]=> + string(6) "Orange" + ["T"]=> + string(4) "TTTT" + ["Te"]=> + string(4) "Test" + ["X"]=> + string(1) "X" + ["a"]=> + string(5) "apple" + ["b"]=> + string(6) "banana" + ["l"]=> + string(5) "lemoN" + ["o"]=> + string(6) "oraNGe" + ["t"]=> + string(3) "ttt" + ["w"]=> + string(2) "ww" + ["x"]=> + string(1) "x" +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(12) { + ["B"]=> + string(6) "BANANA" + ["O"]=> + string(6) "Orange" + ["T"]=> + string(4) "TTTT" + ["Te"]=> + string(4) "Test" + ["X"]=> + string(1) "X" + ["a"]=> + string(5) "apple" + ["b"]=> + string(6) "banana" + ["l"]=> + string(5) "lemoN" + ["o"]=> + string(6) "oraNGe" + ["t"]=> + string(3) "ttt" + ["w"]=> + string(2) "ww" + ["x"]=> + string(1) "x" +} +- Sort_flag = SORT_STRING - +bool(true) +array(12) { + ["B"]=> + string(6) "BANANA" + ["O"]=> + string(6) "Orange" + ["T"]=> + string(4) "TTTT" + ["Te"]=> + string(4) "Test" + ["X"]=> + string(1) "X" + ["a"]=> + string(5) "apple" + ["b"]=> + string(6) "banana" + ["l"]=> + string(5) "lemoN" + ["o"]=> + string(6) "oraNGe" + ["t"]=> + string(3) "ttt" + ["w"]=> + string(2) "ww" + ["x"]=> + string(1) "x" +} +Done diff --git a/tests/std/array/asort_variation6.phpt b/tests/std/array/asort_variation6.phpt new file mode 100644 index 00000000..7782f95d --- /dev/null +++ b/tests/std/array/asort_variation6.phpt @@ -0,0 +1,108 @@ +--TEST-- +Test asort() function : usage variations - sort hexadecimal values +--FILE-- + 0x1AB, 0xFFF => 0xFFF, 0xF => 0xF, 0xFF => 0xFF, 0x2AA => 0x2AA, 0xBB => 0xBB, + 0x1ab => 0x1ab, 0xff => 0xff, -0xff => -0xFF, 0 => 0, -0x2aa => -0x2aa + ); + +echo "\n-- Testing asort() by supplying hexadecimal value array, 'flag' value is default --\n"; +$temp_array = $unsorted_hex_array; +var_dump(asort($temp_array) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing asort() by supplying hexadecimal value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $unsorted_hex_array; +var_dump(asort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing asort() by supplying hexadecimal value array, 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $unsorted_hex_array; +var_dump(asort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECT-- +*** Testing asort() : usage variations *** + +-- Testing asort() by supplying hexadecimal value array, 'flag' value is default -- +bool(true) +array(9) { + [-682]=> + int(-682) + [-255]=> + int(-255) + [0]=> + int(0) + [15]=> + int(15) + [187]=> + int(187) + [255]=> + int(255) + [427]=> + int(427) + [682]=> + int(682) + [4095]=> + int(4095) +} + +-- Testing asort() by supplying hexadecimal value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(9) { + [-682]=> + int(-682) + [-255]=> + int(-255) + [0]=> + int(0) + [15]=> + int(15) + [187]=> + int(187) + [255]=> + int(255) + [427]=> + int(427) + [682]=> + int(682) + [4095]=> + int(4095) +} + +-- Testing asort() by supplying hexadecimal value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(9) { + [-682]=> + int(-682) + [-255]=> + int(-255) + [0]=> + int(0) + [15]=> + int(15) + [187]=> + int(187) + [255]=> + int(255) + [427]=> + int(427) + [682]=> + int(682) + [4095]=> + int(4095) +} +Done diff --git a/tests/std/array/asort_variation7.phpt b/tests/std/array/asort_variation7.phpt new file mode 100644 index 00000000..64363d25 --- /dev/null +++ b/tests/std/array/asort_variation7.phpt @@ -0,0 +1,92 @@ +--TEST-- +Test asort() function : usage variations - sort bool values +--FILE-- + true, 2 => false, 3 => TRUE, 4 => FALSE); + +echo "\n-- Testing asort() by supplying bool value array, 'flag' value is default --\n"; +$temp_array = $bool_values; +var_dump(asort($temp_array) ); +var_dump($temp_array); + +echo "\n-- Testing asort() by supplying bool value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $bool_values; +var_dump(asort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +echo "\n-- Testing asort() by supplying bool value array, 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $bool_values; +var_dump(asort($temp_array, SORT_NUMERIC) ); +var_dump($temp_array); + +echo "\n-- Testing asort() by supplying bool value array, 'flag' value is SORT_STRING --\n"; +$temp_array = $bool_values; +var_dump(asort($temp_array, SORT_STRING) ); +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECT-- +*** Testing asort() : usage variations *** + +-- Testing asort() by supplying bool value array, 'flag' value is default -- +bool(true) +array(4) { + [2]=> + bool(false) + [4]=> + bool(false) + [1]=> + bool(true) + [3]=> + bool(true) +} + +-- Testing asort() by supplying bool value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(4) { + [2]=> + bool(false) + [4]=> + bool(false) + [1]=> + bool(true) + [3]=> + bool(true) +} + +-- Testing asort() by supplying bool value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(4) { + [2]=> + bool(false) + [4]=> + bool(false) + [1]=> + bool(true) + [3]=> + bool(true) +} + +-- Testing asort() by supplying bool value array, 'flag' value is SORT_STRING -- +bool(true) +array(4) { + [2]=> + bool(false) + [4]=> + bool(false) + [1]=> + bool(true) + [3]=> + bool(true) +} +Done diff --git a/tests/std/array/asort_variation8.phpt b/tests/std/array/asort_variation8.phpt new file mode 100644 index 00000000..038c92df --- /dev/null +++ b/tests/std/array/asort_variation8.phpt @@ -0,0 +1,174 @@ +--TEST-- +Test asort() function : usage variations - sort array with diff. sub arrays, 'sort_flags' as default/SORT_REGULAR +--FILE-- + array(), + + // array contains null sub array + "array[1]" => array( "sub_array[1][0]" => array() ), + + // array of arrays along with some values + "array[2]" => array("data[2,0]" => 44, "data[2,1]" => 11, "sub_array[2][0] " => array(64,61) ), + + // array contains sub arrays + "array[3]" => array ( "sub_array[3][0]" => array(33,-5,6), "sub_array[3][1]" => array(11), + "sub_array[3][2]" => array(22,-55), "sub_array[3][3]" => array() ) +); + + +$count = 1; +echo "\n-- Testing asort() by supplying various arrays containing sub arrays --\n"; + +// loop through to test asort() with different arrays +foreach ($various_arrays as $array) { + + echo "\n-- Iteration $count --\n"; + // testing asort() function by supplying different arrays, flag value is default + echo "- With default sort_flag -\n"; + $temp_array = $array; + var_dump(asort($temp_array) ); + var_dump($temp_array); + + // testing asort() function by supplying different arrays, flag value = SORT_REGULAR + echo "- Sort_flag = SORT_REGULAR -\n"; + $temp_array = $array; + var_dump(asort($temp_array, SORT_REGULAR) ); + var_dump($temp_array); + $count++; +} + +echo "Done\n"; +?> +--EXPECT-- +*** Testing asort() : usage variations *** + +-- Testing asort() by supplying various arrays containing sub arrays -- + +-- Iteration 1 -- +- With default sort_flag - +bool(true) +array(0) { +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(0) { +} + +-- Iteration 2 -- +- With default sort_flag - +bool(true) +array(1) { + ["sub_array[1][0]"]=> + array(0) { + } +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(1) { + ["sub_array[1][0]"]=> + array(0) { + } +} + +-- Iteration 3 -- +- With default sort_flag - +bool(true) +array(3) { + ["data[2,1]"]=> + int(11) + ["data[2,0]"]=> + int(44) + ["sub_array[2][0] "]=> + array(2) { + [0]=> + int(64) + [1]=> + int(61) + } +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(3) { + ["data[2,1]"]=> + int(11) + ["data[2,0]"]=> + int(44) + ["sub_array[2][0] "]=> + array(2) { + [0]=> + int(64) + [1]=> + int(61) + } +} + +-- Iteration 4 -- +- With default sort_flag - +bool(true) +array(4) { + ["sub_array[3][3]"]=> + array(0) { + } + ["sub_array[3][1]"]=> + array(1) { + [0]=> + int(11) + } + ["sub_array[3][2]"]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + ["sub_array[3][0]"]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(4) { + ["sub_array[3][3]"]=> + array(0) { + } + ["sub_array[3][1]"]=> + array(1) { + [0]=> + int(11) + } + ["sub_array[3][2]"]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + ["sub_array[3][0]"]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } +} +Done diff --git a/tests/std/array/asort_variation9.phpt b/tests/std/array/asort_variation9.phpt new file mode 100644 index 00000000..ff2d9077 --- /dev/null +++ b/tests/std/array/asort_variation9.phpt @@ -0,0 +1,252 @@ +--TEST-- +Test asort() function : usage variations - sorting arrays with/without keys, 'sort_flags' as default/SORT_REGULAR +--FILE-- + 55, 66, 22, 33, 11), + array ("a" => "orange", "banana", "c" => "apple"), + array(1, 2, 3, 4, 5, 6), + array("first", 5 => "second", "third"), + array(1, 1, 8 => 1, 4 => 1, 19, 3 => 13), + array('bar' => 'baz', "foo" => 1), + array('a'=>1,'b'=>array('e'=>2,'f'=>3),'c'=>array('g'=>4),'d'=>5), +); + +$count = 1; +echo "\n-- Testing asort() by supplying various arrays with key values --\n"; + +// loop through to test asort() with different arrays, +// to test the new keys for the elements in the sorted array +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With default sort_flag -\n"; + $temp_array = $array; + var_dump(asort($temp_array) ); + var_dump($temp_array); + + echo "- Sort_flag = SORT_REGULAR -\n"; + $temp_array = $array; + var_dump(asort($temp_array, SORT_REGULAR) ); + var_dump($temp_array); + $count++; +} + +echo "Done\n"; +?> +--EXPECT-- +*** Testing asort() : usage variations *** + +-- Testing asort() by supplying various arrays with key values -- + +-- Iteration 1 -- +- With default sort_flag - +bool(true) +array(5) { + [9]=> + int(11) + [7]=> + int(22) + [8]=> + int(33) + [5]=> + int(55) + [6]=> + int(66) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(5) { + [9]=> + int(11) + [7]=> + int(22) + [8]=> + int(33) + [5]=> + int(55) + [6]=> + int(66) +} + +-- Iteration 2 -- +- With default sort_flag - +bool(true) +array(3) { + ["c"]=> + string(5) "apple" + [0]=> + string(6) "banana" + ["a"]=> + string(6) "orange" +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(3) { + ["c"]=> + string(5) "apple" + [0]=> + string(6) "banana" + ["a"]=> + string(6) "orange" +} + +-- Iteration 3 -- +- With default sort_flag - +bool(true) +array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) +} + +-- Iteration 4 -- +- With default sort_flag - +bool(true) +array(3) { + [0]=> + string(5) "first" + [5]=> + string(6) "second" + [6]=> + string(5) "third" +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(3) { + [0]=> + string(5) "first" + [5]=> + string(6) "second" + [6]=> + string(5) "third" +} + +-- Iteration 5 -- +- With default sort_flag - +bool(true) +array(6) { + [0]=> + int(1) + [1]=> + int(1) + [8]=> + int(1) + [4]=> + int(1) + [3]=> + int(13) + [9]=> + int(19) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(6) { + [0]=> + int(1) + [1]=> + int(1) + [8]=> + int(1) + [4]=> + int(1) + [3]=> + int(13) + [9]=> + int(19) +} + +-- Iteration 6 -- +- With default sort_flag - +bool(true) +array(2) { + ["foo"]=> + int(1) + ["bar"]=> + string(3) "baz" +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(2) { + ["foo"]=> + int(1) + ["bar"]=> + string(3) "baz" +} + +-- Iteration 7 -- +- With default sort_flag - +bool(true) +array(4) { + ["a"]=> + int(1) + ["d"]=> + int(5) + ["c"]=> + array(1) { + ["g"]=> + int(4) + } + ["b"]=> + array(2) { + ["e"]=> + int(2) + ["f"]=> + int(3) + } +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(4) { + ["a"]=> + int(1) + ["d"]=> + int(5) + ["c"]=> + array(1) { + ["g"]=> + int(4) + } + ["b"]=> + array(2) { + ["e"]=> + int(2) + ["f"]=> + int(3) + } +} +Done diff --git a/tests/std/array/bug12776.phpt b/tests/std/array/bug12776.phpt new file mode 100644 index 00000000..89da38b1 --- /dev/null +++ b/tests/std/array/bug12776.phpt @@ -0,0 +1,31 @@ +--TEST-- +Bug #12776 (array_walk crash) +--SKIPIF-- + + +--FILE-- + 'v'); + array_walk($arr, 'test'); + print "First value: " . $globalArray[0]; + print "\nDone\n"; +} +?> +--EXPECT-- +val: v; key: k +First value: k +Done diff --git a/tests/std/array/bug14580.phpt b/tests/std/array/bug14580.phpt new file mode 100644 index 00000000..8f4c7d5b --- /dev/null +++ b/tests/std/array/bug14580.phpt @@ -0,0 +1,11 @@ +--TEST-- +Bug #14580 (key() not binary safe) +--FILE-- + "foo\0bar"); + $key = key($arr); + echo strlen($key), ': '; + echo urlencode($key), "\n"; +?> +--EXPECT-- +7: foo%00bar diff --git a/tests/std/array/bug20381.phpt b/tests/std/array/bug20381.phpt new file mode 100644 index 00000000..0da52d9f --- /dev/null +++ b/tests/std/array/bug20381.phpt @@ -0,0 +1,79 @@ +--TEST-- +Bug #20381 (array_merge_recursive mangles input arrays) +--FILE-- + 1, + 'a2' => array( 1, 2, 3 ), + 'a3' => array( + 'a' => array( 10, 20, 30 ), + 'b' => 'b' + ) + ); +$b = array( 'a1' => 2, + 'a2' => array( 3, 4, 5 ), + 'a3' => array( + 'c' => 'cc', + 'a' => array( 10, 40 ) + ) + ); + +var_dump($a); +array_merge_recursive( $a, $b ); +var_dump($a); +?> +--EXPECT-- +array(3) { + ["a1"]=> + int(1) + ["a2"]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["a3"]=> + array(2) { + ["a"]=> + array(3) { + [0]=> + int(10) + [1]=> + int(20) + [2]=> + int(30) + } + ["b"]=> + string(1) "b" + } +} +array(3) { + ["a1"]=> + int(1) + ["a2"]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["a3"]=> + array(2) { + ["a"]=> + array(3) { + [0]=> + int(10) + [1]=> + int(20) + [2]=> + int(30) + } + ["b"]=> + string(1) "b" + } +} diff --git a/tests/std/array/bug20865.phpt b/tests/std/array/bug20865.phpt new file mode 100644 index 00000000..6fa79f6a --- /dev/null +++ b/tests/std/array/bug20865.phpt @@ -0,0 +1,13 @@ +--TEST-- +Bug #20865 (array_key_exists and NULL key) +--SKIPIF-- + +--FILE-- + +--EXPECT-- +bool(true) diff --git a/tests/std/array/bug21918.phpt b/tests/std/array/bug21918.phpt new file mode 100644 index 00000000..e855aacd --- /dev/null +++ b/tests/std/array/bug21918.phpt @@ -0,0 +1,53 @@ +--TEST-- +Bug #21918 (different handling of positive vs. negative array indexes) +--FILE-- +'a', '-2'=>'b', 3=>'c', '4'=>'d', 5=>'e', '6001'=>'f', '07'=>'g'); + +foreach($a as $k => $v) { + var_dump($k); + var_dump($v); +} + +echo "==Normal==\n"; +$b = array(); +$b[] = 'a'; + +foreach($b as $k => $v) { + var_dump($k); + var_dump($v); +} + +echo "==Negative==\n"; +$c = array('-2' => 'a'); + +foreach($c as $k => $v) { + var_dump($k); + var_dump($v); +} + +?> +--EXPECT-- +==Mixed== +int(-1) +string(1) "a" +int(-2) +string(1) "b" +int(3) +string(1) "c" +int(4) +string(1) "d" +int(5) +string(1) "e" +int(6001) +string(1) "f" +string(2) "07" +string(1) "g" +==Normal== +int(0) +string(1) "a" +==Negative== +int(-2) +string(1) "a" diff --git a/tests/std/array/bug21998.phpt b/tests/std/array/bug21998.phpt new file mode 100644 index 00000000..e1bb0033 --- /dev/null +++ b/tests/std/array/bug21998.phpt @@ -0,0 +1,24 @@ +--TEST-- +Bug #21998 (array_pop() does not reset the current array position) +--FILE-- + +--EXPECT-- +int(0) +string(1) "c" +int(0) +string(1) "b" +int(0) +string(1) "a" +NULL diff --git a/tests/std/array/bug22088.phpt b/tests/std/array/bug22088.phpt new file mode 100644 index 00000000..4352cff9 --- /dev/null +++ b/tests/std/array/bug22088.phpt @@ -0,0 +1,33 @@ +--TEST-- +Bug #22088 (array_shift() leaves next index to be +1 too much) +--FILE-- + 1, 'b' => 2, 'c' => 3); +$last = array_shift ($a); +$a[] = 'a'; +var_dump($a); + +?> +--EXPECT-- +array(3) { + [0]=> + string(1) "b" + [1]=> + string(1) "c" + [2]=> + string(1) "a" +} +array(3) { + ["b"]=> + int(2) + ["c"]=> + int(3) + [0]=> + string(1) "a" +} diff --git a/tests/std/array/bug22463.phpt b/tests/std/array/bug22463.phpt new file mode 100644 index 00000000..973b3863 --- /dev/null +++ b/tests/std/array/bug22463.phpt @@ -0,0 +1,20 @@ +--TEST-- +Bug #22463 (array_reduce() segfaults) +--FILE-- + +--EXPECT-- +int(5) diff --git a/tests/std/array/bug23581.phpt b/tests/std/array/bug23581.phpt new file mode 100644 index 00000000..5cede9a3 --- /dev/null +++ b/tests/std/array/bug23581.phpt @@ -0,0 +1,43 @@ +--TEST-- +Bug #23581 (array_map(NULL, array, array, ...) yields an undefined result) +--FILE-- + +--EXPECT-- +array(3) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(4) + [2]=> + int(7) + } + [1]=> + array(3) { + [0]=> + int(2) + [1]=> + int(5) + [2]=> + int(8) + } + [2]=> + array(3) { + [0]=> + int(3) + [1]=> + int(6) + [2]=> + int(9) + } +} diff --git a/tests/std/array/bug23788.phpt b/tests/std/array/bug23788.phpt new file mode 100644 index 00000000..014773be --- /dev/null +++ b/tests/std/array/bug23788.phpt @@ -0,0 +1,26 @@ +--TEST-- +Bug #23788 (*_replace() clobbers referenced array elements) +--SKIPIF-- + +--FILE-- + +--EXPECT-- +array(2) { + [0]=> + &int(123) + [1]=> + &bool(true) +} +array(2) { + [0]=> + &int(123) + [1]=> + &bool(true) +} diff --git a/tests/std/array/bug24198.phpt b/tests/std/array/bug24198.phpt new file mode 100644 index 00000000..a1a30afb --- /dev/null +++ b/tests/std/array/bug24198.phpt @@ -0,0 +1,25 @@ +--TEST--n +Bug #24198 (array_merge_recursive() invalid recursion detection) +--FILE-- + 'aa','b' => 'bb'); + +var_dump(array_merge_recursive($c, $c)); +?> +--EXPECT-- +array(2) { + ["a"]=> + array(2) { + [0]=> + string(2) "aa" + [1]=> + string(2) "aa" + } + ["b"]=> + array(2) { + [0]=> + string(2) "bb" + [1]=> + string(2) "bb" + } +} diff --git a/tests/std/array/bug24766.phpt b/tests/std/array/bug24766.phpt new file mode 100644 index 00000000..ebe2f392 --- /dev/null +++ b/tests/std/array/bug24766.phpt @@ -0,0 +1,45 @@ +--TEST-- +Bug #24766 (strange result array from unpack) +--FILE-- + 18, 2 => 52); +var_dump($a, $b); +$k = array_keys($a); +$l = array_keys($b); +var_dump($k, $l); +$i=$k[0]; +var_dump($a[$i]); +$i=$l[0]; +var_dump($b[$i]); +?> +--EXPECT-- +array(2) { + [1]=> + int(18) + [2]=> + int(52) +} +array(2) { + [1]=> + int(18) + [2]=> + int(52) +} +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +int(18) +int(18) diff --git a/tests/std/array/bug24897.phpt b/tests/std/array/bug24897.phpt new file mode 100644 index 00000000..45bcde34 --- /dev/null +++ b/tests/std/array/bug24897.phpt @@ -0,0 +1,21 @@ +--TEST-- +Bug #24897 (inconsistent behaviour or shuffle() & array_multisort()) +--FILE-- + 2); +shuffle($a); +var_dump($a); + +$a = array(1 => 2); +array_multisort($a); +var_dump($a); +?> +--EXPECT-- +array(1) { + [0]=> + int(2) +} +array(1) { + [0]=> + int(2) +} diff --git a/tests/std/array/bug24980.phpt b/tests/std/array/bug24980.phpt new file mode 100644 index 00000000..da98e10e --- /dev/null +++ b/tests/std/array/bug24980.phpt @@ -0,0 +1,52 @@ +--TEST-- +Bug #24980 (array_reduce() uses first element as default running total) +--FILE-- + +--EXPECT-- +running_total is 0, current_value is 2 +running_total is 4, current_value is 3 +running_total is 13, current_value is 5 +running_total is 38, current_value is 7 +Total is 87 +string(3) "abc" +int(15) +int(1200) +int(1) diff --git a/tests/std/array/bug25359.phpt b/tests/std/array/bug25359.phpt new file mode 100644 index 00000000..a718fb9e --- /dev/null +++ b/tests/std/array/bug25359.phpt @@ -0,0 +1,31 @@ +--TEST-- +Bug #25359 (array_multisort() does not work in a function if array is global or reference) +--FILE-- + +--EXPECT-- +array(5) { + [0]=> + string(5) "first" + [1]=> + string(6) "second" + [2]=> + string(5) "third" + [3]=> + string(5) "forth" + [4]=> + string(5) "fifth" +} diff --git a/tests/std/array/bug25708.phpt b/tests/std/array/bug25708.phpt new file mode 100644 index 00000000..f5e49c0e --- /dev/null +++ b/tests/std/array/bug25708.phpt @@ -0,0 +1,230 @@ +--TEST-- +Bug #25708 (extract($GLOBALS, EXTR_REFS) mangles $GLOBALS) +--SKIPIF-- + + +--FILE-- + +--EXPECT-- +NULL +NULL +int(1) +int(2) +-- +int(1) +int(2) +int(1) +int(2) +-- +int(1) +int(2) +int(1) +int(2) +-- +int(1) +int(3) +int(1) +int(3) +-- +int(4) +int(3) +int(4) +int(3) +-- +int(3) +int(3) +int(3) +-- +int(4) +string(1) "x" +int(4) +string(1) "x" +int(3) +-- +int(1) +int(2) +----a +int(1) +int(2) +int(1) +int(2) +-- +int(1) +int(2) +int(1) +int(2) +-- +int(1) +int(2) +int(1) +int(2) +-- +int(1) +int(3) +int(1) +int(3) +-- +int(4) +int(3) +int(4) +int(3) +-- +int(3) +int(3) +int(3) +-- +int(4) +string(1) "x" +int(4) +string(1) "x" +int(3) +-- +int(1) +int(2) +----ra +NULL +NULL +int(1) +int(2) +-- +int(1) +int(2) +int(1) +int(2) +-- +int(1) +int(2) +int(1) +int(2) +-- +int(1) +int(3) +int(1) +int(3) +-- +int(4) +int(3) +int(4) +int(3) +-- +int(3) +int(3) +int(3) +-- +int(4) +string(1) "x" +int(4) +string(1) "x" +int(3) +-- +int(1) +int(2) +---- +int(1) +int(2) +int(1) +int(2) +-- +int(1) +int(2) +int(1) +int(2) +-- +int(1) +int(2) +int(1) +int(2) +-- +int(1) +int(3) +int(1) +int(3) +-- +int(4) +int(3) +int(4) +int(3) +-- +int(3) +int(3) +int(3) +-- +int(4) +string(1) "x" +int(4) +string(1) "x" +int(3) +-- +int(1) +int(2) +----r +string(2) "ok" +string(2) "ok" diff --git a/tests/std/array/bug25758.phpt b/tests/std/array/bug25758.phpt new file mode 100644 index 00000000..a2d2952d --- /dev/null +++ b/tests/std/array/bug25758.phpt @@ -0,0 +1,14 @@ +--TEST-- +Bug #25758 (var_export does not escape ' & \ inside array keys) +--FILE-- + array("quote'")); + echo var_export($a, true); +?> +--EXPECT-- +array ( + 'quote\'' => + array ( + 0 => 'quote\'', + ), +) diff --git a/tests/std/array/bug26458.phpt b/tests/std/array/bug26458.phpt new file mode 100644 index 00000000..67c1586d --- /dev/null +++ b/tests/std/array/bug26458.phpt @@ -0,0 +1,20 @@ +--TEST-- +Bug #26458 (var_dump(), var_export() & debug_zval_dump() are not binary safe for array keys) +--FILE-- + "Hello world"); +var_dump($test); +var_export($test); +debug_zval_dump($test); +?> +--EXPECTF-- +array(1) { + ["A%0B"]=> + string(11) "Hello world" +} +array ( + 'A' . "\0" . 'B' => 'Hello world', +)array(1) %s{ + ["A%0B"]=> + string(11) "Hello world" %s +} diff --git a/tests/std/array/bug28739.phpt b/tests/std/array/bug28739.phpt new file mode 100644 index 00000000..d861e209 --- /dev/null +++ b/tests/std/array/bug28739.phpt @@ -0,0 +1,71 @@ +--TEST-- +Bug #28739 (*diff() and *intersect() not clearing the fci cache before work) +--FILE-- +x = $x; + } +} +function a($a, $b) +{ + var_dump(__FUNCTION__); + return $a->x - $b->x; +} +function b($a, $b) +{ + var_dump(__FUNCTION__); + return $a->x - $b->x; +} +function main() +{ + $p1 = array(new p(2), new p(1), new p(0)); + $p2 = array(new p(0), new p(2), new p(3)); + uasort($p1, 'a'); + print_r($p1); + echo "Now diffing:\n"; + print_r(array_udiff($p1, $p2, 'b')); +} +?> +--EXPECT-- +string(1) "a" +string(1) "a" +Array +( + [2] => p Object + ( + [x] => 0 + ) + + [1] => p Object + ( + [x] => 1 + ) + + [0] => p Object + ( + [x] => 2 + ) + +) +Now diffing: +string(1) "b" +string(1) "b" +string(1) "b" +string(1) "b" +string(1) "b" +string(1) "b" +string(1) "b" +string(1) "b" +string(1) "b" +Array +( + [1] => p Object + ( + [x] => 1 + ) + +) diff --git a/tests/std/array/bug28974.phpt b/tests/std/array/bug28974.phpt new file mode 100644 index 00000000..a2bd86f6 --- /dev/null +++ b/tests/std/array/bug28974.phpt @@ -0,0 +1,89 @@ +--TEST-- +Bug #28974 (array_(p)slice() treats large lengths incorrectly - overflow) +--FILE-- + +--EXPECT-- +Array +( + [0] => 0 + [1] => 1 + [2] => 2 + [3] => 3 + [4] => 4 + [5] => 5 +) +Array +( + [0] => 2 + [1] => 3 + [2] => 4 + [3] => 5 +) +Array +( + [0] => 2 + [1] => 3 + [2] => 4 + [3] => 5 +) +print_r(array_splice($a,2,1)); +Array +( + [0] => 2 +) +$a is :Array +( + [0] => 0 + [1] => 1 + [2] => 3 + [3] => 4 + [4] => 5 +) +print_r(array_splice($b,2,2147483645)); +Array +( + [0] => 2 + [1] => 3 + [2] => 4 + [3] => 5 +) +$b is :Array +( + [0] => 0 + [1] => 1 +) +print_r(array_splice($c,2,2147483646)); +Array +( + [0] => 2 + [1] => 3 + [2] => 4 + [3] => 5 +) +$c is :Array +( + [0] => 0 + [1] => 1 +) diff --git a/tests/std/array/bug29253.phpt b/tests/std/array/bug29253.phpt new file mode 100644 index 00000000..c690df5d --- /dev/null +++ b/tests/std/array/bug29253.phpt @@ -0,0 +1,22 @@ +--TEST-- +Bug #29253 (array_diff with $GLOBALS argument fails) +--SKIPIF-- + + +--FILE-- + +--EXPECTF-- +array(2) { + ["zz"]=> + %A + ["gg"]=> + string(4) "afad" +} +string(4) "afad" diff --git a/tests/std/array/bug29493.phpt b/tests/std/array/bug29493.phpt new file mode 100644 index 00000000..428028b7 --- /dev/null +++ b/tests/std/array/bug29493.phpt @@ -0,0 +1,108 @@ +--TEST-- +Bug #29493 (extract(EXTR_REFS) fails if array has multiple referrals) +--SKIPIF-- + + +--FILE-- + 'aaa'); + // refcount($a) = 1 + // refcount($a['foo']) = 1 + $b = $a; + // refcount($a) = 2 + // refcount($a['foo']) = 1 + $b['foo'] = 'bbb'; + // refcount($a) = 1 + // refcount($a['foo']) = 1 + var_dump($a, $b); + extract($a, EXTR_REFS); + $foo = 'noo'; + var_dump($a, $b); +} +function t2() +{ + $a = array('foo' => 'aaa'); + // refcount($a) = 1 + // refcount($a['foo']) = 1 + $b =& $a; + // refcount($a) = 2 + // is_ref($a) = true + // refcount($a['foo']) = 1 + $b['foo'] = 'bbb'; + // refcount($a) = 2 + // refcount($a['foo']) = 1 + var_dump($a, $b); + extract($a, EXTR_REFS); + $foo = 'noo'; + var_dump($a, $b); +} +function t3() +{ + $a = array('foo' => 'aaa'); + // refcount($a) = 1 + // refcount($a['foo']) = 1 + $b =& $a; + // refcount($a) = 2 + // is_ref($a) = true + // refcount($a['foo']) = 1 + unset($b); + // refcount($a) = 1 + // is_ref($a) = true + // refcount($a['foo']) = 1 + var_dump($a); + extract($a, EXTR_REFS); + $foo = 'noo'; + var_dump($a); +} +function main() +{ + t1(); + t2(); + t3(); +} +?> +--EXPECT-- +array(1) { + ["foo"]=> + string(3) "aaa" +} +array(1) { + ["foo"]=> + string(3) "bbb" +} +array(1) { + ["foo"]=> + &string(3) "noo" +} +array(1) { + ["foo"]=> + string(3) "bbb" +} +array(1) { + ["foo"]=> + string(3) "bbb" +} +array(1) { + ["foo"]=> + string(3) "bbb" +} +array(1) { + ["foo"]=> + &string(3) "noo" +} +array(1) { + ["foo"]=> + &string(3) "noo" +} +array(1) { + ["foo"]=> + string(3) "aaa" +} +array(1) { + ["foo"]=> + &string(3) "noo" +} diff --git a/tests/std/array/bug30074.phpt b/tests/std/array/bug30074.phpt new file mode 100644 index 00000000..7902e966 --- /dev/null +++ b/tests/std/array/bug30074.phpt @@ -0,0 +1,20 @@ +--TEST-- +Bug #30074 (EG(uninitialized_zval_ptr) gets set to reference using EXTR_REFS, affecting later values) +--SKIPIF-- + + +--FILE-- +$undefined), EXTR_REFS); +var_dump(array($a)); +echo "Done\n"; +?> +--EXPECTF-- +Warning: Undefined variable $undefined in %s on line %d +array(1) { + [0]=> + NULL +} +Done diff --git a/tests/std/array/bug30266.phpt b/tests/std/array/bug30266.phpt new file mode 100644 index 00000000..b31df8ef --- /dev/null +++ b/tests/std/array/bug30266.phpt @@ -0,0 +1,32 @@ +--TEST-- +Bug #30266 (Invalid opcode 137/1/8) and array_walk +--SKIPIF-- + +--FILE-- +b = $val; + throw new Exception("Error"); + } +} +function test($item2, $key, $userd) +{ + $userd->crash($item2); +} +function main() +{ + $fruits = array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple"); + $myobj = new testc(); + try { + array_walk($fruits, 'test', $myobj); + } catch (Exception $e) { + echo "Caught: " . $e->getMessage() . "\n"; + } +} +?> +--EXPECT-- +Caught: Error diff --git a/tests/std/array/bug30833.phpt b/tests/std/array/bug30833.phpt new file mode 100644 index 00000000..c79c33fa --- /dev/null +++ b/tests/std/array/bug30833.phpt @@ -0,0 +1,35 @@ +--TEST-- +Bug #30833 (array_count_values() modifies input array) +--FILE-- + +--EXPECT-- +array(2) { + [0]=> + string(3) "abc" + [1]=> + string(4) "0000" +} +array(2) { + ["abc"]=> + int(1) + ["0000"]=> + int(1) +} +array(2) { + [0]=> + string(3) "abc" + [1]=> + string(4) "0000" +} +Done diff --git a/tests/std/array/bug31158.phpt b/tests/std/array/bug31158.phpt new file mode 100644 index 00000000..f5fe6c2e --- /dev/null +++ b/tests/std/array/bug31158.phpt @@ -0,0 +1,27 @@ +--TEST-- +Bug #31158 (array_splice on $GLOBALS crashes) +--INI-- +error_reporting = E_ALL +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +Fatal error: Uncaught Error: array_splice(): Argument #1 ($array) could not be passed by reference in %s:%d +Stack trace: +#0 %s(%d): __() +#1 {main} + thrown in %s on line %d diff --git a/tests/std/array/bug31213.phpt b/tests/std/array/bug31213.phpt new file mode 100644 index 00000000..7a378294 --- /dev/null +++ b/tests/std/array/bug31213.phpt @@ -0,0 +1,56 @@ +--TEST-- +Bug #31213 (Sideeffects caused by bug #29493) +--SKIPIF-- + + +--FILE-- + $a, '_b' => &$b); + var_dump($a, $b); + if ($use_extract) { + extract($arr, EXTR_REFS); + } else { + $_a =& $arr['_a']; + $_b =& $arr['_b']; + } + $_a++; + $_b++; + var_dump($a, $b, $_a, $_b, $arr); +} +function main() +{ + test(false); + test(true); +} +?> +--EXPECT-- +int(1) +int(1) +int(1) +int(2) +int(2) +int(2) +array(2) { + ["_a"]=> + &int(2) + ["_b"]=> + &int(2) +} +int(1) +int(1) +int(1) +int(2) +int(2) +int(2) +array(2) { + ["_a"]=> + &int(2) + ["_b"]=> + &int(2) +} diff --git a/tests/std/array/bug33382.phpt b/tests/std/array/bug33382.phpt new file mode 100644 index 00000000..0153da90 --- /dev/null +++ b/tests/std/array/bug33382.phpt @@ -0,0 +1,27 @@ +--TEST-- +Bug #33382 (array_reverse() fails after *sort() ) +--FILE-- + +--EXPECT-- +array(5) { + [0]=> + int(5) + [1]=> + int(4) + [2]=> + int(3) + [3]=> + int(2) + [4]=> + int(1) +} +Done diff --git a/tests/std/array/bug33989.phpt b/tests/std/array/bug33989.phpt new file mode 100644 index 00000000..44ba60d8 --- /dev/null +++ b/tests/std/array/bug33989.phpt @@ -0,0 +1,15 @@ +--TEST-- +Bug #33989 (extract($GLOBALS,EXTR_REFS) crashes PHP) +--SKIPIF-- + + +--FILE-- + +--EXPECT-- +ok diff --git a/tests/std/array/bug34066.phpt b/tests/std/array/bug34066.phpt new file mode 100644 index 00000000..5fa475b6 --- /dev/null +++ b/tests/std/array/bug34066.phpt @@ -0,0 +1,574 @@ +--TEST-- +Bug #34066 (recursive array_walk causes segfault) +--FILE-- + 0) { + print "{$prefix}{$key}={$val}\n"; + } else { + print "{$prefix}{$key}\n"; + } + print "gen_xml(prefix={$prefix}) end\n"; +} +function main() +{ + $order = array("DocID" => "1", "DocDate" => "19.09.06", "ReSubmissionDate" => "", "DocTyp" => "Stapelauftrag", "CustID" => "00000", "CustomerAddress" => array(array("Name1" => 'name1', "Name2" => 'name2', "Name3" => "", "City" => 'city', "Street" => 'street', "Postal" => 'postcode', "IATA" => "90", "Country" => "Deutschland", "ShortName" => 'short', "ContactKey" => "", "EMail" => 'email@example.com')), "Text1" => "", "Text2" => "", "Wildcard1" => "", "Wildcard2" => "", "Dispatch" => "Paketdienst", "Weight" => "0,0", "BillingCustID" => "4300200000", "ExtDocNr" => "00000000003", "AnalysisLock" => "", "PrintFlag" => "", "FormType" => "0", "Curr" => "EUR", "ExChangeRate" => "1,0000", "WIRRate" => "0", "OneTimeCustomer" => array(array("BankCode" => "", "BankAccount" => "")), "Language" => "0", "PriceGroup" => "1", "PrFlag" => "0", "SalesTaxKey" => "1", "ProceedKey" => "0", "CustDiscountGroup" => "0", "Discount" => array(array("FinDisc1" => "0,00", "Disc1Base" => "145,72", "Disc1Value" => "0,00", "FinDisc2" => "0,00", "Disc2Base" => "145,72", "Disc2Value" => "0,00", "FinDisc3" => "0,00", "Disc3Base" => "145,72", "Disc3Value" => "0,00", "ValueSummary" => "0,00")), "Contact" => array(array("Repr" => "999", "Region" => "99", "Commission" => "0,00", "Agent" => "000000")), "Booking" => array(array("CostUnit" => "0000000000", "CostCentre" => "0000000000", "AccountingArea" => "01")), "InvoiceCycleKey" => "0", "AnalysisKey" => "", "OrderNumber" => "", "OrderDate" => "", "OrderCode" => "", "DocItems" => array("DocItem" => array("PosType" => "1", "ItemRef" => "1002", "CRef" => "", "Desc1" => "Pr�sentation Niederlande per", "Desc2" => "", "ArticleGroup" => "102", "PosTypeVersion" => "E", "Delivery" => array(array("DelWeek" => "", "DelDay" => "", "DelTime" => "")), "PricePu" => "145,72", "PriceUnit" => "0", "PriceCalculation" => "0", "ItemVal" => "145,72", "InputKey" => "0", "AveragePurchasePrice" => "0", "Tax" => array(array("TaxCode" => "00", "TaxBra" => "000", "TaxBraAccess" => "0", "TaxSumIndex" => "0")), "DiscountArticle" => array(array("DiscPC" => "0,00", "DiscKey" => "1")), "ProceedKeyArticle" => "01", "ActionKey" => "00", "ContactCommissionArticle" => "0,00", "QuantdependentPriceKey" => "", "Quant" => "1", "QuantUnit" => "", "Meas" => array(array("Count" => "1", "Length" => "0,000", "Width" => "0,000", "Height" => "0,000")), "DecimalPlace" => "0", "MultiplierQuant" => "1,000000", "DifferingQuantUnit" => "", "DecimalPlaceConversion" => "0", "WeightArticle" => array(array("Amount" => "0", "Unit" => "0")), "Wreath" => "0,000", "Stock" => "1", "CostUnitArticle" => "", "SerialNbKey" => "0", "TextComplementKey" => "0", "PartsListPrintKey" => "", "Prod" => "0000000000")), "Payment" => array("PaymentKey" => "0", "ReminderKey" => "00", "PayTerms" => array(array("PayTerm" => "1", "PayDays" => "000", "CashDiscDays1" => "000", "CashDiscDays2" => "000", "CashDiscPer1" => "0,00", "CashDiscPer2" => "0,00"), array("PayTerm" => "2", "PayDays" => "000", "CashDiscDays1" => "000", "CashDiscDays2" => "000", "CashDiscPer1" => "0,00", "CashDiscPer2" => "0,00"))), "NetAmountByTurnOverTax" => array(array("TurnOverTaxFree" => "145,72", "TurnOverTax1" => "0,00", "TurnOverTax2" => "0,00", "TurnOverTax3" => "0,00", "TurnOverTax4" => "0,00", "TurnOverTax5" => "0,00", "TurnOverTax6" => "0,00", "TurnOverTax7" => "0,00", "TurnOverTax8" => "0,00")), "GrossAmount" => "145,72", "ProceedAmount" => "145,72", "NetAmountByPayTerm2" => array(array("Sum0" => "0,00", "Sum1" => "0,00", "Sum2" => "0,00", "Sum3" => "0,00", "Sum4" => "0,00", "Sum5" => "0,00", "Sum6" => "0,00", "Sum7" => "0,00", "Sum8" => "0,00")), "TaxCodes" => array(array("TaxCode1" => "0", "TaxCode2" => "0", "TaxCode3" => "0", "TaxCode4" => "0", "TaxCode5" => "0", "TaxCode6" => "0", "TaxCode7" => "0", "TaxCode8" => "0"))); + $docs = array(array("Version" => "1.0", "ProducerName" => "xxxxxxxx", "ProductName" => "Classic Line", "xmlns" => "x-schema:CL310_DezABFSchema.XML"), "Company" => array(array("MandateNumber" => "111", "MandateName" => "xxx xxxxxxx-xxxxx xxxxxxx", "MandateCurr" => "EUR")), "Doc" => $order); + dump2xml($docs); + echo "Done\n"; +} +?> +--EXPECT-- +gen_xml(prefix=/Docs/) +gen_xml(prefix=/Docs/@) +/Docs/@Version=1.0 +gen_xml(prefix=/Docs/@) end +gen_xml(prefix=/Docs/@) +/Docs/@ProducerName=xxxxxxxx +gen_xml(prefix=/Docs/@) end +gen_xml(prefix=/Docs/@) +/Docs/@ProductName=Classic Line +gen_xml(prefix=/Docs/@) end +gen_xml(prefix=/Docs/@) +/Docs/@xmlns=x-schema:CL310_DezABFSchema.XML +gen_xml(prefix=/Docs/@) end +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +gen_xml(prefix=/Docs/Company/) +gen_xml(prefix=/Docs/Company/@) +/Docs/Company/@MandateNumber=111 +gen_xml(prefix=/Docs/Company/@) end +gen_xml(prefix=/Docs/Company/@) +/Docs/Company/@MandateName=xxx xxxxxxx-xxxxx xxxxxxx +gen_xml(prefix=/Docs/Company/@) end +gen_xml(prefix=/Docs/Company/@) +/Docs/Company/@MandateCurr=EUR +gen_xml(prefix=/Docs/Company/@) end +gen_xml(prefix=/Docs/Company/) end +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/DocID=1 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/DocDate=19.09.06 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/ReSubmissionDate +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/DocTyp=Stapelauftrag +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/CustID=00000 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +gen_xml(prefix=/Docs/Doc/CustomerAddress/) +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) +/Docs/Doc/CustomerAddress/@Name1=name1 +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) end +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) +/Docs/Doc/CustomerAddress/@Name2=name2 +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) end +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) +/Docs/Doc/CustomerAddress/@Name3 +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) end +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) +/Docs/Doc/CustomerAddress/@City=city +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) end +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) +/Docs/Doc/CustomerAddress/@Street=street +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) end +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) +/Docs/Doc/CustomerAddress/@Postal=postcode +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) end +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) +/Docs/Doc/CustomerAddress/@IATA=90 +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) end +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) +/Docs/Doc/CustomerAddress/@Country=Deutschland +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) end +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) +/Docs/Doc/CustomerAddress/@ShortName=short +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) end +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) +/Docs/Doc/CustomerAddress/@ContactKey +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) end +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) +/Docs/Doc/CustomerAddress/@EMail=email@example.com +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) end +gen_xml(prefix=/Docs/Doc/CustomerAddress/) end +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/Text1 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/Text2 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/Wildcard1 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/Wildcard2 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/Dispatch=Paketdienst +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/Weight=0,0 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/BillingCustID=4300200000 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/ExtDocNr=00000000003 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/AnalysisLock +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/PrintFlag +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/FormType=0 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/Curr=EUR +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/ExChangeRate=1,0000 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/WIRRate=0 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +gen_xml(prefix=/Docs/Doc/OneTimeCustomer/) +gen_xml(prefix=/Docs/Doc/OneTimeCustomer/@) +/Docs/Doc/OneTimeCustomer/@BankCode +gen_xml(prefix=/Docs/Doc/OneTimeCustomer/@) end +gen_xml(prefix=/Docs/Doc/OneTimeCustomer/@) +/Docs/Doc/OneTimeCustomer/@BankAccount +gen_xml(prefix=/Docs/Doc/OneTimeCustomer/@) end +gen_xml(prefix=/Docs/Doc/OneTimeCustomer/) end +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/Language=0 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/PriceGroup=1 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/PrFlag=0 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/SalesTaxKey=1 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/ProceedKey=0 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/CustDiscountGroup=0 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +gen_xml(prefix=/Docs/Doc/Discount/) +gen_xml(prefix=/Docs/Doc/Discount/@) +/Docs/Doc/Discount/@FinDisc1=0,00 +gen_xml(prefix=/Docs/Doc/Discount/@) end +gen_xml(prefix=/Docs/Doc/Discount/@) +/Docs/Doc/Discount/@Disc1Base=145,72 +gen_xml(prefix=/Docs/Doc/Discount/@) end +gen_xml(prefix=/Docs/Doc/Discount/@) +/Docs/Doc/Discount/@Disc1Value=0,00 +gen_xml(prefix=/Docs/Doc/Discount/@) end +gen_xml(prefix=/Docs/Doc/Discount/@) +/Docs/Doc/Discount/@FinDisc2=0,00 +gen_xml(prefix=/Docs/Doc/Discount/@) end +gen_xml(prefix=/Docs/Doc/Discount/@) +/Docs/Doc/Discount/@Disc2Base=145,72 +gen_xml(prefix=/Docs/Doc/Discount/@) end +gen_xml(prefix=/Docs/Doc/Discount/@) +/Docs/Doc/Discount/@Disc2Value=0,00 +gen_xml(prefix=/Docs/Doc/Discount/@) end +gen_xml(prefix=/Docs/Doc/Discount/@) +/Docs/Doc/Discount/@FinDisc3=0,00 +gen_xml(prefix=/Docs/Doc/Discount/@) end +gen_xml(prefix=/Docs/Doc/Discount/@) +/Docs/Doc/Discount/@Disc3Base=145,72 +gen_xml(prefix=/Docs/Doc/Discount/@) end +gen_xml(prefix=/Docs/Doc/Discount/@) +/Docs/Doc/Discount/@Disc3Value=0,00 +gen_xml(prefix=/Docs/Doc/Discount/@) end +gen_xml(prefix=/Docs/Doc/Discount/@) +/Docs/Doc/Discount/@ValueSummary=0,00 +gen_xml(prefix=/Docs/Doc/Discount/@) end +gen_xml(prefix=/Docs/Doc/Discount/) end +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +gen_xml(prefix=/Docs/Doc/Contact/) +gen_xml(prefix=/Docs/Doc/Contact/@) +/Docs/Doc/Contact/@Repr=999 +gen_xml(prefix=/Docs/Doc/Contact/@) end +gen_xml(prefix=/Docs/Doc/Contact/@) +/Docs/Doc/Contact/@Region=99 +gen_xml(prefix=/Docs/Doc/Contact/@) end +gen_xml(prefix=/Docs/Doc/Contact/@) +/Docs/Doc/Contact/@Commission=0,00 +gen_xml(prefix=/Docs/Doc/Contact/@) end +gen_xml(prefix=/Docs/Doc/Contact/@) +/Docs/Doc/Contact/@Agent=000000 +gen_xml(prefix=/Docs/Doc/Contact/@) end +gen_xml(prefix=/Docs/Doc/Contact/) end +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +gen_xml(prefix=/Docs/Doc/Booking/) +gen_xml(prefix=/Docs/Doc/Booking/@) +/Docs/Doc/Booking/@CostUnit=0000000000 +gen_xml(prefix=/Docs/Doc/Booking/@) end +gen_xml(prefix=/Docs/Doc/Booking/@) +/Docs/Doc/Booking/@CostCentre=0000000000 +gen_xml(prefix=/Docs/Doc/Booking/@) end +gen_xml(prefix=/Docs/Doc/Booking/@) +/Docs/Doc/Booking/@AccountingArea=01 +gen_xml(prefix=/Docs/Doc/Booking/@) end +gen_xml(prefix=/Docs/Doc/Booking/) end +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/InvoiceCycleKey=0 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/AnalysisKey +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/OrderNumber +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/OrderDate +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/OrderCode +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +gen_xml(prefix=/Docs/Doc/DocItems/) +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/PosType=1 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/ItemRef=1002 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/CRef +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/Desc1=Pr�sentation Niederlande per +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/Desc2 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/ArticleGroup=102 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/PosTypeVersion=E +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Delivery/) +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Delivery/@) +/Docs/Doc/DocItems/DocItem/Delivery/@DelWeek +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Delivery/@) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Delivery/@) +/Docs/Doc/DocItems/DocItem/Delivery/@DelDay +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Delivery/@) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Delivery/@) +/Docs/Doc/DocItems/DocItem/Delivery/@DelTime +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Delivery/@) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Delivery/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/PricePu=145,72 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/PriceUnit=0 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/PriceCalculation=0 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/ItemVal=145,72 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/InputKey=0 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/AveragePurchasePrice=0 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Tax/) +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Tax/@) +/Docs/Doc/DocItems/DocItem/Tax/@TaxCode=00 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Tax/@) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Tax/@) +/Docs/Doc/DocItems/DocItem/Tax/@TaxBra=000 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Tax/@) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Tax/@) +/Docs/Doc/DocItems/DocItem/Tax/@TaxBraAccess=0 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Tax/@) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Tax/@) +/Docs/Doc/DocItems/DocItem/Tax/@TaxSumIndex=0 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Tax/@) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Tax/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/DiscountArticle/) +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/DiscountArticle/@) +/Docs/Doc/DocItems/DocItem/DiscountArticle/@DiscPC=0,00 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/DiscountArticle/@) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/DiscountArticle/@) +/Docs/Doc/DocItems/DocItem/DiscountArticle/@DiscKey=1 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/DiscountArticle/@) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/DiscountArticle/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/ProceedKeyArticle=01 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/ActionKey=00 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/ContactCommissionArticle=0,00 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/QuantdependentPriceKey +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/Quant=1 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/QuantUnit +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Meas/) +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Meas/@) +/Docs/Doc/DocItems/DocItem/Meas/@Count=1 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Meas/@) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Meas/@) +/Docs/Doc/DocItems/DocItem/Meas/@Length=0,000 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Meas/@) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Meas/@) +/Docs/Doc/DocItems/DocItem/Meas/@Width=0,000 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Meas/@) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Meas/@) +/Docs/Doc/DocItems/DocItem/Meas/@Height=0,000 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Meas/@) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Meas/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/DecimalPlace=0 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/MultiplierQuant=1,000000 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/DifferingQuantUnit +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/DecimalPlaceConversion=0 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/WeightArticle/) +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/WeightArticle/@) +/Docs/Doc/DocItems/DocItem/WeightArticle/@Amount=0 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/WeightArticle/@) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/WeightArticle/@) +/Docs/Doc/DocItems/DocItem/WeightArticle/@Unit=0 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/WeightArticle/@) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/WeightArticle/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/Wreath=0,000 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/Stock=1 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/CostUnitArticle +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/SerialNbKey=0 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/TextComplementKey=0 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/PartsListPrintKey +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/Prod=0000000000 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/) end +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +gen_xml(prefix=/Docs/Doc/Payment/) +/Docs/Doc/Payment/PaymentKey=0 +gen_xml(prefix=/Docs/Doc/Payment/) end +gen_xml(prefix=/Docs/Doc/Payment/) +/Docs/Doc/Payment/ReminderKey=00 +gen_xml(prefix=/Docs/Doc/Payment/) end +gen_xml(prefix=/Docs/Doc/Payment/) +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/) +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) +/Docs/Doc/Payment/PayTerms/@PayTerm=1 +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) end +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) +/Docs/Doc/Payment/PayTerms/@PayDays=000 +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) end +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) +/Docs/Doc/Payment/PayTerms/@CashDiscDays1=000 +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) end +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) +/Docs/Doc/Payment/PayTerms/@CashDiscDays2=000 +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) end +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) +/Docs/Doc/Payment/PayTerms/@CashDiscPer1=0,00 +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) end +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) +/Docs/Doc/Payment/PayTerms/@CashDiscPer2=0,00 +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) end +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/) end +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/) +/Docs/Doc/Payment/PayTerms +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) +/Docs/Doc/Payment/PayTerms/@PayTerm=2 +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) end +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) +/Docs/Doc/Payment/PayTerms/@PayDays=000 +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) end +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) +/Docs/Doc/Payment/PayTerms/@CashDiscDays1=000 +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) end +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) +/Docs/Doc/Payment/PayTerms/@CashDiscDays2=000 +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) end +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) +/Docs/Doc/Payment/PayTerms/@CashDiscPer1=0,00 +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) end +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) +/Docs/Doc/Payment/PayTerms/@CashDiscPer2=0,00 +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) end +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/) end +gen_xml(prefix=/Docs/Doc/Payment/) end +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +gen_xml(prefix=/Docs/Doc/NetAmountByTurnOverTax/) +gen_xml(prefix=/Docs/Doc/NetAmountByTurnOverTax/@) +/Docs/Doc/NetAmountByTurnOverTax/@TurnOverTaxFree=145,72 +gen_xml(prefix=/Docs/Doc/NetAmountByTurnOverTax/@) end +gen_xml(prefix=/Docs/Doc/NetAmountByTurnOverTax/@) +/Docs/Doc/NetAmountByTurnOverTax/@TurnOverTax1=0,00 +gen_xml(prefix=/Docs/Doc/NetAmountByTurnOverTax/@) end +gen_xml(prefix=/Docs/Doc/NetAmountByTurnOverTax/@) +/Docs/Doc/NetAmountByTurnOverTax/@TurnOverTax2=0,00 +gen_xml(prefix=/Docs/Doc/NetAmountByTurnOverTax/@) end +gen_xml(prefix=/Docs/Doc/NetAmountByTurnOverTax/@) +/Docs/Doc/NetAmountByTurnOverTax/@TurnOverTax3=0,00 +gen_xml(prefix=/Docs/Doc/NetAmountByTurnOverTax/@) end +gen_xml(prefix=/Docs/Doc/NetAmountByTurnOverTax/@) +/Docs/Doc/NetAmountByTurnOverTax/@TurnOverTax4=0,00 +gen_xml(prefix=/Docs/Doc/NetAmountByTurnOverTax/@) end +gen_xml(prefix=/Docs/Doc/NetAmountByTurnOverTax/@) +/Docs/Doc/NetAmountByTurnOverTax/@TurnOverTax5=0,00 +gen_xml(prefix=/Docs/Doc/NetAmountByTurnOverTax/@) end +gen_xml(prefix=/Docs/Doc/NetAmountByTurnOverTax/@) +/Docs/Doc/NetAmountByTurnOverTax/@TurnOverTax6=0,00 +gen_xml(prefix=/Docs/Doc/NetAmountByTurnOverTax/@) end +gen_xml(prefix=/Docs/Doc/NetAmountByTurnOverTax/@) +/Docs/Doc/NetAmountByTurnOverTax/@TurnOverTax7=0,00 +gen_xml(prefix=/Docs/Doc/NetAmountByTurnOverTax/@) end +gen_xml(prefix=/Docs/Doc/NetAmountByTurnOverTax/@) +/Docs/Doc/NetAmountByTurnOverTax/@TurnOverTax8=0,00 +gen_xml(prefix=/Docs/Doc/NetAmountByTurnOverTax/@) end +gen_xml(prefix=/Docs/Doc/NetAmountByTurnOverTax/) end +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/GrossAmount=145,72 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/ProceedAmount=145,72 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +gen_xml(prefix=/Docs/Doc/NetAmountByPayTerm2/) +gen_xml(prefix=/Docs/Doc/NetAmountByPayTerm2/@) +/Docs/Doc/NetAmountByPayTerm2/@Sum0=0,00 +gen_xml(prefix=/Docs/Doc/NetAmountByPayTerm2/@) end +gen_xml(prefix=/Docs/Doc/NetAmountByPayTerm2/@) +/Docs/Doc/NetAmountByPayTerm2/@Sum1=0,00 +gen_xml(prefix=/Docs/Doc/NetAmountByPayTerm2/@) end +gen_xml(prefix=/Docs/Doc/NetAmountByPayTerm2/@) +/Docs/Doc/NetAmountByPayTerm2/@Sum2=0,00 +gen_xml(prefix=/Docs/Doc/NetAmountByPayTerm2/@) end +gen_xml(prefix=/Docs/Doc/NetAmountByPayTerm2/@) +/Docs/Doc/NetAmountByPayTerm2/@Sum3=0,00 +gen_xml(prefix=/Docs/Doc/NetAmountByPayTerm2/@) end +gen_xml(prefix=/Docs/Doc/NetAmountByPayTerm2/@) +/Docs/Doc/NetAmountByPayTerm2/@Sum4=0,00 +gen_xml(prefix=/Docs/Doc/NetAmountByPayTerm2/@) end +gen_xml(prefix=/Docs/Doc/NetAmountByPayTerm2/@) +/Docs/Doc/NetAmountByPayTerm2/@Sum5=0,00 +gen_xml(prefix=/Docs/Doc/NetAmountByPayTerm2/@) end +gen_xml(prefix=/Docs/Doc/NetAmountByPayTerm2/@) +/Docs/Doc/NetAmountByPayTerm2/@Sum6=0,00 +gen_xml(prefix=/Docs/Doc/NetAmountByPayTerm2/@) end +gen_xml(prefix=/Docs/Doc/NetAmountByPayTerm2/@) +/Docs/Doc/NetAmountByPayTerm2/@Sum7=0,00 +gen_xml(prefix=/Docs/Doc/NetAmountByPayTerm2/@) end +gen_xml(prefix=/Docs/Doc/NetAmountByPayTerm2/@) +/Docs/Doc/NetAmountByPayTerm2/@Sum8=0,00 +gen_xml(prefix=/Docs/Doc/NetAmountByPayTerm2/@) end +gen_xml(prefix=/Docs/Doc/NetAmountByPayTerm2/) end +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +gen_xml(prefix=/Docs/Doc/TaxCodes/) +gen_xml(prefix=/Docs/Doc/TaxCodes/@) +/Docs/Doc/TaxCodes/@TaxCode1=0 +gen_xml(prefix=/Docs/Doc/TaxCodes/@) end +gen_xml(prefix=/Docs/Doc/TaxCodes/@) +/Docs/Doc/TaxCodes/@TaxCode2=0 +gen_xml(prefix=/Docs/Doc/TaxCodes/@) end +gen_xml(prefix=/Docs/Doc/TaxCodes/@) +/Docs/Doc/TaxCodes/@TaxCode3=0 +gen_xml(prefix=/Docs/Doc/TaxCodes/@) end +gen_xml(prefix=/Docs/Doc/TaxCodes/@) +/Docs/Doc/TaxCodes/@TaxCode4=0 +gen_xml(prefix=/Docs/Doc/TaxCodes/@) end +gen_xml(prefix=/Docs/Doc/TaxCodes/@) +/Docs/Doc/TaxCodes/@TaxCode5=0 +gen_xml(prefix=/Docs/Doc/TaxCodes/@) end +gen_xml(prefix=/Docs/Doc/TaxCodes/@) +/Docs/Doc/TaxCodes/@TaxCode6=0 +gen_xml(prefix=/Docs/Doc/TaxCodes/@) end +gen_xml(prefix=/Docs/Doc/TaxCodes/@) +/Docs/Doc/TaxCodes/@TaxCode7=0 +gen_xml(prefix=/Docs/Doc/TaxCodes/@) end +gen_xml(prefix=/Docs/Doc/TaxCodes/@) +/Docs/Doc/TaxCodes/@TaxCode8=0 +gen_xml(prefix=/Docs/Doc/TaxCodes/@) end +gen_xml(prefix=/Docs/Doc/TaxCodes/) end +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/) end +Done diff --git a/tests/std/array/bug34066_1.phpt b/tests/std/array/bug34066_1.phpt new file mode 100644 index 00000000..d23acf4d --- /dev/null +++ b/tests/std/array/bug34066_1.phpt @@ -0,0 +1,501 @@ +--TEST-- +Bug #34066 (recursive array_walk causes segfault) +--FILE-- + 0) { + print "{$prefix}{$key}={$val}\n"; + } else { + print "{$prefix}{$key}\n"; + } + print "gen_xml(prefix={$prefix}) end\n"; +} +function main() +{ + $order = array("DocID" => "1", "DocDate" => "19.09.06", "ReSubmissionDate" => "", "DocTyp" => "Stapelauftrag", "CustID" => "00000", "CustomerAddress" => array(array("Name1" => 'name1', "Name2" => 'name2', "Name3" => "", "City" => 'city', "Street" => 'street', "Postal" => 'postcode', "IATA" => "90", "Country" => "Deutschland", "ShortName" => 'short', "ContactKey" => "", "EMail" => 'email@example.com')), "Text1" => "", "Text2" => "", "Wildcard1" => "", "Wildcard2" => "", "Dispatch" => "Paketdienst", "Weight" => "0,0", "BillingCustID" => "4300200000", "ExtDocNr" => "00000000003", "AnalysisLock" => "", "PrintFlag" => "", "FormType" => "0", "Curr" => "EUR", "ExChangeRate" => "1,0000", "WIRRate" => "0", "OneTimeCustomer" => array(array("BankCode" => "", "BankAccount" => "")), "Language" => "0", "PriceGroup" => "1", "PrFlag" => "0", "SalesTaxKey" => "1", "ProceedKey" => "0", "CustDiscountGroup" => "0", "Discount" => array(array("FinDisc1" => "0,00", "Disc1Base" => "145,72", "Disc1Value" => "0,00", "FinDisc2" => "0,00", "Disc2Base" => "145,72", "Disc2Value" => "0,00", "FinDisc3" => "0,00", "Disc3Base" => "145,72", "Disc3Value" => "0,00", "ValueSummary" => "0,00")), "Contact" => array(array("Repr" => "999", "Region" => "99", "Commission" => "0,00", "Agent" => "000000")), "Booking" => array(array("CostUnit" => "0000000000", "CostCentre" => "0000000000", "AccountingArea" => "01")), "InvoiceCycleKey" => "0", "AnalysisKey" => "", "OrderNumber" => "", "OrderDate" => "", "OrderCode" => "", "DocItems" => array("DocItem" => array("PosType" => "1", "ItemRef" => "1002", "CRef" => "", "Desc1" => "Pr�sentation Niederlande per", "Desc2" => "", "ArticleGroup" => "102", "PosTypeVersion" => "E", "Delivery" => array(array("DelWeek" => "", "DelDay" => "", "DelTime" => "")), "PricePu" => "145,72", "PriceUnit" => "0", "PriceCalculation" => "0", "ItemVal" => "145,72", "InputKey" => "0", "AveragePurchasePrice" => "0", "Tax" => array(array("TaxCode" => "00", "TaxBra" => "000", "TaxBraAccess" => "0", "TaxSumIndex" => "0")), "DiscountArticle" => array(array("DiscPC" => "0,00", "DiscKey" => "1")), "ProceedKeyArticle" => "01", "ActionKey" => "00", "ContactCommissionArticle" => "0,00", "QuantdependentPriceKey" => "", "Quant" => "1", "QuantUnit" => "", "Meas" => array(array("Count" => "1", "Length" => "0,000", "Width" => "0,000", "Height" => "0,000")), "DecimalPlace" => "0", "MultiplierQuant" => "1,000000", "DifferingQuantUnit" => "", "DecimalPlaceConversion" => "0", "WeightArticle" => array(array("Amount" => "0", "Unit" => "0")), "Wreath" => "0,000", "Stock" => "1", "CostUnitArticle" => "", "SerialNbKey" => "0", "TextComplementKey" => "0", "PartsListPrintKey" => "", "Prod" => "0000000000")), "Payment" => array("PaymentKey" => "0", "ReminderKey" => "00", "PayTerms" => array(array("PayTerm" => "1", "PayDays" => "000", "CashDiscDays1" => "000", "CashDiscDays2" => "000", "CashDiscPer1" => "0,00", "CashDiscPer2" => "0,00"), array("PayTerm" => "2", "PayDays" => "000", "CashDiscDays1" => "000", "CashDiscDays2" => "000", "CashDiscPer1" => "0,00", "CashDiscPer2" => "0,00"))), "NetAmountByTurnOverTax" => array(array("TurnOverTaxFree" => "145,72", "TurnOverTax1" => "0,00", "TurnOverTax2" => "0,00", "TurnOverTax3" => "0,00", "TurnOverTax4" => "0,00", "TurnOverTax5" => "0,00", "TurnOverTax6" => "0,00", "TurnOverTax7" => "0,00", "TurnOverTax8" => "0,00")), "GrossAmount" => "145,72", "ProceedAmount" => "145,72", "NetAmountByPayTerm2" => array(array("Sum0" => "0,00", "Sum1" => "0,00", "Sum2" => "0,00", "Sum3" => "0,00", "Sum4" => "0,00", "Sum5" => "0,00", "Sum6" => "0,00", "Sum7" => "0,00", "Sum8" => "0,00")), "TaxCodes" => array(array("TaxCode1" => "0", "TaxCode2" => "0", "TaxCode3" => "0", "TaxCode4" => "0", "TaxCode5" => "0", "TaxCode6" => "0", "TaxCode7" => "0", "TaxCode8" => "0"))); + $docs = array(array("Version" => "1.0", "ProducerName" => "xxxxxxxx", "ProductName" => "Classic Line", "xmlns" => "x-schema:CL310_DezABFSchema.XML"), "Company" => array(array("MandateNumber" => "111", "MandateName" => "xxx xxxxxxx-xxxxx xxxxxxx", "MandateCurr" => "EUR")), "Doc" => $order); + dump2xml($docs); + echo "Done\n"; +} +?> +--EXPECT-- +gen_xml(prefix=/Docs/) +/Docs/Version=1.0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/ProducerName=xxxxxxxx +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/ProductName=Classic Line +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/xmlns=x-schema:CL310_DezABFSchema.XML +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/MandateNumber=111 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/MandateName=xxx xxxxxxx-xxxxx xxxxxxx +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/MandateCurr=EUR +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/DocID=1 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/DocDate=19.09.06 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/ReSubmissionDate +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/DocTyp=Stapelauftrag +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/CustID=00000 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Name1=name1 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Name2=name2 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Name3 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/City=city +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Street=street +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Postal=postcode +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/IATA=90 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Country=Deutschland +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/ShortName=short +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/ContactKey +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/EMail=email@example.com +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Text1 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Text2 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Wildcard1 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Wildcard2 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Dispatch=Paketdienst +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Weight=0,0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/BillingCustID=4300200000 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/ExtDocNr=00000000003 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/AnalysisLock +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/PrintFlag +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/FormType=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Curr=EUR +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/ExChangeRate=1,0000 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/WIRRate=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/BankCode +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/BankAccount +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Language=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/PriceGroup=1 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/PrFlag=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/SalesTaxKey=1 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/ProceedKey=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/CustDiscountGroup=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/FinDisc1=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Disc1Base=145,72 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Disc1Value=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/FinDisc2=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Disc2Base=145,72 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Disc2Value=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/FinDisc3=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Disc3Base=145,72 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Disc3Value=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/ValueSummary=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Repr=999 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Region=99 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Commission=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Agent=000000 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/CostUnit=0000000000 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/CostCentre=0000000000 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/AccountingArea=01 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/InvoiceCycleKey=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/AnalysisKey +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/OrderNumber +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/OrderDate +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/OrderCode +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/PosType=1 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/ItemRef=1002 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/CRef +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Desc1=Pr�sentation Niederlande per +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Desc2 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/ArticleGroup=102 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/PosTypeVersion=E +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/DelWeek +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/DelDay +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/DelTime +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/PricePu=145,72 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/PriceUnit=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/PriceCalculation=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/ItemVal=145,72 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/InputKey=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/AveragePurchasePrice=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TaxCode=00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TaxBra=000 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TaxBraAccess=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TaxSumIndex=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/DiscPC=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/DiscKey=1 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/ProceedKeyArticle=01 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/ActionKey=00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/ContactCommissionArticle=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/QuantdependentPriceKey +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Quant=1 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/QuantUnit +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Count=1 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Length=0,000 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Width=0,000 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Height=0,000 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/DecimalPlace=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/MultiplierQuant=1,000000 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/DifferingQuantUnit +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/DecimalPlaceConversion=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Amount=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Unit=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Wreath=0,000 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Stock=1 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/CostUnitArticle +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/SerialNbKey=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TextComplementKey=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/PartsListPrintKey +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Prod=0000000000 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/PaymentKey=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/ReminderKey=00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/PayTerm=1 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/PayDays=000 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/CashDiscDays1=000 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/CashDiscDays2=000 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/CashDiscPer1=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/CashDiscPer2=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/PayTerm=2 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/PayDays=000 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/CashDiscDays1=000 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/CashDiscDays2=000 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/CashDiscPer1=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/CashDiscPer2=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TurnOverTaxFree=145,72 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TurnOverTax1=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TurnOverTax2=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TurnOverTax3=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TurnOverTax4=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TurnOverTax5=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TurnOverTax6=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TurnOverTax7=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TurnOverTax8=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/GrossAmount=145,72 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/ProceedAmount=145,72 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Sum0=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Sum1=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Sum2=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Sum3=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Sum4=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Sum5=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Sum6=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Sum7=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Sum8=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TaxCode1=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TaxCode2=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TaxCode3=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TaxCode4=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TaxCode5=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TaxCode6=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TaxCode7=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TaxCode8=0 +gen_xml(prefix=/Docs/) end +Done diff --git a/tests/std/array/bug34227.phpt b/tests/std/array/bug34227.phpt new file mode 100644 index 00000000..b7c094c7 --- /dev/null +++ b/tests/std/array/bug34227.phpt @@ -0,0 +1,85 @@ +--TEST-- +Bug #34277 (array_filter() crashes with references and objects) +--FILE-- +m2(); + } + function m2() + { + $this->m3(); + } + function m3() + { + $this->m4(); + } + function m4() + { + $this->m5(); + } + function m5() + { + $this->m6(); + } + function m6() + { + $this->m7(); + } + function m7() + { + $this->m8(); + } + function m8() + { + $this->m9(); + } + function m9() + { + $this->m10(); + } + function m10() + { + $this->m11(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + } + function m11($a1, $a2, $a3, $a4, $a5, $a6, $a7, $a8, $a9, $a10) + { + $arr = explode('a', 'b'); + } +} +function f($str) +{ + $obj = new C(); + $obj->m1(); + return TRUE; +} +function p5($a1, $a2, $a3, $a4, $a5, $a6, $a7, $a8, $a9, $a10, $a11, $a12) +{ + $ret = array_filter(array(0), 'f'); +} +function p4() +{ + p5(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12); +} +function p3() +{ + p4(); +} +function p2() +{ + p3(); +} +function p1() +{ + p2(); +} +function main() +{ + p1(); + echo "ok\n"; +} +?> +--EXPECT-- +ok diff --git a/tests/std/array/bug34982.phpt b/tests/std/array/bug34982.phpt new file mode 100644 index 00000000..b6629fc2 --- /dev/null +++ b/tests/std/array/bug34982.phpt @@ -0,0 +1,39 @@ +--TEST-- +Bug #34982 (array_walk_recursive() modifies elements outside function scope) +--FILE-- + +--EXPECT-- +Array +( + [0] => changed + [1] => Array + ( + [0] => changed + ) + +) +Array +( + [0] => element 1 + [1] => Array + ( + [0] => subelement1 + ) + +) diff --git a/tests/std/array/bug35014.phpt b/tests/std/array/bug35014.phpt new file mode 100644 index 00000000..3935657f --- /dev/null +++ b/tests/std/array/bug35014.phpt @@ -0,0 +1,28 @@ +--TEST-- +Bug #35014 (array_product() always returns 0) (32bit) +--SKIPIF-- + +--FILE-- + +--EXPECT-- +int(0) +int(3) +int(9) +float(1) +float(9999999800000000) +float(2.8404260053902914E+20) +float(8589934590) diff --git a/tests/std/array/bug35014_64bit.phpt b/tests/std/array/bug35014_64bit.phpt new file mode 100644 index 00000000..29fa9e18 --- /dev/null +++ b/tests/std/array/bug35014_64bit.phpt @@ -0,0 +1,30 @@ +--TEST-- +Bug #35014 (array_product() always returns 0) (64bit) +--SKIPIF-- + +--INI-- +precision=14 +--FILE-- + +--EXPECT-- +int(0) +int(3) +int(9) +float(1) +int(9999999800000001) +float(1.219953680144986E+30) +float(3.6893488147419103E+19) diff --git a/tests/std/array/bug35022.phpt b/tests/std/array/bug35022.phpt new file mode 100644 index 00000000..a7787aaf --- /dev/null +++ b/tests/std/array/bug35022.phpt @@ -0,0 +1,27 @@ +--TEST-- +Bug #35022 (Regression in the behavior of key/current functions) +--SKIPIF-- + +--FILE-- + " . current($state) . "\n"; + } +} +function main() +{ + $state = array("one" => 1, "two" => 2, "three" => 3); + foo($state); + reset($state); + var_dump(key($state), current($state)); +} +?> +--EXPECT-- +three => 3 +two => 2 +one => 1 +string(3) "one" +int(1) diff --git a/tests/std/array/bug35821.phpt b/tests/std/array/bug35821.phpt new file mode 100644 index 00000000..0887f064 --- /dev/null +++ b/tests/std/array/bug35821.phpt @@ -0,0 +1,32 @@ +--TEST-- +Bug #35821 (array_map() segfaults when exception is throwed from the callback) +--SKIPIF-- + +--FILE-- +ThrowException(); + } +} +function main() +{ + $arr = array(new Element(), new Element(), new Element()); + array_map(array('Element', 'CallBack'), $arr); + echo "Done\n"; +} +?> +--EXPECTF-- +Fatal error: Uncaught Exception in %s:%d +Stack trace: +#0 %s(%d): Element->ThrowException() +#1 [internal function]: Element::CallBack(Object(Element)) +#2 %s(%d): array_map(Array, Array) +#3 {main} + thrown in %s on line %d diff --git a/tests/std/array/bug36975.phpt b/tests/std/array/bug36975.phpt new file mode 100644 index 00000000..67a34325 --- /dev/null +++ b/tests/std/array/bug36975.phpt @@ -0,0 +1,62 @@ +--TEST-- +Bug #36975 (natcasesort() causes array_pop() to misbehave) +--FILE-- + 'foo', 0 => 'baz'); +array_pop($b); +$b[] = 'bar'; +array_push($b, 'bar'); +print_r($b); + +$c = array(0, 0, 0, 0, 0); +asort($c); +array_pop($c); +$c[] = 'foo'; +$c[] = 'bar'; +var_dump($c); +?> +--EXPECT-- +natcasesort success! +array(6) { + [0]=> + string(2) "aa" + [1]=> + string(2) "aa" + [2]=> + string(2) "bb" + [3]=> + string(2) "bb" + [4]=> + string(2) "cc" + [5]=> + string(2) "cc" +} +Array +( + [1] => foo + [2] => bar + [3] => bar +) +array(6) { + [0]=> + int(0) + [1]=> + int(0) + [2]=> + int(0) + [3]=> + int(0) + [4]=> + string(3) "foo" + [5]=> + string(3) "bar" +} diff --git a/tests/std/array/bug38464.phpt b/tests/std/array/bug38464.phpt new file mode 100644 index 00000000..5480109b --- /dev/null +++ b/tests/std/array/bug38464.phpt @@ -0,0 +1,20 @@ +--TEST-- +Bug #38464 (array_count_values() mishandles numeric strings) +--FILE-- + +--EXPECT-- +array(5) { + ["-000"]=> + int(1) + [" 001"]=> + int(1) + [1]=> + int(1) + [" 123"]=> + int(1) + ["+123"]=> + int(1) +} diff --git a/tests/std/array/bug39576.phpt b/tests/std/array/bug39576.phpt new file mode 100644 index 00000000..7e3b52d6 --- /dev/null +++ b/tests/std/array/bug39576.phpt @@ -0,0 +1,53 @@ +--TEST-- +Bug #39576 (array_walk() doesn't separate userdata zval) +--SKIPIF-- + +--FILE-- +name = 'test'; + $test->_columns['name'] = new stdClass(); + array_walk(get_object_vars($test), 'test', $test->_columns); + var_dump($test); + array_intersect_key(get_object_vars($test), $test->_primary); + echo "Done\n"; +} +?> +--EXPECTF-- +Notice: Only variables should be passed by reference in %s on line %d + +Warning: test(): Argument #3 ($columns) must be passed by reference, value given in %s on line %d + +Warning: test(): Argument #3 ($columns) must be passed by reference, value given in %s on line %d + +Warning: test(): Argument #3 ($columns) must be passed by reference, value given in %s on line %d + +Warning: test(): Argument #3 ($columns) must be passed by reference, value given in %s on line %d +object(Test)#%d (4) { + ["_table"]=> + string(0) "" + ["_columns"]=> + array(1) { + ["name"]=> + object(stdClass)#%d (0) { + } + } + ["_primary"]=> + array(0) { + } + ["name"]=> + string(4) "test" +} +Done diff --git a/tests/std/array/bug40191.phpt b/tests/std/array/bug40191.phpt new file mode 100644 index 00000000..c1a0d6b6 --- /dev/null +++ b/tests/std/array/bug40191.phpt @@ -0,0 +1,21 @@ +--TEST-- +Bug #40191 (use of array_unique() with objects triggers segfault) +--FILE-- +append('foo'); +$arrObj->append('bar'); +$arrObj->append('foo'); + +try { + $arr = array_unique($arrObj); +} catch (TypeError $e) { + echo $e->getMessage(), "\n"; +} + +echo "Done\n"; +?> +--EXPECT-- +array_unique(): Argument #1 ($array) must be of type array, ArrayObject given +Done diff --git a/tests/std/array/bug40709.phpt b/tests/std/array/bug40709.phpt new file mode 100644 index 00000000..4a04deb7 --- /dev/null +++ b/tests/std/array/bug40709.phpt @@ -0,0 +1,29 @@ +--TEST-- +Bug #40709 (array_reduce() behaves strange with one item stored arrays) +--FILE-- + +--EXPECT-- +result for arr1: 1,2,3 +result for arr2: 1 +result for arr1: 1,2,3 +result for arr2: 1 +Done diff --git a/tests/std/array/bug41686.phpt b/tests/std/array/bug41686.phpt new file mode 100644 index 00000000..b94acb60 --- /dev/null +++ b/tests/std/array/bug41686.phpt @@ -0,0 +1,56 @@ +--TEST-- +Bug #41686 (Omitting length param in array_slice not possible) +--FILE-- +1,'b'=>1,'c'=>2); + +var_dump( + array_slice($a, 1), + array_slice($a, 1, 2, TRUE), + array_slice($a, 1, NULL, TRUE), + array_slice($b, 1), + array_slice($b, 1, 2, TRUE), + array_slice($b, 1, NULL, TRUE) +); + +echo "Done\n"; +?> +--EXPECT-- +array(2) { + [0]=> + int(2) + [1]=> + int(3) +} +array(2) { + [1]=> + int(2) + [2]=> + int(3) +} +array(2) { + [1]=> + int(2) + [2]=> + int(3) +} +array(2) { + ["b"]=> + int(1) + ["c"]=> + int(2) +} +array(2) { + ["b"]=> + int(1) + ["c"]=> + int(2) +} +array(2) { + ["b"]=> + int(1) + ["c"]=> + int(2) +} +Done diff --git a/tests/std/array/bug42177.phpt b/tests/std/array/bug42177.phpt new file mode 100644 index 00000000..c838a7db --- /dev/null +++ b/tests/std/array/bug42177.phpt @@ -0,0 +1,40 @@ +--TEST-- +Bug #42177 (Warning "array_merge_recursive(): recursion detected" comes again...) +--SKIPIF-- + +--FILE-- + 1, 'key3' => 2 ); +$a2 = array(); +$a1 = array_merge_recursive( $a1, $a2 ); +$a1 = array_merge_recursive( $a1, $a2 ); +unset( $a1, $a2 ); + +$a1 = array(); +$a2 = array( 'key1' => 1, 'key3' => 2 ); +$a1 = array_merge_recursive( $a1, $a2 ); +$a1 = array_merge_recursive( $a1, $a2 ); +unset( $a1, $a2 ); + +$a1 = array(); +$a2 = array( 'key1' => &$a1 ); +$a1 = array_merge_recursive( $a1, $a2 ); +try { + $a1 = array_merge_recursive( $a1, $a2 ); +} catch (\Error $e) { + echo $e->getMessage() . " on line " . $e->getLine() . "\n"; +} +unset( $a1, $a2 ); + +$x = 'foo'; +$y =& $x; +$a1 = array($x, $y, $x, $y); +$a2 = array( 'key1' => $a1, $x, $y ); +$a1 = array_merge_recursive( $a1, $a2 ); +$a1 = array_merge_recursive( $a1, $a2 ); +unset( $a1, $a2 ); + +?> +--EXPECT-- +Recursion detected on line 19 diff --git a/tests/std/array/bug42233.phpt b/tests/std/array/bug42233.phpt new file mode 100644 index 00000000..a538761b --- /dev/null +++ b/tests/std/array/bug42233.phpt @@ -0,0 +1,38 @@ +--TEST-- +Bug #42233 (extract(): scandic characters not allowed as variable name) +--SKIPIF-- + + +--FILE-- + '1', + 'æ' => '2', + 'æøåäö' => '3', +); + +var_dump($test); +var_dump(extract($test)); +var_dump($a); +var_dump($æ); +var_dump($æøåäö); + +echo "Done.\n"; +?> +--EXPECT-- +array(3) { + ["a"]=> + string(1) "1" + ["æ"]=> + string(1) "2" + ["æøåäö"]=> + string(1) "3" +} +int(3) +string(1) "1" +string(1) "2" +string(1) "3" +Done. diff --git a/tests/std/array/bug42838.phpt b/tests/std/array/bug42838.phpt new file mode 100644 index 00000000..2298db2b --- /dev/null +++ b/tests/std/array/bug42838.phpt @@ -0,0 +1,23 @@ +--TEST-- +Bug #42838 (Wrong results in array_diff_uassoc()) +--FILE-- + $b ? 1 : -1; +} +function main() +{ + $array1 = array("a" => "green", "b" => "Brown", 'c' => 'blue', 0 => 'red'); + $array2 = array("a" => "green", "b" => "Brown", 'c' => 'blue', 0 => 'red'); + $result = array_diff_uassoc($array1, $array2, "key_compare_func"); + print_r($result); +} +?> +--EXPECT-- +Array +( +) diff --git a/tests/std/array/bug42850.phpt b/tests/std/array/bug42850.phpt new file mode 100644 index 00000000..7b1cccac --- /dev/null +++ b/tests/std/array/bug42850.phpt @@ -0,0 +1,64 @@ +--TEST-- +Bug #42850 (array_walk_recursive() leaves references) +--FILE-- + 'val1', array('key2' => 'val2')); + var_dump($data); + array_walk_recursive($data, 'apply_dumb'); + $data2 = $data; + $data2[0] = 'altered'; + var_dump($data); + var_dump($data2); + myfunc($data); + var_dump($data); +} +?> +--EXPECT-- +array(2) { + ["key1"]=> + string(4) "val1" + [0]=> + array(1) { + ["key2"]=> + string(4) "val2" + } +} +array(2) { + ["key1"]=> + string(4) "val1" + [0]=> + array(1) { + ["key2"]=> + string(4) "val2" + } +} +array(2) { + ["key1"]=> + string(4) "val1" + [0]=> + string(7) "altered" +} +array(2) { + ["key1"]=> + string(4) "val1" + [0]=> + array(1) { + ["key2"]=> + string(4) "val2" + } +} diff --git a/tests/std/array/bug43495.phpt b/tests/std/array/bug43495.phpt new file mode 100644 index 00000000..37c4f6b6 --- /dev/null +++ b/tests/std/array/bug43495.phpt @@ -0,0 +1,24 @@ +--TEST-- +Bug #43495 (array_merge_recursive() crashes with recursive arrays) +--FILE-- +array("key2"=>array())); +$a["key1"]["key2"]["key3"]=&$a; + +$b=array("key1"=>array("key2"=>array())); +$b["key1"]["key2"]["key3"]=&$b; + + +try { + array_merge_recursive($a,$b); +} catch (\Error $e) { + echo $e->getMessage() . "\n"; +} + +/* Break recursion */ +$a["key1"]["key2"]["key3"] = null; +$b["key1"]["key2"]["key3"] = null; + +?> +--EXPECT-- +Recursion detected diff --git a/tests/std/array/bug43505.phpt b/tests/std/array/bug43505.phpt new file mode 100644 index 00000000..3a7b1151 --- /dev/null +++ b/tests/std/array/bug43505.phpt @@ -0,0 +1,40 @@ +--TEST-- +Bug #43505 (Assign by reference bug) +--INI-- +error_reporting=0 +--SKIPIF-- + + +--FILE-- + +--EXPECT-- +array(1) { + ["test"]=> + &NULL +} +array(1) { + ["test"]=> + &NULL +} diff --git a/tests/std/array/bug43541.phpt b/tests/std/array/bug43541.phpt new file mode 100644 index 00000000..847f61ad --- /dev/null +++ b/tests/std/array/bug43541.phpt @@ -0,0 +1,22 @@ +--TEST-- +Bug #43541 (length parameter omitted or not does not work when casted to float) +--FILE-- + +--EXPECT-- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} diff --git a/tests/std/array/bug44181.phpt b/tests/std/array/bug44181.phpt new file mode 100644 index 00000000..0432d51f --- /dev/null +++ b/tests/std/array/bug44181.phpt @@ -0,0 +1,23 @@ +--TEST-- +Bug #44181 (extract EXTR_OVERWRITE|EXTR_REFS can fail to create references) +--SKIPIF-- + + +--FILE-- + 'original.foo'); + +$foo = 'test'; +$ref = &$a; + +extract($a, EXTR_OVERWRITE|EXTR_REFS); +$foo = 'changed.foo'; + +var_dump($a['foo']); +echo "Done\n"; +?> +--EXPECTF-- +string(%d) "changed.foo" +Done diff --git a/tests/std/array/bug44182.phpt b/tests/std/array/bug44182.phpt new file mode 100644 index 00000000..86504a7a --- /dev/null +++ b/tests/std/array/bug44182.phpt @@ -0,0 +1,23 @@ +--TEST-- +Bug #44182 (extract EXTR_REFS can fail to split copy-on-write references) +--SKIPIF-- + + +--FILE-- + 'original.foo'); + +$nonref = $a['foo']; +$ref = &$a; + +extract($a, EXTR_REFS); +$a['foo'] = 'changed.foo'; + +var_dump($nonref); +echo "Done\n"; +?> +--EXPECTF-- +string(%d) "original.foo" +Done diff --git a/tests/std/array/bug44929.phpt b/tests/std/array/bug44929.phpt new file mode 100644 index 00000000..efcbcda1 --- /dev/null +++ b/tests/std/array/bug44929.phpt @@ -0,0 +1,35 @@ +--TEST-- +Bug #44929 (natsort doesn't handle leading zeros well) +--FILE-- + +--EXPECT-- +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]=> + string(2) "03" + [2]=> + string(3) "005" + [1]=> + string(3) "008" + [3]=> + string(5) "00011" + [5]=> + string(6) "000014" +} diff --git a/tests/std/array/bug45312.phpt b/tests/std/array/bug45312.phpt new file mode 100644 index 00000000..f005c508 --- /dev/null +++ b/tests/std/array/bug45312.phpt @@ -0,0 +1,52 @@ +--TEST-- +Bug #45312 (Segmentation fault on second request for array functions) +--FILE-- +priv_member = $val; + } + static function comp_func_cr($a, $b) + { + if ($a->priv_member === $b->priv_member) { + return 0; + } + return $a->priv_member > $b->priv_member ? 1 : -1; + } + static function comp_func_cr2($a, $b) + { + echo "."; + if ($a->priv_member === $b->priv_member) { + return 0; + } + return $a->priv_member < $b->priv_member ? 1 : -1; + } + function dump() + { + echo $this->priv_member . "\n"; + } +} +function main() +{ + $a = array("0.1" => new cr(9), "0.5" => new cr(12), 0 => new cr(23), 1 => new cr(4), 2 => new cr(-15)); + $b = array("0.2" => new cr(9), "0.5" => new cr(22), 0 => new cr(3), 1 => new cr(4), 2 => new cr(-15)); + $result = array_udiff_assoc($a, $b, array("cr", "comp_func_cr")); + foreach ($result as $val) { + $val->dump(); + } + $result = array_udiff_assoc($a, $b, array("cr", "comp_func_cr2")); + foreach ($result as $val) { + $val->dump(); + } +} +?> +--EXPECT-- +9 +12 +23 +....9 +12 +23 diff --git a/tests/std/array/bug46873.phpt b/tests/std/array/bug46873.phpt new file mode 100644 index 00000000..2c5f262c --- /dev/null +++ b/tests/std/array/bug46873.phpt @@ -0,0 +1,17 @@ +--TEST-- +Bug #46873 (extract($foo) crashes if $foo['foo'] exists) +--SKIPIF-- + + +--FILE-- + 1, 'bar' => 2, 'test' => 3); +extract($foo); +var_dump($foo, $bar, $test); +?> +--EXPECT-- +int(1) +int(2) +int(3) diff --git a/tests/std/array/bug48224.phpt b/tests/std/array/bug48224.phpt new file mode 100644 index 00000000..5b46e183 --- /dev/null +++ b/tests/std/array/bug48224.phpt @@ -0,0 +1,15 @@ +--TEST-- +Bug #48224 (array_rand no longer shuffles) +--FILE-- + +--EXPECT-- +bool(true) diff --git a/tests/std/array/bug48854.phpt b/tests/std/array/bug48854.phpt new file mode 100644 index 00000000..ed5b8e1a --- /dev/null +++ b/tests/std/array/bug48854.phpt @@ -0,0 +1,43 @@ +--TEST-- +Bug #48854 (array_merge_recursive modifies arrays after first one) +--FILE-- + 5, + 'children' => array( + 'dogs' => 0, + ), +); + +$array2 = array( + 'friends' => 10, + 'children' => array( + 'cats' => 5, + ), +); + +$merged = array_merge_recursive($array1, $array2); + +var_dump($array1, $array2); + +?> +--EXPECT-- +array(2) { + ["friends"]=> + int(5) + ["children"]=> + array(1) { + ["dogs"]=> + int(0) + } +} +array(2) { + ["friends"]=> + int(10) + ["children"]=> + array(1) { + ["cats"]=> + int(5) + } +} diff --git a/tests/std/array/bug50006.phpt b/tests/std/array/bug50006.phpt new file mode 100644 index 00000000..c7c59752 --- /dev/null +++ b/tests/std/array/bug50006.phpt @@ -0,0 +1,30 @@ +--TEST-- +Bug #50006 (Segfault caused by uksort()) +--FILE-- + 0, 'bar-bazbazbaz-' => 0, 'foo' => 0); + uksort($data, 'magic_sort_cmp'); + print_r($data); +} +?> +--EXPECT-- +Array +( + [foo] => 0 + [bar-bazbazbaz.] => 0 + [bar-bazbazbaz-] => 0 +) diff --git a/tests/std/array/bug50006_1.phpt b/tests/std/array/bug50006_1.phpt new file mode 100644 index 00000000..9a565f87 --- /dev/null +++ b/tests/std/array/bug50006_1.phpt @@ -0,0 +1,30 @@ +--TEST-- +Bug #50006 (Segfault caused by uksort()) - usort variant +--FILE-- + +--EXPECT-- +Array +( + [0] => foo + [1] => bar-bazbazbaz. + [2] => bar-bazbazbaz- +) diff --git a/tests/std/array/bug50006_2.phpt b/tests/std/array/bug50006_2.phpt new file mode 100644 index 00000000..82956367 --- /dev/null +++ b/tests/std/array/bug50006_2.phpt @@ -0,0 +1,30 @@ +--TEST-- +Bug #50006 (Segfault caused by uksort()) - uasort variant +--FILE-- + +--EXPECT-- +Array +( + [2] => foo + [0] => bar-bazbazbaz. + [1] => bar-bazbazbaz- +) diff --git a/tests/std/array/bug51552.phpt b/tests/std/array/bug51552.phpt new file mode 100644 index 00000000..609b9eaf --- /dev/null +++ b/tests/std/array/bug51552.phpt @@ -0,0 +1,26 @@ +--TEST-- +Bug #51552 (debug_backtrace() causes segmentation fault and/or memory issues) +--FILE-- + +--EXPECT-- +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 diff --git a/tests/std/array/bug52534.phpt b/tests/std/array/bug52534.phpt new file mode 100644 index 00000000..dfff3fdb --- /dev/null +++ b/tests/std/array/bug52534.phpt @@ -0,0 +1,14 @@ +--TEST-- +Bug #52534 (var_export array with negative key) +--FILE-- + 'Hello'); + +var_export($aArray); + +?> +--EXPECT-- +array ( + -1 => 'Hello', +) diff --git a/tests/std/array/bug52719.phpt b/tests/std/array/bug52719.phpt new file mode 100644 index 00000000..91bb4ec1 --- /dev/null +++ b/tests/std/array/bug52719.phpt @@ -0,0 +1,23 @@ +--TEST-- +Bug #52719: array_walk_recursive crashes if third param of the function is by reference +--SKIPIF-- + + +--FILE-- + +--EXPECTF-- +Warning: {closure:%s:%d}(): Argument #3 ($userdata) must be passed by reference, value given in %s on line %d + +Warning: {closure:%s:%d}(): Argument #3 ($userdata) must be passed by reference, value given in %s on line %d +Done diff --git a/tests/std/array/bug61058.phpt b/tests/std/array/bug61058.phpt new file mode 100644 index 00000000..e5960a55 --- /dev/null +++ b/tests/std/array/bug61058.phpt @@ -0,0 +1,15 @@ +--TEST-- +Bug #61058 (array_fill leaks if start index is PHP_INT_MAX) +--SKIPIF-- + +--FILE-- +getMessage() . "\n"; +} +?> +--EXPECT-- +Cannot add element to the array as the next element is already occupied diff --git a/tests/std/array/bug61730.phpt b/tests/std/array/bug61730.phpt new file mode 100644 index 00000000..ff137151 --- /dev/null +++ b/tests/std/array/bug61730.phpt @@ -0,0 +1,37 @@ +--TEST-- +Bug #61730 (Segfault from array_walk modifying an array passed by reference) +--FILE-- + +--EXPECT-- +int(0) +int(3) +int(6) +int(9) +Array +( +) diff --git a/tests/std/array/bug61967.phpt b/tests/std/array/bug61967.phpt new file mode 100644 index 00000000..ee107e5b --- /dev/null +++ b/tests/std/array/bug61967.phpt @@ -0,0 +1,30 @@ +--TEST-- +Bug #61967: unset array item in array_walk_recursive cause inconsistent array +--SKIPIF-- + + +--FILE-- + +--EXPECT-- +int(0) +int(1) +int(2) +int(3) +int(4) diff --git a/tests/std/array/bug62607.phpt b/tests/std/array/bug62607.phpt new file mode 100644 index 00000000..a2a3dfd3 --- /dev/null +++ b/tests/std/array/bug62607.phpt @@ -0,0 +1,17 @@ +--TEST-- +Bug #62607: array_walk_recursive move internal pointer +--SKIPIF-- + + +--FILE-- +'b'); +echo 'Before -> '.current($arr).PHP_EOL; +array_walk_recursive($arr, function(&$val){}); +echo 'After -> '.current($arr); +?> +--EXPECT-- +Before -> b +After -> b diff --git a/tests/std/array/bug65251.phpt b/tests/std/array/bug65251.phpt new file mode 100644 index 00000000..93fe5276 --- /dev/null +++ b/tests/std/array/bug65251.phpt @@ -0,0 +1,24 @@ +--TEST-- +Bug #65251: array_merge_recursive() recursion detection broken +--INI-- +report_memleaks=0 +--SKIPIF-- + +--FILE-- +getMessage() . "\n"; +} + +echo "===DONE===\n"; +?> +--EXPECT-- +===DONE=== diff --git a/tests/std/array/bug65304.phpt b/tests/std/array/bug65304.phpt new file mode 100644 index 00000000..8ed4c508 --- /dev/null +++ b/tests/std/array/bug65304.phpt @@ -0,0 +1,10 @@ +--TEST-- +Bug #65304 (Use of max int in array_sum) +--FILE-- + +--EXPECTF-- +float(%s) +float(%s) diff --git a/tests/std/array/bug67693.phpt b/tests/std/array/bug67693.phpt new file mode 100644 index 00000000..c9aa2d86 --- /dev/null +++ b/tests/std/array/bug67693.phpt @@ -0,0 +1,25 @@ +--TEST-- +Bug #67693 - incorrect push to empty array +--FILE-- + 0); + +array_pop($array); + +array_push($array, 0); +array_push($array, 0); + +var_dump($array); + +echo"\nDone"; +?> +--EXPECT-- +array(2) { + [-1]=> + int(0) + [0]=> + int(0) +} + +Done diff --git a/tests/std/array/bug68553.phpt b/tests/std/array/bug68553.phpt new file mode 100644 index 00000000..f17af0a5 --- /dev/null +++ b/tests/std/array/bug68553.phpt @@ -0,0 +1,85 @@ +--TEST-- +Bug #68553 (array_column: null values in $index_key become incrementing keys in result) +--SKIPIF-- + +--FILE-- + 10], + ['a' => 20], + ['a' => true], + ['a' => false], + ['a' => fopen(__FILE__, "r")], + ['a' => -5], + ['a' => 7.38], + ['a' => null, "test"], + ['a' => null], +]; + +var_dump(array_column($a, null, 'a')); + +try { + var_dump(array_column([['a' => new stdClass]], null, 'a')); +} catch (Error $e) { + echo $e->getMessage(), "\n"; +} +try { + var_dump(array_column([['a' => []]], null, 'a')); +} catch (Error $e) { + echo $e->getMessage(), "\n"; +} +?> +--EXPECTF-- +Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d + +Deprecated: Implicit conversion from float 7.38 to int loses precision in %s on line %d +array(8) { + [10]=> + array(1) { + ["a"]=> + int(10) + } + [20]=> + array(1) { + ["a"]=> + int(20) + } + [1]=> + array(1) { + ["a"]=> + bool(true) + } + [0]=> + array(1) { + ["a"]=> + bool(false) + } + [%d]=> + array(1) { + ["a"]=> + resource(%d) of type (stream) + } + [-5]=> + array(1) { + ["a"]=> + int(-5) + } + [7]=> + array(1) { + ["a"]=> + float(7.38) + } + [""]=> + array(1) { + ["a"]=> + NULL + } +} +Cannot access offset of type stdClass on array +Cannot access offset of type array on array diff --git a/tests/std/array/bug69068.phpt b/tests/std/array/bug69068.phpt new file mode 100644 index 00000000..a069b44b --- /dev/null +++ b/tests/std/array/bug69068.phpt @@ -0,0 +1,28 @@ +--TEST-- +Bug #69068: Exchanging array during array_walk -> memory errors +--SKIPIF-- + +--FILE-- + +--EXPECT-- +int(1) +int(2) +int(4) +int(5) +array(2) { + [0]=> + int(4) + [1]=> + int(5) +} diff --git a/tests/std/array/bug69068_2.phpt b/tests/std/array/bug69068_2.phpt new file mode 100644 index 00000000..cd744128 --- /dev/null +++ b/tests/std/array/bug69068_2.phpt @@ -0,0 +1,39 @@ +--TEST-- +Bug #69068: Exchanging array during array_walk -> memory errors (variation) +--SKIPIF-- + + +--FILE-- + +--EXPECT-- +int(1) +int(2) +int(4) +int(5) +array(2) { + [0]=> + int(40) + [1]=> + int(50) +} +array(2) { + [0]=> + int(4) + [1]=> + int(5) +} diff --git a/tests/std/array/bug69166.phpt b/tests/std/array/bug69166.phpt new file mode 100644 index 00000000..d0b5fadd --- /dev/null +++ b/tests/std/array/bug69166.phpt @@ -0,0 +1,17 @@ +--TEST-- +Fixed #69166 (Assigning array_values() to array does not reset key counter) +--FILE-- + +--EXPECT-- +array(2) { + [0]=> + int(0) + [1]=> + int(1) +} diff --git a/tests/std/array/bug69198.phpt b/tests/std/array/bug69198.phpt new file mode 100644 index 00000000..5d4130e7 --- /dev/null +++ b/tests/std/array/bug69198.phpt @@ -0,0 +1,19 @@ +--TEST-- +Bug #69198 (Compact function generate array with length but no content) +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +Warning: compact(): Undefined variable $willNeverBeDefined in %s on line %d +array(0) { +} +bool(true) +bool(true) +bool(true) diff --git a/tests/std/array/bug69299.phpt b/tests/std/array/bug69299.phpt new file mode 100644 index 00000000..77c76166 --- /dev/null +++ b/tests/std/array/bug69299.phpt @@ -0,0 +1,18 @@ +--TEST-- +Bug #69299 (Regression in array_filter's $flag argument in PHP 7) +--FILE-- + 'bar', 'fiz' => 'buz'); +$filtered = array_filter($toFilter, function ($value, $key) { + if ($value === 'buz' + || $key === 'foo' + ) { + return false; + } + return true; +}, ARRAY_FILTER_USE_BOTH); +var_dump($filtered); +?> +--EXPECT-- +array(0) { +} diff --git a/tests/std/array/bug69371.phpt b/tests/std/array/bug69371.phpt new file mode 100644 index 00000000..a4350e66 --- /dev/null +++ b/tests/std/array/bug69371.phpt @@ -0,0 +1,23 @@ +--TEST-- +Bug #69371 (Hash table collision leads to inaccessible array keys) +--SKIPIF-- +--FILE-- + 1, + "d6_filter_format" => 2, + "d6_user" => 3, + "d6_field_instance_widget_settings" => 4, + "d6_field_formatter_settings" => 5, +); + +$weights = array( + 5, 1, 3, 2, 0 +); +array_multisort($weights, SORT_DESC, SORT_NUMERIC, $array); + +var_dump($array["d6_node_type"]); + +?> +--EXPECT-- +int(1) diff --git a/tests/std/array/bug69413.phpt b/tests/std/array/bug69413.phpt new file mode 100644 index 00000000..3a0ab8d0 --- /dev/null +++ b/tests/std/array/bug69413.phpt @@ -0,0 +1,18 @@ +--TEST-- +Bug #69413: Warning in array_count_values() about array values not being string/int +--FILE-- + +--EXPECT-- +array(2) { + ["a"]=> + int(1) + ["b"]=> + int(1) +} diff --git a/tests/std/array/bug69674.phpt b/tests/std/array/bug69674.phpt new file mode 100644 index 00000000..0d58b6ae --- /dev/null +++ b/tests/std/array/bug69674.phpt @@ -0,0 +1,8 @@ +--TEST-- +Bug #69674 (SIGSEGV array.c:953) +--FILE-- + +--EXPECT-- +bool(false) diff --git a/tests/std/array/bug69723.phpt b/tests/std/array/bug69723.phpt new file mode 100644 index 00000000..90422a52 --- /dev/null +++ b/tests/std/array/bug69723.phpt @@ -0,0 +1,32 @@ +--TEST-- +Bug #69723 (Passing parameters by reference and array_column) +--FILE-- + 'superman', 'nanana' => 'no nana'], ['superhero' => 'acuaman', 'nanana' => 'no nana']]; + var_dump(array_column($array, 'superhero')); + byReference($array); + var_dump(array_column($array, 'superhero')); +} +?> +--EXPECT-- +array(2) { + [0]=> + string(8) "superman" + [1]=> + string(7) "acuaman" +} +array(2) { + [0]=> + string(5) "robin" + [1]=> + string(5) "robin" +} diff --git a/tests/std/array/bug70250.phpt b/tests/std/array/bug70250.phpt new file mode 100644 index 00000000..29e54ea9 --- /dev/null +++ b/tests/std/array/bug70250.phpt @@ -0,0 +1,26 @@ +--TEST-- +Bug #70250 (extract() turns array elements to references) +--SKIPIF-- + + +--FILE-- + 'value']; + +$ref = &$array['key']; + +unset($ref); + +extract($array); + +$key = "bad"; + +var_dump($array); +?> +--EXPECT-- +array(1) { + ["key"]=> + string(5) "value" +} diff --git a/tests/std/array/bug70668.phpt b/tests/std/array/bug70668.phpt new file mode 100644 index 00000000..b35107a0 --- /dev/null +++ b/tests/std/array/bug70668.phpt @@ -0,0 +1,63 @@ +--TEST-- +Bug #70668 (array_keys() doesn't respect references when $strict is true) +--FILE-- + +--EXPECT-- +array(1) { + [0]=> + int(0) +} +array(1) { + [0]=> + int(1) +} +array(1) { + [0]=> + int(2) +} +array(1) { + [0]=> + int(3) +} +array(1) { + [0]=> + int(4) +} +array(1) { + [0]=> + int(5) +} +array(1) { + [0]=> + int(6) +} +array(1) { + [0]=> + int(7) +} diff --git a/tests/std/array/bug70713.phpt b/tests/std/array/bug70713.phpt new file mode 100644 index 00000000..6a1af9b6 --- /dev/null +++ b/tests/std/array/bug70713.phpt @@ -0,0 +1,29 @@ +--TEST-- +Bug #70713: Use After Free Vulnerability in array_walk()/array_walk_recursive() +--SKIPIF-- + +--FILE-- + new obj()); + try { + array_walk_recursive($arr, 'settype'); + } catch (\TypeError $e) { + echo $e->getMessage() . "\n"; + } +} +?> +--EXPECT-- +Iterated value is no longer an array or object diff --git a/tests/std/array/bug70808.phpt b/tests/std/array/bug70808.phpt new file mode 100644 index 00000000..df82da8c --- /dev/null +++ b/tests/std/array/bug70808.phpt @@ -0,0 +1,23 @@ +--TEST-- +Bug #70808 (array_merge_recursive corrupts memory of unset items) +--FILE-- + array(0, 1)); +$arr2 = array("key" => array(2)); + +unset($arr1["key"][1]); + +$result = array_merge_recursive($arr1, $arr2); +print_r($result); +?> +--EXPECT-- +Array +( + [key] => Array + ( + [0] => 0 + [2] => 2 + ) + +) diff --git a/tests/std/array/bug70910.phpt b/tests/std/array/bug70910.phpt new file mode 100644 index 00000000..f4aed175 --- /dev/null +++ b/tests/std/array/bug70910.phpt @@ -0,0 +1,19 @@ +--TEST-- +Bug #70910 (extract() breaks variable references) +--SKIPIF-- + + +--FILE-- + 'new value']; + +extract($hash); +var_dump($var === $ref); +?> +--EXPECT-- +bool(true) diff --git a/tests/std/array/bug71220.phpt b/tests/std/array/bug71220.phpt new file mode 100644 index 00000000..5c5f43ee --- /dev/null +++ b/tests/std/array/bug71220.phpt @@ -0,0 +1,13 @@ +--TEST-- +Bug #71220 (Null pointer deref (segfault) in compact via ob_start) +--FILE-- +getMessage(); +} +?> +--EXPECT-- +Cannot call compact() dynamically diff --git a/tests/std/array/bug71334.phpt b/tests/std/array/bug71334.phpt new file mode 100644 index 00000000..31b720a5 --- /dev/null +++ b/tests/std/array/bug71334.phpt @@ -0,0 +1,31 @@ +--TEST-- +Bug #71334: Cannot access array keys while uksort() +--SKIPIF-- +--FILE-- + [1], '-' => [2], 'bar-test' => [3]]; + public function _mySort($x, $y) + { + if (!isset($this->a[$x])) { + throw new Exception('Missing X: "' . $x . '"'); + } + if (!isset($this->a[$y])) { + throw new Exception('Missing Y: "' . $y . '"'); + } + return $x <=> $y; + } + public function __construct() + { + uksort($this->a, [$this, '_mySort']); + } +} +function main() +{ + new myClass(); + echo "Done"; +} +?> +--EXPECT-- +Done diff --git a/tests/std/array/bug71603.phpt b/tests/std/array/bug71603.phpt new file mode 100644 index 00000000..099c1b97 --- /dev/null +++ b/tests/std/array/bug71603.phpt @@ -0,0 +1,15 @@ +--TEST-- +Bug #71603 (compact() maintains references in php7) +--FILE-- + +--EXPECT-- +string(4) "okey" diff --git a/tests/std/array/bug71660.phpt b/tests/std/array/bug71660.phpt new file mode 100644 index 00000000..067f5333 --- /dev/null +++ b/tests/std/array/bug71660.phpt @@ -0,0 +1,18 @@ +--TEST-- +Bug #71660 (array_column behaves incorrectly after foreach by reference) +--FILE-- + 12345, 'name' => 'sam'); +foreach ($arr as &$v) { + $v = $v; +} + +$arr = [$arr]; + +var_dump(array_column($arr, 'name', 'id')); +?> +--EXPECT-- +array(1) { + [12345]=> + string(3) "sam" +} diff --git a/tests/std/array/bug71837.phpt b/tests/std/array/bug71837.phpt new file mode 100644 index 00000000..686d144c --- /dev/null +++ b/tests/std/array/bug71837.phpt @@ -0,0 +1,27 @@ +--TEST-- +Bug #71837 (Wrong arrays behaviour) +--FILE-- + +--EXPECT-- +Array +( + [0] => Array + ( + [0] => Array + ( + [0] => 100 + ) + + ) + +) diff --git a/tests/std/array/bug72031.phpt b/tests/std/array/bug72031.phpt new file mode 100644 index 00000000..00c3eac3 --- /dev/null +++ b/tests/std/array/bug72031.phpt @@ -0,0 +1,39 @@ +--TEST-- +Bug #72031: array_column() against an array of objects discards all values matching null +--FILE-- +prop = $prop; + } +} +function main() +{ + $objects = [new myObj(-1), new myObj(0), new myObj(1), new myObj(2), new myObj(null), new myObj(true), new myObj(false), new myObj('abc'), new myObj('')]; + var_dump(array_column($objects, 'prop')); +} +?> +--EXPECT-- +array(9) { + [0]=> + int(-1) + [1]=> + int(0) + [2]=> + int(1) + [3]=> + int(2) + [4]=> + NULL + [5]=> + bool(true) + [6]=> + bool(false) + [7]=> + string(3) "abc" + [8]=> + string(0) "" +} diff --git a/tests/std/array/bug72116.phpt b/tests/std/array/bug72116.phpt new file mode 100644 index 00000000..182f6994 --- /dev/null +++ b/tests/std/array/bug72116.phpt @@ -0,0 +1,17 @@ +--TEST-- +Bug #72116 (insertion after array_fill fails) +--FILE-- + +--EXPECT-- +array(2) { + [0]=> + string(2) ".." + [1]=> + string(1) "a" +} diff --git a/tests/std/array/bug72369.phpt b/tests/std/array/bug72369.phpt new file mode 100644 index 00000000..e20b410d --- /dev/null +++ b/tests/std/array/bug72369.phpt @@ -0,0 +1,18 @@ +--TEST-- +Bug #72369 (array_merge() produces references in PHP7) +--SKIPIF-- + +--FILE-- + &$x]; +unset($x); +$a = ['test' => 'yyy']; +$a = array_merge($a, $d); +debug_zval_dump($a); +?> +--EXPECTF-- +array(1) refcount(%d){ + ["test"]=> + string(3) "xxx" interned +} diff --git a/tests/std/array/bug72622.phpt b/tests/std/array/bug72622.phpt new file mode 100644 index 00000000..78813e8d --- /dev/null +++ b/tests/std/array/bug72622.phpt @@ -0,0 +1,37 @@ +--TEST-- +Bug #72622 (array_walk + array_replace_recursive create references from nothing) +--SKIPIF-- + + +--FILE-- + 'foo']; + $arr4 = walk(['foo' => 'bar']); + $arr5 = array_replace_recursive($arr3, $arr4); + $arr5['foo'] = 'baz'; + var_dump($arr3, $arr4, $arr5); +} +?> +--EXPECT-- +array(1) { + ["foo"]=> + string(3) "foo" +} +array(1) { + ["foo"]=> + string(3) "bar" +} +array(1) { + ["foo"]=> + string(3) "baz" +} diff --git a/tests/std/array/bug74345.phpt b/tests/std/array/bug74345.phpt new file mode 100644 index 00000000..afa08886 --- /dev/null +++ b/tests/std/array/bug74345.phpt @@ -0,0 +1,49 @@ +--TEST-- +Bug #74345: Call trampoline leaked if callback not invoked +--SKIPIF-- +--FILE-- +getMessage(), "\n"; + } + try { + array_map($cb, null, null); + } catch (Error $e) { + echo $e->getMessage(), "\n"; + } + array_filter([], $cb); + array_reduce([], $cb); + + $array = []; + array_walk($array, $cb); + array_walk_recursive($array, $cb); + usort($array, $cb); + + try { + preg_replace_callback('/./', $cb, new stdClass); + } catch (Error $e) { + echo $e->getMessage(), "\n"; + } + + echo "===DONE===\n"; +} +?> +--EXPECT-- +array_map(): Argument #2 ($array) must be of type array, null given +array_map(): Argument #2 ($array) must be of type array, null given +preg_replace_callback(): Argument #3 ($subject) must be of type array|string, stdClass given +===DONE=== diff --git a/tests/std/array/bug74361.phpt b/tests/std/array/bug74361.phpt new file mode 100644 index 00000000..6e745902 --- /dev/null +++ b/tests/std/array/bug74361.phpt @@ -0,0 +1,11 @@ +--TEST-- +Bug #74361: Compaction in array_rand() violates COW +--FILE-- + 4]; +var_dump(array_rand($array)); + +?> +--EXPECT-- +int(4) diff --git a/tests/std/array/bug74361_2.phpt b/tests/std/array/bug74361_2.phpt new file mode 100644 index 00000000..4f4bdcf5 --- /dev/null +++ b/tests/std/array/bug74361_2.phpt @@ -0,0 +1,24 @@ +--TEST-- +Bug #74361: Compaction in array_rand() violates COW (variation) +--FILE-- + +--EXPECT-- +int(9) +int(10) +int(11) +int(12) +int(13) +int(14) +int(15) diff --git a/tests/std/array/bug75433.phpt b/tests/std/array/bug75433.phpt new file mode 100644 index 00000000..caf4816a --- /dev/null +++ b/tests/std/array/bug75433.phpt @@ -0,0 +1,18 @@ +--TEST-- +array_values() preserves next index from source array when shallow-copying +--FILE-- + +--EXPECT-- +Array +( + [0] => 1 + [1] => 2 + [2] => 4 +) diff --git a/tests/std/array/bug75653.phpt b/tests/std/array/bug75653.phpt new file mode 100644 index 00000000..d11c1e0c --- /dev/null +++ b/tests/std/array/bug75653.phpt @@ -0,0 +1,20 @@ +--TEST-- +Bug #75653: array_values don't work on empty array +--FILE-- + +--EXPECT-- +array(2) { + [0]=> + string(5) "data2" + [1]=> + string(5) "data3" +} diff --git a/tests/std/array/bug76505.phpt b/tests/std/array/bug76505.phpt new file mode 100644 index 00000000..ad0b2c86 --- /dev/null +++ b/tests/std/array/bug76505.phpt @@ -0,0 +1,33 @@ +--TEST-- +Bug #76505 (array_merge_recursive() is duplicating sub-array keys) +--FILE-- + array( + 2 => 100, + 98 => 200, + ) +); + +$array2 = array( + 'k' => array( + 64 => 300 + ) +); + +$array3 = array_merge_recursive( $array1, $array2 ); + +var_dump($array3); +?> +--EXPECT-- +array(1) { + ["k"]=> + array(3) { + [2]=> + int(100) + [98]=> + int(200) + [99]=> + int(300) + } +} diff --git a/tests/std/array/bug76713.phpt b/tests/std/array/bug76713.phpt new file mode 100644 index 00000000..9daae219 --- /dev/null +++ b/tests/std/array/bug76713.phpt @@ -0,0 +1,35 @@ +--TEST-- +Bug #76713 (Segmentation fault caused by property corruption) +--FILE-- +name; + } +} +function main() +{ + $obj = new Stdclass(); + $obj->prop = str_pad("a", 10, 'a'); + test($obj); + test($obj); + test($obj); + var_dump($obj->prop); + $obj2 = new C(); + $obj2->name = str_pad("b", 10, 'b'); + test($obj2); + test($obj2); + test($obj2); + var_dump($obj2->prop); +} +?> +--EXPECT-- +string(10) "aaaaaaaaaa" +string(10) "bbbbbbbbbb" diff --git a/tests/std/array/bug76778.phpt b/tests/std/array/bug76778.phpt new file mode 100644 index 00000000..e07b6f35 --- /dev/null +++ b/tests/std/array/bug76778.phpt @@ -0,0 +1,20 @@ +--TEST-- +Bug #76778 (array_reduce leaks memory if callback throws exception) +--SKIPIF-- + +--FILE-- + +--EXPECT-- +===DONE=== diff --git a/tests/std/array/bug77135.phpt b/tests/std/array/bug77135.phpt new file mode 100644 index 00000000..c524ba7a --- /dev/null +++ b/tests/std/array/bug77135.phpt @@ -0,0 +1,91 @@ +--TEST-- +Test extract() with $this +--SKIPIF-- + + +--FILE-- + EXTR_OVERWRITE, 'EXTR_SKIP' => EXTR_SKIP, 'EXTR_PREFIX_SAME' => EXTR_PREFIX_SAME, 'EXTR_PREFIX_ALL' => EXTR_PREFIX_ALL, 'EXTR_PREFIX_INVALID' => EXTR_PREFIX_INVALID, 'EXTR_IF_EXISTS' => EXTR_IF_EXISTS, 'EXTR_PREFIX_IF_EXISTS' => EXTR_PREFIX_IF_EXISTS]; + foreach ($options as $name => $flags) { + echo "{$name}\n"; + $this->handle($name, $flags); + $this->handle("{$name}_REFS", $flags | EXTR_REFS); + echo "\n"; + } + } + private function handle(string $name, int $flags): void + { + $array = ["this" => "value"]; + try { + $result = extract($array, $flags, "x"); + echo " extract() = {$result}\n"; + echo " \$this = " . get_class($this) . "\n"; + echo " \$v_this = " . (isset($x_this) ? $x_this : "NULL") . "\n"; + } catch (\Throwable $e) { + echo " Exception: " . $e->getMessage() . "\n"; + } + } +} +function main() +{ + (new Extract())->run(); +} +?> +--EXPECT-- +EXTR_OVERWRITE + Exception: Cannot re-assign $this + Exception: Cannot re-assign $this + +EXTR_SKIP + extract() = 0 + $this = Extract + $v_this = NULL + extract() = 0 + $this = Extract + $v_this = NULL + +EXTR_PREFIX_SAME + extract() = 1 + $this = Extract + $v_this = value + extract() = 1 + $this = Extract + $v_this = value + +EXTR_PREFIX_ALL + extract() = 1 + $this = Extract + $v_this = value + extract() = 1 + $this = Extract + $v_this = value + +EXTR_PREFIX_INVALID + extract() = 1 + $this = Extract + $v_this = value + extract() = 1 + $this = Extract + $v_this = value + +EXTR_IF_EXISTS + extract() = 0 + $this = Extract + $v_this = NULL + extract() = 0 + $this = Extract + $v_this = NULL + +EXTR_PREFIX_IF_EXISTS + extract() = 0 + $this = Extract + $v_this = NULL + extract() = 0 + $this = Extract + $v_this = NULL diff --git a/tests/std/array/bug77395.phpt b/tests/std/array/bug77395.phpt new file mode 100644 index 00000000..817b36f8 --- /dev/null +++ b/tests/std/array/bug77395.phpt @@ -0,0 +1,27 @@ +--TEST-- +Bug #77395 (segfault about array_multisort) +--SKIPIF-- +--FILE-- + 'bb'], ['aa' => 'bb']]; + try { + array_multisort(array_column($data, 'bb'), SORT_DESC, $data); + // PHP Warning error + } catch (\ValueError $e) { + echo $e->getMessage() . "\n"; + } +} +?> +--EXPECT-- +Array sizes are inconsistent diff --git a/tests/std/array/bug77669.phpt b/tests/std/array/bug77669.phpt new file mode 100644 index 00000000..c267d2b5 --- /dev/null +++ b/tests/std/array/bug77669.phpt @@ -0,0 +1,39 @@ +--TEST-- +Bug #77669: Crash in extract() when overwriting extracted array +--SKIPIF-- + +--FILE-- + +--EXPECT-- +===DONE=== diff --git a/tests/std/array/bug77793.phpt b/tests/std/array/bug77793.phpt new file mode 100644 index 00000000..bf5caa44 --- /dev/null +++ b/tests/std/array/bug77793.phpt @@ -0,0 +1,23 @@ +--TEST-- +Bug #77793: Segmentation fault in extract() when overwriting reference with itself +--SKIPIF-- + + +--FILE-- + $str . 'bar']; +$var = &$vars['var']; +extract($vars); +var_dump($vars, $var); + +?> +--EXPECT-- +array(1) { + ["var"]=> + &string(6) "foobar" +} +string(6) "foobar" diff --git a/tests/std/array/bug77931.phpt b/tests/std/array/bug77931.phpt new file mode 100644 index 00000000..d876d4b0 --- /dev/null +++ b/tests/std/array/bug77931.phpt @@ -0,0 +1,26 @@ +--TEST-- +Bug #77931: Warning for array_map mentions wrong type +--FILE-- +getMessage(), "\n"; +} +try { + array_map('trim', array(), array(), true); +} catch (TypeError $e) { + echo $e->getMessage(), "\n"; +} +try { + array_map('trim', array(), array(), array(), null); +} catch (TypeError $e) { + echo $e->getMessage(), "\n"; +} + +?> +--EXPECT-- +array_map(): Argument #3 must be of type array, int given +array_map(): Argument #4 must be of type array, true given +array_map(): Argument #5 must be of type array, null given diff --git a/tests/std/array/bug78759.phpt b/tests/std/array/bug78759.phpt new file mode 100644 index 00000000..4ab6414d --- /dev/null +++ b/tests/std/array/bug78759.phpt @@ -0,0 +1,20 @@ +--TEST-- +Bug #78759: array_search in $GLOBALS +--SKIPIF-- + + +--FILE-- + +--EXPECT-- +int(22) +string(1) "a" +string(1) "a" diff --git a/tests/std/array/bug79839.phpt b/tests/std/array/bug79839.phpt new file mode 100644 index 00000000..8cd49751 --- /dev/null +++ b/tests/std/array/bug79839.phpt @@ -0,0 +1,33 @@ +--TEST-- +Bug #79839: array_walk() does not respect property types +--SKIPIF-- + + +--FILE-- +getMessage(), "\n"; + } + var_dump($test); +} +?> +--EXPECT-- +Cannot assign array to reference held by property Test::$prop of type int +object(Test)#1 (1) { + ["prop"]=> + int(42) +} diff --git a/tests/std/array/bug79868.phpt b/tests/std/array/bug79868.phpt new file mode 100644 index 00000000..5c6267d6 --- /dev/null +++ b/tests/std/array/bug79868.phpt @@ -0,0 +1,15 @@ +--TEST-- +Bug #79868: Sorting with array_unique gives unwanted result +--FILE-- + +--EXPECT-- +array(2) { + [0]=> + string(1) "b" + [1]=> + string(1) "a" +} diff --git a/tests/std/array/bug79930.phpt b/tests/std/array/bug79930.phpt new file mode 100644 index 00000000..bb4e1dd8 --- /dev/null +++ b/tests/std/array/bug79930.phpt @@ -0,0 +1,33 @@ +--TEST-- +Bug #79930: array_merge_recursive() crashes when called with array with single reference +--FILE-- + $a . 'b', +]; + +// Create rc=1 reference. +array_walk($array, function () {}); + +$m = array_merge_recursive(['value' => 'a'], $array); + +var_dump($a, $array, $m); + +?> +--EXPECT-- +string(1) "a" +array(1) { + ["value"]=> + string(2) "ab" +} +array(1) { + ["value"]=> + array(2) { + [0]=> + string(1) "a" + [1]=> + string(2) "ab" + } +} diff --git a/tests/std/array/compact.phpt b/tests/std/array/compact.phpt new file mode 100644 index 00000000..c10c7dd1 --- /dev/null +++ b/tests/std/array/compact.phpt @@ -0,0 +1,42 @@ +--TEST-- +compact() +--SKIPIF-- + + +--FILE-- + +--EXPECTF-- +Warning: compact(): Undefined variable $c\u0327ity in %s on line %d +array(2) { + ["event"]=> + string(8) "SIGGRAPH" + ["state"]=> + string(2) "CA" +} + +Warning: compact(): Argument #1 must be string or array of strings, true given in %s on line %d + +Warning: compact(): Argument #2 must be string or array of strings, int given in %s on line %d +array(1) { + ["bar"]=> + string(3) "baz" +} diff --git a/tests/std/array/compact_basic.phpt b/tests/std/array/compact_basic.phpt new file mode 100644 index 00000000..42f1ccce --- /dev/null +++ b/tests/std/array/compact_basic.phpt @@ -0,0 +1,78 @@ +--TEST-- +Test compact() function : basic functionality +--SKIPIF-- + + +--FILE-- +"val"); +$e=NULL; +$f="string"; + +// simple array test +var_dump (compact(array("a", "b", "c", "d", "e", "f"))); +// simple parameter test +var_dump (compact("a", "b", "c", "d", "e", "f")); +var_dump (compact(array("keyval"=>"a", "b"=>"b"))); +var_dump(compact(array("g"))); + +echo "Done"; +?> +--EXPECTF-- +*** Testing compact() : basic functionality *** +array(6) { + ["a"]=> + int(1) + ["b"]=> + float(0.2) + ["c"]=> + bool(true) + ["d"]=> + array(1) { + ["key"]=> + string(3) "val" + } + ["e"]=> + NULL + ["f"]=> + string(6) "string" +} +array(6) { + ["a"]=> + int(1) + ["b"]=> + float(0.2) + ["c"]=> + bool(true) + ["d"]=> + array(1) { + ["key"]=> + string(3) "val" + } + ["e"]=> + NULL + ["f"]=> + string(6) "string" +} +array(2) { + ["a"]=> + int(1) + ["b"]=> + float(0.2) +} + +Warning: compact(): Undefined variable $g in %s on line %d +array(0) { +} +Done diff --git a/tests/std/array/compact_no_this.phpt b/tests/std/array/compact_no_this.phpt new file mode 100644 index 00000000..aa60e846 --- /dev/null +++ b/tests/std/array/compact_no_this.phpt @@ -0,0 +1,27 @@ +--TEST-- +compact() without object context +--SKIPIF-- + +--FILE-- +test() +); + +var_dump(compact('this')); + +var_dump((function(){ return compact('this'); })()); + +?> +--EXPECT-- +array(0) { +} +array(0) { +} +array(0) { +} diff --git a/tests/std/array/compact_order.phpt b/tests/std/array/compact_order.phpt new file mode 100644 index 00000000..bf6051cc --- /dev/null +++ b/tests/std/array/compact_order.phpt @@ -0,0 +1,25 @@ +--TEST-- +compact() and hashmap order +--FILE-- + +--EXPECT-- +array(2) { + ["foo"]=> + NULL + ["bar"]=> + NULL +} +array(2) { + ["bar"]=> + NULL + ["foo"]=> + NULL +} diff --git a/tests/std/array/compact_this.phpt b/tests/std/array/compact_this.phpt new file mode 100644 index 00000000..20657e90 --- /dev/null +++ b/tests/std/array/compact_this.phpt @@ -0,0 +1,46 @@ +--TEST-- +compact() with object context +--FILE-- +test() +); + +var_dump( + (new class { + function test(){ + return compact([['this']]); + } + })->test() +); + +var_dump( + (new class { + function test(){ + return (function(){ return compact('this'); })(); + } + })->test() +); + +?> +--EXPECTF-- +array(1) { + ["this"]=> + object(%s)#1 (0) { + } +} +array(1) { + ["this"]=> + object(%s)#1 (0) { + } +} +array(1) { + ["this"]=> + object(%s)#1 (0) { + } +} diff --git a/tests/std/array/compact_variation1.phpt b/tests/std/array/compact_variation1.phpt new file mode 100644 index 00000000..f07ccd93 --- /dev/null +++ b/tests/std/array/compact_variation1.phpt @@ -0,0 +1,46 @@ +--TEST-- +Test compact() function : usage variations - arrays containing references. +--SKIPIF-- + + +--FILE-- +getMessage() . "\n"; +} + +try { + var_dump(compact($arr2)); +} catch (Error $e) { + echo $e->getMessage() . "\n"; +} + +var_dump(compact($arr3)); + +?> +--EXPECT-- +*** Testing compact() : usage variations - arrays containing references *** +Recursion detected +Recursion detected +array(1) { + ["c"]=> + int(3) +} diff --git a/tests/std/array/compact_variation2.phpt b/tests/std/array/compact_variation2.phpt new file mode 100644 index 00000000..48d772fc --- /dev/null +++ b/tests/std/array/compact_variation2.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test compact() function: ensure compact() doesn't pick up variables declared outside of current scope. +--SKIPIF-- + + +--FILE-- + +--EXPECTF-- +*** Testing compact() : usage variations - variables outside of current scope *** + +Warning: compact(): Undefined variable $a in %s on line %d +array(2) { + ["b"]=> + string(3) "f.b" + ["c"]=> + string(3) "f.c" +} + +Warning: compact(): Undefined variable $a in %s on line %d +array(2) { + ["b"]=> + string(3) "f.b" + ["c"]=> + string(3) "f.c" +} diff --git a/tests/std/array/compare_function.inc b/tests/std/array/compare_function.inc new file mode 100644 index 00000000..4fa672e7 --- /dev/null +++ b/tests/std/array/compare_function.inc @@ -0,0 +1,13 @@ + diff --git a/tests/std/array/count_basic.phpt b/tests/std/array/count_basic.phpt new file mode 100644 index 00000000..6d778b4b --- /dev/null +++ b/tests/std/array/count_basic.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test count() function : basic functionality +--FILE-- + +--EXPECT-- +*** Testing count() : basic functionality *** + +-- One Dimensional Array: -- +int(3) + +-- Two Dimensional Array: -- +$mode = COUNT_NORMAL: int(3) +$mode = 0: int(3) +$mode = COUNT_RECURSIVE: int(6) +$mode = 1: int(6) +Done diff --git a/tests/std/array/count_invalid.phpt b/tests/std/array/count_invalid.phpt new file mode 100644 index 00000000..061ed5fa --- /dev/null +++ b/tests/std/array/count_invalid.phpt @@ -0,0 +1,56 @@ +--TEST-- +Only arrays and countable objects can be counted +--SKIPIF-- +--FILE-- +getMessage() . \PHP_EOL; +} + +try { + $result = count("string"); + var_dump($result); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} + +try { + $result = count(123); + var_dump($result); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} + +try { + $result = count(true); + var_dump($result); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} + +try { + $result = count(false); + var_dump($result); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} + +try { + $result = count((object) []); + var_dump($result); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} + +?> +--EXPECT-- +count(): Argument #1 ($value) must be of type Countable|array +count(): Argument #1 ($value) must be of type Countable|array +count(): Argument #1 ($value) must be of type Countable|array +count(): Argument #1 ($value) must be of type Countable|array +count(): Argument #1 ($value) must be of type Countable|array +int(1) diff --git a/tests/std/array/count_invalid_mode.phpt b/tests/std/array/count_invalid_mode.phpt new file mode 100644 index 00000000..ef4b2655 --- /dev/null +++ b/tests/std/array/count_invalid_mode.phpt @@ -0,0 +1,34 @@ +--TEST-- +Test count() function : invalid modes in weak type mode +--SKIPIF-- +--FILE-- +getMessage() . \PHP_EOL; + } +} +?> +--EXPECT-- +int(0) +int(0) +int(0) +int(0) +int(0) +int(0) +int(0) +int(0) diff --git a/tests/std/array/count_recursive.phpt b/tests/std/array/count_recursive.phpt new file mode 100644 index 00000000..e85c08a5 --- /dev/null +++ b/tests/std/array/count_recursive.phpt @@ -0,0 +1,131 @@ +--TEST-- +Test count() function +--SKIPIF-- + +--FILE-- + 1, "b" => 2, array("c" => 3, array("d" => 5))); + print "COUNT_NORMAL: should be 3, is " . count($arr, COUNT_NORMAL) . "\n"; + print "COUNT_RECURSIVE: should be 6, is " . count($arr, COUNT_RECURSIVE) . "\n"; + print "-- Testing various types with no second argument --\n"; + print "COUNT_NORMAL: should be 2, is " . count(array("a", array("b"))) . "\n"; + $arr = array('a' => array(NULL, NULL, NULL), 1 => array(NULL => 1, 1 => NULL), array(array(array(array(array(NULL)))))); + print "-- Testing really cool arrays --\n"; + print "COUNT_NORMAL: should be 3, is " . count($arr, COUNT_NORMAL) . "\n"; + print "COUNT_RECURSIVE: should be 13, is " . count($arr, COUNT_RECURSIVE) . "\n"; + echo "\n*** Testing possible variations of count() function on arrays ***"; + $count_array = array(array(), array(1 => "string"), array("" => "string", 0 => "a", NULL => "b", -1 => "c", array(array(array(NULL)))), array(-2 => 12, array(array(1, 2, array(array("0"))))), array("a" => 1, "b" => -2.344, "b" => "string", "c" => NULL, "d" => -2.344), array(4 => 1, 3 => -2.344, "3" => "string", "2" => NULL, 1 => -2.344, array()), array(TRUE => TRUE, FALSE => FALSE, "" => "", " " => " ", NULL => NULL, "\x000" => "\x000", "\x00" => "\x00"), array(NULL, 1 => "Hi", "string" => "hello", array("" => "World", "-2.34" => "a", "0" => "b"))); + $i = 0; + foreach ($count_array as $count_value) { + echo "\n-- Iteration {$i} --\n"; + print "COUNT_NORMAL is " . count($count_value, COUNT_NORMAL) . "\n"; + print "COUNT_RECURSIVE is " . count($count_value, COUNT_RECURSIVE) . "\n"; + $i++; + } + print "\n-- Testing count() on an empty sub-array --\n"; + $arr = array(1, array(3, 4, array())); + print "COUNT_NORMAL: should be 2, is " . count($arr, COUNT_NORMAL) . "\n"; + print "COUNT_RECURSIVE: should be 5, is " . count($arr, COUNT_RECURSIVE) . "\n"; + echo "\n-- Testing count() on objects with Countable interface --\n"; + $obj = new count_class(); + print "COUNT_NORMAL: should be 3, is " . count($obj) . "\n"; + echo "\n-- Testing count() on resource type --\n"; + $resource1 = fopen(__FILE__, "r"); + // Creating file(stream type) resource + $resource2 = opendir("."); + // Creating dir resource + /* creating an array with resources as elements */ + $arr_resource = array("a" => $resource1, "b" => $resource2); + var_dump(count($arr_resource)); + echo "\n-- Testing count() on arrays containing references --\n"; + $arr = array(1, array("a", "b", "c")); + $arr[2] =& $arr[1]; + echo "Count normal" . \PHP_EOL; + var_dump(count($arr, COUNT_NORMAL)); + echo "Count recursive" . \PHP_EOL; + var_dump(count($arr, COUNT_RECURSIVE)); + /* closing the resource handles */ + fclose($resource1); + closedir($resource2); +} +?> +--EXPECT-- +*** Testing basic functionality of count() function *** +-- Testing arrays -- +COUNT_NORMAL: should be 2, is 2 +COUNT_RECURSIVE: should be 8, is 8 +-- Testing hashes -- +COUNT_NORMAL: should be 3, is 3 +COUNT_RECURSIVE: should be 6, is 6 +-- Testing various types with no second argument -- +COUNT_NORMAL: should be 2, is 2 +-- Testing really cool arrays -- +COUNT_NORMAL: should be 3, is 3 +COUNT_RECURSIVE: should be 13, is 13 + +*** Testing possible variations of count() function on arrays *** +-- Iteration 0 -- +COUNT_NORMAL is 0 +COUNT_RECURSIVE is 0 + +-- Iteration 1 -- +COUNT_NORMAL is 1 +COUNT_RECURSIVE is 1 + +-- Iteration 2 -- +COUNT_NORMAL is 4 +COUNT_RECURSIVE is 7 + +-- Iteration 3 -- +COUNT_NORMAL is 2 +COUNT_RECURSIVE is 8 + +-- Iteration 4 -- +COUNT_NORMAL is 4 +COUNT_RECURSIVE is 4 + +-- Iteration 5 -- +COUNT_NORMAL is 5 +COUNT_RECURSIVE is 5 + +-- Iteration 6 -- +COUNT_NORMAL is 6 +COUNT_RECURSIVE is 6 + +-- Iteration 7 -- +COUNT_NORMAL is 4 +COUNT_RECURSIVE is 7 + +-- Testing count() on an empty sub-array -- +COUNT_NORMAL: should be 2, is 2 +COUNT_RECURSIVE: should be 5, is 5 + +-- Testing count() on objects with Countable interface -- +COUNT_NORMAL: should be 3, is 3 + +-- Testing count() on resource type -- +int(2) + +-- Testing count() on arrays containing references -- +Count normal +int(3) +Count recursive +int(9) diff --git a/tests/std/array/count_symbol_table.phpt b/tests/std/array/count_symbol_table.phpt new file mode 100644 index 00000000..0fe69871 --- /dev/null +++ b/tests/std/array/count_symbol_table.phpt @@ -0,0 +1,25 @@ +--TEST-- +Test count() function : count on symbol table +--SKIPIF-- + + +--FILE-- + +--EXPECT-- +int(2) +int(1) diff --git a/tests/std/array/count_variation3.phpt b/tests/std/array/count_variation3.phpt new file mode 100644 index 00000000..37d6fb63 --- /dev/null +++ b/tests/std/array/count_variation3.phpt @@ -0,0 +1,34 @@ +--TEST-- +Test count() function : usage variations - Infinitely recursive array +--FILE-- + +--EXPECTF-- +*** Testing count() : usage variations *** + +-- $mode not set: -- +int(4) + +-- $mode = 1: -- + +Warning:%S Recursion detected in %s on line %d +int(4) +Done diff --git a/tests/std/array/current_basic.phpt b/tests/std/array/current_basic.phpt new file mode 100644 index 00000000..48d4e5a0 --- /dev/null +++ b/tests/std/array/current_basic.phpt @@ -0,0 +1,25 @@ +--TEST-- +Test current() function : basic functionality +--FILE-- + 3); +var_dump(current($array)); +next($array); +var_dump(current($array)); +end($array); +var_dump(current($array)); +next($array); +var_dump(current($array)); +?> +--EXPECT-- +*** Testing current() : basic functionality *** +string(4) "zero" +string(3) "one" +int(3) +bool(false) diff --git a/tests/std/array/current_variation2.phpt b/tests/std/array/current_variation2.phpt new file mode 100644 index 00000000..723841d5 --- /dev/null +++ b/tests/std/array/current_variation2.phpt @@ -0,0 +1,112 @@ +--TEST-- +Test current() function : usage variations - arrays containing different data types +--SKIPIF-- + + +--FILE-- + array(0, 1, 12345, -2345), + // float data + /*2*/ + 'float' => array(10.5, -10.5, 123456789000.0, 1.23456789E-9, 0.5), + // null data + /*3*/ + 'null' => array(NULL, null), + // boolean data + /*4*/ + 'bool' => array(true, false, TRUE, FALSE), + // empty data + /*5*/ + 'empty string' => array("", ''), + /*6*/ + 'empty array' => array(), + // string data + /*7*/ + 'string' => array("string", 'string', $heredoc), + // object data + /*8*/ + 'object' => array(new classA()), + // undefined data + /*9*/ + 'undefined' => array(@$undefined_var), + // unset data + /*10*/ + 'unset' => array(@$unset_var), + // resource variable + /*11*/ + 'resource' => array($fp), + ); + // loop through each element of $inputs to check the behavior of current() + $iterator = 1; + foreach ($inputs as $key => $input) { + echo "\n-- Iteration {$iterator} : {$key} data --\n"; + var_dump(current($input)); + $iterator++; + } + fclose($fp); +} +?> +--EXPECTF-- +*** Testing current() : usage variations *** + +-- Iteration 1 : int data -- +int(0) + +-- Iteration 2 : float data -- +float(10.5) + +-- Iteration 3 : null data -- +NULL + +-- Iteration 4 : bool data -- +bool(true) + +-- Iteration 5 : empty string data -- +string(0) "" + +-- Iteration 6 : empty array data -- +bool(false) + +-- Iteration 7 : string data -- +string(6) "string" + +-- Iteration 8 : object data -- +object(classA)#%d (0) { +} + +-- Iteration 9 : undefined data -- +NULL + +-- Iteration 10 : unset data -- +NULL + +-- Iteration 11 : resource data -- +resource(%d) of type (stream) diff --git a/tests/std/array/current_variation3.phpt b/tests/std/array/current_variation3.phpt new file mode 100644 index 00000000..cba2fa2a --- /dev/null +++ b/tests/std/array/current_variation3.phpt @@ -0,0 +1,34 @@ +--TEST-- +Test current() function : usage variations - referenced variables +--FILE-- + +--EXPECT-- +*** Testing current() : usage variations *** + +-- Initial position of internal pointer -- +string(4) "zero" + +-- Position after calling next() -- +$array1: string(3) "one" +$array2: string(3) "one" diff --git a/tests/std/array/current_variation4.phpt b/tests/std/array/current_variation4.phpt new file mode 100644 index 00000000..8f24296f --- /dev/null +++ b/tests/std/array/current_variation4.phpt @@ -0,0 +1,63 @@ +--TEST-- +Test current() function : usage variations - multi-dimensional arrays +--FILE-- + +--EXPECT-- +*** Testing current() : usage variations *** + +-- Two Dimensional Array -- +Initial Position: string(4) "zero" +Next Position: array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +End Position: string(3) "two" + +-- Access an Array Within an Array -- +Initial Position: int(1) + +-- Recursive, Multidimensional Array -- +Current Position: string(3) "two" +string(3) "two" +int(1) diff --git a/tests/std/array/current_variation5.phpt b/tests/std/array/current_variation5.phpt new file mode 100644 index 00000000..c5ef89b7 --- /dev/null +++ b/tests/std/array/current_variation5.phpt @@ -0,0 +1,43 @@ +--TEST-- +Test current() function : usage variations - reference & normal parameters +--FILE-- + +--EXPECT-- +*** Testing current() : usage variations *** + +-- Function: reference parameter -- +string(3) "yes" +string(5) "maybe" +string(5) "maybe" +string(2) "no" + +-- Function: normal parameter -- +string(3) "yes" +string(5) "maybe" +string(5) "maybe" +string(2) "no" diff --git a/tests/std/array/current_variation6.phpt b/tests/std/array/current_variation6.phpt new file mode 100644 index 00000000..d7fb0dcc --- /dev/null +++ b/tests/std/array/current_variation6.phpt @@ -0,0 +1,20 @@ +--TEST-- +Test current() function : internal pointer maintenance at the end of array +--FILE-- + 1, "bar" => 2, "baz" => 3]; +reset($array); +while ($cur = current($array)) { + var_dump($cur); + next($array); +} + +unset($array["baz"]); +$array[] = 4; +var_dump(current($array)); +?> +--EXPECT-- +int(1) +int(2) +int(3) +int(4) diff --git a/tests/std/array/data.inc b/tests/std/array/data.inc new file mode 100644 index 00000000..c8ad4fe2 --- /dev/null +++ b/tests/std/array/data.inc @@ -0,0 +1,13 @@ +'PHP: Hypertext Preprocessor', + 5=>'Test', + 'test'=>27, + 1000=>'test', + "-1000"=>array('banana', 'orange'), + 'monkey', + $tmp=>-1/3 +); +?> diff --git a/tests/std/array/end.phpt b/tests/std/array/end.phpt new file mode 100644 index 00000000..5876ed2f --- /dev/null +++ b/tests/std/array/end.phpt @@ -0,0 +1,177 @@ +--TEST-- +Test end() function +--SKIPIF-- + +--INI-- +precision=14 +--FILE-- + "A", 2 => "B", "C" => 3, 4 => 4, "one" => 1, "" => NULL), array(1, array(1, 2 => 3), "one" => 1, "5" => 5), array(-1, -2, -3, -4, "-0.005" => "neg0.005", 2.0 => "float2", "neg.9" => -0.9), array(1.0005, 2.0, -3.0, -4.9999999), array(true, false), array("PHP", "Web2.0", "SOA"), array(1, array()), array(1, 2, ""), array(" "), array(2147483647, 2147483648, -2147483647, -2147483648), array(0x7fffffff, -0x80000000, 017777777777, -020000000000), array(-670.0, -4100.03, 1.0E-5, -100000.0, 2.0)); + /* loop through $arrays to print the last element of each sub-array */ + echo "*** Testing end() on different arrays ***\n"; + $counter = 1; + foreach ($arrays as $sub_array) { + echo "-- Iteration {$counter} --\n"; + var_dump(end($sub_array)); + /* ensure that internal pointer is moved to last element */ + var_dump(current($sub_array)); + $counter++; + } + /* checking for end() on sub-arrays */ + echo "\n*** Testing end() with sub-arrays ***\n"; + $test_array = array(1, array(1 => "one", "two" => 2, "" => "f")); + var_dump(end($test_array)); + var_dump(end($test_array[1])); + /* checking working of end() when array elements are deleted */ + echo "\n*** Testing end() when array elements are deleted ***\n"; + $array_test = array("a", "b", "d", 7, "u" => "U", -4, "-.008" => "neg.008"); + // remove first element from array + echo "\n-- Remove first element from array --\n"; + unset($array_test[0]); + var_dump(end($array_test)); + // remove last element from array, rewind and check end() + echo "\n-- Remove last element from array --\n"; + unset($array_test['-.008']); + var_dump(end($array_test)); + reset($array_test); + var_dump(end($array_test)); + // remove any element !first, !last, rewind and check end() + echo "\n-- Remove any element from array apart from first and last element --\n"; + unset($array_test[7]); + var_dump(end($array_test)); + var_dump(reset($array_test)); + var_dump(end($array_test)); + /* Checking on OBJECTS type */ + echo "\n*** Testing end() on objects ***\n"; + $object1 = new foo(); + //new object created + $object2 = new foo1(); + $array_object = array(); + $array_object[0] =& $object1; + $array_object[1] =& $object2; + var_dump(end($array_object)); + var_dump($array_object); + /* Checking on RESOURCE type */ + echo "\n*** Testing end() on resource type ***\n"; + //file type resource + $file_handle = fopen(__FILE__, "r"); + //directory type resource + $dir_handle = opendir(__DIR__); + //store resources in array + $resources = array($file_handle, $dir_handle); + var_dump(end($resources)); + var_dump(current($resources)); + echo "Done\n"; + /* cleaning resource handles */ + fclose($file_handle); + //file resource handle deleted + closedir($dir_handle); +} +?> +--EXPECTF-- +*** Testing end() on different arrays *** +-- Iteration 1 -- +int(0) +int(0) +-- Iteration 2 -- +int(100) +int(100) +-- Iteration 3 -- +string(1) "y" +string(1) "y" +-- Iteration 4 -- +NULL +NULL +-- Iteration 5 -- +int(5) +int(5) +-- Iteration 6 -- +float(-0.9) +float(-0.9) +-- Iteration 7 -- +float(-4.9999999) +float(-4.9999999) +-- Iteration 8 -- +bool(false) +bool(false) +-- Iteration 9 -- +string(3) "SOA" +string(3) "SOA" +-- Iteration 10 -- +array(0) { +} +array(0) { +} +-- Iteration 11 -- +string(0) "" +string(0) "" +-- Iteration 12 -- +string(1) " " +string(1) " " +-- Iteration 13 -- +float(-2147483648) +float(-2147483648) +-- Iteration 14 -- +float(-2147483648) +float(-2147483648) +-- Iteration 15 -- +float(2) +float(2) + +*** Testing end() with sub-arrays *** +array(3) { + [1]=> + string(3) "one" + ["two"]=> + int(2) + [""]=> + string(1) "f" +} +string(1) "f" + +*** Testing end() when array elements are deleted *** + +-- Remove first element from array -- +string(7) "neg.008" + +-- Remove last element from array -- +int(-4) +int(-4) + +-- Remove any element from array apart from first and last element -- +int(-4) +string(1) "b" +int(-4) + +*** Testing end() on objects *** +object(foo1)#%d (0) { +} +array(2) { + [0]=> + &object(foo)#%d (0) { + } + [1]=> + &object(foo1)#%d (0) { + } +} + +*** Testing end() on resource type *** +resource(%d) of type (stream) +resource(%d) of type (stream) +Done diff --git a/tests/std/array/end_64bit.phpt b/tests/std/array/end_64bit.phpt new file mode 100644 index 00000000..33383ef5 --- /dev/null +++ b/tests/std/array/end_64bit.phpt @@ -0,0 +1,173 @@ +--TEST-- +Test end() function +--SKIPIF-- + +--INI-- +precision=14 +--FILE-- + "A", 2 => "B", "C" => 3, 4 => 4, "one" => 1, "" => NULL), array(1, array(1, 2 => 3), "one" => 1, "5" => 5), array(-1, -2, -3, -4, "-0.005" => "neg0.005", 2 => "float2", "neg.9" => -0.9), array(1.0005, 2.0, -3.0, -4.9999999), array(true, false), array("PHP", "Web2.0", "SOA"), array(1, array()), array(1, 2, ""), array(" "), array(2147483647, 2147483648, -2147483647, -2147483648), array(0x7fffffff, -0x80000000, 017777777777, -020000000000), array(-670.0, -4100.03, 1.0E-5, -100000.0, 2.0)); + /* loop through $arrays to print the last element of each sub-array */ + echo "*** Testing end() on different arrays ***\n"; + $counter = 1; + foreach ($arrays as $sub_array) { + echo "-- Iteration {$counter} --\n"; + var_dump(end($sub_array)); + /* ensure that internal pointer is moved to last element */ + var_dump(current($sub_array)); + $counter++; + } + /* checking for end() on sub-arrays */ + echo "\n*** Testing end() with sub-arrays ***\n"; + $test_array = array(1, array(1 => "one", "two" => 2, "" => "f")); + var_dump(end($test_array)); + var_dump(end($test_array[1])); + /* checking working of end() when array elements are deleted */ + echo "\n*** Testing end() when array elements are deleted ***\n"; + $array_test = array("a", "b", "d", 7, "u" => "U", -4, "-.008" => "neg.008"); + // remove first element from array + echo "\n-- Remove first element from array --\n"; + unset($array_test[0]); + var_dump(end($array_test)); + // remove last element from array, rewind and check end() + echo "\n-- Remove last element from array --\n"; + unset($array_test['-.008']); + var_dump(end($array_test)); + reset($array_test); + var_dump(end($array_test)); + // remove any element !first, !last, rewind and check end() + echo "\n-- Remove any element from array apart from first and last element --\n"; + unset($array_test[7]); + var_dump(end($array_test)); + var_dump(reset($array_test)); + var_dump(end($array_test)); + /* Checking on OBJECTS type */ + echo "\n*** Testing end() on objects ***\n"; + $object1 = new foo(); + //new object created + $object2 = new foo1(); + $array_object = array(); + $array_object[0] =& $object1; + $array_object[1] =& $object2; + var_dump(end($array_object)); + var_dump($array_object); + /* Checking on RESOURCE type */ + echo "\n*** Testing end() on resource type ***\n"; + //file type resource + $file_handle = fopen(__FILE__, "r"); + //directory type resource + $dir_handle = opendir(__DIR__); + //store resources in array + $resources = array($file_handle, $dir_handle); + var_dump(end($resources)); + var_dump(current($resources)); + echo "Done\n"; +} +?> +--EXPECTF-- +*** Testing end() on different arrays *** +-- Iteration 1 -- +int(0) +int(0) +-- Iteration 2 -- +int(100) +int(100) +-- Iteration 3 -- +string(1) "y" +string(1) "y" +-- Iteration 4 -- +NULL +NULL +-- Iteration 5 -- +int(5) +int(5) +-- Iteration 6 -- +float(-0.9) +float(-0.9) +-- Iteration 7 -- +float(-4.9999999) +float(-4.9999999) +-- Iteration 8 -- +bool(false) +bool(false) +-- Iteration 9 -- +string(3) "SOA" +string(3) "SOA" +-- Iteration 10 -- +array(0) { +} +array(0) { +} +-- Iteration 11 -- +string(0) "" +string(0) "" +-- Iteration 12 -- +string(1) " " +string(1) " " +-- Iteration 13 -- +int(-2147483648) +int(-2147483648) +-- Iteration 14 -- +int(-2147483648) +int(-2147483648) +-- Iteration 15 -- +float(2) +float(2) + +*** Testing end() with sub-arrays *** +array(3) { + [1]=> + string(3) "one" + ["two"]=> + int(2) + [""]=> + string(1) "f" +} +string(1) "f" + +*** Testing end() when array elements are deleted *** + +-- Remove first element from array -- +string(7) "neg.008" + +-- Remove last element from array -- +int(-4) +int(-4) + +-- Remove any element from array apart from first and last element -- +int(-4) +string(1) "b" +int(-4) + +*** Testing end() on objects *** +object(foo1)#%d (0) { +} +array(2) { + [0]=> + &object(foo)#%d (0) { + } + [1]=> + &object(foo1)#%d (0) { + } +} + +*** Testing end() on resource type *** +resource(%d) of type (stream) +resource(%d) of type (stream) +Done diff --git a/tests/std/array/end_basic.phpt b/tests/std/array/end_basic.phpt new file mode 100644 index 00000000..04c49e1c --- /dev/null +++ b/tests/std/array/end_basic.phpt @@ -0,0 +1,39 @@ +--TEST-- +Test end() function : basic functionality +--FILE-- + 'two'); + +echo "\n-- Initial Position: --\n"; +echo key($array) . " => " . current($array) . "\n"; + +echo "\n-- Call to end() --\n"; +var_dump(end($array)); + +echo "\n-- Current Position: --\n"; +echo key($array) . " => " . current($array) . "\n"; + +echo "\n-- Add a new element to array --\n"; +$array[2] = 'foo'; +var_dump(end($array)); +?> +--EXPECT-- +*** Testing end() : basic functionality *** + +-- Initial Position: -- +0 => zero + +-- Call to end() -- +string(3) "two" + +-- Current Position: -- +200 => two + +-- Add a new element to array -- +string(3) "foo" diff --git a/tests/std/array/end_variation2.phpt b/tests/std/array/end_variation2.phpt new file mode 100644 index 00000000..3bf399a4 --- /dev/null +++ b/tests/std/array/end_variation2.phpt @@ -0,0 +1,36 @@ +--TEST-- +Test end() function : usage variations - Multi-dimensional arrays +--FILE-- + 'z', array(9, 8, 7)); + +echo "\n-- Pass a two-dimensional array as \$array_arg --\n"; +var_dump(end($array_arg)); + +echo "\n-- Pass a sub-array as \$array_arg --\n"; +var_dump(end($array_arg[0])); +?> +--EXPECT-- +*** Testing end() : usage variations *** + +-- Pass a two-dimensional array as $array_arg -- +array(3) { + [0]=> + int(9) + [1]=> + int(8) + [2]=> + int(7) +} + +-- Pass a sub-array as $array_arg -- +int(7) diff --git a/tests/std/array/end_variation3.phpt b/tests/std/array/end_variation3.phpt new file mode 100644 index 00000000..8d2b78ab --- /dev/null +++ b/tests/std/array/end_variation3.phpt @@ -0,0 +1,34 @@ +--TEST-- +Test end() function : usage variations - Referenced variables +--FILE-- + +--EXPECT-- +*** Testing end() : usage variations *** + +-- Initial position of internal pointer -- +string(4) "zero" + +-- Position after calling end() -- +$array1: string(3) "two" +$array2: string(3) "two" diff --git a/tests/std/array/extract_error.phpt b/tests/std/array/extract_error.phpt new file mode 100644 index 00000000..594f158d --- /dev/null +++ b/tests/std/array/extract_error.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test extract() function (error conditions) +--SKIPIF-- + + +--FILE-- +getMessage() . "\n"; +} + +try { + var_dump( extract($arr, 7 , "wddr") ); +} catch (\ValueError $e) { + echo $e->getMessage() . "\n"; +} + +/* Two Arguments, second as prefix but without prefix string as third argument */ +try { + var_dump( extract($arr,EXTR_PREFIX_IF_EXISTS) ); +} catch (\ValueError $e) { + echo $e->getMessage() . "\n"; +} + +?> +--EXPECT-- +*** Testing Error Conditions *** +extract(): Argument #2 ($flags) must be a valid extract type +extract(): Argument #2 ($flags) must be a valid extract type +extract(): Argument #3 ($prefix) is required when using this extract type diff --git a/tests/std/array/extract_error_variation1.phpt b/tests/std/array/extract_error_variation1.phpt new file mode 100644 index 00000000..224f31a6 --- /dev/null +++ b/tests/std/array/extract_error_variation1.phpt @@ -0,0 +1,19 @@ +--TEST-- +Test extract() function - error condition - Invalid prefix. +--SKIPIF-- + + +--FILE-- + "one", "2" => "two", "3" => "three", "4" => "four", "5" => "five"]; + +try { + extract($a, EXTR_PREFIX_ALL, '85bogus'); +} catch (\ValueError $e) { + echo $e->getMessage(); +} +?> +--EXPECT-- +extract(): Argument #3 ($prefix) must be a valid identifier diff --git a/tests/std/array/extract_safety.phpt b/tests/std/array/extract_safety.phpt new file mode 100644 index 00000000..12e9ef5a --- /dev/null +++ b/tests/std/array/extract_safety.phpt @@ -0,0 +1,28 @@ +--TEST-- +Test extract() for overwrite of GLOBALS +--SKIPIF-- + + +--FILE-- + "bar"); +var_dump(extract(array("GLOBALS" => $splat, EXTR_OVERWRITE))); + +unset ($splat); + +var_dump($GLOBALS["str"]); + +echo "\nDone"; +?> +--EXPECT-- +string(4) "John" +int(1) +string(4) "John" + +Done diff --git a/tests/std/array/extract_typed_ref.phpt b/tests/std/array/extract_typed_ref.phpt new file mode 100644 index 00000000..9f9b1544 --- /dev/null +++ b/tests/std/array/extract_typed_ref.phpt @@ -0,0 +1,31 @@ +--TEST-- +extract() into typed references must respect their type +--SKIPIF-- + + +--FILE-- +i; + $s =& $test->s; + try { + extract(['i' => 'foo', 's' => 42]); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + var_dump($test->i, $test->s); +} +?> +--EXPECT-- +Cannot assign string to reference held by property Test::$i of type int +int(0) +string(0) "" diff --git a/tests/std/array/extract_variation1.phpt b/tests/std/array/extract_variation1.phpt new file mode 100644 index 00000000..c37a5128 --- /dev/null +++ b/tests/std/array/extract_variation1.phpt @@ -0,0 +1,31 @@ +--TEST-- +Test extract() function (variation 1) +--SKIPIF-- + + +--FILE-- + +--EXPECTF-- +int(4) +string(4) "John" +int(%d) +int(4) +string(4) "John" + +Done diff --git a/tests/std/array/extract_variation10.phpt b/tests/std/array/extract_variation10.phpt new file mode 100644 index 00000000..2e6c0c9d --- /dev/null +++ b/tests/std/array/extract_variation10.phpt @@ -0,0 +1,18 @@ +--TEST-- +Test extract() function - ensure EXTR_REFS doesn't mess with isRef flag on COW references to array elements. +--SKIPIF-- + + +--FILE-- + 'original.foo'); +$nonref = $a['foo']; +$ref = &$a; +extract($a, EXTR_REFS); +$a['foo'] = 'changed.foo'; +var_dump($nonref); +?> +--EXPECT-- +string(12) "original.foo" diff --git a/tests/std/array/extract_variation11.phpt b/tests/std/array/extract_variation11.phpt new file mode 100644 index 00000000..208ded28 --- /dev/null +++ b/tests/std/array/extract_variation11.phpt @@ -0,0 +1,18 @@ +--TEST-- +Test extract() function - ensure EXTR_REFS works when array is referenced and keys clash with variables in current scope. +--SKIPIF-- + + +--FILE-- + 'original.foo'); +$ref = &$a; +$foo = 'test'; +extract($a, EXTR_OVERWRITE|EXTR_REFS); +$foo = 'changed.foo'; +var_dump($a['foo']); +?> +--EXPECT-- +string(11) "changed.foo" diff --git a/tests/std/array/extract_variation2.phpt b/tests/std/array/extract_variation2.phpt new file mode 100644 index 00000000..657dc78b --- /dev/null +++ b/tests/std/array/extract_variation2.phpt @@ -0,0 +1,74 @@ +--TEST-- +Test extract() function (variation 2) +--SKIPIF-- + + +--FILE-- + +--EXPECT-- +-- Iteration 0 -- +int(0) +int(0) +int(0) +int(0) +int(0) +int(0) +int(0) +int(0) +int(0) + +-- Iteration 1 -- +int(0) +int(0) +int(0) +int(0) +int(9) +int(0) +int(9) +int(9) +int(0) + +-- Iteration 2 -- +int(0) +int(0) +int(0) +int(0) +int(5) +int(0) +int(5) +int(5) +int(0) +Done diff --git a/tests/std/array/extract_variation3.phpt b/tests/std/array/extract_variation3.phpt new file mode 100644 index 00000000..cce0da67 --- /dev/null +++ b/tests/std/array/extract_variation3.phpt @@ -0,0 +1,74 @@ +--TEST-- +Test extract() function (variation 3) +--SKIPIF-- + + +--FILE-- + "aaa", "A" => "AAA", "c" => "ccc", "d" => "ddd", "e" => "eee" ), + array( "1" => "one", "2" => "two", "3" => "three", "4" => "four", "5" => "five" ), +); + +$counter = 0; + +foreach ( $mixed_array as $sub_array ) { + echo "\n-- Iteration $counter --\n"; + $counter++; + + var_dump ( extract($sub_array)); /* Single Argument */ + + /* variations of two arguments */ + var_dump ( extract($sub_array, EXTR_OVERWRITE)); + var_dump ( extract($sub_array, EXTR_SKIP)); + var_dump ( extract($sub_array, EXTR_IF_EXISTS)); + + /* variations of three arguments with use of various extract types*/ + var_dump ( extract($sub_array, EXTR_PREFIX_INVALID, "ssd")); + var_dump ( extract($sub_array, EXTR_PREFIX_SAME, "sss")); + var_dump ( extract($sub_array, EXTR_PREFIX_ALL, "bb")); + var_dump ( extract($sub_array, EXTR_PREFIX_ALL, "")); // "_" taken as default prefix + var_dump ( extract($sub_array, EXTR_PREFIX_IF_EXISTS, "bb")); +} + +echo "Done\n"; +?> +--EXPECT-- +-- Iteration 0 -- +int(0) +int(0) +int(0) +int(0) +int(8) +int(0) +int(8) +int(8) +int(0) + +-- Iteration 1 -- +int(5) +int(5) +int(0) +int(5) +int(5) +int(5) +int(5) +int(5) +int(5) + +-- Iteration 2 -- +int(0) +int(0) +int(0) +int(0) +int(5) +int(0) +int(5) +int(5) +int(0) +Done diff --git a/tests/std/array/extract_variation4.phpt b/tests/std/array/extract_variation4.phpt new file mode 100644 index 00000000..343b681e --- /dev/null +++ b/tests/std/array/extract_variation4.phpt @@ -0,0 +1,74 @@ +--TEST-- +Test extract() function (variation 4) +--SKIPIF-- + + +--FILE-- + "one", 2 => "two", 3 => 7, 4 => "four", 5 => "five" ), + array( "f" => "fff", "1" => "one", 4 => 6, "" => "blank", 2 => "float", "F" => "FFF", + "blank" => "", 3 => 3.7, 5 => 7, 6 => 8.6, '5' => "Five", "4name" => "jonny", "a" => NULL, NULL => 3 ), + array( 12, "name", 'age', '45' ), +); + +$counter = 0; + +foreach ( $mixed_array as $sub_array ) { + echo "\n-- Iteration $counter --\n"; + $counter++; + + var_dump ( extract($sub_array)); /* Single Argument */ + + /* variations of two arguments */ + var_dump ( extract($sub_array, EXTR_OVERWRITE)); + var_dump ( extract($sub_array, EXTR_SKIP)); + var_dump ( extract($sub_array, EXTR_IF_EXISTS)); + + /* variations of three arguments with use of various extract types*/ + var_dump ( extract($sub_array, EXTR_PREFIX_INVALID, "ssd")); + var_dump ( extract($sub_array, EXTR_PREFIX_SAME, "sss")); + var_dump ( extract($sub_array, EXTR_PREFIX_ALL, "bb")); + var_dump ( extract($sub_array, EXTR_PREFIX_ALL, "")); // "_" taken as default prefix + var_dump ( extract($sub_array, EXTR_PREFIX_IF_EXISTS, "bb")); +} + +echo "Done\n"; +?> +--EXPECT-- +-- Iteration 0 -- +int(0) +int(0) +int(0) +int(0) +int(5) +int(0) +int(5) +int(5) +int(0) + +-- Iteration 1 -- +int(4) +int(4) +int(0) +int(4) +int(12) +int(4) +int(11) +int(11) +int(4) + +-- Iteration 2 -- +int(0) +int(0) +int(0) +int(0) +int(4) +int(0) +int(4) +int(4) +int(0) +Done diff --git a/tests/std/array/extract_variation5.phpt b/tests/std/array/extract_variation5.phpt new file mode 100644 index 00000000..edc3ad5e --- /dev/null +++ b/tests/std/array/extract_variation5.phpt @@ -0,0 +1,62 @@ +--TEST-- +Test extract() function (variation 5) +--SKIPIF-- + + +--FILE-- + 1, "one" => 2, "three" => 3, 3, 4, 3 => 33, 4 => 44, 5, 6, + 5 => 57, "5.4" => 554, "5.7" => 557 ) +); + +$counter = 0; + +foreach ( $mixed_array as $sub_array ) { + echo "\n-- Iteration $counter --\n"; + $counter++; + + var_dump ( extract($sub_array)); /* Single Argument */ + + /* variations of two arguments */ + var_dump ( extract($sub_array, EXTR_OVERWRITE)); + var_dump ( extract($sub_array, EXTR_SKIP)); + var_dump ( extract($sub_array, EXTR_IF_EXISTS)); + + /* variations of three arguments with use of various extract types*/ + var_dump ( extract($sub_array, EXTR_PREFIX_INVALID, "ssd")); + var_dump ( extract($sub_array, EXTR_PREFIX_SAME, "sss")); + var_dump ( extract($sub_array, EXTR_PREFIX_ALL, "bb")); + var_dump ( extract($sub_array, EXTR_PREFIX_ALL, "")); // "_" taken as default prefix + var_dump ( extract($sub_array, EXTR_PREFIX_IF_EXISTS, "bb")); +} + +echo "Done\n"; +?> +--EXPECT-- +-- Iteration 0 -- +int(0) +int(0) +int(0) +int(0) +int(3) +int(0) +int(3) +int(3) +int(0) + +-- Iteration 1 -- +int(2) +int(2) +int(0) +int(2) +int(8) +int(2) +int(8) +int(8) +int(2) +Done diff --git a/tests/std/array/extract_variation6.phpt b/tests/std/array/extract_variation6.phpt new file mode 100644 index 00000000..21648f23 --- /dev/null +++ b/tests/std/array/extract_variation6.phpt @@ -0,0 +1,33 @@ +--TEST-- +Test extract() function (variation 6) +--SKIPIF-- + + +--FILE-- + 'aaa'); +var_dump ( extract($a, EXTR_REFS)); +var_dump($foo); + +$b = $a; +$b['foo'] = 'bbb'; +var_dump ( extract($a, EXTR_REFS)); +var_dump($foo); +var_dump($a); + +echo "Done\n"; +?> +--EXPECT-- +int(1) +string(3) "aaa" +int(1) +string(3) "bbb" +array(1) { + ["foo"]=> + &string(3) "bbb" +} +Done diff --git a/tests/std/array/extract_variation7.phpt b/tests/std/array/extract_variation7.phpt new file mode 100644 index 00000000..e37de2b7 --- /dev/null +++ b/tests/std/array/extract_variation7.phpt @@ -0,0 +1,28 @@ +--TEST-- +Test extract() function (variation 7) +--SKIPIF-- + + +--FILE-- + "one", "2" => "two", "3" => "three", "4" => "four", "5" => "five" ); +var_dump ( extract($a, EXTR_PREFIX_ALL, "same")); + +$b = array( "f" => "fff", "1" => "one", 4 => 6, "" => "blank", 2 => "float", "F" => "FFF", + "blank" => "", 3 => 3.7, 5 => 7, 6 => 8.6, '5' => "Five", "4name" => "jonny", "a" => NULL, NULL => 3 ); +var_dump ( extract($b, EXTR_PREFIX_ALL, "same")); +var_dump ( extract($b, EXTR_PREFIX_ALL, "diff")); + +echo "Done\n"; +?> +--EXPECT-- +*** Testing for EXTR_PREFIX_ALL called twice with same prefix string *** +int(5) +int(11) +int(11) +Done diff --git a/tests/std/array/extract_variation8.phpt b/tests/std/array/extract_variation8.phpt new file mode 100644 index 00000000..2a5b33db --- /dev/null +++ b/tests/std/array/extract_variation8.phpt @@ -0,0 +1,30 @@ +--TEST-- +Test extract() function (variation 8) +--SKIPIF-- + + +--FILE-- + +--EXPECT-- +*** Testing for Numerical prefixes *** +int(3) +int(1) + +Done diff --git a/tests/std/array/extract_variation9.phpt b/tests/std/array/extract_variation9.phpt new file mode 100644 index 00000000..ca847552 --- /dev/null +++ b/tests/std/array/extract_variation9.phpt @@ -0,0 +1,26 @@ +--TEST-- +Test extract() function (variation 9) +--SKIPIF-- + + +--FILE-- + +--EXPECT-- +*** Testing for object *** +int(1) +Done diff --git a/tests/std/array/gh14140.phpt b/tests/std/array/gh14140.phpt new file mode 100644 index 00000000..ffba9617 --- /dev/null +++ b/tests/std/array/gh14140.phpt @@ -0,0 +1,24 @@ +--TEST-- +GH-14140: Floating point bug in range operation on Apple Silicon hardware +--SKIPIF-- + +--FILE-- + +--EXPECT-- +Array +( + [0] => -0.03 + [1] => -0.02 + [2] => -0.01 + [3] => 0 + [4] => 0.01 + [5] => 0.02 + [6] => 0.03 +) diff --git a/tests/std/array/gh14775.phpt b/tests/std/array/gh14775.phpt new file mode 100644 index 00000000..9902d7f6 --- /dev/null +++ b/tests/std/array/gh14775.phpt @@ -0,0 +1,17 @@ +--TEST-- +GH-14775: Range negative step overflow +--SKIPIF-- + + +--FILE-- +getMessage() . PHP_EOL; +} +--EXPECTF-- +range(): Argument #3 ($step) must be greater than %s diff --git a/tests/std/array/gh15982.phpt b/tests/std/array/gh15982.phpt new file mode 100644 index 00000000..2eb9eceb --- /dev/null +++ b/tests/std/array/gh15982.phpt @@ -0,0 +1,11 @@ +--TEST-- +GH-15982 (Assertion failure with array_find when references are involved) +--FILE-- + true)); +?> +--EXPECT-- +string(5) "hello" diff --git a/tests/std/array/gh16053.phpt b/tests/std/array/gh16053.phpt new file mode 100644 index 00000000..c290078e --- /dev/null +++ b/tests/std/array/gh16053.phpt @@ -0,0 +1,29 @@ +--TEST-- +GH-16053: Assertion failure in Zend/zend_hash.c +--FILE-- + $x); + $arr2 = array("string" => "hello"); + var_dump($arr1); + var_dump(array_merge_recursive($arr1, $arr2)); +} +?> +--EXPECTF-- +array(1) { + ["string"]=> + object(test)#%d (0) { + } +} +array(1) { + ["string"]=> + array(1) { + [0]=> + string(5) "hello" + } +} diff --git a/tests/std/array/gh16649/array_splice_normal_destructor.phpt b/tests/std/array/gh16649/array_splice_normal_destructor.phpt new file mode 100644 index 00000000..882ad1d9 --- /dev/null +++ b/tests/std/array/gh16649/array_splice_normal_destructor.phpt @@ -0,0 +1,22 @@ +--TEST-- +GH-16649: array_splice with normal destructor should work fine +--SKIPIF-- + +--FILE-- + +--EXPECT-- +Destructor called +array(1) { + [0]=> + string(1) "1" +} diff --git a/tests/std/array/gh16649/array_splice_uaf_add_elements.phpt b/tests/std/array/gh16649/array_splice_uaf_add_elements.phpt new file mode 100644 index 00000000..66aa5c4f --- /dev/null +++ b/tests/std/array/gh16649/array_splice_uaf_add_elements.phpt @@ -0,0 +1,24 @@ +--TEST-- +GH-16649: array_splice UAF when destructor adds elements to array +--SKIPIF-- + +--FILE-- +getMessage() . "\n"; +} +?> +--EXPECT-- +Exception caught: Array was modified during array_splice operation diff --git a/tests/std/array/gh16649/array_splice_uaf_array_deallocated.phpt b/tests/std/array/gh16649/array_splice_uaf_array_deallocated.phpt new file mode 100644 index 00000000..85133e23 --- /dev/null +++ b/tests/std/array/gh16649/array_splice_uaf_array_deallocated.phpt @@ -0,0 +1,24 @@ +--TEST-- +GH-16649: array_splice UAF when array is released entirely +--SKIPIF-- + +--FILE-- +getMessage() . "\n"; +} +?> +--EXPECT-- +Exception caught: Array was modified during array_splice operation diff --git a/tests/std/array/gh16649/array_splice_uaf_complex_modification.phpt b/tests/std/array/gh16649/array_splice_uaf_complex_modification.phpt new file mode 100644 index 00000000..f6e64ca3 --- /dev/null +++ b/tests/std/array/gh16649/array_splice_uaf_complex_modification.phpt @@ -0,0 +1,27 @@ +--TEST-- +GH-16649: array_splice UAF with complex array modification +--SKIPIF-- + +--FILE-- +getMessage() . "\n"; +} +?> +--EXPECT-- +Exception caught: Array was modified during array_splice operation diff --git a/tests/std/array/gh16649/array_splice_uaf_multiple_destructors.phpt b/tests/std/array/gh16649/array_splice_uaf_multiple_destructors.phpt new file mode 100644 index 00000000..c39ef6d0 --- /dev/null +++ b/tests/std/array/gh16649/array_splice_uaf_multiple_destructors.phpt @@ -0,0 +1,35 @@ +--TEST-- +GH-16649: array_splice UAF with multiple destructors +--SKIPIF-- + +--FILE-- +id = $id; + } + + function __destruct() { + global $arr; + echo "Destructor {$this->id} called\n"; + if ($this->id == 2) { + $arr = null; + } + } +} + +$arr = ["start", new MultiDestructor(1), new MultiDestructor(2), "end"]; + +try { + array_splice($arr, 1, 2); + echo "ERROR: Should have thrown exception\n"; +} catch (Error $e) { + echo "Exception caught: " . $e->getMessage() . "\n"; +} +?> +--EXPECT-- +Destructor 1 called +Destructor 2 called +Exception caught: Array was modified during array_splice operation diff --git a/tests/std/array/gh16649/array_splice_uaf_original_case.phpt b/tests/std/array/gh16649/array_splice_uaf_original_case.phpt new file mode 100644 index 00000000..e4357414 --- /dev/null +++ b/tests/std/array/gh16649/array_splice_uaf_original_case.phpt @@ -0,0 +1,31 @@ +--TEST-- +GH-16649: array_splice UAF with destructor modifying array (original case) +--SKIPIF-- + +--FILE-- + "1", "3" => new C, "2" => "2"]; + +try { + array_splice($arr, 1, 2); + echo "ERROR: Should have thrown exception\n"; +} catch (Error $e) { + echo "Exception caught: " . $e->getMessage() . "\n"; +} +?> +--EXPECT-- +Exception caught: Array was modified during array_splice operation diff --git a/tests/std/array/gh16649/array_splice_uaf_packed_to_hash.phpt b/tests/std/array/gh16649/array_splice_uaf_packed_to_hash.phpt new file mode 100644 index 00000000..13dd56a9 --- /dev/null +++ b/tests/std/array/gh16649/array_splice_uaf_packed_to_hash.phpt @@ -0,0 +1,25 @@ +--TEST-- +GH-16649: array_splice UAF when array is converted from packed to hash +--SKIPIF-- + +--FILE-- +getMessage() . "\n"; +} +?> +--EXPECT-- +Exception caught: Array was modified during array_splice operation diff --git a/tests/std/array/gh16649/array_splice_with_replacement.phpt b/tests/std/array/gh16649/array_splice_with_replacement.phpt new file mode 100644 index 00000000..f06932dc --- /dev/null +++ b/tests/std/array/gh16649/array_splice_with_replacement.phpt @@ -0,0 +1,25 @@ +--TEST-- +GH-16649: array_splice with replacement array when destructor modifies array +--SKIPIF-- + +--FILE-- +getMessage() . "\n"; +} +?> +--EXPECT-- +Exception caught: Array was modified during array_splice operation diff --git a/tests/std/array/gh16905.phpt b/tests/std/array/gh16905.phpt new file mode 100644 index 00000000..d3a64ddb --- /dev/null +++ b/tests/std/array/gh16905.phpt @@ -0,0 +1,89 @@ +--TEST-- +GH-16905 (Internal iterator functions can't handle UNDEF properties) +--SKIPIF-- + +--FILE-- +b = 1; + $x->c = 2; + var_dump(reset($x)); + var_dump(current($x)); + var_dump(end($x)); + var_dump(reset($x)); + var_dump(next($x)); + var_dump(end($x)); + var_dump(prev($x)); + var_dump(key($x)); + var_dump(current($x)); + $x2 = new TestAllUndef(); + var_dump(key($x2)); + var_dump(current($x2)); + $x2->a = 1; + var_dump(key($x2)); + var_dump(current($x2)); + reset($x2); + var_dump(key($x2)); + var_dump(current($x2)); +} +?> +--EXPECTF-- +Deprecated: reset(): Calling reset() on an object is deprecated in %s on line %d +int(1) + +Deprecated: current(): Calling current() on an object is deprecated in %s on line %d +int(1) + +Deprecated: end(): Calling end() on an object is deprecated in %s on line %d +int(2) + +Deprecated: reset(): Calling reset() on an object is deprecated in %s on line %d +int(1) + +Deprecated: next(): Calling next() on an object is deprecated in %s on line %d +int(2) + +Deprecated: end(): Calling end() on an object is deprecated in %s on line %d +int(2) + +Deprecated: prev(): Calling prev() on an object is deprecated in %s on line %d +int(1) + +Deprecated: key(): Calling key() on an object is deprecated in %s on line %d +string(1) "b" + +Deprecated: current(): Calling current() on an object is deprecated in %s on line %d +int(1) + +Deprecated: key(): Calling key() on an object is deprecated in %s on line %d +NULL + +Deprecated: current(): Calling current() on an object is deprecated in %s on line %d +bool(false) + +Deprecated: key(): Calling key() on an object is deprecated in %s on line %d +NULL + +Deprecated: current(): Calling current() on an object is deprecated in %s on line %d +bool(false) + +Deprecated: reset(): Calling reset() on an object is deprecated in %s on line %d + +Deprecated: key(): Calling key() on an object is deprecated in %s on line %d +string(1) "a" + +Deprecated: current(): Calling current() on an object is deprecated in %s on line %d +int(1) diff --git a/tests/std/array/gh16957.phpt b/tests/std/array/gh16957.phpt new file mode 100644 index 00000000..74094906 --- /dev/null +++ b/tests/std/array/gh16957.phpt @@ -0,0 +1,43 @@ +--TEST-- +GH-16957 (Assertion failure in array_shift with self-referencing array) +--SKIPIF-- + +--FILE-- + 1, 300 => 'two'); +var_dump($shifted = array_shift($new_array2)); +var_dump($new_array2); +var_dump($new_array2 === $shifted); +?> +--EXPECT-- +array(2) { + [0]=> + int(1) + [1]=> + string(3) "two" +} +array(2) { + [0]=> + int(1) + [1]=> + string(3) "two" +} +bool(true) +array(2) { + [0]=> + int(1) + [1]=> + string(3) "two" +} +array(2) { + [0]=> + int(1) + [1]=> + string(3) "two" +} +bool(true) diff --git a/tests/std/array/gh17447.phpt b/tests/std/array/gh17447.phpt new file mode 100644 index 00000000..e107efbd --- /dev/null +++ b/tests/std/array/gh17447.phpt @@ -0,0 +1,12 @@ +--TEST-- +GH-17447 (Assertion failure when array poping a self addressing variable) +--FILE-- + +--EXPECT-- +array(0) { +} +array(0) { +} diff --git a/tests/std/array/gh17977.phpt b/tests/std/array/gh17977.phpt new file mode 100644 index 00000000..4a4f344d --- /dev/null +++ b/tests/std/array/gh17977.phpt @@ -0,0 +1,18 @@ +--TEST-- +array_any() / array_all() leak +--DESCRIPTION-- +Found in GH-16831#issuecomment-2700410631 +--FILE-- + 1], static fn () => true)); +var_dump(array_all([$key => 1], static fn () => false)); + +?> +--EXPECT-- +bool(true) +bool(false) diff --git a/tests/std/array/gh18480.phpt b/tests/std/array/gh18480.phpt new file mode 100644 index 00000000..21571de2 --- /dev/null +++ b/tests/std/array/gh18480.phpt @@ -0,0 +1,45 @@ +--TEST-- +GH-18480 (array_splice overflow with large offset / length values) +--SKIPIF-- + + +--FILE-- + PHP_INT_MAX]; + $offset = PHP_INT_MAX; + var_dump(array_splice($a,$offset, $length)); + $a = ["a" => PHP_INT_MAX]; + $offset = PHP_INT_MIN; + var_dump(array_splice($a,$offset, $length)); +} +--EXPECTF-- +array(0) { +} +array(0) { +} +array(0) { +} +array(0) { +} +array(0) { +} +array(1) { + [0]=> + int(%d) +} +array(0) { +} +array(1) { + ["a"]=> + int(%d) +} diff --git a/tests/std/array/gh19300_1.phpt b/tests/std/array/gh19300_1.phpt new file mode 100644 index 00000000..a7182257 --- /dev/null +++ b/tests/std/array/gh19300_1.phpt @@ -0,0 +1,42 @@ +--TEST-- +GH-19300 (Nested array_multisort invocation with error breaks) - correct invocation variation +--SKIPIF-- +--FILE-- +data; + } +} +function main() +{ + $inputs = [new MyStringable('3'), new MyStringable('1'), new MyStringable('2')]; + var_dump(array_multisort($inputs, SORT_STRING)); + var_dump($inputs); +} +?> +--EXPECT-- +bool(true) +array(3) { + [0]=> + object(MyStringable)#2 (1) { + ["data":"MyStringable":private]=> + string(1) "1" + } + [1]=> + object(MyStringable)#3 (1) { + ["data":"MyStringable":private]=> + string(1) "2" + } + [2]=> + object(MyStringable)#1 (1) { + ["data":"MyStringable":private]=> + string(1) "3" + } +} diff --git a/tests/std/array/gh19300_2.phpt b/tests/std/array/gh19300_2.phpt new file mode 100644 index 00000000..41a54f2e --- /dev/null +++ b/tests/std/array/gh19300_2.phpt @@ -0,0 +1,39 @@ +--TEST-- +GH-19300 (Nested array_multisort invocation with error breaks) - error variation +--SKIPIF-- +--FILE-- +getMessage(), "\n"; + } +} +function main() +{ + set_error_handler('error_handle'); + $inputs = [new stdClass(), new stdClass(), new stdClass()]; + var_dump(array_multisort($inputs, SORT_NUMERIC)); + var_dump($inputs); +} +?> +--EXPECT-- +array_multisort(): Argument #1 ($array) must be an array or a sort flag +array_multisort(): Argument #1 ($array) must be an array or a sort flag +array_multisort(): Argument #1 ($array) must be an array or a sort flag +array_multisort(): Argument #1 ($array) must be an array or a sort flag +bool(true) +array(3) { + [0]=> + object(stdClass)#1 (0) { + } + [1]=> + object(stdClass)#2 (0) { + } + [2]=> + object(stdClass)#3 (0) { + } +} diff --git a/tests/std/array/gh19926.phpt b/tests/std/array/gh19926.phpt new file mode 100644 index 00000000..ecff0cfa --- /dev/null +++ b/tests/std/array/gh19926.phpt @@ -0,0 +1,25 @@ +--TEST-- +GH-19926 (Assertion failure zend_hash_internal_pointer_reset_ex) +--SKIPIF-- + +--FILE-- + +--EXPECT-- +Exception caught, no assertion failure diff --git a/tests/std/array/gh19926_pointer.phpt b/tests/std/array/gh19926_pointer.phpt new file mode 100644 index 00000000..c134f3b5 --- /dev/null +++ b/tests/std/array/gh19926_pointer.phpt @@ -0,0 +1,19 @@ +--TEST-- +GH-19926 (internal pointer behavior after array_splice) +--FILE-- + +--EXPECT-- +Before array_splice: int(3) +After array_splice: int(999) diff --git a/tests/std/array/gh20043.phpt b/tests/std/array/gh20043.phpt new file mode 100644 index 00000000..d5c7e064 --- /dev/null +++ b/tests/std/array/gh20043.phpt @@ -0,0 +1,12 @@ +--TEST-- +GH-20043 (array_unique assertion failure with RC1 array causing an exception on sort) +--FILE-- +getMessage(); +} +?> +--EXPECT-- +Object of class stdClass could not be converted to string diff --git a/tests/std/array/gh9244.phpt b/tests/std/array/gh9244.phpt new file mode 100644 index 00000000..04c34d42 --- /dev/null +++ b/tests/std/array/gh9244.phpt @@ -0,0 +1,11 @@ +--TEST-- +Bug GH-9244 (Segfault with array_multisort + array_shift) +--FILE-- + 1, 'bar' => 2]; +$order = [4, 3]; +array_multisort($order, $items); +var_dump(array_shift($items)); +?> +--EXPECT-- +int(2) diff --git a/tests/std/array/gh9296.phpt b/tests/std/array/gh9296.phpt new file mode 100644 index 00000000..cfbc5cbb --- /dev/null +++ b/tests/std/array/gh9296.phpt @@ -0,0 +1,17 @@ +--TEST-- +GH-9296: incorrect ksort(..., SORT_REGULAR) behaviour on arrays with numeric and string keys +--FILE-- + 0, 600 => 1]; +ksort($array, SORT_REGULAR); +var_dump($array); +var_dump(array_key_first($array) <=> array_key_last($array)); +?> +--EXPECT-- +array(2) { + [600]=> + int(1) + ["aaa"]=> + int(0) +} +int(-1) diff --git a/tests/std/array/in_array_variation1.phpt b/tests/std/array/in_array_variation1.phpt new file mode 100644 index 00000000..0c88a453 --- /dev/null +++ b/tests/std/array/in_array_variation1.phpt @@ -0,0 +1,635 @@ +--TEST-- +Test in_array() function : usage variations - different needdle values +--FILE-- + "A", 2 => "B", "C" => 3, 4 => 4, "one" => 1, "" => NULL, "b", "ab", "abcd"), + array(4, array(1, 2 => 3), "one" => 1, "5" => 5 ), + array(-1, -2, -3, -4, -2.989888, "-0.005" => "neg0.005", 2 => "float2", "-.9" => -.9), + array(TRUE, FALSE), + array("", array()), + array("abcd\x00abcd\x00abcd"), + array("abcd\tabcd\nabcd\rabcd\0abcdefghij") +); + +$array_compare = array ( + 4, + "4", + 4.00, + "b", + "5", + -2, + -2.0, + -2.98989, + "-.9", + "True", + "", + array(), + NULL, + "ab", + "abcd", + 0.0, + -0, + "abcd\x00abcd\x00abcd" +); +/* loop to check if elements in $array_compare exist in $arrays + using in_array() */ +$counter = 1; +foreach($arrays as $array) { + foreach($array_compare as $compare) { + echo "-- Iteration $counter --\n"; + //strict option OFF + var_dump(in_array($compare,$array)); + //strict option ON + var_dump(in_array($compare,$array,TRUE)); + //strict option OFF + var_dump(in_array($compare,$array,FALSE)); + $counter++; + } +} + +echo "Done\n"; +?> +--EXPECT-- +*** Testing in_array() with different needle values *** +-- Iteration 1 -- +bool(false) +bool(false) +bool(false) +-- Iteration 2 -- +bool(false) +bool(false) +bool(false) +-- Iteration 3 -- +bool(false) +bool(false) +bool(false) +-- Iteration 4 -- +bool(false) +bool(false) +bool(false) +-- Iteration 5 -- +bool(false) +bool(false) +bool(false) +-- Iteration 6 -- +bool(false) +bool(false) +bool(false) +-- Iteration 7 -- +bool(false) +bool(false) +bool(false) +-- Iteration 8 -- +bool(false) +bool(false) +bool(false) +-- Iteration 9 -- +bool(false) +bool(false) +bool(false) +-- Iteration 10 -- +bool(false) +bool(false) +bool(false) +-- Iteration 11 -- +bool(false) +bool(false) +bool(false) +-- Iteration 12 -- +bool(false) +bool(false) +bool(false) +-- Iteration 13 -- +bool(true) +bool(false) +bool(true) +-- Iteration 14 -- +bool(false) +bool(false) +bool(false) +-- Iteration 15 -- +bool(false) +bool(false) +bool(false) +-- Iteration 16 -- +bool(true) +bool(false) +bool(true) +-- Iteration 17 -- +bool(true) +bool(true) +bool(true) +-- Iteration 18 -- +bool(false) +bool(false) +bool(false) +-- Iteration 19 -- +bool(true) +bool(true) +bool(true) +-- Iteration 20 -- +bool(true) +bool(false) +bool(true) +-- Iteration 21 -- +bool(true) +bool(false) +bool(true) +-- Iteration 22 -- +bool(true) +bool(true) +bool(true) +-- Iteration 23 -- +bool(false) +bool(false) +bool(false) +-- Iteration 24 -- +bool(false) +bool(false) +bool(false) +-- Iteration 25 -- +bool(false) +bool(false) +bool(false) +-- Iteration 26 -- +bool(false) +bool(false) +bool(false) +-- Iteration 27 -- +bool(false) +bool(false) +bool(false) +-- Iteration 28 -- +bool(false) +bool(false) +bool(false) +-- Iteration 29 -- +bool(true) +bool(false) +bool(true) +-- Iteration 30 -- +bool(true) +bool(false) +bool(true) +-- Iteration 31 -- +bool(true) +bool(true) +bool(true) +-- Iteration 32 -- +bool(true) +bool(true) +bool(true) +-- Iteration 33 -- +bool(true) +bool(true) +bool(true) +-- Iteration 34 -- +bool(true) +bool(false) +bool(true) +-- Iteration 35 -- +bool(true) +bool(false) +bool(true) +-- Iteration 36 -- +bool(false) +bool(false) +bool(false) +-- Iteration 37 -- +bool(true) +bool(true) +bool(true) +-- Iteration 38 -- +bool(true) +bool(false) +bool(true) +-- Iteration 39 -- +bool(true) +bool(false) +bool(true) +-- Iteration 40 -- +bool(false) +bool(false) +bool(false) +-- Iteration 41 -- +bool(true) +bool(false) +bool(true) +-- Iteration 42 -- +bool(false) +bool(false) +bool(false) +-- Iteration 43 -- +bool(false) +bool(false) +bool(false) +-- Iteration 44 -- +bool(false) +bool(false) +bool(false) +-- Iteration 45 -- +bool(false) +bool(false) +bool(false) +-- Iteration 46 -- +bool(false) +bool(false) +bool(false) +-- Iteration 47 -- +bool(false) +bool(false) +bool(false) +-- Iteration 48 -- +bool(false) +bool(false) +bool(false) +-- Iteration 49 -- +bool(false) +bool(false) +bool(false) +-- Iteration 50 -- +bool(false) +bool(false) +bool(false) +-- Iteration 51 -- +bool(false) +bool(false) +bool(false) +-- Iteration 52 -- +bool(false) +bool(false) +bool(false) +-- Iteration 53 -- +bool(false) +bool(false) +bool(false) +-- Iteration 54 -- +bool(false) +bool(false) +bool(false) +-- Iteration 55 -- +bool(false) +bool(false) +bool(false) +-- Iteration 56 -- +bool(false) +bool(false) +bool(false) +-- Iteration 57 -- +bool(false) +bool(false) +bool(false) +-- Iteration 58 -- +bool(false) +bool(false) +bool(false) +-- Iteration 59 -- +bool(false) +bool(false) +bool(false) +-- Iteration 60 -- +bool(true) +bool(true) +bool(true) +-- Iteration 61 -- +bool(true) +bool(false) +bool(true) +-- Iteration 62 -- +bool(false) +bool(false) +bool(false) +-- Iteration 63 -- +bool(true) +bool(false) +bool(true) +-- Iteration 64 -- +bool(false) +bool(false) +bool(false) +-- Iteration 65 -- +bool(false) +bool(false) +bool(false) +-- Iteration 66 -- +bool(false) +bool(false) +bool(false) +-- Iteration 67 -- +bool(false) +bool(false) +bool(false) +-- Iteration 68 -- +bool(false) +bool(false) +bool(false) +-- Iteration 69 -- +bool(false) +bool(false) +bool(false) +-- Iteration 70 -- +bool(false) +bool(false) +bool(false) +-- Iteration 71 -- +bool(false) +bool(false) +bool(false) +-- Iteration 72 -- +bool(false) +bool(false) +bool(false) +-- Iteration 73 -- +bool(true) +bool(false) +bool(true) +-- Iteration 74 -- +bool(true) +bool(false) +bool(true) +-- Iteration 75 -- +bool(true) +bool(false) +bool(true) +-- Iteration 76 -- +bool(true) +bool(false) +bool(true) +-- Iteration 77 -- +bool(true) +bool(false) +bool(true) +-- Iteration 78 -- +bool(true) +bool(false) +bool(true) +-- Iteration 79 -- +bool(true) +bool(false) +bool(true) +-- Iteration 80 -- +bool(true) +bool(false) +bool(true) +-- Iteration 81 -- +bool(true) +bool(false) +bool(true) +-- Iteration 82 -- +bool(true) +bool(false) +bool(true) +-- Iteration 83 -- +bool(true) +bool(false) +bool(true) +-- Iteration 84 -- +bool(true) +bool(false) +bool(true) +-- Iteration 85 -- +bool(true) +bool(false) +bool(true) +-- Iteration 86 -- +bool(true) +bool(false) +bool(true) +-- Iteration 87 -- +bool(true) +bool(false) +bool(true) +-- Iteration 88 -- +bool(true) +bool(false) +bool(true) +-- Iteration 89 -- +bool(true) +bool(false) +bool(true) +-- Iteration 90 -- +bool(true) +bool(false) +bool(true) +-- Iteration 91 -- +bool(false) +bool(false) +bool(false) +-- Iteration 92 -- +bool(false) +bool(false) +bool(false) +-- Iteration 93 -- +bool(false) +bool(false) +bool(false) +-- Iteration 94 -- +bool(false) +bool(false) +bool(false) +-- Iteration 95 -- +bool(false) +bool(false) +bool(false) +-- Iteration 96 -- +bool(false) +bool(false) +bool(false) +-- Iteration 97 -- +bool(false) +bool(false) +bool(false) +-- Iteration 98 -- +bool(false) +bool(false) +bool(false) +-- Iteration 99 -- +bool(false) +bool(false) +bool(false) +-- Iteration 100 -- +bool(false) +bool(false) +bool(false) +-- Iteration 101 -- +bool(true) +bool(true) +bool(true) +-- Iteration 102 -- +bool(true) +bool(true) +bool(true) +-- Iteration 103 -- +bool(true) +bool(false) +bool(true) +-- Iteration 104 -- +bool(false) +bool(false) +bool(false) +-- Iteration 105 -- +bool(false) +bool(false) +bool(false) +-- Iteration 106 -- +bool(false) +bool(false) +bool(false) +-- Iteration 107 -- +bool(false) +bool(false) +bool(false) +-- Iteration 108 -- +bool(false) +bool(false) +bool(false) +-- Iteration 109 -- +bool(false) +bool(false) +bool(false) +-- Iteration 110 -- +bool(false) +bool(false) +bool(false) +-- Iteration 111 -- +bool(false) +bool(false) +bool(false) +-- Iteration 112 -- +bool(false) +bool(false) +bool(false) +-- Iteration 113 -- +bool(false) +bool(false) +bool(false) +-- Iteration 114 -- +bool(false) +bool(false) +bool(false) +-- Iteration 115 -- +bool(false) +bool(false) +bool(false) +-- Iteration 116 -- +bool(false) +bool(false) +bool(false) +-- Iteration 117 -- +bool(false) +bool(false) +bool(false) +-- Iteration 118 -- +bool(false) +bool(false) +bool(false) +-- Iteration 119 -- +bool(false) +bool(false) +bool(false) +-- Iteration 120 -- +bool(false) +bool(false) +bool(false) +-- Iteration 121 -- +bool(false) +bool(false) +bool(false) +-- Iteration 122 -- +bool(false) +bool(false) +bool(false) +-- Iteration 123 -- +bool(false) +bool(false) +bool(false) +-- Iteration 124 -- +bool(false) +bool(false) +bool(false) +-- Iteration 125 -- +bool(false) +bool(false) +bool(false) +-- Iteration 126 -- +bool(true) +bool(true) +bool(true) +-- Iteration 127 -- +bool(false) +bool(false) +bool(false) +-- Iteration 128 -- +bool(false) +bool(false) +bool(false) +-- Iteration 129 -- +bool(false) +bool(false) +bool(false) +-- Iteration 130 -- +bool(false) +bool(false) +bool(false) +-- Iteration 131 -- +bool(false) +bool(false) +bool(false) +-- Iteration 132 -- +bool(false) +bool(false) +bool(false) +-- Iteration 133 -- +bool(false) +bool(false) +bool(false) +-- Iteration 134 -- +bool(false) +bool(false) +bool(false) +-- Iteration 135 -- +bool(false) +bool(false) +bool(false) +-- Iteration 136 -- +bool(false) +bool(false) +bool(false) +-- Iteration 137 -- +bool(false) +bool(false) +bool(false) +-- Iteration 138 -- +bool(false) +bool(false) +bool(false) +-- Iteration 139 -- +bool(false) +bool(false) +bool(false) +-- Iteration 140 -- +bool(false) +bool(false) +bool(false) +-- Iteration 141 -- +bool(false) +bool(false) +bool(false) +-- Iteration 142 -- +bool(false) +bool(false) +bool(false) +-- Iteration 143 -- +bool(false) +bool(false) +bool(false) +-- Iteration 144 -- +bool(false) +bool(false) +bool(false) +Done diff --git a/tests/std/array/in_array_variation2.phpt b/tests/std/array/in_array_variation2.phpt new file mode 100644 index 00000000..39762322 --- /dev/null +++ b/tests/std/array/in_array_variation2.phpt @@ -0,0 +1,95 @@ +--TEST-- +Test in_array() function : usage variations - different haystack values +--FILE-- +'d', + 3, + ".001" =>-67, + "-.051" =>"k", + 0 =>"-.08", + "e" =>"5", + "y" =>NULL, + NULL =>"", + 0, + TRUE, + FALSE, + -27.39999999999, + " ", + "abcd\x00abcd\x00\abcd\x00abcdefghij", + "abcd\nabcd\tabcd\rabcd\0abcd" +); +$array_type = array(TRUE, FALSE, 1, 0, -1, "1", "0", "-1", NULL, array(), "PHP", ""); +/* loop to do loose and strict type check of elements in + $array_type on elements in $misc_array using in_array(); + checking PHP type comparison tables +*/ +$counter = 1; +foreach($array_type as $type) { + echo "-- Iteration $counter --\n"; + //loose type checking + var_dump( in_array($type,$misc_array ) ); + //strict type checking + var_dump( in_array($type,$misc_array,true) ); + //loose type checking + var_dump( in_array($type,$misc_array,false) ); + $counter++; +} + +echo "Done\n"; +?> +--EXPECT-- +*** Testing in_array() with different haystack values *** +-- Iteration 1 -- +bool(true) +bool(true) +bool(true) +-- Iteration 2 -- +bool(true) +bool(true) +bool(true) +-- Iteration 3 -- +bool(true) +bool(false) +bool(true) +-- Iteration 4 -- +bool(true) +bool(true) +bool(true) +-- Iteration 5 -- +bool(true) +bool(false) +bool(true) +-- Iteration 6 -- +bool(true) +bool(false) +bool(true) +-- Iteration 7 -- +bool(true) +bool(false) +bool(true) +-- Iteration 8 -- +bool(true) +bool(false) +bool(true) +-- Iteration 9 -- +bool(true) +bool(true) +bool(true) +-- Iteration 10 -- +bool(true) +bool(false) +bool(true) +-- Iteration 11 -- +bool(true) +bool(false) +bool(true) +-- Iteration 12 -- +bool(true) +bool(true) +bool(true) +Done diff --git a/tests/std/array/in_array_variation3.phpt b/tests/std/array/in_array_variation3.phpt new file mode 100644 index 00000000..de0a5e7d --- /dev/null +++ b/tests/std/array/in_array_variation3.phpt @@ -0,0 +1,56 @@ +--TEST-- +Test in_array() function : usage variations - haystack as sub-array/object +--SKIPIF-- + +--FILE-- + "one", "two" => 2, 3 => 3); + public function foo() + { + echo "Public function\n"; + } +} +function main() +{ + /* Test in_array() with haystack as sub-array and object */ + /* checking for sub-arrays with in_array() */ + echo "*** Testing sub-arrays with in_array() ***\n"; + $sub_array = array("one", array(1, 2 => "two", "three" => 3), 4 => "four", "five" => 5, array('', 'i')); + var_dump(in_array("four", $sub_array)); + //checking for element in a sub-array + var_dump(in_array(3, $sub_array[1])); + var_dump(in_array(array('', 'i'), $sub_array)); + /* checking for objects in in_array() */ + echo "\n*** Testing objects with in_array() ***\n"; + $in_array_obj = new in_array_check(); + //creating new object + //error: as wrong datatype for second argument + try { + var_dump(in_array("array_var", $in_array_obj)); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + //error: as wrong datatype for second argument + try { + var_dump(in_array("foo", $in_array_obj)); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } + //element found as "one" exists in array $array_var + var_dump(in_array("one", $in_array_obj->array_var)); + echo "Done\n"; +} +?> +--EXPECT-- +*** Testing sub-arrays with in_array() *** +bool(true) +bool(true) +bool(true) + +*** Testing objects with in_array() *** +in_array(): Argument #2 ($haystack) must be of type array, in_array_check given +in_array(): Argument #2 ($haystack) must be of type array, in_array_check given +bool(true) +Done diff --git a/tests/std/array/in_array_variation4.phpt b/tests/std/array/in_array_variation4.phpt new file mode 100644 index 00000000..c7c91278 --- /dev/null +++ b/tests/std/array/in_array_variation4.phpt @@ -0,0 +1,70 @@ +--TEST-- +Test in_array() function : usage variations - haystack as resource/multi dimensional array +--FILE-- + TRUE, "b"=> TRUE, + array("c"=> TRUE, "d"=>TRUE) + ) + ) + ); + +//matching string having integer in beginning, result:true in loose type check +var_dump( in_array('123abc', array(123)) ); +var_dump( in_array('123abc', array(123), TRUE) ); // false in strict mode + +echo "Done\n"; +?> +--EXPECT-- +*** Testing resource type with in_array() *** +bool(true) +bool(false) + +*** Testing miscelleneos inputs with in_array() *** +bool(false) +bool(false) +bool(false) +bool(false) +bool(true) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +Done diff --git a/tests/std/array/in_array_with_ref.phpt b/tests/std/array/in_array_with_ref.phpt new file mode 100644 index 00000000..2ad3667d --- /dev/null +++ b/tests/std/array/in_array_with_ref.phpt @@ -0,0 +1,14 @@ +--TEST-- +in_array() with references +--FILE-- + +--EXPECT-- +bool(true) +bool(true) diff --git a/tests/std/array/key_basic.phpt b/tests/std/array/key_basic.phpt new file mode 100644 index 00000000..f6b9300b --- /dev/null +++ b/tests/std/array/key_basic.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test key() function : basic functionality +--FILE-- + 'one', 'two', 'three' => 3); +echo "\n-- Initial Position: --\n"; +var_dump(key($array)); + +echo "\n-- Next Position: --\n"; +next($array); +var_dump(key($array)); + +echo "\n-- End Position: --\n"; +end($array); +var_dump(key($array)); + +echo "\n-- Past end of the array --\n"; +next($array); +var_dump(key($array)); +?> +--EXPECT-- +*** Testing key() : basic functionality *** + +-- Initial Position: -- +int(0) + +-- Next Position: -- +int(99) + +-- End Position: -- +string(5) "three" + +-- Past end of the array -- +NULL diff --git a/tests/std/array/key_exists_basic.phpt b/tests/std/array/key_exists_basic.phpt new file mode 100644 index 00000000..37fed4e2 --- /dev/null +++ b/tests/std/array/key_exists_basic.phpt @@ -0,0 +1,16 @@ +--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-- + 1); +var_dump(key_exists('bar', $a)); +var_dump(key_exists('foo', $a)); +?> +--EXPECT-- +*** test key_exists() by calling it with its expected arguments *** +bool(true) +bool(false) diff --git a/tests/std/array/key_exists_variation1.phpt b/tests/std/array/key_exists_variation1.phpt new file mode 100644 index 00000000..b902a9ea --- /dev/null +++ b/tests/std/array/key_exists_variation1.phpt @@ -0,0 +1,16 @@ +--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-- + 1, 'foo' => array('bar' => 2, 'baz' => 3)); +var_dump(key_exists('baz', $a)); +var_dump(key_exists('baz', $a['foo'])); +?> +--EXPECT-- +*** test key_exists() by calling it with its expected arguments *** +bool(false) +bool(true) diff --git a/tests/std/array/key_exists_variation2.phpt b/tests/std/array/key_exists_variation2.phpt new file mode 100644 index 00000000..cb2b9502 --- /dev/null +++ b/tests/std/array/key_exists_variation2.phpt @@ -0,0 +1,64 @@ +--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-- + '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"; + $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)); +} +?> +--EXPECT-- +*** 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/tests/std/array/key_variation2.phpt b/tests/std/array/key_variation2.phpt new file mode 100644 index 00000000..a81c3350 --- /dev/null +++ b/tests/std/array/key_variation2.phpt @@ -0,0 +1,132 @@ +--TEST-- +Test key() function : usage variations +--SKIPIF-- + + +--FILE-- + array( + 0 => 'zero', + 1 => 'one', + 12345 => 'positive', + -2345 => 'negative', + ), + + // null data +/*4*/ 'null uppercase' => array( + NULL => 'null 1', + ), + +/*5*/ 'null lowercase' => array( + null => 'null 2', + ), + + // boolean data +/*6*/ 'bool lowercase' => array( + true => 'lowert', + false => 'lowerf', + ), + +/*7*/ 'bool uppercase' => array( + TRUE => 'uppert', + FALSE => 'upperf', + ), + + // empty data +/*8*/ 'empty double quotes' => array( + "" => 'emptyd', + ), + +/*9*/ 'empty single quotes' => array( + '' => 'emptys', + ), + + // string data +/*10*/ 'string' => array( + "stringd" => 'stringd', + 'strings' => 'strings', + $heredoc => 'stringh', + ), + + // undefined data +/*11*/ 'undefined' => array( + @$undefined_var => 'undefined', + ), + + // unset data +/*12*/ 'unset' => array( + @$unset_var => 'unset', + ), +); + +// loop through each element of $inputs to check the behavior of key() +$iterator = 1; +foreach($inputs as $key => $input) { + echo "\n-- Iteration $iterator : $key data --\n"; + while (key($input) !== NULL) { + var_dump(key($input)); + next($input); + } + $iterator++; +}; +?> +--EXPECT-- +*** Testing key() : usage variations *** + +-- Iteration 1 : int data -- +int(0) +int(1) +int(12345) +int(-2345) + +-- Iteration 2 : null uppercase data -- +string(0) "" + +-- Iteration 3 : null lowercase data -- +string(0) "" + +-- Iteration 4 : bool lowercase data -- +int(1) +int(0) + +-- Iteration 5 : bool uppercase data -- +int(1) +int(0) + +-- Iteration 6 : empty double quotes data -- +string(0) "" + +-- Iteration 7 : empty single quotes data -- +string(0) "" + +-- Iteration 8 : string data -- +string(7) "stringd" +string(7) "strings" +string(11) "hello world" + +-- Iteration 9 : undefined data -- +string(0) "" + +-- Iteration 10 : unset data -- +string(0) "" diff --git a/tests/std/array/key_variation3.phpt b/tests/std/array/key_variation3.phpt new file mode 100644 index 00000000..dfebd4bd --- /dev/null +++ b/tests/std/array/key_variation3.phpt @@ -0,0 +1,36 @@ +--TEST-- +Test key() function : usage variations +--FILE-- + +--EXPECT-- +*** Testing key() : usage variations *** + +-- Initial position of internal pointer -- +int(0) + +-- Position after calling next() -- +$array1: int(1) +$array2: int(1) diff --git a/tests/std/array/key_variation4.phpt b/tests/std/array/key_variation4.phpt new file mode 100644 index 00000000..a71e6732 --- /dev/null +++ b/tests/std/array/key_variation4.phpt @@ -0,0 +1,56 @@ +--TEST-- +Test key() function : usage variations +--FILE-- + +--EXPECT-- +*** Testing key() : usage variations *** + +-- Two Dimensional Array -- +Initial Position: int(0) +Next Position: int(1) +End Position: int(2) + +-- Access an Array Within an Array -- +Initial Position: int(0) + +-- Recursive, Multidimensional Array -- +Current Position: int(2) +int(2) +int(0) diff --git a/tests/std/array/krsort_basic.phpt b/tests/std/array/krsort_basic.phpt new file mode 100644 index 00000000..6137e1b2 --- /dev/null +++ b/tests/std/array/krsort_basic.phpt @@ -0,0 +1,240 @@ +--TEST-- +Test krsort() function : basic functionality +--FILE-- + "l", "orange" => "o", "banana" => "b" ); +$unsorted_strings = array( + "l" => "lemon", "o" => "orange", + "O" => "Orange", "O1" => "Orange1", "o2" => "orange2", "O3" => "Orange3", "o20" => "orange20", + "b" => "banana", +); +// an array containing unsorted numeric values with indices +$unsorted_numerics = array( 100 => 4, 33 => 3, 555 => 2, 22 => 1 ); + +echo "\n-- Testing krsort() by supplying string array, 'flag' value is default --\n"; +$temp_array = $unsorted_strings; +var_dump( krsort($temp_array) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing krsort() by supplying numeric array, 'flag' value is default --\n"; +$temp_array = $unsorted_numerics; +var_dump( krsort($temp_array) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing krsort() by supplying string array, 'flag' = SORT_REGULAR --\n"; +$temp_array = $unsorted_strings; +var_dump( krsort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing krsort() by supplying numeric array, 'flag' = SORT_REGULAR --\n"; +$temp_array = $unsorted_numerics; +var_dump( krsort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing krsort() by supplying string array, 'flag' = SORT_STRING --\n"; +$temp_array = $unsorted_strings; +var_dump( krsort($temp_array, SORT_STRING) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing krsort() by supplying string array (case insensitive), 'flag' = SORT_STRING|SORT_FLAG_CASE --\n"; +$temp_array = $unsorted_strings; +var_dump( krsort($temp_array, SORT_STRING|SORT_FLAG_CASE) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing krsort() by supplying string array (natural), 'flag' = SORT_NATURAL --\n"; +$temp_array = $unsorted_strings; +var_dump( krsort($temp_array, SORT_NATURAL) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing krsort() by supplying string array (natural, case insensitive), 'flag' = SORT_NATURAL|SORT_FLAG_CASE --\n"; +$temp_array = $unsorted_strings; +var_dump( krsort($temp_array, SORT_NATURAL|SORT_FLAG_CASE) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing krsort() by supplying numeric array, 'flag' = SORT_NUMERIC --\n"; +$temp_array = $unsorted_numerics; +var_dump( krsort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "Done\n"; +?> +--EXPECT-- +*** Testing krsort() : basic functionality *** + +-- Testing krsort() by supplying string array, 'flag' value is default -- +bool(true) +array(8) { + ["o20"]=> + string(8) "orange20" + ["o2"]=> + string(7) "orange2" + ["o"]=> + string(6) "orange" + ["l"]=> + string(5) "lemon" + ["b"]=> + string(6) "banana" + ["O3"]=> + string(7) "Orange3" + ["O1"]=> + string(7) "Orange1" + ["O"]=> + string(6) "Orange" +} + +-- Testing krsort() by supplying numeric array, 'flag' value is default -- +bool(true) +array(4) { + [555]=> + int(2) + [100]=> + int(4) + [33]=> + int(3) + [22]=> + int(1) +} + +-- Testing krsort() by supplying string array, 'flag' = SORT_REGULAR -- +bool(true) +array(8) { + ["o20"]=> + string(8) "orange20" + ["o2"]=> + string(7) "orange2" + ["o"]=> + string(6) "orange" + ["l"]=> + string(5) "lemon" + ["b"]=> + string(6) "banana" + ["O3"]=> + string(7) "Orange3" + ["O1"]=> + string(7) "Orange1" + ["O"]=> + string(6) "Orange" +} + +-- Testing krsort() by supplying numeric array, 'flag' = SORT_REGULAR -- +bool(true) +array(4) { + [555]=> + int(2) + [100]=> + int(4) + [33]=> + int(3) + [22]=> + int(1) +} + +-- Testing krsort() by supplying string array, 'flag' = SORT_STRING -- +bool(true) +array(8) { + ["o20"]=> + string(8) "orange20" + ["o2"]=> + string(7) "orange2" + ["o"]=> + string(6) "orange" + ["l"]=> + string(5) "lemon" + ["b"]=> + string(6) "banana" + ["O3"]=> + string(7) "Orange3" + ["O1"]=> + string(7) "Orange1" + ["O"]=> + string(6) "Orange" +} + +-- Testing krsort() by supplying string array (case insensitive), 'flag' = SORT_STRING|SORT_FLAG_CASE -- +bool(true) +array(8) { + ["O3"]=> + string(7) "Orange3" + ["o20"]=> + string(8) "orange20" + ["o2"]=> + string(7) "orange2" + ["O1"]=> + string(7) "Orange1" + ["o"]=> + string(6) "orange" + ["O"]=> + string(6) "Orange" + ["l"]=> + string(5) "lemon" + ["b"]=> + string(6) "banana" +} + +-- Testing krsort() by supplying string array (natural), 'flag' = SORT_NATURAL -- +bool(true) +array(8) { + ["o20"]=> + string(8) "orange20" + ["o2"]=> + string(7) "orange2" + ["o"]=> + string(6) "orange" + ["l"]=> + string(5) "lemon" + ["b"]=> + string(6) "banana" + ["O3"]=> + string(7) "Orange3" + ["O1"]=> + string(7) "Orange1" + ["O"]=> + string(6) "Orange" +} + +-- Testing krsort() by supplying string array (natural, case insensitive), 'flag' = SORT_NATURAL|SORT_FLAG_CASE -- +bool(true) +array(8) { + ["o20"]=> + string(8) "orange20" + ["O3"]=> + string(7) "Orange3" + ["o2"]=> + string(7) "orange2" + ["O1"]=> + string(7) "Orange1" + ["o"]=> + string(6) "orange" + ["O"]=> + string(6) "Orange" + ["l"]=> + string(5) "lemon" + ["b"]=> + string(6) "banana" +} + +-- Testing krsort() by supplying numeric array, 'flag' = SORT_NUMERIC -- +bool(true) +array(4) { + [555]=> + int(2) + [100]=> + int(4) + [33]=> + int(3) + [22]=> + int(1) +} +Done diff --git a/tests/std/array/krsort_object.phpt b/tests/std/array/krsort_object.phpt new file mode 100644 index 00000000..6e75ce1f --- /dev/null +++ b/tests/std/array/krsort_object.phpt @@ -0,0 +1,220 @@ +--TEST-- +Test krsort() function : object functionality - sort objects +--FILE-- +class_value = $value; + } +} +// class declaration for string objects +class StringObject +{ + public $class_value; + // initializing object member value + function __construct($value) + { + $this->class_value = $value; + } + // return string value + function __tostring(): string { + return (string) $this->value; + } +} +function main() +{ + /* + * testing krsort() by providing array of integer/string objects with following flag values: + * 1.Default flag value + * 2.SORT_REGULAR - compare items normally + */ + echo "*** Testing krsort() : object functionality ***\n"; + // array of integer objects with different key values + $unsorted_int_obj = array(10 => new IntegerObject(11), 20 => new IntegerObject(66), 3 => new IntegerObject(23), 4 => new IntegerObject(-5), 50 => new IntegerObject(0.001), 6 => new IntegerObject(0)); + // array of string objects with different key values + $unsorted_str_obj = array("axx" => new StringObject("axx"), "t" => new StringObject("t"), "w" => new StringObject("w"), "py" => new StringObject("py"), "apple" => new StringObject("apple"), "Orange" => new StringObject("Orange"), "Lemon" => new StringObject("Lemon"), "aPPle" => new StringObject("aPPle")); + echo "\n-- Testing krsort() by supplying various object arrays, 'flag' value is default --\n"; + // testing krsort() function by supplying integer object array, flag value is default + $temp_array = $unsorted_int_obj; + var_dump(krsort($temp_array)); + var_dump($temp_array); + // testing krsort() function by supplying string object array, flag value is default + $temp_array = $unsorted_str_obj; + var_dump(krsort($temp_array)); + var_dump($temp_array); + echo "\n-- Testing krsort() by supplying various object arrays, 'flag' value is SORT_REGULAR --\n"; + // testing krsort() function by supplying integer object array, flag value = SORT_REGULAR + $temp_array = $unsorted_int_obj; + var_dump(krsort($temp_array, SORT_REGULAR)); + var_dump($temp_array); + // testing krsort() function by supplying string object array, flag value = SORT_REGULAR + $temp_array = $unsorted_str_obj; + var_dump(krsort($temp_array, SORT_REGULAR)); + var_dump($temp_array); + echo "Done\n"; +} +?> +--EXPECTF-- +*** Testing krsort() : object functionality *** + +-- Testing krsort() by supplying various object arrays, 'flag' value is default -- +bool(true) +array(6) { + [50]=> + object(IntegerObject)#%d (1) { + ["class_value"]=> + float(0.001) + } + [20]=> + object(IntegerObject)#%d (1) { + ["class_value"]=> + int(66) + } + [10]=> + object(IntegerObject)#%d (1) { + ["class_value"]=> + int(11) + } + [6]=> + object(IntegerObject)#%d (1) { + ["class_value"]=> + int(0) + } + [4]=> + object(IntegerObject)#%d (1) { + ["class_value"]=> + int(-5) + } + [3]=> + object(IntegerObject)#%d (1) { + ["class_value"]=> + int(23) + } +} +bool(true) +array(8) { + ["w"]=> + object(StringObject)#%d (1) { + ["class_value"]=> + string(1) "w" + } + ["t"]=> + object(StringObject)#%d (1) { + ["class_value"]=> + string(1) "t" + } + ["py"]=> + object(StringObject)#%d (1) { + ["class_value"]=> + string(2) "py" + } + ["axx"]=> + object(StringObject)#%d (1) { + ["class_value"]=> + string(3) "axx" + } + ["apple"]=> + object(StringObject)#%d (1) { + ["class_value"]=> + string(5) "apple" + } + ["aPPle"]=> + object(StringObject)#%d (1) { + ["class_value"]=> + string(5) "aPPle" + } + ["Orange"]=> + object(StringObject)#%d (1) { + ["class_value"]=> + string(6) "Orange" + } + ["Lemon"]=> + object(StringObject)#%d (1) { + ["class_value"]=> + string(5) "Lemon" + } +} + +-- Testing krsort() by supplying various object arrays, 'flag' value is SORT_REGULAR -- +bool(true) +array(6) { + [50]=> + object(IntegerObject)#%d (1) { + ["class_value"]=> + float(0.001) + } + [20]=> + object(IntegerObject)#%d (1) { + ["class_value"]=> + int(66) + } + [10]=> + object(IntegerObject)#%d (1) { + ["class_value"]=> + int(11) + } + [6]=> + object(IntegerObject)#%d (1) { + ["class_value"]=> + int(0) + } + [4]=> + object(IntegerObject)#%d (1) { + ["class_value"]=> + int(-5) + } + [3]=> + object(IntegerObject)#%d (1) { + ["class_value"]=> + int(23) + } +} +bool(true) +array(8) { + ["w"]=> + object(StringObject)#%d (1) { + ["class_value"]=> + string(1) "w" + } + ["t"]=> + object(StringObject)#%d (1) { + ["class_value"]=> + string(1) "t" + } + ["py"]=> + object(StringObject)#%d (1) { + ["class_value"]=> + string(2) "py" + } + ["axx"]=> + object(StringObject)#%d (1) { + ["class_value"]=> + string(3) "axx" + } + ["apple"]=> + object(StringObject)#%d (1) { + ["class_value"]=> + string(5) "apple" + } + ["aPPle"]=> + object(StringObject)#%d (1) { + ["class_value"]=> + string(5) "aPPle" + } + ["Orange"]=> + object(StringObject)#%d (1) { + ["class_value"]=> + string(6) "Orange" + } + ["Lemon"]=> + object(StringObject)#%d (1) { + ["class_value"]=> + string(5) "Lemon" + } +} +Done diff --git a/tests/std/array/krsort_variation10.phpt b/tests/std/array/krsort_variation10.phpt new file mode 100644 index 00000000..104ed032 --- /dev/null +++ b/tests/std/array/krsort_variation10.phpt @@ -0,0 +1,93 @@ +--TEST-- +Test krsort() function : usage variations - sort heredoc strings +--FILE-- + "Heredoc", + $simple_heredoc2 => "HEREDOC", + $multiline_heredoc => "heredoc string\twith!@# and 123\nTest this!!!" +); + +echo "\n-- Testing krsort() by supplying heredoc string array, 'flag' value is default --\n"; +$temp_array = $array; +var_dump(krsort($temp_array) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing krsort() by supplying heredoc string array, 'flag' = SORT_REGULAR --\n"; +$temp_array = $array; +var_dump(krsort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing krsort() by supplying heredoc string array, 'flag' = SORT_STRING --\n"; +$temp_array = $array; +var_dump(krsort($temp_array, SORT_STRING) ); // expecting : bool(true) +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECT-- +*** Testing krsort() : usage variations *** + +-- Testing krsort() by supplying heredoc string array, 'flag' value is default -- +bool(true) +array(3) { + ["heredoc string with!@# and 123 +Test this!!!"]=> + string(43) "heredoc string with!@# and 123 +Test this!!!" + ["Heredoc"]=> + string(7) "Heredoc" + ["HEREDOC"]=> + string(7) "HEREDOC" +} + +-- Testing krsort() by supplying heredoc string array, 'flag' = SORT_REGULAR -- +bool(true) +array(3) { + ["heredoc string with!@# and 123 +Test this!!!"]=> + string(43) "heredoc string with!@# and 123 +Test this!!!" + ["Heredoc"]=> + string(7) "Heredoc" + ["HEREDOC"]=> + string(7) "HEREDOC" +} + +-- Testing krsort() by supplying heredoc string array, 'flag' = SORT_STRING -- +bool(true) +array(3) { + ["heredoc string with!@# and 123 +Test this!!!"]=> + string(43) "heredoc string with!@# and 123 +Test this!!!" + ["Heredoc"]=> + string(7) "Heredoc" + ["HEREDOC"]=> + string(7) "HEREDOC" +} +Done diff --git a/tests/std/array/krsort_variation11.phpt b/tests/std/array/krsort_variation11.phpt new file mode 100644 index 00000000..9e0e696f --- /dev/null +++ b/tests/std/array/krsort_variation11.phpt @@ -0,0 +1,77 @@ +--TEST-- +Test krsort() function : usage variations - sort bool values +--SKIPIF-- +--FILE-- + true, false => false, TRUE => TRUE, FALSE => FALSE); + +echo "\n-- Testing krsort() by supplying boolean value array, 'flag' value is default --\n"; +$temp_array = $bool_values; +var_dump(krsort($temp_array) ); +var_dump($temp_array); + +echo "\n-- Testing krsort() by supplying boolean value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $bool_values; +var_dump(krsort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +echo "\n-- Testing krsort() by supplying boolean value array, 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $bool_values; +var_dump(krsort($temp_array, SORT_NUMERIC) ); +var_dump($temp_array); + +echo "\n-- Testing krsort() by supplying boolean value array, 'flag' value is SORT_STRING --\n"; +$temp_array = $bool_values; +var_dump(krsort($temp_array, SORT_STRING) ); +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECT-- +*** Testing krsort() : usage variations *** + +-- Testing krsort() by supplying boolean value array, 'flag' value is default -- +bool(true) +array(2) { + [1]=> + bool(true) + [0]=> + bool(false) +} + +-- Testing krsort() by supplying boolean value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(2) { + [1]=> + bool(true) + [0]=> + bool(false) +} + +-- Testing krsort() by supplying boolean value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(2) { + [1]=> + bool(true) + [0]=> + bool(false) +} + +-- Testing krsort() by supplying boolean value array, 'flag' value is SORT_STRING -- +bool(true) +array(2) { + [1]=> + bool(true) + [0]=> + bool(false) +} +Done diff --git a/tests/std/array/krsort_variation3.phpt b/tests/std/array/krsort_variation3.phpt new file mode 100644 index 00000000..979d3844 --- /dev/null +++ b/tests/std/array/krsort_variation3.phpt @@ -0,0 +1,204 @@ +--TEST-- +Test krsort() function : usage variations - sort integer/float values +--FILE-- + 11, -2 => -11, 3 => 21, -4 => -21, 5 => 31, -6 => -31, 7 => 0, 8 => 41, -10 =>-41), + + // mixed value array with different types of keys + array(1 => .0001, 2 => .0021, -3 => -.01, 4 => -1, 5 => 0, 6 => .09, 7 => 2, -8 => -.9, 9 => 10.6E-2, + -10 => -10.6E-2, 11 => 33) +); + +// set of possible flag values +$flags = array("SORT_REGULAR" => SORT_REGULAR, "SORT_NUMERIC" => SORT_NUMERIC); + +$count = 1; +echo "\n-- Testing krsort() by supplying various integer/float arrays --\n"; + +// loop through to test krsort() with different arrays +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With default sort flag -\n"; + $temp_array = $array; + var_dump(krsort($temp_array) ); + var_dump($temp_array); + + // loop through $flags array and call krsort() with all possible sort flag values + foreach($flags as $key => $flag){ + echo "- Sort flag = $key -\n"; + $temp_array = $array; + var_dump(krsort($temp_array, $flag) ); + var_dump($temp_array); + } + $count++; +} + +echo "Done\n"; +?> +--EXPECT-- +*** Testing krsort() : usage variations *** + +-- Testing krsort() by supplying various integer/float arrays -- + +-- Iteration 1 -- +- With default sort flag - +bool(true) +array(9) { + [8]=> + int(41) + [7]=> + int(0) + [5]=> + int(31) + [3]=> + int(21) + [1]=> + int(11) + [-2]=> + int(-11) + [-4]=> + int(-21) + [-6]=> + int(-31) + [-10]=> + int(-41) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(9) { + [8]=> + int(41) + [7]=> + int(0) + [5]=> + int(31) + [3]=> + int(21) + [1]=> + int(11) + [-2]=> + int(-11) + [-4]=> + int(-21) + [-6]=> + int(-31) + [-10]=> + int(-41) +} +- Sort flag = SORT_NUMERIC - +bool(true) +array(9) { + [8]=> + int(41) + [7]=> + int(0) + [5]=> + int(31) + [3]=> + int(21) + [1]=> + int(11) + [-2]=> + int(-11) + [-4]=> + int(-21) + [-6]=> + int(-31) + [-10]=> + int(-41) +} + +-- Iteration 2 -- +- With default sort flag - +bool(true) +array(11) { + [11]=> + int(33) + [9]=> + float(0.106) + [7]=> + int(2) + [6]=> + float(0.09) + [5]=> + int(0) + [4]=> + int(-1) + [2]=> + float(0.0021) + [1]=> + float(0.0001) + [-3]=> + float(-0.01) + [-8]=> + float(-0.9) + [-10]=> + float(-0.106) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(11) { + [11]=> + int(33) + [9]=> + float(0.106) + [7]=> + int(2) + [6]=> + float(0.09) + [5]=> + int(0) + [4]=> + int(-1) + [2]=> + float(0.0021) + [1]=> + float(0.0001) + [-3]=> + float(-0.01) + [-8]=> + float(-0.9) + [-10]=> + float(-0.106) +} +- Sort flag = SORT_NUMERIC - +bool(true) +array(11) { + [11]=> + int(33) + [9]=> + float(0.106) + [7]=> + int(2) + [6]=> + float(0.09) + [5]=> + int(0) + [4]=> + int(-1) + [2]=> + float(0.0021) + [1]=> + float(0.0001) + [-3]=> + float(-0.01) + [-8]=> + float(-0.9) + [-10]=> + float(-0.106) +} +Done diff --git a/tests/std/array/krsort_variation4.phpt b/tests/std/array/krsort_variation4.phpt new file mode 100644 index 00000000..1f28d021 --- /dev/null +++ b/tests/std/array/krsort_variation4.phpt @@ -0,0 +1,109 @@ +--TEST-- +Test krsort() function : usage variations - sort octal values +--FILE-- + 01, 0321 => 02, 0345 => 03, 066 => 04, 0772 => 05, + 077 => 06, -066 => -01, -0345 => -02, 0 => 0 +); + +echo "\n-- Testing krsort() by supplying octal value array, 'flag' value is default --\n"; +$temp_array = $unsorted_oct_array; +var_dump( krsort($temp_array) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing krsort() by supplying octal value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $unsorted_oct_array; +var_dump( krsort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing krsort() by supplying octal value array, 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $unsorted_oct_array; +var_dump( krsort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECT-- +*** Testing krsort() : usage variations *** + +-- Testing krsort() by supplying octal value array, 'flag' value is default -- +bool(true) +array(9) { + [669]=> + int(1) + [506]=> + int(5) + [229]=> + int(3) + [209]=> + int(2) + [63]=> + int(6) + [54]=> + int(4) + [0]=> + int(0) + [-54]=> + int(-1) + [-229]=> + int(-2) +} + +-- Testing krsort() by supplying octal value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(9) { + [669]=> + int(1) + [506]=> + int(5) + [229]=> + int(3) + [209]=> + int(2) + [63]=> + int(6) + [54]=> + int(4) + [0]=> + int(0) + [-54]=> + int(-1) + [-229]=> + int(-2) +} + +-- Testing krsort() by supplying octal value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(9) { + [669]=> + int(1) + [506]=> + int(5) + [229]=> + int(3) + [209]=> + int(2) + [63]=> + int(6) + [54]=> + int(4) + [0]=> + int(0) + [-54]=> + int(-1) + [-229]=> + int(-2) +} +Done diff --git a/tests/std/array/krsort_variation5.phpt b/tests/std/array/krsort_variation5.phpt new file mode 100644 index 00000000..616a23c8 --- /dev/null +++ b/tests/std/array/krsort_variation5.phpt @@ -0,0 +1,227 @@ +--TEST-- +Test krsort() function : usage variations - sort strings +--SKIPIF-- + +--FILE-- + null, NULL => NULL, "\a" => "\a", "\cx" => "\cx", "\e" => "\e", + "\f" => "\f", "\n" =>"\n", "\r" => "\r", "\t" => "\t", "\xhh" => "\xhh", + "\ddd" => "\ddd", "\v" => "\v" + ), + + // array containing different strings with key values + array ( 'Lemon' => "lemoN", 'o' => "Orange", 'B' => "banana", 'Apple' => "apple", 'te' => "Test", + 't' => "TTTT", 'T' => "ttt", 'W' => "ww", 'X' => "x", 'x' => "X", 'O' => "oraNGe", + 'B' => "BANANA" + ) +); + +$flags = array("SORT_REGULAR" => SORT_REGULAR, "SORT_STRING" => SORT_STRING); + +$count = 1; +echo "\n-- Testing krsort() by supplying various string arrays --\n"; + +// loop through to test krsort() with different arrays +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With default sort flag -\n"; + $temp_array = $array; + var_dump(krsort($temp_array) ); // expecting : bool(true) + var_dump($temp_array); + + // loop through $flags array and call krsort() with all possible sort flag values + foreach($flags as $key => $flag){ + echo "- Sort flag = $key -\n"; + $temp_array = $array; + var_dump(krsort($temp_array, $flag) ); // expecting : bool(true) + var_dump($temp_array); + } + $count++; +} + +echo "Done\n"; +?> +--EXPECT-- +*** Testing krsort() : usage variations *** + +-- Testing krsort() by supplying various string arrays -- + +-- Iteration 1 -- +- With default sort flag - +bool(true) +array(11) { + ["\xhh"]=> + string(4) "\xhh" + ["\ddd"]=> + string(4) "\ddd" + ["\cx"]=> + string(3) "\cx" + ["\a"]=> + string(2) "\a" + [""]=> + string(1) "" + [" "]=> + string(1) " " + [" "]=> + string(1) " " + [" "]=> + string(1) " " + [" +"]=> + string(1) " +" + [" "]=> + string(1) " " + [""]=> + NULL +} +- Sort flag = SORT_REGULAR - +bool(true) +array(11) { + ["\xhh"]=> + string(4) "\xhh" + ["\ddd"]=> + string(4) "\ddd" + ["\cx"]=> + string(3) "\cx" + ["\a"]=> + string(2) "\a" + [""]=> + string(1) "" + [" "]=> + string(1) " " + [" "]=> + string(1) " " + [" "]=> + string(1) " " + [" +"]=> + string(1) " +" + [" "]=> + string(1) " " + [""]=> + NULL +} +- Sort flag = SORT_STRING - +bool(true) +array(11) { + ["\xhh"]=> + string(4) "\xhh" + ["\ddd"]=> + string(4) "\ddd" + ["\cx"]=> + string(3) "\cx" + ["\a"]=> + string(2) "\a" + [""]=> + string(1) "" + [" "]=> + string(1) " " + [" "]=> + string(1) " " + [" "]=> + string(1) " " + [" +"]=> + string(1) " +" + [" "]=> + string(1) " " + [""]=> + NULL +} + +-- Iteration 2 -- +- With default sort flag - +bool(true) +array(11) { + ["x"]=> + string(1) "X" + ["te"]=> + string(4) "Test" + ["t"]=> + string(4) "TTTT" + ["o"]=> + string(6) "Orange" + ["X"]=> + string(1) "x" + ["W"]=> + string(2) "ww" + ["T"]=> + string(3) "ttt" + ["O"]=> + string(6) "oraNGe" + ["Lemon"]=> + string(5) "lemoN" + ["B"]=> + string(6) "BANANA" + ["Apple"]=> + string(5) "apple" +} +- Sort flag = SORT_REGULAR - +bool(true) +array(11) { + ["x"]=> + string(1) "X" + ["te"]=> + string(4) "Test" + ["t"]=> + string(4) "TTTT" + ["o"]=> + string(6) "Orange" + ["X"]=> + string(1) "x" + ["W"]=> + string(2) "ww" + ["T"]=> + string(3) "ttt" + ["O"]=> + string(6) "oraNGe" + ["Lemon"]=> + string(5) "lemoN" + ["B"]=> + string(6) "BANANA" + ["Apple"]=> + string(5) "apple" +} +- Sort flag = SORT_STRING - +bool(true) +array(11) { + ["x"]=> + string(1) "X" + ["te"]=> + string(4) "Test" + ["t"]=> + string(4) "TTTT" + ["o"]=> + string(6) "Orange" + ["X"]=> + string(1) "x" + ["W"]=> + string(2) "ww" + ["T"]=> + string(3) "ttt" + ["O"]=> + string(6) "oraNGe" + ["Lemon"]=> + string(5) "lemoN" + ["B"]=> + string(6) "BANANA" + ["Apple"]=> + string(5) "apple" +} +Done diff --git a/tests/std/array/krsort_variation6.phpt b/tests/std/array/krsort_variation6.phpt new file mode 100644 index 00000000..c737cb4b --- /dev/null +++ b/tests/std/array/krsort_variation6.phpt @@ -0,0 +1,109 @@ +--TEST-- +Test krsort() function : usage variations - sort hexadecimal values +--FILE-- + 0x1AB, 0xFFF => 0xFFF, 0xF => 0xF, 0xFF => 0xFF, 0x2AA => 0x2AA, 0xBB => 0xBB, + 0x1ab => 0x1ab, 0xff => 0xff, -0xff => -0xFF, 0 => 0, -0x2aa => -0x2aa +); + +echo "\n-- Testing krsort() by supplying hexadecimal value array, 'flag' value is default --\n"; +$temp_array = $unsorted_hex_array; +var_dump(krsort( $temp_array) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing krsort() by supplying hexadecimal value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $unsorted_hex_array; +var_dump(krsort( $temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing krsort() by supplying hexadecimal value array, 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $unsorted_hex_array; +var_dump(krsort( $temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECT-- +*** Testing krsort() : usage variations *** + +-- Testing krsort() by supplying hexadecimal value array, 'flag' value is default -- +bool(true) +array(9) { + [4095]=> + int(4095) + [682]=> + int(682) + [427]=> + int(427) + [255]=> + int(255) + [187]=> + int(187) + [15]=> + int(15) + [0]=> + int(0) + [-255]=> + int(-255) + [-682]=> + int(-682) +} + +-- Testing krsort() by supplying hexadecimal value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(9) { + [4095]=> + int(4095) + [682]=> + int(682) + [427]=> + int(427) + [255]=> + int(255) + [187]=> + int(187) + [15]=> + int(15) + [0]=> + int(0) + [-255]=> + int(-255) + [-682]=> + int(-682) +} + +-- Testing krsort() by supplying hexadecimal value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(9) { + [4095]=> + int(4095) + [682]=> + int(682) + [427]=> + int(427) + [255]=> + int(255) + [187]=> + int(187) + [15]=> + int(15) + [0]=> + int(0) + [-255]=> + int(-255) + [-682]=> + int(-682) +} +Done diff --git a/tests/std/array/krsort_variation7.phpt b/tests/std/array/krsort_variation7.phpt new file mode 100644 index 00000000..9d25d93a --- /dev/null +++ b/tests/std/array/krsort_variation7.phpt @@ -0,0 +1,172 @@ +--TEST-- +Test krsort() function : usage variations - sort array with diff. sub arrays +--FILE-- + array(), + + // array contains null sub array + 2 => array( 1 => array() ), + + // array of arrays along with some values + 3 => array(4 => 44, 1 => 11, 3 => array(64,61) ), + + // array contains sub arrays + 4 => array ( 3 => array(33,-5,6), 1 => array(11), + 2 => array(22,-55), 0 => array() ) +); + + +$count = 1; +echo "\n-- Testing krsort() by supplying various arrays containing sub arrays --\n"; + +// loop through to test krsort() with different arrays +foreach ($various_arrays as $array) { + + echo "\n-- Iteration $count --\n"; + echo "- With default sort flag -\n"; + $temp_array = $array; + var_dump( krsort($temp_array) ); + var_dump($temp_array); + + echo "- Sort flag = SORT_REGULAR -\n"; + $temp_array = $array; + var_dump( krsort($temp_array, SORT_REGULAR) ); + var_dump($temp_array); + $count++; +} + +echo "Done\n"; +?> +--EXPECT-- +*** Testing krsort() : usage variations *** + +-- Testing krsort() by supplying various arrays containing sub arrays -- + +-- Iteration 1 -- +- With default sort flag - +bool(true) +array(0) { +} +- Sort flag = SORT_REGULAR - +bool(true) +array(0) { +} + +-- Iteration 2 -- +- With default sort flag - +bool(true) +array(1) { + [1]=> + array(0) { + } +} +- Sort flag = SORT_REGULAR - +bool(true) +array(1) { + [1]=> + array(0) { + } +} + +-- Iteration 3 -- +- With default sort flag - +bool(true) +array(3) { + [4]=> + int(44) + [3]=> + array(2) { + [0]=> + int(64) + [1]=> + int(61) + } + [1]=> + int(11) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(3) { + [4]=> + int(44) + [3]=> + array(2) { + [0]=> + int(64) + [1]=> + int(61) + } + [1]=> + int(11) +} + +-- Iteration 4 -- +- With default sort flag - +bool(true) +array(4) { + [3]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } + [2]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + [1]=> + array(1) { + [0]=> + int(11) + } + [0]=> + array(0) { + } +} +- Sort flag = SORT_REGULAR - +bool(true) +array(4) { + [3]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } + [2]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + [1]=> + array(1) { + [0]=> + int(11) + } + [0]=> + array(0) { + } +} +Done diff --git a/tests/std/array/krsort_variation8.phpt b/tests/std/array/krsort_variation8.phpt new file mode 100644 index 00000000..458ee1e3 --- /dev/null +++ b/tests/std/array/krsort_variation8.phpt @@ -0,0 +1,156 @@ +--TEST-- +Test krsort() function : usage variations - sort mixed values, 'sort_flags' as default/SORT_REGULAR (OK to fail as result is unpredectable) +--SKIPIF-- + +--FILE-- + array(), + "array2" => array ( "sub_array[2,1]" => array(33,-5,6), "sub_array[2,2]" => array(11), + "sub_array[2,3]" => array(22,-55), "sub_array[2,4]" => array() + ), + 4 => 4, "4" => "4", 4 => 4.01, "b" => "b", "5" => "5", -2 => -2, -2 => -2.01, + -2 => -2.98989, "-.9" => "-.9", "True" => "True", "" => "", NULL => NULL, + "ab" => "ab", "abcd" => "abcd", 0 => 0.01, -0 => -0, '' => '' , + "abcd\x00abcd\x00abcd" => "abcd\x00abcd\x00abcd", 0 => 0.001 +); + +echo "\n-- Testing krsort() by supplying mixed value array, 'flag' value is default --\n"; +$temp_array = $mixed_values; +var_dump( krsort($temp_array) ); +var_dump($temp_array); + +echo "\n-- Testing krsort() by supplying mixed value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $mixed_values; +var_dump( krsort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing krsort() : usage variations *** + +-- Testing krsort() by supplying mixed value array, 'flag' value is default -- +bool(true) +array(13) { + ["b"]=> + string(1) "b" + ["array2"]=> + array(4) { + ["sub_array[2,1]"]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } + ["sub_array[2,2]"]=> + array(1) { + [0]=> + int(11) + } + ["sub_array[2,3]"]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + ["sub_array[2,4]"]=> + array(0) { + } + } + ["array1"]=> + array(0) { + } + ["abcd%0abcd%0abcd"]=> + string(14) "abcd%0abcd%0abcd" + ["abcd"]=> + string(4) "abcd" + ["ab"]=> + string(2) "ab" + ["True"]=> + string(4) "True" + [5]=> + string(1) "5" + [4]=> + float(4.01) + [0]=> + float(0.001) + ["-.9"]=> + string(3) "-.9" + [-2]=> + float(-2.98989) + [""]=> + string(0) "" +} + +-- Testing krsort() by supplying mixed value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(13) { + ["b"]=> + string(1) "b" + ["array2"]=> + array(4) { + ["sub_array[2,1]"]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } + ["sub_array[2,2]"]=> + array(1) { + [0]=> + int(11) + } + ["sub_array[2,3]"]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + ["sub_array[2,4]"]=> + array(0) { + } + } + ["array1"]=> + array(0) { + } + ["abcd%0abcd%0abcd"]=> + string(14) "abcd%0abcd%0abcd" + ["abcd"]=> + string(4) "abcd" + ["ab"]=> + string(2) "ab" + ["True"]=> + string(4) "True" + [5]=> + string(1) "5" + [4]=> + float(4.01) + [0]=> + float(0.001) + ["-.9"]=> + string(3) "-.9" + [-2]=> + float(-2.98989) + [""]=> + string(0) "" +} +Done diff --git a/tests/std/array/krsort_variation9.phpt b/tests/std/array/krsort_variation9.phpt new file mode 100644 index 00000000..b0309f37 --- /dev/null +++ b/tests/std/array/krsort_variation9.phpt @@ -0,0 +1,252 @@ +--TEST-- +Test krsort() function : usage variations - sort array with/without key values +--FILE-- + 55, 66, 22, 33, 11), + array ("a" => "orange", "banana", "c" => "apple"), + array(1, 2, 3, 4, 5, 6), + array("first", 5 => "second", 1 => "third"), + array(1, 1, 8 => 1, 4 => 1, 19, 3 => 13), + array('bar' => 'baz', "foo" => 1), + array('a' => 1,'b' => array('e' => 2,'f' => 3),'c' => array('g' => 4),'d' => 5), +); + +$count = 1; +echo "\n-- Testing krsort() by supplying various arrays with/without key values --\n"; + +// loop through to test krsort() with different arrays, +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With default sort flag -\n"; + $temp_array = $array; + var_dump( krsort($temp_array) ); + var_dump($temp_array); + + echo "- Sort flag = SORT_REGULAR -\n"; + $temp_array = $array; + var_dump( krsort($temp_array, SORT_REGULAR) ); + var_dump($temp_array); + $count++; +} + +echo "Done\n"; +?> +--EXPECT-- +*** Testing krsort() : usage variations *** + +-- Testing krsort() by supplying various arrays with/without key values -- + +-- Iteration 1 -- +- With default sort flag - +bool(true) +array(5) { + [9]=> + int(11) + [8]=> + int(33) + [7]=> + int(22) + [6]=> + int(66) + [5]=> + int(55) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(5) { + [9]=> + int(11) + [8]=> + int(33) + [7]=> + int(22) + [6]=> + int(66) + [5]=> + int(55) +} + +-- Iteration 2 -- +- With default sort flag - +bool(true) +array(3) { + ["c"]=> + string(5) "apple" + ["a"]=> + string(6) "orange" + [0]=> + string(6) "banana" +} +- Sort flag = SORT_REGULAR - +bool(true) +array(3) { + ["c"]=> + string(5) "apple" + ["a"]=> + string(6) "orange" + [0]=> + string(6) "banana" +} + +-- Iteration 3 -- +- With default sort flag - +bool(true) +array(6) { + [5]=> + int(6) + [4]=> + int(5) + [3]=> + int(4) + [2]=> + int(3) + [1]=> + int(2) + [0]=> + int(1) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(6) { + [5]=> + int(6) + [4]=> + int(5) + [3]=> + int(4) + [2]=> + int(3) + [1]=> + int(2) + [0]=> + int(1) +} + +-- Iteration 4 -- +- With default sort flag - +bool(true) +array(3) { + [5]=> + string(6) "second" + [1]=> + string(5) "third" + [0]=> + string(5) "first" +} +- Sort flag = SORT_REGULAR - +bool(true) +array(3) { + [5]=> + string(6) "second" + [1]=> + string(5) "third" + [0]=> + string(5) "first" +} + +-- Iteration 5 -- +- With default sort flag - +bool(true) +array(6) { + [9]=> + int(19) + [8]=> + int(1) + [4]=> + int(1) + [3]=> + int(13) + [1]=> + int(1) + [0]=> + int(1) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(6) { + [9]=> + int(19) + [8]=> + int(1) + [4]=> + int(1) + [3]=> + int(13) + [1]=> + int(1) + [0]=> + int(1) +} + +-- Iteration 6 -- +- With default sort flag - +bool(true) +array(2) { + ["foo"]=> + int(1) + ["bar"]=> + string(3) "baz" +} +- Sort flag = SORT_REGULAR - +bool(true) +array(2) { + ["foo"]=> + int(1) + ["bar"]=> + string(3) "baz" +} + +-- Iteration 7 -- +- With default sort flag - +bool(true) +array(4) { + ["d"]=> + int(5) + ["c"]=> + array(1) { + ["g"]=> + int(4) + } + ["b"]=> + array(2) { + ["e"]=> + int(2) + ["f"]=> + int(3) + } + ["a"]=> + int(1) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(4) { + ["d"]=> + int(5) + ["c"]=> + array(1) { + ["g"]=> + int(4) + } + ["b"]=> + array(2) { + ["e"]=> + int(2) + ["f"]=> + int(3) + } + ["a"]=> + int(1) +} +Done diff --git a/tests/std/array/ksort_basic.phpt b/tests/std/array/ksort_basic.phpt new file mode 100644 index 00000000..96135981 --- /dev/null +++ b/tests/std/array/ksort_basic.phpt @@ -0,0 +1,238 @@ +--TEST-- +Test ksort() function : basic functionality +--FILE-- + "lemon", "o" => "orange", + "O" => "Orange", "O1" => "Orange1", "o2" => "orange2", "O3" => "Orange3", "o20" => "orange20", + "b" => "banana", +); +// an array containing unsorted numeric values with indices +$unsorted_numerics = array( 100 => 4, 33 => 3, 555 => 2, 22 => 1 ); + +echo "\n-- Testing ksort() by supplying string array, 'flag' value is default --\n"; +$temp_array = $unsorted_strings; +var_dump( ksort($temp_array) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing ksort() by supplying numeric array, 'flag' value is default --\n"; +$temp_array = $unsorted_numerics; +var_dump( ksort($temp_array) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing ksort() by supplying string array, 'flag' = SORT_REGULAR --\n"; +$temp_array = $unsorted_strings; +var_dump( ksort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing ksort() by supplying numeric array, 'flag' = SORT_REGULAR --\n"; +$temp_array = $unsorted_numerics; +var_dump( ksort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing ksort() by supplying string array, 'flag' = SORT_STRING --\n"; +$temp_array = $unsorted_strings; +var_dump( ksort($temp_array, SORT_STRING) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing ksort() by supplying string array (case insensitive), 'flag' = SORT_STRING|SORT_FLAG_CASE --\n"; +$temp_array = $unsorted_strings; +var_dump( ksort($temp_array, SORT_STRING|SORT_FLAG_CASE) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing ksort() by supplying string array (natural), 'flag' = SORT_NATURAL --\n"; +$temp_array = $unsorted_strings; +var_dump( ksort($temp_array, SORT_NATURAL) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing ksort() by supplying string array (natural, case insensitive), 'flag' = SORT_NATURAL|SORT_FLAG_CASE --\n"; +$temp_array = $unsorted_strings; +var_dump( ksort($temp_array, SORT_NATURAL|SORT_FLAG_CASE) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing ksort() by supplying numeric array, 'flag' = SORT_NUMERIC --\n"; +$temp_array = $unsorted_numerics; +var_dump( ksort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "Done\n"; +?> +--EXPECT-- +*** Testing ksort() : basic functionality *** + +-- Testing ksort() by supplying string array, 'flag' value is default -- +bool(true) +array(8) { + ["O"]=> + string(6) "Orange" + ["O1"]=> + string(7) "Orange1" + ["O3"]=> + string(7) "Orange3" + ["b"]=> + string(6) "banana" + ["l"]=> + string(5) "lemon" + ["o"]=> + string(6) "orange" + ["o2"]=> + string(7) "orange2" + ["o20"]=> + string(8) "orange20" +} + +-- Testing ksort() by supplying numeric array, 'flag' value is default -- +bool(true) +array(4) { + [22]=> + int(1) + [33]=> + int(3) + [100]=> + int(4) + [555]=> + int(2) +} + +-- Testing ksort() by supplying string array, 'flag' = SORT_REGULAR -- +bool(true) +array(8) { + ["O"]=> + string(6) "Orange" + ["O1"]=> + string(7) "Orange1" + ["O3"]=> + string(7) "Orange3" + ["b"]=> + string(6) "banana" + ["l"]=> + string(5) "lemon" + ["o"]=> + string(6) "orange" + ["o2"]=> + string(7) "orange2" + ["o20"]=> + string(8) "orange20" +} + +-- Testing ksort() by supplying numeric array, 'flag' = SORT_REGULAR -- +bool(true) +array(4) { + [22]=> + int(1) + [33]=> + int(3) + [100]=> + int(4) + [555]=> + int(2) +} + +-- Testing ksort() by supplying string array, 'flag' = SORT_STRING -- +bool(true) +array(8) { + ["O"]=> + string(6) "Orange" + ["O1"]=> + string(7) "Orange1" + ["O3"]=> + string(7) "Orange3" + ["b"]=> + string(6) "banana" + ["l"]=> + string(5) "lemon" + ["o"]=> + string(6) "orange" + ["o2"]=> + string(7) "orange2" + ["o20"]=> + string(8) "orange20" +} + +-- Testing ksort() by supplying string array (case insensitive), 'flag' = SORT_STRING|SORT_FLAG_CASE -- +bool(true) +array(8) { + ["b"]=> + string(6) "banana" + ["l"]=> + string(5) "lemon" + ["o"]=> + string(6) "orange" + ["O"]=> + string(6) "Orange" + ["O1"]=> + string(7) "Orange1" + ["o2"]=> + string(7) "orange2" + ["o20"]=> + string(8) "orange20" + ["O3"]=> + string(7) "Orange3" +} + +-- Testing ksort() by supplying string array (natural), 'flag' = SORT_NATURAL -- +bool(true) +array(8) { + ["O"]=> + string(6) "Orange" + ["O1"]=> + string(7) "Orange1" + ["O3"]=> + string(7) "Orange3" + ["b"]=> + string(6) "banana" + ["l"]=> + string(5) "lemon" + ["o"]=> + string(6) "orange" + ["o2"]=> + string(7) "orange2" + ["o20"]=> + string(8) "orange20" +} + +-- Testing ksort() by supplying string array (natural, case insensitive), 'flag' = SORT_NATURAL|SORT_FLAG_CASE -- +bool(true) +array(8) { + ["b"]=> + string(6) "banana" + ["l"]=> + string(5) "lemon" + ["o"]=> + string(6) "orange" + ["O"]=> + string(6) "Orange" + ["O1"]=> + string(7) "Orange1" + ["o2"]=> + string(7) "orange2" + ["O3"]=> + string(7) "Orange3" + ["o20"]=> + string(8) "orange20" +} + +-- Testing ksort() by supplying numeric array, 'flag' = SORT_NUMERIC -- +bool(true) +array(4) { + [22]=> + int(1) + [33]=> + int(3) + [100]=> + int(4) + [555]=> + int(2) +} +Done diff --git a/tests/std/array/ksort_object.phpt b/tests/std/array/ksort_object.phpt new file mode 100644 index 00000000..86e2d6b4 --- /dev/null +++ b/tests/std/array/ksort_object.phpt @@ -0,0 +1,220 @@ +--TEST-- +Test ksort() function : object functionality - sort objects +--FILE-- +class_value = $value; + } +} +// class declaration for string objects +class StringObject +{ + public $class_value; + // initializing object member value + function __construct($value) + { + $this->class_value = $value; + } + // return string value + function __tostring(): string { + return (string) $this->value; + } +} +function main() +{ + /* + * testing ksort() by providing array ofinteger/string objects with following flag values: + * 1.SORT_NUMERIC - compare items numerically + * 2.SORT_STRING - compare items as strings + */ + echo "*** Testing ksort() : object functionality ***\n"; + // array of integer objects + $unsorted_int_obj = array(11 => new IntegerObject(11), 66 => new IntegerObject(66), 23 => new IntegerObject(23), -5 => new IntegerObject(-5), 1 => new IntegerObject(0.001), 0 => new IntegerObject(0)); + // array of string objects + $unsorted_str_obj = array("axx" => new StringObject("axx"), "t" => new StringObject("t"), "w" => new StringObject("w"), "py" => new StringObject("py"), "apple" => new StringObject("apple"), "Orange" => new StringObject("Orange"), "Lemon" => new StringObject("Lemon"), "aPPle" => new StringObject("aPPle")); + echo "\n-- Testing ksort() by supplying various object arrays, 'flag' value is default --\n"; + // testing ksort() function by supplying integer object array, flag value is default + $temp_array = $unsorted_int_obj; + var_dump(ksort($temp_array)); + var_dump($temp_array); + // testing ksort() function by supplying string object array, flag value is default + $temp_array = $unsorted_str_obj; + var_dump(ksort($temp_array)); + var_dump($temp_array); + echo "\n-- Testing ksort() by supplying various object arrays, 'flag' value is SORT_REGULAR --\n"; + // testing ksort() function by supplying integer object array, flag value = SORT_REGULAR + $temp_array = $unsorted_int_obj; + var_dump(ksort($temp_array, SORT_REGULAR)); + var_dump($temp_array); + // testing ksort() function by supplying string object array, flag value = SORT_REGULAR + $temp_array = $unsorted_str_obj; + var_dump(ksort($temp_array, SORT_REGULAR)); + var_dump($temp_array); + echo "Done\n"; +} +?> +--EXPECTF-- +*** Testing ksort() : object functionality *** + +-- Testing ksort() by supplying various object arrays, 'flag' value is default -- +bool(true) +array(6) { + [-5]=> + object(IntegerObject)#%d (1) { + ["class_value"]=> + int(-5) + } + [0]=> + object(IntegerObject)#%d (1) { + ["class_value"]=> + int(0) + } + [1]=> + object(IntegerObject)#%d (1) { + ["class_value"]=> + float(0.001) + } + [11]=> + object(IntegerObject)#%d (1) { + ["class_value"]=> + int(11) + } + [23]=> + object(IntegerObject)#%d (1) { + ["class_value"]=> + int(23) + } + [66]=> + object(IntegerObject)#%d (1) { + ["class_value"]=> + int(66) + } +} +bool(true) +array(8) { + ["Lemon"]=> + object(StringObject)#%d (1) { + ["class_value"]=> + string(5) "Lemon" + } + ["Orange"]=> + object(StringObject)#%d (1) { + ["class_value"]=> + string(6) "Orange" + } + ["aPPle"]=> + object(StringObject)#%d (1) { + ["class_value"]=> + string(5) "aPPle" + } + ["apple"]=> + object(StringObject)#%d (1) { + ["class_value"]=> + string(5) "apple" + } + ["axx"]=> + object(StringObject)#%d (1) { + ["class_value"]=> + string(3) "axx" + } + ["py"]=> + object(StringObject)#%d (1) { + ["class_value"]=> + string(2) "py" + } + ["t"]=> + object(StringObject)#%d (1) { + ["class_value"]=> + string(1) "t" + } + ["w"]=> + object(StringObject)#%d (1) { + ["class_value"]=> + string(1) "w" + } +} + +-- Testing ksort() by supplying various object arrays, 'flag' value is SORT_REGULAR -- +bool(true) +array(6) { + [-5]=> + object(IntegerObject)#%d (1) { + ["class_value"]=> + int(-5) + } + [0]=> + object(IntegerObject)#%d (1) { + ["class_value"]=> + int(0) + } + [1]=> + object(IntegerObject)#%d (1) { + ["class_value"]=> + float(0.001) + } + [11]=> + object(IntegerObject)#%d (1) { + ["class_value"]=> + int(11) + } + [23]=> + object(IntegerObject)#%d (1) { + ["class_value"]=> + int(23) + } + [66]=> + object(IntegerObject)#%d (1) { + ["class_value"]=> + int(66) + } +} +bool(true) +array(8) { + ["Lemon"]=> + object(StringObject)#%d (1) { + ["class_value"]=> + string(5) "Lemon" + } + ["Orange"]=> + object(StringObject)#%d (1) { + ["class_value"]=> + string(6) "Orange" + } + ["aPPle"]=> + object(StringObject)#%d (1) { + ["class_value"]=> + string(5) "aPPle" + } + ["apple"]=> + object(StringObject)#%d (1) { + ["class_value"]=> + string(5) "apple" + } + ["axx"]=> + object(StringObject)#%d (1) { + ["class_value"]=> + string(3) "axx" + } + ["py"]=> + object(StringObject)#%d (1) { + ["class_value"]=> + string(2) "py" + } + ["t"]=> + object(StringObject)#%d (1) { + ["class_value"]=> + string(1) "t" + } + ["w"]=> + object(StringObject)#%d (1) { + ["class_value"]=> + string(1) "w" + } +} +Done diff --git a/tests/std/array/ksort_variation10.phpt b/tests/std/array/ksort_variation10.phpt new file mode 100644 index 00000000..6d151b92 --- /dev/null +++ b/tests/std/array/ksort_variation10.phpt @@ -0,0 +1,108 @@ +--TEST-- +Test ksort() function : usage variations - sort octal values +--FILE-- + 01, 0321 => 02, 0345 => 03, 066 => 04, 0772 => 05, + 077 => 06, -066 => -01, -0345 => -02, 0 => 0 +); + +echo "\n-- Testing ksort() by supplying octal value array, 'flag' value is default --\n"; +$temp_array = $unsorted_oct_array; +var_dump( ksort($temp_array) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing ksort() by supplying octal value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $unsorted_oct_array; +var_dump( ksort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing ksort() by supplying octal value array, 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $unsorted_oct_array; +var_dump( ksort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECT-- +*** Testing ksort() : usage variations *** + +-- Testing ksort() by supplying octal value array, 'flag' value is default -- +bool(true) +array(9) { + [-229]=> + int(-2) + [-54]=> + int(-1) + [0]=> + int(0) + [54]=> + int(4) + [63]=> + int(6) + [209]=> + int(2) + [229]=> + int(3) + [506]=> + int(5) + [669]=> + int(1) +} + +-- Testing ksort() by supplying octal value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(9) { + [-229]=> + int(-2) + [-54]=> + int(-1) + [0]=> + int(0) + [54]=> + int(4) + [63]=> + int(6) + [209]=> + int(2) + [229]=> + int(3) + [506]=> + int(5) + [669]=> + int(1) +} + +-- Testing ksort() by supplying octal value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(9) { + [-229]=> + int(-2) + [-54]=> + int(-1) + [0]=> + int(0) + [54]=> + int(4) + [63]=> + int(6) + [209]=> + int(2) + [229]=> + int(3) + [506]=> + int(5) + [669]=> + int(1) +} +Done diff --git a/tests/std/array/ksort_variation11.phpt b/tests/std/array/ksort_variation11.phpt new file mode 100644 index 00000000..59b18aa6 --- /dev/null +++ b/tests/std/array/ksort_variation11.phpt @@ -0,0 +1,93 @@ +--TEST-- +Test ksort() function : usage variations - sort heredoc strings +--FILE-- + "Heredoc", + $simple_heredoc2 => "HEREDOC", + $multiline_heredoc => "heredoc string\twith!@# and 123\nTest this!!!" +); + +echo "\n-- Testing ksort() by supplying heredoc string array, 'flag' value is default --\n"; +$temp_array = $array; +var_dump(ksort($temp_array) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing ksort() by supplying heredoc string array, 'flag' = SORT_REGULAR --\n"; +$temp_array = $array; +var_dump(ksort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing ksort() by supplying heredoc string array, 'flag' = SORT_STRING --\n"; +$temp_array = $array; +var_dump(ksort($temp_array, SORT_STRING) ); // expecting : bool(true) +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECT-- +*** Testing ksort() : usage variations *** + +-- Testing ksort() by supplying heredoc string array, 'flag' value is default -- +bool(true) +array(3) { + ["HEREDOC"]=> + string(7) "HEREDOC" + ["Heredoc"]=> + string(7) "Heredoc" + ["heredoc string with!@# and 123 +Test this!!!"]=> + string(43) "heredoc string with!@# and 123 +Test this!!!" +} + +-- Testing ksort() by supplying heredoc string array, 'flag' = SORT_REGULAR -- +bool(true) +array(3) { + ["HEREDOC"]=> + string(7) "HEREDOC" + ["Heredoc"]=> + string(7) "Heredoc" + ["heredoc string with!@# and 123 +Test this!!!"]=> + string(43) "heredoc string with!@# and 123 +Test this!!!" +} + +-- Testing ksort() by supplying heredoc string array, 'flag' = SORT_STRING -- +bool(true) +array(3) { + ["HEREDOC"]=> + string(7) "HEREDOC" + ["Heredoc"]=> + string(7) "Heredoc" + ["heredoc string with!@# and 123 +Test this!!!"]=> + string(43) "heredoc string with!@# and 123 +Test this!!!" +} +Done diff --git a/tests/std/array/ksort_variation3.phpt b/tests/std/array/ksort_variation3.phpt new file mode 100644 index 00000000..35954ba6 --- /dev/null +++ b/tests/std/array/ksort_variation3.phpt @@ -0,0 +1,204 @@ +--TEST-- +Test ksort() function : usage variations - sort integer/float values +--FILE-- + 11, -2 => -11, 3 => 21, -4 => -21, 5 => 31, -6 => -31, 7 => 0, 8 => 41, -10 =>-41), + + // mixed value array with different types of keys + array(1 => .0001, 2 => .0021, -3 => -.01, 4 => -1, 5 => 0, 6 => .09, 7 => 2, -8 => -.9, + 9 => 10.6E-2, -10 => -10.6E-2, 11 => 33) +); + +// set of possible flag values +$flags = array("SORT_REGULAR" => SORT_REGULAR, "SORT_NUMERIC" => SORT_NUMERIC); + +$count = 1; +echo "\n-- Testing ksort() by supplying various integer/float arrays --\n"; + +// loop through to test ksort() with different arrays +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With default sort flag -\n"; + $temp_array = $array; + var_dump(ksort($temp_array) ); + var_dump($temp_array); + + // loop through $flags array and call ksort() with all possible sort flag values + foreach($flags as $key => $flag){ + echo "- Sort flag = $key -\n"; + $temp_array = $array; + var_dump(ksort($temp_array, $flag) ); + var_dump($temp_array); + } + $count++; +} + +echo "Done\n"; +?> +--EXPECT-- +*** Testing ksort() : usage variations *** + +-- Testing ksort() by supplying various integer/float arrays -- + +-- Iteration 1 -- +- With default sort flag - +bool(true) +array(9) { + [-10]=> + int(-41) + [-6]=> + int(-31) + [-4]=> + int(-21) + [-2]=> + int(-11) + [1]=> + int(11) + [3]=> + int(21) + [5]=> + int(31) + [7]=> + int(0) + [8]=> + int(41) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(9) { + [-10]=> + int(-41) + [-6]=> + int(-31) + [-4]=> + int(-21) + [-2]=> + int(-11) + [1]=> + int(11) + [3]=> + int(21) + [5]=> + int(31) + [7]=> + int(0) + [8]=> + int(41) +} +- Sort flag = SORT_NUMERIC - +bool(true) +array(9) { + [-10]=> + int(-41) + [-6]=> + int(-31) + [-4]=> + int(-21) + [-2]=> + int(-11) + [1]=> + int(11) + [3]=> + int(21) + [5]=> + int(31) + [7]=> + int(0) + [8]=> + int(41) +} + +-- Iteration 2 -- +- With default sort flag - +bool(true) +array(11) { + [-10]=> + float(-0.106) + [-8]=> + float(-0.9) + [-3]=> + float(-0.01) + [1]=> + float(0.0001) + [2]=> + float(0.0021) + [4]=> + int(-1) + [5]=> + int(0) + [6]=> + float(0.09) + [7]=> + int(2) + [9]=> + float(0.106) + [11]=> + int(33) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(11) { + [-10]=> + float(-0.106) + [-8]=> + float(-0.9) + [-3]=> + float(-0.01) + [1]=> + float(0.0001) + [2]=> + float(0.0021) + [4]=> + int(-1) + [5]=> + int(0) + [6]=> + float(0.09) + [7]=> + int(2) + [9]=> + float(0.106) + [11]=> + int(33) +} +- Sort flag = SORT_NUMERIC - +bool(true) +array(11) { + [-10]=> + float(-0.106) + [-8]=> + float(-0.9) + [-3]=> + float(-0.01) + [1]=> + float(0.0001) + [2]=> + float(0.0021) + [4]=> + int(-1) + [5]=> + int(0) + [6]=> + float(0.09) + [7]=> + int(2) + [9]=> + float(0.106) + [11]=> + int(33) +} +Done diff --git a/tests/std/array/ksort_variation4.phpt b/tests/std/array/ksort_variation4.phpt new file mode 100644 index 00000000..30dc42bf --- /dev/null +++ b/tests/std/array/ksort_variation4.phpt @@ -0,0 +1,77 @@ +--TEST-- +Test ksort() function : usage variations - sort bool values +--SKIPIF-- +--FILE-- + true, false => false, TRUE => TRUE, FALSE => FALSE); + +echo "\n-- Testing ksort() by supplying boolean value array, 'flag' value is default --\n"; +$temp_array = $bool_values; +var_dump(ksort($temp_array) ); +var_dump($temp_array); + +echo "\n-- Testing ksort() by supplying boolean value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $bool_values; +var_dump(ksort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +echo "\n-- Testing ksort() by supplying boolean value array, 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $bool_values; +var_dump(ksort($temp_array, SORT_NUMERIC) ); +var_dump($temp_array); + +echo "\n-- Testing ksort() by supplying boolean value array, 'flag' value is SORT_STRING --\n"; +$temp_array = $bool_values; +var_dump(ksort($temp_array, SORT_STRING) ); +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECT-- +*** Testing ksort() : usage variations *** + +-- Testing ksort() by supplying boolean value array, 'flag' value is default -- +bool(true) +array(2) { + [0]=> + bool(false) + [1]=> + bool(true) +} + +-- Testing ksort() by supplying boolean value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(2) { + [0]=> + bool(false) + [1]=> + bool(true) +} + +-- Testing ksort() by supplying boolean value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(2) { + [0]=> + bool(false) + [1]=> + bool(true) +} + +-- Testing ksort() by supplying boolean value array, 'flag' value is SORT_STRING -- +bool(true) +array(2) { + [0]=> + bool(false) + [1]=> + bool(true) +} +Done diff --git a/tests/std/array/ksort_variation5.phpt b/tests/std/array/ksort_variation5.phpt new file mode 100644 index 00000000..b948ddbd --- /dev/null +++ b/tests/std/array/ksort_variation5.phpt @@ -0,0 +1,227 @@ +--TEST-- +Test ksort() function : usage variations - sort strings +--SKIPIF-- + +--FILE-- + null, NULL => NULL, "\a" => "\a", "\cx" => "\cx", "\e" => "\e", + "\f" => "\f", "\n" =>"\n", "\r" => "\r", "\t" => "\t", "\xhh" => "\xhh", + "\ddd" => "\ddd", "\v" => "\v" + ), + + // array containing different strings with key values + array ( 'Lemon' => "lemoN", 'o' => "Orange", 'B' => "banana", 'Apple' => "apple", 'te' => "Test", + 't' => "TTTT", 'T' => "ttt", 'W' => "ww", 'X' => "x", 'x' => "X", 'O' => "oraNGe", + 'B' => "BANANA" + ) +); + +$flags = array("SORT_REGULAR" => SORT_REGULAR, "SORT_STRING" => SORT_STRING); + +$count = 1; +echo "\n-- Testing ksort() by supplying various string arrays --\n"; + +// loop through to test ksort() with different arrays +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With default sort flag -\n"; + $temp_array = $array; + var_dump(ksort($temp_array) ); // expecting : bool(true) + var_dump($temp_array); + + // loop through $flags array and call ksort() with all possible sort flag values + foreach($flags as $key => $flag){ + echo "- Sort flag = $key -\n"; + $temp_array = $array; + var_dump(ksort($temp_array, $flag) ); // expecting : bool(true) + var_dump($temp_array); + } + $count++; +} + +echo "Done\n"; +?> +--EXPECT-- +*** Testing ksort() : usage variations *** + +-- Testing ksort() by supplying various string arrays -- + +-- Iteration 1 -- +- With default sort flag - +bool(true) +array(11) { + [""]=> + NULL + [" "]=> + string(1) " " + [" +"]=> + string(1) " +" + [" "]=> + string(1) " " + [" "]=> + string(1) " " + [" "]=> + string(1) " " + [""]=> + string(1) "" + ["\a"]=> + string(2) "\a" + ["\cx"]=> + string(3) "\cx" + ["\ddd"]=> + string(4) "\ddd" + ["\xhh"]=> + string(4) "\xhh" +} +- Sort flag = SORT_REGULAR - +bool(true) +array(11) { + [""]=> + NULL + [" "]=> + string(1) " " + [" +"]=> + string(1) " +" + [" "]=> + string(1) " " + [" "]=> + string(1) " " + [" "]=> + string(1) " " + [""]=> + string(1) "" + ["\a"]=> + string(2) "\a" + ["\cx"]=> + string(3) "\cx" + ["\ddd"]=> + string(4) "\ddd" + ["\xhh"]=> + string(4) "\xhh" +} +- Sort flag = SORT_STRING - +bool(true) +array(11) { + [""]=> + NULL + [" "]=> + string(1) " " + [" +"]=> + string(1) " +" + [" "]=> + string(1) " " + [" "]=> + string(1) " " + [" "]=> + string(1) " " + [""]=> + string(1) "" + ["\a"]=> + string(2) "\a" + ["\cx"]=> + string(3) "\cx" + ["\ddd"]=> + string(4) "\ddd" + ["\xhh"]=> + string(4) "\xhh" +} + +-- Iteration 2 -- +- With default sort flag - +bool(true) +array(11) { + ["Apple"]=> + string(5) "apple" + ["B"]=> + string(6) "BANANA" + ["Lemon"]=> + string(5) "lemoN" + ["O"]=> + string(6) "oraNGe" + ["T"]=> + string(3) "ttt" + ["W"]=> + string(2) "ww" + ["X"]=> + string(1) "x" + ["o"]=> + string(6) "Orange" + ["t"]=> + string(4) "TTTT" + ["te"]=> + string(4) "Test" + ["x"]=> + string(1) "X" +} +- Sort flag = SORT_REGULAR - +bool(true) +array(11) { + ["Apple"]=> + string(5) "apple" + ["B"]=> + string(6) "BANANA" + ["Lemon"]=> + string(5) "lemoN" + ["O"]=> + string(6) "oraNGe" + ["T"]=> + string(3) "ttt" + ["W"]=> + string(2) "ww" + ["X"]=> + string(1) "x" + ["o"]=> + string(6) "Orange" + ["t"]=> + string(4) "TTTT" + ["te"]=> + string(4) "Test" + ["x"]=> + string(1) "X" +} +- Sort flag = SORT_STRING - +bool(true) +array(11) { + ["Apple"]=> + string(5) "apple" + ["B"]=> + string(6) "BANANA" + ["Lemon"]=> + string(5) "lemoN" + ["O"]=> + string(6) "oraNGe" + ["T"]=> + string(3) "ttt" + ["W"]=> + string(2) "ww" + ["X"]=> + string(1) "x" + ["o"]=> + string(6) "Orange" + ["t"]=> + string(4) "TTTT" + ["te"]=> + string(4) "Test" + ["x"]=> + string(1) "X" +} +Done diff --git a/tests/std/array/ksort_variation6.phpt b/tests/std/array/ksort_variation6.phpt new file mode 100644 index 00000000..b9c35b54 --- /dev/null +++ b/tests/std/array/ksort_variation6.phpt @@ -0,0 +1,109 @@ +--TEST-- +Test ksort() function : usage variations - sort hexadecimal values +--FILE-- + 0x1AB, 0xFFF => 0xFFF, 0xF => 0xF, 0xFF => 0xFF, 0x2AA => 0x2AA, 0xBB => 0xBB, + 0x1ab => 0x1ab, 0xff => 0xff, -0xff => -0xFF, 0 => 0, -0x2aa => -0x2aa +); + +echo "\n-- Testing ksort() by supplying hexadecimal value array, 'flag' value is default --\n"; +$temp_array = $unsorted_hex_array; +var_dump(ksort( $temp_array) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing ksort() by supplying hexadecimal value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $unsorted_hex_array; +var_dump(ksort( $temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing ksort() by supplying hexadecimal value array, 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $unsorted_hex_array; +var_dump(ksort( $temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECT-- +*** Testing ksort() : usage variations *** + +-- Testing ksort() by supplying hexadecimal value array, 'flag' value is default -- +bool(true) +array(9) { + [-682]=> + int(-682) + [-255]=> + int(-255) + [0]=> + int(0) + [15]=> + int(15) + [187]=> + int(187) + [255]=> + int(255) + [427]=> + int(427) + [682]=> + int(682) + [4095]=> + int(4095) +} + +-- Testing ksort() by supplying hexadecimal value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(9) { + [-682]=> + int(-682) + [-255]=> + int(-255) + [0]=> + int(0) + [15]=> + int(15) + [187]=> + int(187) + [255]=> + int(255) + [427]=> + int(427) + [682]=> + int(682) + [4095]=> + int(4095) +} + +-- Testing ksort() by supplying hexadecimal value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(9) { + [-682]=> + int(-682) + [-255]=> + int(-255) + [0]=> + int(0) + [15]=> + int(15) + [187]=> + int(187) + [255]=> + int(255) + [427]=> + int(427) + [682]=> + int(682) + [4095]=> + int(4095) +} +Done diff --git a/tests/std/array/ksort_variation7.phpt b/tests/std/array/ksort_variation7.phpt new file mode 100644 index 00000000..7ca42069 --- /dev/null +++ b/tests/std/array/ksort_variation7.phpt @@ -0,0 +1,172 @@ +--TEST-- +Test ksort() function : usage variations - sort array with diff. sub arrays +--FILE-- + array(), + + // array contains null sub array + 2 => array( 1 => array() ), + + // array of arrays along with some values + 3 => array(4 => 44, 1 => 11, 3 => array(64,61) ), + + // array contains sub arrays + 4 => array ( 3 => array(33,-5,6), 1 => array(11), + 2 => array(22,-55), 0 => array() ) +); + + +$count = 1; +echo "\n-- Testing ksort() by supplying various arrays containing sub arrays --\n"; + +// loop through to test ksort() with different arrays +foreach ($various_arrays as $array) { + + echo "\n-- Iteration $count --\n"; + echo "- With default sort flag -\n"; + $temp_array = $array; + var_dump( ksort($temp_array) ); + var_dump($temp_array); + + echo "- Sort flag = SORT_REGULAR -\n"; + $temp_array = $array; + var_dump( ksort($temp_array, SORT_REGULAR) ); + var_dump($temp_array); + $count++; +} + +echo "Done\n"; +?> +--EXPECT-- +*** Testing ksort() : usage variations *** + +-- Testing ksort() by supplying various arrays containing sub arrays -- + +-- Iteration 1 -- +- With default sort flag - +bool(true) +array(0) { +} +- Sort flag = SORT_REGULAR - +bool(true) +array(0) { +} + +-- Iteration 2 -- +- With default sort flag - +bool(true) +array(1) { + [1]=> + array(0) { + } +} +- Sort flag = SORT_REGULAR - +bool(true) +array(1) { + [1]=> + array(0) { + } +} + +-- Iteration 3 -- +- With default sort flag - +bool(true) +array(3) { + [1]=> + int(11) + [3]=> + array(2) { + [0]=> + int(64) + [1]=> + int(61) + } + [4]=> + int(44) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(3) { + [1]=> + int(11) + [3]=> + array(2) { + [0]=> + int(64) + [1]=> + int(61) + } + [4]=> + int(44) +} + +-- Iteration 4 -- +- With default sort flag - +bool(true) +array(4) { + [0]=> + array(0) { + } + [1]=> + array(1) { + [0]=> + int(11) + } + [2]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + [3]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } +} +- Sort flag = SORT_REGULAR - +bool(true) +array(4) { + [0]=> + array(0) { + } + [1]=> + array(1) { + [0]=> + int(11) + } + [2]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + [3]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } +} +Done diff --git a/tests/std/array/ksort_variation8.phpt b/tests/std/array/ksort_variation8.phpt new file mode 100644 index 00000000..0a788726 --- /dev/null +++ b/tests/std/array/ksort_variation8.phpt @@ -0,0 +1,155 @@ +--TEST-- +Test ksort() function : usage variations - sort mixed values, 'sort_flags' as default/SORT_REGULAR (OK to fail as result is unpredectable) +--SKIPIF-- + +--FILE-- + array(), + "array2" => array ( "sub_array[2,1]" => array(33,-5,6), "sub_array[2,2]" => array(11), + "sub_array[2,3]" => array(22,-55), "sub_array[2,4]" => array() + ), + 4 => 4, "4" => "4", 4 => 4.01, "b" => "b", "5" => "5", -2 => -2, -2 => -2.01, + -2 => -2.98989, "-.9" => "-.9", "True" => "True", "" => "", NULL => NULL, + "ab" => "ab", "abcd" => "abcd", 0 => 0.01, -0 => -0, '' => '' , + "abcd\x00abcd\x00abcd" => "abcd\x00abcd\x00abcd", 0 => 0.001 +); + +echo "\n-- Testing ksort() by supplying mixed value array, 'flag' value is default --\n"; +$temp_array = $mixed_values; +var_dump( ksort($temp_array) ); +var_dump($temp_array); + +echo "\n-- Testing ksort() by supplying mixed value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $mixed_values; +var_dump( ksort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing ksort() : usage variations *** + +-- Testing ksort() by supplying mixed value array, 'flag' value is default -- +bool(true) +array(13) { + [""]=> + string(0) "" + [-2]=> + float(-2.98989) + ["-.9"]=> + string(3) "-.9" + [0]=> + float(0.001) + [4]=> + float(4.01) + [5]=> + string(1) "5" + ["True"]=> + string(4) "True" + ["ab"]=> + string(2) "ab" + ["abcd"]=> + string(4) "abcd" + ["abcd%0abcd%0abcd"]=> + string(14) "abcd%0abcd%0abcd" + ["array1"]=> + array(0) { + } + ["array2"]=> + array(4) { + ["sub_array[2,1]"]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } + ["sub_array[2,2]"]=> + array(1) { + [0]=> + int(11) + } + ["sub_array[2,3]"]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + ["sub_array[2,4]"]=> + array(0) { + } + } + ["b"]=> + string(1) "b" +} + +-- Testing ksort() by supplying mixed value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(13) { + [""]=> + string(0) "" + [-2]=> + float(-2.98989) + ["-.9"]=> + string(3) "-.9" + [0]=> + float(0.001) + [4]=> + float(4.01) + [5]=> + string(1) "5" + ["True"]=> + string(4) "True" + ["ab"]=> + string(2) "ab" + ["abcd"]=> + string(4) "abcd" + ["abcd%0abcd%0abcd"]=> + string(14) "abcd%0abcd%0abcd" + ["array1"]=> + array(0) { + } + ["array2"]=> + array(4) { + ["sub_array[2,1]"]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } + ["sub_array[2,2]"]=> + array(1) { + [0]=> + int(11) + } + ["sub_array[2,3]"]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + ["sub_array[2,4]"]=> + array(0) { + } + } + ["b"]=> + string(1) "b" +} +Done diff --git a/tests/std/array/ksort_variation9.phpt b/tests/std/array/ksort_variation9.phpt new file mode 100644 index 00000000..0023a9e0 --- /dev/null +++ b/tests/std/array/ksort_variation9.phpt @@ -0,0 +1,251 @@ +--TEST-- +Test ksort() function : usage variations - sorting arrays with/without keys +--FILE-- + 55, 66, 22, 33, 11), + array ("a" => "orange", "banana", "c" => "apple"), + array(1, 2, 3, 4, 5, 6), + array("first", 5 => "second", 1 => "third"), + array(1, 1, 8 => 1, 4 => 1, 19, 3 => 13), + array('bar' => 'baz', "foo" => 1), + array('a' => 1,'b' => array('e' => 2,'f' => 3),'c' => array('g' => 4),'d' => 5), +); + +$count = 1; +echo "\n-- Testing ksort() by supplying various arrays with/without key values --\n"; + +// loop through to test ksort() with different arrays, +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With default sort flag -\n"; + $temp_array = $array; + var_dump( ksort($temp_array) ); + var_dump($temp_array); + + echo "- Sort flag = SORT_REGULAR -\n"; + $temp_array = $array; + var_dump( ksort($temp_array, SORT_REGULAR) ); + var_dump($temp_array); + $count++; +} + +echo "Done\n"; +?> +--EXPECT-- +*** Testing ksort() : usage variations *** + +-- Testing ksort() by supplying various arrays with/without key values -- + +-- Iteration 1 -- +- With default sort flag - +bool(true) +array(5) { + [5]=> + int(55) + [6]=> + int(66) + [7]=> + int(22) + [8]=> + int(33) + [9]=> + int(11) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(5) { + [5]=> + int(55) + [6]=> + int(66) + [7]=> + int(22) + [8]=> + int(33) + [9]=> + int(11) +} + +-- Iteration 2 -- +- With default sort flag - +bool(true) +array(3) { + [0]=> + string(6) "banana" + ["a"]=> + string(6) "orange" + ["c"]=> + string(5) "apple" +} +- Sort flag = SORT_REGULAR - +bool(true) +array(3) { + [0]=> + string(6) "banana" + ["a"]=> + string(6) "orange" + ["c"]=> + string(5) "apple" +} + +-- Iteration 3 -- +- With default sort flag - +bool(true) +array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) +} + +-- Iteration 4 -- +- With default sort flag - +bool(true) +array(3) { + [0]=> + string(5) "first" + [1]=> + string(5) "third" + [5]=> + string(6) "second" +} +- Sort flag = SORT_REGULAR - +bool(true) +array(3) { + [0]=> + string(5) "first" + [1]=> + string(5) "third" + [5]=> + string(6) "second" +} + +-- Iteration 5 -- +- With default sort flag - +bool(true) +array(6) { + [0]=> + int(1) + [1]=> + int(1) + [3]=> + int(13) + [4]=> + int(1) + [8]=> + int(1) + [9]=> + int(19) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(6) { + [0]=> + int(1) + [1]=> + int(1) + [3]=> + int(13) + [4]=> + int(1) + [8]=> + int(1) + [9]=> + int(19) +} + +-- Iteration 6 -- +- With default sort flag - +bool(true) +array(2) { + ["bar"]=> + string(3) "baz" + ["foo"]=> + int(1) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(2) { + ["bar"]=> + string(3) "baz" + ["foo"]=> + int(1) +} + +-- Iteration 7 -- +- With default sort flag - +bool(true) +array(4) { + ["a"]=> + int(1) + ["b"]=> + array(2) { + ["e"]=> + int(2) + ["f"]=> + int(3) + } + ["c"]=> + array(1) { + ["g"]=> + int(4) + } + ["d"]=> + int(5) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(4) { + ["a"]=> + int(1) + ["b"]=> + array(2) { + ["e"]=> + int(2) + ["f"]=> + int(3) + } + ["c"]=> + array(1) { + ["g"]=> + int(4) + } + ["d"]=> + int(5) +} +Done diff --git a/tests/std/array/locale_sort.phpt b/tests/std/array/locale_sort.phpt new file mode 100644 index 00000000..2caccce7 --- /dev/null +++ b/tests/std/array/locale_sort.phpt @@ -0,0 +1,60 @@ +--TEST-- +Sort with SORT_LOCALE_STRING +--SKIPIF-- + +--FILE-- + "Alberta", +"BC" => "Colombie-Britannique", +"MB" => "Manitoba", +"NB" => "Nouveau-Brunswick", +"NL" => "Terre-Neuve-et-Labrador", +"NS" => "Nouvelle-Écosse", +"ON" => "Ontario", +"PE" => "Île-du-Prince-Édouard", +"QC" => "Québec", +"SK" => "Saskatchewan", +"NT" => "Territoires du Nord-Ouest", +"NU" => "Nunavut", +"YT" => "Territoire du Yukon"); +asort($table, SORT_LOCALE_STRING); +var_dump($table); +?> +--EXPECT-- +array(13) { + ["AB"]=> + string(7) "Alberta" + ["BC"]=> + string(20) "Colombie-Britannique" + ["PE"]=> + string(21) "Île-du-Prince-Édouard" + ["MB"]=> + string(8) "Manitoba" + ["NB"]=> + string(17) "Nouveau-Brunswick" + ["NS"]=> + string(15) "Nouvelle-Écosse" + ["NU"]=> + string(7) "Nunavut" + ["ON"]=> + string(7) "Ontario" + ["QC"]=> + string(6) "Québec" + ["SK"]=> + string(12) "Saskatchewan" + ["NL"]=> + string(23) "Terre-Neuve-et-Labrador" + ["YT"]=> + string(19) "Territoire du Yukon" + ["NT"]=> + string(25) "Territoires du Nord-Ouest" +} diff --git a/tests/std/array/max.phpt b/tests/std/array/max.phpt new file mode 100644 index 00000000..06546100 --- /dev/null +++ b/tests/std/array/max.phpt @@ -0,0 +1,45 @@ +--TEST-- +max() tests +--INI-- +precision=14 +--FILE-- +getMessage() . "\n"; +} + +try { + var_dump(max(array())); +} catch (\ValueError $e) { + echo $e->getMessage() . "\n"; +} + +try { + var_dump(max(new stdclass)); +} catch (\TypeError $e) { + echo $e->getMessage() . "\n"; +} + +var_dump(max(2,1,2)); +var_dump(max(2.1,2.11,2.09)); +var_dump(max("", "t", "b")); +var_dump(max(false, true, false)); +var_dump(max(true, false, true)); +var_dump(max(1, true, false, true)); +var_dump(max(0, true, false, true)); + +?> +--EXPECT-- +max(): Argument #1 ($value) must be of type array, int given +max(): Argument #1 ($value) must contain at least one element +max(): Argument #1 ($value) must be of type array, stdClass given +int(2) +float(2.11) +string(1) "t" +bool(true) +bool(true) +int(1) +bool(true) diff --git a/tests/std/array/max_basic.phpt b/tests/std/array/max_basic.phpt new file mode 100644 index 00000000..4880e97d --- /dev/null +++ b/tests/std/array/max_basic.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test return type and value for expected input max() +--FILE-- + +--EXPECT-- +*** Testing sequences of numbers *** +int(2) +int(2) +float(2.11) +string(1) "t" +bool(true) +bool(true) +int(1) +bool(true) +array(2) { + [0]=> + int(2) + [1]=> + int(3) +} + +Done diff --git a/tests/std/array/max_basiclong_64bit.phpt b/tests/std/array/max_basiclong_64bit.phpt new file mode 100644 index 00000000..6d40be03 --- /dev/null +++ b/tests/std/array/max_basiclong_64bit.phpt @@ -0,0 +1,33 @@ +--TEST-- +Test max function : 64bit long tests +--SKIPIF-- + +--FILE-- + +--EXPECT-- +int(9223372036854775807) +int(9223372036854775807) diff --git a/tests/std/array/max_int_float_optimisation.phpt b/tests/std/array/max_int_float_optimisation.phpt new file mode 100644 index 00000000..0f5df35d --- /dev/null +++ b/tests/std/array/max_int_float_optimisation.phpt @@ -0,0 +1,61 @@ +--TEST-- +Check max() optimisation for int and float types +--SKIPIF-- + +--FILE-- + +--EXPECT-- +Start as int optimisation: +int(10) +int(10) +int(10) +int(10) +int(10) +int(10) +string(2) "15" +Check that int not representable as float works: +int(-9223372036854775807) +float(1.8446744073709552E+19) +float(INF) +Start as float optimisation: +float(10.5) +float(10.5) +float(10.5) +float(10.5) +float(10.5) +float(10.5) +string(4) "15.5" +Check that int not representable as float works: +int(-9223372036854775807) +float(1.8446744073709552E+19) +float(INF) diff --git a/tests/std/array/max_variation1.phpt b/tests/std/array/max_variation1.phpt new file mode 100644 index 00000000..a87033ce --- /dev/null +++ b/tests/std/array/max_variation1.phpt @@ -0,0 +1,35 @@ +--TEST-- +Test variations in usage of max() +--FILE-- + +--EXPECTF-- +*** Testing boundary conditions *** +int(2147483646) +%s(2147483648) +%s(2147483648) +int(-2147483646) +int(-2147483647) +int(-2147483647) + +*** Testing large number of arguments *** +int(21) + +Done diff --git a/tests/std/array/max_variation2.phpt b/tests/std/array/max_variation2.phpt new file mode 100644 index 00000000..8577a095 --- /dev/null +++ b/tests/std/array/max_variation2.phpt @@ -0,0 +1,53 @@ +--TEST-- +Test variations in usage of max() +--FILE-- + +--EXPECTF-- +*** Testing arrays *** +int(2) +int(2) +float(2.11) +string(1) "t" +bool(true) +bool(true) +int(1) +bool(true) +array(2) { + [0]=> + int(2) + [1]=> + int(3) +} +int(2147483646) +%s(2147483648) +%s(2147483648) +int(-2147483646) +int(-2147483647) +int(-2147483647) + +Done diff --git a/tests/std/array/min.phpt b/tests/std/array/min.phpt new file mode 100644 index 00000000..97be4ad6 --- /dev/null +++ b/tests/std/array/min.phpt @@ -0,0 +1,45 @@ +--TEST-- +min() tests +--INI-- +precision=14 +--FILE-- +getMessage() . "\n"; +} + +try { + var_dump(min(array())); +} catch (\ValueError $e) { + echo $e->getMessage() . "\n"; +} + +try { + var_dump(min(new stdclass)); +} catch (\TypeError $e) { + echo $e->getMessage() . "\n"; +} + +var_dump(min(2,1,2)); +var_dump(min(2.1,2.11,2.09)); +var_dump(min("", "t", "b")); +var_dump(min(false, true, false)); +var_dump(min(true, false, true)); +var_dump(min(1, true, false, true)); +var_dump(min(0, true, false, true)); + +?> +--EXPECT-- +min(): Argument #1 ($value) must be of type array, int given +min(): Argument #1 ($value) must contain at least one element +min(): Argument #1 ($value) must be of type array, stdClass given +int(1) +float(2.09) +string(0) "" +bool(false) +bool(false) +bool(false) +int(0) diff --git a/tests/std/array/min_basic.phpt b/tests/std/array/min_basic.phpt new file mode 100644 index 00000000..6706dd90 --- /dev/null +++ b/tests/std/array/min_basic.phpt @@ -0,0 +1,35 @@ +--TEST-- +Test return type and value for expected input min() +--FILE-- + +--EXPECT-- +*** Testing sequences of numbers *** +int(1) +int(-2) +float(2.09) +string(0) "" +bool(false) +bool(false) +bool(false) +int(0) +int(0) + +Done diff --git a/tests/std/array/min_basiclong_64bit.phpt b/tests/std/array/min_basiclong_64bit.phpt new file mode 100644 index 00000000..50e5dda1 --- /dev/null +++ b/tests/std/array/min_basiclong_64bit.phpt @@ -0,0 +1,33 @@ +--TEST-- +Test min function : 64bit long tests +--SKIPIF-- + +--FILE-- + +--EXPECT-- +int(-9223372036854775808) +int(-9223372036854775808) diff --git a/tests/std/array/min_int_float_optimisation.phpt b/tests/std/array/min_int_float_optimisation.phpt new file mode 100644 index 00000000..e383b833 --- /dev/null +++ b/tests/std/array/min_int_float_optimisation.phpt @@ -0,0 +1,61 @@ +--TEST-- +Check min() optimisation for int and float types +--SKIPIF-- + +--FILE-- + +--EXPECT-- +Start as int optimisation: +int(2) +int(2) +int(2) +int(2) +int(2) +int(2) +string(1) "1" +Check that int not representable as float works: +int(9223372036854775806) +float(-1.8446744073709552E+19) +int(9223372036854775806) +Start as float optimisation: +float(2.5) +float(2.5) +float(2.5) +float(2.5) +float(2.5) +float(2.5) +string(3) "1.5" +Check that int not representable as float works: +int(9223372036854775806) +float(-1.8446744073709552E+19) +int(9223372036854775806) diff --git a/tests/std/array/min_variation1.phpt b/tests/std/array/min_variation1.phpt new file mode 100644 index 00000000..d09b2196 --- /dev/null +++ b/tests/std/array/min_variation1.phpt @@ -0,0 +1,35 @@ +--TEST-- +Test variations in usage of min() +--FILE-- + +--EXPECTF-- +*** Testing boundary conditions *** +int(2147483645) +int(2147483647) +int(2147483646) +int(-2147483647) +%s(-2147483648) +%s(-2147483649) + +*** Testing large number of arguments *** +int(0) + +Done diff --git a/tests/std/array/min_variation2.phpt b/tests/std/array/min_variation2.phpt new file mode 100644 index 00000000..44acde72 --- /dev/null +++ b/tests/std/array/min_variation2.phpt @@ -0,0 +1,48 @@ +--TEST-- +Test variations in usage of min() +--FILE-- + +--EXPECTF-- +*** Testing arrays *** +int(1) +int(-2) +float(2.09) +string(0) "" +bool(false) +bool(false) +bool(false) +int(0) +int(0) +int(2147483645) +int(2147483647) +int(2147483646) +int(-2147483647) +%s(-2147483648) +%s(-2147483649) + +Done diff --git a/tests/std/array/natcasesort_basic.phpt b/tests/std/array/natcasesort_basic.phpt new file mode 100644 index 00000000..8891d0bb --- /dev/null +++ b/tests/std/array/natcasesort_basic.phpt @@ -0,0 +1,52 @@ +--TEST-- +Test natcasesort() function : basic functionality +--FILE-- + +--EXPECT-- +*** Testing natcasesort() : basic functionality *** + +-- Before sorting: -- +array(5) { + [0]=> + string(3) "A01" + [1]=> + string(2) "a1" + [2]=> + string(3) "b10" + [3]=> + string(3) "a01" + [4]=> + string(3) "b01" +} + +-- After Sorting: -- +bool(true) +array(5) { + [0]=> + string(3) "A01" + [3]=> + string(3) "a01" + [1]=> + string(2) "a1" + [4]=> + string(3) "b01" + [2]=> + string(3) "b10" +} +Done diff --git a/tests/std/array/natcasesort_object1.phpt b/tests/std/array/natcasesort_object1.phpt new file mode 100644 index 00000000..5014b8f3 --- /dev/null +++ b/tests/std/array/natcasesort_object1.phpt @@ -0,0 +1,81 @@ +--TEST-- +Test natcasesort() function : object functionality - array of objects +--FILE-- +class_value = $value; + } + // return string value + function __tostring(): string { + return (string) $this->class_value; + } +} +function main() +{ + /* + * Pass natcasesort() an array of objects to test how it re-orders them + */ + echo "*** Testing natcasesort() : object functionality ***\n"; + // array of string objects + $unsorted_str_obj = array(new for_string_natcasesort("axx"), new for_string_natcasesort("t"), new for_string_natcasesort("w"), new for_string_natcasesort("py"), new for_string_natcasesort("apple"), new for_string_natcasesort("Orange"), new for_string_natcasesort("Lemon"), new for_string_natcasesort("aPPle")); + echo "\n-- Testing natcasesort() by supplying various object arrays --\n"; + // testing natcasesort() function by supplying string object array + var_dump(natcasesort($unsorted_str_obj)); + var_dump($unsorted_str_obj); + echo "Done"; +} +?> +--EXPECTF-- +*** Testing natcasesort() : object functionality *** + +-- Testing natcasesort() by supplying various object arrays -- +bool(true) +array(8) { + [4]=> + object(for_string_natcasesort)#%d (1) { + ["class_value"]=> + string(5) "apple" + } + [7]=> + object(for_string_natcasesort)#%d (1) { + ["class_value"]=> + string(5) "aPPle" + } + [0]=> + object(for_string_natcasesort)#%d (1) { + ["class_value"]=> + string(3) "axx" + } + [6]=> + object(for_string_natcasesort)#%d (1) { + ["class_value"]=> + string(5) "Lemon" + } + [5]=> + object(for_string_natcasesort)#%d (1) { + ["class_value"]=> + string(6) "Orange" + } + [3]=> + object(for_string_natcasesort)#%d (1) { + ["class_value"]=> + string(2) "py" + } + [1]=> + object(for_string_natcasesort)#%d (1) { + ["class_value"]=> + string(1) "t" + } + [2]=> + object(for_string_natcasesort)#%d (1) { + ["class_value"]=> + string(1) "w" + } +} +Done diff --git a/tests/std/array/natcasesort_object2.phpt b/tests/std/array/natcasesort_object2.phpt new file mode 100644 index 00000000..4e744a2b --- /dev/null +++ b/tests/std/array/natcasesort_object2.phpt @@ -0,0 +1,83 @@ +--TEST-- +Test natcasesort() function : object functionality - mixed visibility within objects +--FILE-- +public_class_value = $value1; + $this->private_class_value = $value2; + $this->protected_class_value = $value3; + } + // return string value + function __tostring(): string { + return (string) $this->public_class_value; + } +} +function main() +{ + /* + * Pass natcasesort() an array of objects which have properties of different + * visibilities to test how it re-orders the array. + */ + echo "*** Testing natcasesort() : object functionality ***\n"; + // array of string objects + $unsorted_str_obj = array(new for_string_natcasesort("axx", "AXX", "ass"), new for_string_natcasesort("t", "eee", "abb"), new for_string_natcasesort("w", "W", "c"), new for_string_natcasesort("py", "PY", "pt")); + echo "\n-- Testing natcasesort() by supplying object arrays --\n"; + // testing natcasesort() function by supplying string object array + $temp_array = $unsorted_str_obj; + var_dump(natcasesort($temp_array)); + var_dump($temp_array); + echo "Done"; +} +?> +--EXPECTF-- +*** Testing natcasesort() : object functionality *** + +-- Testing natcasesort() by supplying object arrays -- +bool(true) +array(4) { + [0]=> + object(for_string_natcasesort)#%d (3) { + ["public_class_value"]=> + string(3) "axx" + ["private_class_value":"for_string_natcasesort":private]=> + string(3) "AXX" + ["protected_class_value":protected]=> + string(3) "ass" + } + [3]=> + object(for_string_natcasesort)#%d (3) { + ["public_class_value"]=> + string(2) "py" + ["private_class_value":"for_string_natcasesort":private]=> + string(2) "PY" + ["protected_class_value":protected]=> + string(2) "pt" + } + [1]=> + object(for_string_natcasesort)#%d (3) { + ["public_class_value"]=> + string(1) "t" + ["private_class_value":"for_string_natcasesort":private]=> + string(3) "eee" + ["protected_class_value":protected]=> + string(3) "abb" + } + [2]=> + object(for_string_natcasesort)#%d (3) { + ["public_class_value"]=> + string(1) "w" + ["private_class_value":"for_string_natcasesort":private]=> + string(1) "W" + ["protected_class_value":protected]=> + string(1) "c" + } +} +Done diff --git a/tests/std/array/natcasesort_variation10.phpt b/tests/std/array/natcasesort_variation10.phpt new file mode 100644 index 00000000..89d54ac8 --- /dev/null +++ b/tests/std/array/natcasesort_variation10.phpt @@ -0,0 +1,46 @@ +--TEST-- +Test natcasesort() function : usage variations - position of internal array pointer +--FILE-- + " . current ($array_arg) . "\n"; + +echo "\n-- Call natcasesort() --\n"; +var_dump(natcasesort($array_arg)); +var_dump($array_arg); + +echo "\n-- Position of Internal Pointer in Passed Array: --\n"; +echo key($array_arg) . " => " . current ($array_arg) . "\n"; + +echo "Done"; +?> +--EXPECT-- +*** Testing natcasesort() : usage variations *** + +-- Initial Position of Internal Pointer: -- +0 => img13 + +-- Call natcasesort() -- +bool(true) +array(4) { + [3]=> + string(4) "img1" + [2]=> + string(4) "img2" + [0]=> + string(5) "img13" + [1]=> + string(5) "img20" +} + +-- Position of Internal Pointer in Passed Array: -- +3 => img1 +Done diff --git a/tests/std/array/natcasesort_variation11.phpt b/tests/std/array/natcasesort_variation11.phpt new file mode 100644 index 00000000..1a24eae0 --- /dev/null +++ b/tests/std/array/natcasesort_variation11.phpt @@ -0,0 +1,199 @@ +--TEST-- +Test natcasesort() function : usage variations - Different array keys +--SKIPIF-- + + +--FILE-- + array( + 0 => 'zero', + 1 => 'one', + 12345 => 'positive', + -2345 => 'negative', + ), + + // null data +/*4*/ 'null uppercase' => array( + NULL => 'null 1', + ), + +/*5*/ 'null lowercase' => array( + null => 'null 2', + ), + + // boolean data +/*6*/ 'bool lowercase' => array( + true => 'lowert', + false => 'lowerf', + ), + +/*7*/ 'bool uppercase' => array( + TRUE => 'uppert', + FALSE => 'upperf', + ), + + // empty data +/*8*/ 'empty double quotes' => array( + "" => 'emptyd', + ), + +/*9*/ 'empty single quotes' => array( + '' => 'emptys', + ), + + // string data +/*10*/ 'string' => array( + "stringd" => 'stringd', + 'strings' => 'strings', + $heredoc => 'stringh', + ), + + // undefined data +/*11*/ 'undefined' => array( + @$undefined_var => 'undefined', + ), + + // unset data +/*12*/ 'unset' => array( + @$unset_var => 'unset', + ), + + // duplicate values +/*13*/ 'duplicate' => array( + 'foo' => 'bar', + 'baz' => 'bar', + 'hello' => 'world' + ), + +); + +// loop through each element of $inputs to check the behavior of natcasesort() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( natcasesort($input) ); + var_dump($input); + $iterator++; +}; + +echo "Done"; +?> +--EXPECT-- +*** Testing natcasesort() : usage variations *** + +-- Iteration 1 -- +bool(true) +array(4) { + [-2345]=> + string(8) "negative" + [1]=> + string(3) "one" + [12345]=> + string(8) "positive" + [0]=> + string(4) "zero" +} + +-- Iteration 2 -- +bool(true) +array(1) { + [""]=> + string(6) "null 1" +} + +-- Iteration 3 -- +bool(true) +array(1) { + [""]=> + string(6) "null 2" +} + +-- Iteration 4 -- +bool(true) +array(2) { + [0]=> + string(6) "lowerf" + [1]=> + string(6) "lowert" +} + +-- Iteration 5 -- +bool(true) +array(2) { + [0]=> + string(6) "upperf" + [1]=> + string(6) "uppert" +} + +-- Iteration 6 -- +bool(true) +array(1) { + [""]=> + string(6) "emptyd" +} + +-- Iteration 7 -- +bool(true) +array(1) { + [""]=> + string(6) "emptys" +} + +-- Iteration 8 -- +bool(true) +array(3) { + ["stringd"]=> + string(7) "stringd" + ["hello world"]=> + string(7) "stringh" + ["strings"]=> + string(7) "strings" +} + +-- Iteration 9 -- +bool(true) +array(1) { + [""]=> + string(9) "undefined" +} + +-- Iteration 10 -- +bool(true) +array(1) { + [""]=> + string(5) "unset" +} + +-- Iteration 11 -- +bool(true) +array(3) { + ["foo"]=> + string(3) "bar" + ["baz"]=> + string(3) "bar" + ["hello"]=> + string(5) "world" +} +Done diff --git a/tests/std/array/natcasesort_variation2.phpt b/tests/std/array/natcasesort_variation2.phpt new file mode 100644 index 00000000..f32c0151 --- /dev/null +++ b/tests/std/array/natcasesort_variation2.phpt @@ -0,0 +1,185 @@ +--TEST-- +Test natcasesort() function : usage variations - Pass arrays of different data types +--SKIPIF-- + + +--FILE-- + array(0, 1, 12345, -2345), + // float data + /*2*/ + 'float' => array(10.5, -10.5, 123456789000.0, 1.23456789E-9, 0.5), + // null data + /*3*/ + 'null' => array(NULL, null), + // boolean data + /*4*/ + 'bool' => array(true, false, TRUE, FALSE), + // empty data + /*5*/ + 'empty string' => array("", ''), + /*6*/ + 'empty array' => array(), + // string data + /*7*/ + 'string' => array("string", 'string', $heredoc), + // object data + /*8*/ + 'object' => array(new classA()), + // undefined data + /*9*/ + 'undefined' => array(@$undefined_var), + // unset data + /*10*/ + 'unset' => array(@$unset_var), + // resource variable + /*11*/ + 'resource' => array($fp), + ); + // loop through each element of $inputs to check the behavior of natcasesort() + $iterator = 1; + foreach ($inputs as $input) { + echo "\n-- Iteration {$iterator} --\n"; + var_dump(natcasesort($input)); + var_dump($input); + $iterator++; + } + fclose($fp); + echo "Done"; +} +?> +--EXPECTF-- +*** Testing natcasesort() : usage variation *** + +-- Iteration 1 -- +bool(true) +array(4) { + [3]=> + int(-2345) + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(12345) +} + +-- Iteration 2 -- +bool(true) +array(5) { + [1]=> + float(-10.5) + [4]=> + float(0.5) + [3]=> + float(1.23456789E-9) + [0]=> + float(10.5) + [2]=> + float(123456789000) +} + +-- Iteration 3 -- +bool(true) +array(2) { + [0]=> + NULL + [1]=> + NULL +} + +-- Iteration 4 -- +bool(true) +array(4) { + [1]=> + bool(false) + [3]=> + bool(false) + [0]=> + bool(true) + [2]=> + bool(true) +} + +-- Iteration 5 -- +bool(true) +array(2) { + [0]=> + string(0) "" + [1]=> + string(0) "" +} + +-- Iteration 6 -- +bool(true) +array(0) { +} + +-- Iteration 7 -- +bool(true) +array(3) { + [2]=> + string(11) "hello world" + [0]=> + string(6) "string" + [1]=> + string(6) "string" +} + +-- Iteration 8 -- +bool(true) +array(1) { + [0]=> + object(classA)#%d (0) { + } +} + +-- Iteration 9 -- +bool(true) +array(1) { + [0]=> + NULL +} + +-- Iteration 10 -- +bool(true) +array(1) { + [0]=> + NULL +} + +-- Iteration 11 -- +bool(true) +array(1) { + [0]=> + resource(%d) of type (stream) +} +Done diff --git a/tests/std/array/natcasesort_variation3.phpt b/tests/std/array/natcasesort_variation3.phpt new file mode 100644 index 00000000..3cb87328 --- /dev/null +++ b/tests/std/array/natcasesort_variation3.phpt @@ -0,0 +1,129 @@ +--TEST-- +Test natcasesort() function : usage variations - different numeric types +--SKIPIF-- + +--FILE-- + +--EXPECT-- +*** Testing natcasesort() : usage variation *** + +-- Iteration 1 -- +bool(true) +array(9) { + [1]=> + int(-11) + [3]=> + int(-21) + [5]=> + int(-31) + [8]=> + int(-41) + [6]=> + int(0) + [0]=> + int(11) + [2]=> + int(21) + [4]=> + int(31) + [7]=> + int(41) +} + +-- Iteration 1 -- +bool(true) +array(7) { + [6]=> + float(-0.1) + [1]=> + float(-10.5) + [5]=> + float(0.01) + [4]=> + float(0.5) + [3]=> + float(0.106) + [0]=> + float(10.5) + [2]=> + float(1050) +} + +-- Iteration 1 -- +bool(true) +array(11) { + [2]=> + float(-0.01) + [7]=> + float(-0.9) + [9]=> + float(-0.106) + [3]=> + int(-1) + [4]=> + int(0) + [0]=> + float(0.0001) + [1]=> + float(0.0021) + [5]=> + float(0.09) + [8]=> + float(0.106) + [6]=> + int(2) + [10]=> + int(33) +} + +-- Iteration 1 -- +bool(true) +array(7) { + [2]=> + int(-2147483647) + [3]=> + float(-2147483648) + [6]=> + float(-2147483649) + [4]=> + int(0) + [5]=> + int(0) + [0]=> + int(2147483647) + [1]=> + float(2147483648) +} +Done diff --git a/tests/std/array/natcasesort_variation4.phpt b/tests/std/array/natcasesort_variation4.phpt new file mode 100644 index 00000000..4e3477bb --- /dev/null +++ b/tests/std/array/natcasesort_variation4.phpt @@ -0,0 +1,81 @@ +--TEST-- +Test natcasesort() function : usage variations - different string types +--FILE-- + +--EXPECT-- +*** Testing natcasesort() : usage variation *** +bool(true) +array(11) { + [0]=> + NULL + [1]=> + NULL + [5]=> + string(1) " " + [6]=> + string(1) " +" + [7]=> + string(1) " " + [10]=> + string(1) " " + [4]=> + string(1) "" + [2]=> + string(2) "\a" + [3]=> + string(3) "\cx" + [9]=> + string(4) "\ddd" + [8]=> + string(4) "\xhh" +} +bool(true) +array(12) { + [3]=> + string(5) "apple" + [2]=> + string(6) "banana" + [11]=> + string(6) "BANANA" + [0]=> + string(5) "lemoN" + [1]=> + string(6) "Orange" + [10]=> + string(6) "oraNGe" + [4]=> + string(4) "Test" + [6]=> + string(3) "ttt" + [5]=> + string(4) "TTTT" + [7]=> + string(2) "ww" + [8]=> + string(1) "x" + [9]=> + string(1) "X" +} +Done diff --git a/tests/std/array/natcasesort_variation5.phpt b/tests/std/array/natcasesort_variation5.phpt new file mode 100644 index 00000000..03025f2c --- /dev/null +++ b/tests/std/array/natcasesort_variation5.phpt @@ -0,0 +1,44 @@ +--TEST-- +Test natcasesort() function : usage variations - different hex values +--FILE-- + +--EXPECT-- +*** Testing natcasesort() : usage variation *** +bool(true) +array(11) { + [8]=> + int(-255) + [10]=> + int(-682) + [9]=> + int(0) + [2]=> + int(15) + [5]=> + int(187) + [3]=> + int(255) + [7]=> + int(255) + [0]=> + int(427) + [6]=> + int(427) + [4]=> + int(682) + [1]=> + int(4095) +} +Done diff --git a/tests/std/array/natcasesort_variation6.phpt b/tests/std/array/natcasesort_variation6.phpt new file mode 100644 index 00000000..7145f8bf --- /dev/null +++ b/tests/std/array/natcasesort_variation6.phpt @@ -0,0 +1,53 @@ +--TEST-- +Test natcasesort() function : usage variations - referenced variables +--SKIPIF-- + +--FILE-- + +--EXPECT-- +*** Testing natcasesort() : usage variation *** + +-- Initial test -- +bool(true) +array(3) { + [1]=> + &int(33) + [0]=> + &int(100) + [2]=> + &int(555) +} + +-- Change $value1 -- +bool(true) +array(3) { + [0]=> + &int(-29) + [1]=> + &int(33) + [2]=> + &int(555) +} +Done diff --git a/tests/std/array/natcasesort_variation7.phpt b/tests/std/array/natcasesort_variation7.phpt new file mode 100644 index 00000000..70ee9e92 --- /dev/null +++ b/tests/std/array/natcasesort_variation7.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test natcasesort() function : usage variations - recursive arrays +--FILE-- + +--EXPECT-- +*** Testing natcasesort() : usage variations *** +array(5) { + [0]=> + int(1) + [1]=> + float(3) + [2]=> + string(4) "zero" + [3]=> + string(1) "2" + [4]=> + *RECURSION* +} +bool(true) +array(5) { + [0]=> + int(1) + [3]=> + string(1) "2" + [1]=> + float(3) + [4]=> + *RECURSION* + [2]=> + string(4) "zero" +} +Done diff --git a/tests/std/array/natcasesort_variation8.phpt b/tests/std/array/natcasesort_variation8.phpt new file mode 100644 index 00000000..d040f228 --- /dev/null +++ b/tests/std/array/natcasesort_variation8.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test natcasesort() function : usage variations - octal values +--FILE-- + +--EXPECT-- +*** Testing natcasesort() : usage variation *** +bool(true) +array(9) { + [6]=> + int(-54) + [7]=> + int(-229) + [8]=> + int(0) + [3]=> + int(54) + [5]=> + int(63) + [1]=> + int(209) + [2]=> + int(229) + [4]=> + int(506) + [0]=> + int(669) +} +Done diff --git a/tests/std/array/natcasesort_variation9.phpt b/tests/std/array/natcasesort_variation9.phpt new file mode 100644 index 00000000..037db9e7 --- /dev/null +++ b/tests/std/array/natcasesort_variation9.phpt @@ -0,0 +1,104 @@ +--TEST-- +Test natcasesort() function : usage variations - mixed array +--FILE-- + +--EXPECTF-- +*** Testing natcasesort() : usage variation *** +bool(true) +array(22) { + [12]=> + string(0) "" + [13]=> + NULL + [19]=> + string(0) "" + [21]=> + bool(false) + [10]=> + string(3) "-.9" + [7]=> + int(-2) + [8]=> + float(-2) + [9]=> + float(-2.98989) + [2]=> + int(-4) + [16]=> + float(0) + [17]=> + int(0) + [20]=> + bool(true) + [3]=> + string(1) "4" + [4]=> + float(4) + [6]=> + string(1) "5" + [14]=> + string(2) "ab" + [15]=> + string(4) "abcd" + [18]=> + string(14) "abcd%0abcd%0abcd" + [0]=> + array(0) { + } + [1]=> + array(4) { + [0]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } + [1]=> + array(1) { + [0]=> + int(11) + } + [2]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + [3]=> + array(0) { + } + } + [5]=> + string(1) "b" + [11]=> + string(4) "True" +} +Done diff --git a/tests/std/array/natsort_basic.phpt b/tests/std/array/natsort_basic.phpt new file mode 100644 index 00000000..555abe1a --- /dev/null +++ b/tests/std/array/natsort_basic.phpt @@ -0,0 +1,33 @@ +--TEST-- +Test natsort(): basic functionality +--FILE-- + +--EXPECT-- +Standard sorting +Array +( + [0] => img1.png + [1] => img10.png + [2] => img12.png + [3] => img2.png +) + +Natural order sorting +Array +( + [3] => img1.png + [2] => img2.png + [1] => img10.png + [0] => img12.png +) diff --git a/tests/std/array/negative_index.phpt b/tests/std/array/negative_index.phpt new file mode 100644 index 00000000..a9f442ac --- /dev/null +++ b/tests/std/array/negative_index.phpt @@ -0,0 +1,31 @@ +--TEST-- +Test arrays starting with negative indices +--FILE-- + true, true, true]; +$c = ["string" => true, -2 => true, true, true]; +unset($c["string"]); +$d[-2] = true; +$d[] = true; +$d[] = true; +$e = [-2 => false]; +array_pop($e); +$e[] = true; +$e[] = true; +$e[] = true; + +var_dump($a === $b && $b === $c && $c === $d && $d == $e); +var_dump($a); +?> +--EXPECT-- +bool(true) +array(3) { + [-2]=> + bool(true) + [-1]=> + bool(true) + [0]=> + bool(true) +} diff --git a/tests/std/array/negative_index_empty_array.phpt b/tests/std/array/negative_index_empty_array.phpt new file mode 100644 index 00000000..322ac6e8 --- /dev/null +++ b/tests/std/array/negative_index_empty_array.phpt @@ -0,0 +1,18 @@ +--TEST-- +Test empty arrays with first added index being negative +--FILE-- + +--EXPECT-- +array(2) { + [-5]=> + string(2) "-5" + [-4]=> + string(8) "after -5" +} diff --git a/tests/std/array/next_basic.phpt b/tests/std/array/next_basic.phpt new file mode 100644 index 00000000..d006d7d5 --- /dev/null +++ b/tests/std/array/next_basic.phpt @@ -0,0 +1,28 @@ +--TEST-- +Test next() function : basic functionality +--FILE-- + " . current($array) . "\n"; +var_dump(next($array)); + +echo key($array) . " => " . current($array) . "\n"; +var_dump(next($array)); + +echo key($array) . " => " . current($array) . "\n"; +var_dump(next($array)); +?> +--EXPECT-- +*** Testing next() : basic functionality *** +0 => zero +string(3) "one" +1 => one +string(3) "two" +2 => two +bool(false) diff --git a/tests/std/array/next_variation2.phpt b/tests/std/array/next_variation2.phpt new file mode 100644 index 00000000..6293652a --- /dev/null +++ b/tests/std/array/next_variation2.phpt @@ -0,0 +1,38 @@ +--TEST-- +Test next() function : usage variation - Mulit-dimensional arrays +--FILE-- + 'z', array(9, 8, 7)); + +echo "\n-- Pass a two-dimensional array as \$array_arg --\n"; +var_dump(next($array_arg)); +var_dump(next($array_arg)); + +echo "\n-- Pass a sub-array as \$array_arg --\n"; +var_dump(next($array_arg[0])); +?> +--EXPECT-- +*** Testing next() : usage variations *** + +-- Pass a two-dimensional array as $array_arg -- +array(3) { + [0]=> + int(9) + [1]=> + int(8) + [2]=> + int(7) +} +bool(false) + +-- Pass a sub-array as $array_arg -- +int(8) diff --git a/tests/std/array/packed_001.phpt b/tests/std/array/packed_001.phpt new file mode 100644 index 00000000..7a36ed3f --- /dev/null +++ b/tests/std/array/packed_001.phpt @@ -0,0 +1,85 @@ +--TEST-- +array_keys() and array_values() w/ packed optimization +--FILE-- +1, 1=>2, 2=>3], + [1=>1, 2=>2, 3=>3], + [0=>1, 2=>3], + $x, +]; + +foreach ($inputs as $input) { + print_r(array_keys($input)); + print_r(array_values($input)); +} +?> +--EXPECT-- +Array +( +) +Array +( +) +Array +( + [0] => 0 + [1] => 1 + [2] => 2 +) +Array +( + [0] => 1 + [1] => 2 + [2] => 3 +) +Array +( + [0] => 0 + [1] => 1 + [2] => 2 +) +Array +( + [0] => 1 + [1] => 2 + [2] => 3 +) +Array +( + [0] => 1 + [1] => 2 + [2] => 3 +) +Array +( + [0] => 1 + [1] => 2 + [2] => 3 +) +Array +( + [0] => 0 + [1] => 2 +) +Array +( + [0] => 1 + [1] => 3 +) +Array +( + [0] => 0 + [1] => 2 +) +Array +( + [0] => 1 + [1] => 3 +) diff --git a/tests/std/array/prev_basic.phpt b/tests/std/array/prev_basic.phpt new file mode 100644 index 00000000..ffbafd4c --- /dev/null +++ b/tests/std/array/prev_basic.phpt @@ -0,0 +1,46 @@ +--TEST-- +Test prev() function : basic functionality +--FILE-- + " . current($array) . "\n"; +var_dump(prev($array)); + +echo key($array) . " => " . current($array) . "\n"; +var_dump(prev($array)); + +echo key($array) . " => " . current($array) . "\n"; +var_dump(prev($array)); + +echo "\n*** Testing an array with differing values/keys ***\n"; +$array2 = array('one', 2 => "help", 3, false, 'stringkey2' => 'val2', 'stringkey1' => 'val1'); +end($array2); +$length = count($array2); +for ($i = $length; $i > 0; $i--) { + var_dump(prev($array2)); +} + +?> +--EXPECT-- +*** Testing prev() : basic functionality *** +2 => two +string(3) "one" +1 => one +string(4) "zero" +0 => zero +bool(false) + +*** Testing an array with differing values/keys *** +string(4) "val2" +bool(false) +int(3) +string(4) "help" +string(3) "one" +bool(false) diff --git a/tests/std/array/prev_error2.phpt b/tests/std/array/prev_error2.phpt new file mode 100644 index 00000000..6d9457f8 --- /dev/null +++ b/tests/std/array/prev_error2.phpt @@ -0,0 +1,26 @@ +--TEST-- +prev - ensure warning is received when passing an indirect temporary. +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +-- Passing an indirect temporary variable -- + +Notice: Only variables should be passed by reference in %s on line %d +int(1) diff --git a/tests/std/array/prev_error3.phpt b/tests/std/array/prev_error3.phpt new file mode 100644 index 00000000..807de141 --- /dev/null +++ b/tests/std/array/prev_error3.phpt @@ -0,0 +1,18 @@ +--TEST-- +prev - ensure we cannot pass a temporary +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +Fatal error: Uncaught Error: prev(): Argument #1 ($array) could not be passed by reference in %s:%d +Stack trace: +#0 {main} + thrown in %s on line %d diff --git a/tests/std/array/prev_variation2.phpt b/tests/std/array/prev_variation2.phpt new file mode 100644 index 00000000..dd7f9b63 --- /dev/null +++ b/tests/std/array/prev_variation2.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test prev() function : usage variation - Multi-dimensional arrays +--FILE-- + 'z'); +end($array_arg); + +echo "\n-- Pass a two-dimensional array as \$array_arg --\n"; +var_dump(prev($array_arg)); +var_dump(prev($array_arg)); + +echo "\n-- Pass a sub-array as \$array_arg --\n"; +var_dump(prev($array_arg[0])); +?> +--EXPECT-- +*** Testing prev() : usage variations *** + +-- Pass a two-dimensional array as $array_arg -- +array(3) { + [0]=> + int(9) + [1]=> + int(8) + [2]=> + int(7) +} +bool(false) + +-- Pass a sub-array as $array_arg -- +int(8) diff --git a/tests/std/array/range/bug21182.phpt b/tests/std/array/range/bug21182.phpt new file mode 100644 index 00000000..af4602ab --- /dev/null +++ b/tests/std/array/range/bug21182.phpt @@ -0,0 +1,12 @@ +--TEST-- +Bug #21182 (range modifies arguments) +--FILE-- + +--EXPECT-- +a1: 20 +a2: 20 : type : string diff --git a/tests/std/array/range/bug24220.phpt b/tests/std/array/range/bug24220.phpt new file mode 100644 index 00000000..018296aa --- /dev/null +++ b/tests/std/array/range/bug24220.phpt @@ -0,0 +1,91 @@ +--TEST-- +Bug #24220 (range() numeric string handling) +--FILE-- + +--EXPECT-- +array(2) { + [0]=> + int(2003) + [1]=> + int(2004) +} +array(26) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + [3]=> + string(1) "d" + [4]=> + string(1) "e" + [5]=> + string(1) "f" + [6]=> + string(1) "g" + [7]=> + string(1) "h" + [8]=> + string(1) "i" + [9]=> + string(1) "j" + [10]=> + string(1) "k" + [11]=> + string(1) "l" + [12]=> + string(1) "m" + [13]=> + string(1) "n" + [14]=> + string(1) "o" + [15]=> + string(1) "p" + [16]=> + string(1) "q" + [17]=> + string(1) "r" + [18]=> + string(1) "s" + [19]=> + string(1) "t" + [20]=> + string(1) "u" + [21]=> + string(1) "v" + [22]=> + string(1) "w" + [23]=> + string(1) "x" + [24]=> + string(1) "y" + [25]=> + string(1) "z" +} +array(10) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + [6]=> + int(7) + [7]=> + int(8) + [8]=> + int(9) + [9]=> + int(10) +} diff --git a/tests/std/array/range/bug32021.phpt b/tests/std/array/range/bug32021.phpt new file mode 100644 index 00000000..a555b964 --- /dev/null +++ b/tests/std/array/range/bug32021.phpt @@ -0,0 +1,18 @@ +--TEST-- +Bug #32021 (Crash caused by range('', 'z')) +--SKIPIF-- +--FILE-- + +--EXPECTF-- +%s: Argument #1 ($start) must not be empty, casted to 0 in %s on line %d + +%s: Argument #1 ($start) must be a single byte string if argument #2 ($end) is a single byte string, argument #2 ($end) converted to 0 in %s on line %d +array(1) { + [0]=> + int(0) +} +DONE diff --git a/tests/std/array/range/bug41121.phpt b/tests/std/array/range/bug41121.phpt new file mode 100644 index 00000000..b2d133ef --- /dev/null +++ b/tests/std/array/range/bug41121.phpt @@ -0,0 +1,128 @@ +--TEST-- +Bug #41121 (range() overflow handling for large numbers on 32bit machines) +--INI-- +precision=14 +--SKIPIF-- + +--FILE-- + high +var_dump(range(2147483647, 2147483645, 1 )); +var_dump(range(2147483648, 2147483645, 1 )); + +?> +--EXPECT-- +array(3) { + [0]=> + int(2147483400) + [1]=> + int(2147483500) + [2]=> + int(2147483600) +} +array(3) { + [0]=> + float(2147483646) + [1]=> + float(2147483647) + [2]=> + float(2147483648) +} +array(12) { + [0]=> + float(2147483646) + [1]=> + float(2147483647) + [2]=> + float(2147483648) + [3]=> + float(2147483649) + [4]=> + float(2147483650) + [5]=> + float(2147483651) + [6]=> + float(2147483652) + [7]=> + float(2147483653) + [8]=> + float(2147483654) + [9]=> + float(2147483655) + [10]=> + float(2147483656) + [11]=> + float(2147483657) +} +array(4) { + [0]=> + int(2147483630) + [1]=> + int(2147483635) + [2]=> + int(2147483640) + [3]=> + int(2147483645) +} +array(4) { + [0]=> + float(-2147483645) + [1]=> + float(-2147483646) + [2]=> + float(-2147483647) + [3]=> + float(-2147483648) +} +array(5) { + [0]=> + float(-2147483645) + [1]=> + float(-2147483646) + [2]=> + float(-2147483647) + [3]=> + float(-2147483648) + [4]=> + float(-2147483649) +} +array(4) { + [0]=> + int(-2147483630) + [1]=> + int(-2147483635) + [2]=> + int(-2147483640) + [3]=> + int(-2147483645) +} +array(3) { + [0]=> + int(2147483647) + [1]=> + int(2147483646) + [2]=> + int(2147483645) +} +array(4) { + [0]=> + float(2147483648) + [1]=> + float(2147483647) + [2]=> + float(2147483646) + [3]=> + float(2147483645) +} diff --git a/tests/std/array/range/bug54459.phpt b/tests/std/array/range/bug54459.phpt new file mode 100644 index 00000000..9eed6dea --- /dev/null +++ b/tests/std/array/range/bug54459.phpt @@ -0,0 +1,219 @@ +--TEST-- +Bug #54459 (Range function accuracy) +--INI-- +precision=14 +--SKIPIF-- + +--FILE-- + $v){ + echo $i, ' = ', $v, PHP_EOL; +} +foreach (range("90", "100", .1) as $i => $v){ + echo $i, ' = ', $v, PHP_EOL; +} +?> +--EXPECT-- +0 = 90 +1 = 90.1 +2 = 90.2 +3 = 90.3 +4 = 90.4 +5 = 90.5 +6 = 90.6 +7 = 90.7 +8 = 90.8 +9 = 90.9 +10 = 91 +11 = 91.1 +12 = 91.2 +13 = 91.3 +14 = 91.4 +15 = 91.5 +16 = 91.6 +17 = 91.7 +18 = 91.8 +19 = 91.9 +20 = 92 +21 = 92.1 +22 = 92.2 +23 = 92.3 +24 = 92.4 +25 = 92.5 +26 = 92.6 +27 = 92.7 +28 = 92.8 +29 = 92.9 +30 = 93 +31 = 93.1 +32 = 93.2 +33 = 93.3 +34 = 93.4 +35 = 93.5 +36 = 93.6 +37 = 93.7 +38 = 93.8 +39 = 93.9 +40 = 94 +41 = 94.1 +42 = 94.2 +43 = 94.3 +44 = 94.4 +45 = 94.5 +46 = 94.6 +47 = 94.7 +48 = 94.8 +49 = 94.9 +50 = 95 +51 = 95.1 +52 = 95.2 +53 = 95.3 +54 = 95.4 +55 = 95.5 +56 = 95.6 +57 = 95.7 +58 = 95.8 +59 = 95.9 +60 = 96 +61 = 96.1 +62 = 96.2 +63 = 96.3 +64 = 96.4 +65 = 96.5 +66 = 96.6 +67 = 96.7 +68 = 96.8 +69 = 96.9 +70 = 97 +71 = 97.1 +72 = 97.2 +73 = 97.3 +74 = 97.4 +75 = 97.5 +76 = 97.6 +77 = 97.7 +78 = 97.8 +79 = 97.9 +80 = 98 +81 = 98.1 +82 = 98.2 +83 = 98.3 +84 = 98.4 +85 = 98.5 +86 = 98.6 +87 = 98.7 +88 = 98.8 +89 = 98.9 +90 = 99 +91 = 99.1 +92 = 99.2 +93 = 99.3 +94 = 99.4 +95 = 99.5 +96 = 99.6 +97 = 99.7 +98 = 99.8 +99 = 99.9 +100 = 100 +0 = 90 +1 = 90.1 +2 = 90.2 +3 = 90.3 +4 = 90.4 +5 = 90.5 +6 = 90.6 +7 = 90.7 +8 = 90.8 +9 = 90.9 +10 = 91 +11 = 91.1 +12 = 91.2 +13 = 91.3 +14 = 91.4 +15 = 91.5 +16 = 91.6 +17 = 91.7 +18 = 91.8 +19 = 91.9 +20 = 92 +21 = 92.1 +22 = 92.2 +23 = 92.3 +24 = 92.4 +25 = 92.5 +26 = 92.6 +27 = 92.7 +28 = 92.8 +29 = 92.9 +30 = 93 +31 = 93.1 +32 = 93.2 +33 = 93.3 +34 = 93.4 +35 = 93.5 +36 = 93.6 +37 = 93.7 +38 = 93.8 +39 = 93.9 +40 = 94 +41 = 94.1 +42 = 94.2 +43 = 94.3 +44 = 94.4 +45 = 94.5 +46 = 94.6 +47 = 94.7 +48 = 94.8 +49 = 94.9 +50 = 95 +51 = 95.1 +52 = 95.2 +53 = 95.3 +54 = 95.4 +55 = 95.5 +56 = 95.6 +57 = 95.7 +58 = 95.8 +59 = 95.9 +60 = 96 +61 = 96.1 +62 = 96.2 +63 = 96.3 +64 = 96.4 +65 = 96.5 +66 = 96.6 +67 = 96.7 +68 = 96.8 +69 = 96.9 +70 = 97 +71 = 97.1 +72 = 97.2 +73 = 97.3 +74 = 97.4 +75 = 97.5 +76 = 97.6 +77 = 97.7 +78 = 97.8 +79 = 97.9 +80 = 98 +81 = 98.1 +82 = 98.2 +83 = 98.3 +84 = 98.4 +85 = 98.5 +86 = 98.6 +87 = 98.7 +88 = 98.8 +89 = 98.9 +90 = 99 +91 = 99.1 +92 = 99.2 +93 = 99.3 +94 = 99.4 +95 = 99.5 +96 = 99.6 +97 = 99.7 +98 = 99.8 +99 = 99.9 +100 = 100 diff --git a/tests/std/array/range/gh13094.phpt b/tests/std/array/range/gh13094.phpt new file mode 100644 index 00000000..2e70adb6 --- /dev/null +++ b/tests/std/array/range/gh13094.phpt @@ -0,0 +1,29 @@ +--TEST-- +GH-13094 (range(9.9, '0') causes segmentation fault) +--FILE-- + +--EXPECT-- +array(10) { + [0]=> + float(9.9) + [1]=> + float(8.9) + [2]=> + float(7.9) + [3]=> + float(6.9) + [4]=> + float(5.9) + [5]=> + float(4.9) + [6]=> + float(3.9000000000000004) + [7]=> + float(2.9000000000000004) + [8]=> + float(1.9000000000000004) + [9]=> + float(0.9000000000000004) +} diff --git a/tests/std/array/range/range_bug70239_0.phpt b/tests/std/array/range/range_bug70239_0.phpt new file mode 100644 index 00000000..52f046a7 --- /dev/null +++ b/tests/std/array/range/range_bug70239_0.phpt @@ -0,0 +1,12 @@ +--TEST-- +Bug #70239 Creating a huge array doesn't result in exhausted, but segfault, var 1 +--FILE-- +getMessage() . "\n"; +} +?> +--EXPECT-- +range(): Argument #2 ($end) must be a finite number, INF provided diff --git a/tests/std/array/range/range_bug70239_1.phpt b/tests/std/array/range/range_bug70239_1.phpt new file mode 100644 index 00000000..681d594a --- /dev/null +++ b/tests/std/array/range/range_bug70239_1.phpt @@ -0,0 +1,12 @@ +--TEST-- +Bug #70239 Creating a huge array doesn't result in exhausted, but segfault, var 2 +--FILE-- +getMessage() . "\n"; +} +?> +--EXPECT-- +range(): Argument #1 ($start) must be a finite number, INF provided diff --git a/tests/std/array/range/range_bug70239_2.phpt b/tests/std/array/range/range_bug70239_2.phpt new file mode 100644 index 00000000..a4ec3c55 --- /dev/null +++ b/tests/std/array/range/range_bug70239_2.phpt @@ -0,0 +1,12 @@ +--TEST-- +Bug #70239 Creating a huge array doesn't result in exhausted, but segfault, var 3 +--FILE-- +getMessage() . "\n"; +} +?> +--EXPECTF-- +The supplied range exceeds the maximum array size: start=0 end=%d step=1 diff --git a/tests/std/array/range/range_bug70239_3.phpt b/tests/std/array/range/range_bug70239_3.phpt new file mode 100644 index 00000000..7099eb1e --- /dev/null +++ b/tests/std/array/range/range_bug70239_3.phpt @@ -0,0 +1,12 @@ +--TEST-- +Bug #70239 Creating a huge array doesn't result in exhausted, but segfault, var 4 +--FILE-- +getMessage() . "\n"; +} +?> +--EXPECTF-- +The supplied range exceeds the maximum array size: start=-%d end=0 step=1 diff --git a/tests/std/array/range/range_bug71132.phpt b/tests/std/array/range/range_bug71132.phpt new file mode 100644 index 00000000..5e3bcc8f --- /dev/null +++ b/tests/std/array/range/range_bug71132.phpt @@ -0,0 +1,10 @@ +--TEST-- +Bug #71132 (range function produces 2 segfaults with long integers) +--FILE-- + +--EXPECT-- +int(514) +int(514) diff --git a/tests/std/array/range/range_bug71197.phpt b/tests/std/array/range/range_bug71197.phpt new file mode 100644 index 00000000..2031ec7c --- /dev/null +++ b/tests/std/array/range/range_bug71197.phpt @@ -0,0 +1,8 @@ +--TEST-- +Bug #71197 (range function produces another 2 segfaults with long integers) +--FILE-- + +--EXPECT-- diff --git a/tests/std/array/range/range_bug72017.phpt b/tests/std/array/range/range_bug72017.phpt new file mode 100644 index 00000000..b5a56d7f --- /dev/null +++ b/tests/std/array/range/range_bug72017.phpt @@ -0,0 +1,17 @@ +--TEST-- +Bug #72017 (incorrect truncation due to floating point precision issue) +--FILE-- + +--EXPECT-- +array(4) { + [0]=> + float(4.5) + [1]=> + float(4.4) + [2]=> + float(4.3) + [3]=> + float(4.2) +} diff --git a/tests/std/array/range/range_inputs_float_NAN_values.phpt b/tests/std/array/range/range_inputs_float_NAN_values.phpt new file mode 100644 index 00000000..03ed069f --- /dev/null +++ b/tests/std/array/range/range_inputs_float_NAN_values.phpt @@ -0,0 +1,69 @@ +--TEST-- +Test range() function with non finite numbers +--INI-- +serialize_precision=14 +--FILE-- +getMessage(), PHP_EOL; + } + } +} + +?> +--EXPECT-- +float(NAN) +float(NAN) +float(NAN) +range(NAN, NAN); +range(): Argument #1 ($start) must be a finite number, NAN provided +range(NAN, NAN); +range(): Argument #1 ($start) must be a finite number, NAN provided +range(NAN, NAN); +range(): Argument #1 ($start) must be a finite number, NAN provided +range(NAN, 5.5); +range(): Argument #1 ($start) must be a finite number, NAN provided +range(NAN, NAN); +range(): Argument #1 ($start) must be a finite number, NAN provided +range(NAN, NAN); +range(): Argument #1 ($start) must be a finite number, NAN provided +range(NAN, NAN); +range(): Argument #1 ($start) must be a finite number, NAN provided +range(NAN, 5.5); +range(): Argument #1 ($start) must be a finite number, NAN provided +range(NAN, NAN); +range(): Argument #1 ($start) must be a finite number, NAN provided +range(NAN, NAN); +range(): Argument #1 ($start) must be a finite number, NAN provided +range(NAN, NAN); +range(): Argument #1 ($start) must be a finite number, NAN provided +range(NAN, 5.5); +range(): Argument #1 ($start) must be a finite number, NAN provided +range(5.5, NAN); +range(): Argument #2 ($end) must be a finite number, NAN provided +range(5.5, NAN); +range(): Argument #2 ($end) must be a finite number, NAN provided +range(5.5, NAN); +range(): Argument #2 ($end) must be a finite number, NAN provided +range(5.5, 5.5); +array(1) { + [0]=> + float(5.5) +} diff --git a/tests/std/array/range/range_inputs_float_basic.phpt b/tests/std/array/range/range_inputs_float_basic.phpt new file mode 100644 index 00000000..c6ba7fd7 --- /dev/null +++ b/tests/std/array/range/range_inputs_float_basic.phpt @@ -0,0 +1,149 @@ +--TEST-- +range(): float boundary inputs +--INI-- +serialize_precision=14 +--FILE-- + +--EXPECT-- +Increasing Range +array(6) { + [0]=> + float(1.5) + [1]=> + float(2.5) + [2]=> + float(3.5) + [3]=> + float(4.5) + [4]=> + float(5.5) + [5]=> + float(6.5) +} + +Decreasing range +array(6) { + [0]=> + float(6.5) + [1]=> + float(5.5) + [2]=> + float(4.5) + [3]=> + float(3.5) + [4]=> + float(2.5) + [5]=> + float(1.5) +} + +Boundaries are equal +array(1) { + [0]=> + float(5.5) +} + +Passing int step +array(4) { + [0]=> + float(1.5) + [1]=> + float(4.5) + [2]=> + float(7.5) + [3]=> + float(10.5) +} +array(4) { + [0]=> + float(10.5) + [1]=> + float(7.5) + [2]=> + float(4.5) + [3]=> + float(1.5) +} +array(4) { + [0]=> + float(1.5) + [1]=> + float(4.5) + [2]=> + float(7.5) + [3]=> + float(10.5) +} + +Passing float step +array(7) { + [0]=> + float(1.6) + [1]=> + float(1.7) + [2]=> + float(1.8) + [3]=> + float(1.9) + [4]=> + float(2) + [5]=> + float(2.1) + [6]=> + float(2.2) +} +array(7) { + [0]=> + float(2.2) + [1]=> + float(2.1) + [2]=> + float(2) + [3]=> + float(1.9) + [4]=> + float(1.8) + [5]=> + float(1.7) + [6]=> + float(1.6) +} +array(7) { + [0]=> + float(1.6) + [1]=> + float(1.7) + [2]=> + float(1.8) + [3]=> + float(1.9) + [4]=> + float(2) + [5]=> + float(2.1) + [6]=> + float(2.2) +} +Done diff --git a/tests/std/array/range/range_inputs_float_small_step_exhaustion.phpt b/tests/std/array/range/range_inputs_float_small_step_exhaustion.phpt new file mode 100644 index 00000000..b00b3142 --- /dev/null +++ b/tests/std/array/range/range_inputs_float_small_step_exhaustion.phpt @@ -0,0 +1,18 @@ +--TEST-- +Creating a range that exceeds the maximum array size +--FILE-- +getMessage(), \PHP_EOL; +} +try { + var_dump(range(PHP_INT_MIN, PHP_INT_MAX, 1)); +} catch (\ValueError $e) { + echo $e->getMessage(), \PHP_EOL; +} +?> +--EXPECTF-- +The supplied range exceeds the maximum array size: start=0.0 end=100000000000.0 step=0.1 +The supplied range exceeds the maximum array size: start=-%d end=%d step=1 diff --git a/tests/std/array/range/range_inputs_int_basic.phpt b/tests/std/array/range/range_inputs_int_basic.phpt new file mode 100644 index 00000000..1995470a --- /dev/null +++ b/tests/std/array/range/range_inputs_int_basic.phpt @@ -0,0 +1,189 @@ +--TEST-- +range(): integer boundary inputs +--INI-- +serialize_precision=14 +--FILE-- + +--EXPECT-- +Increasing Range +array(10) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + [6]=> + int(7) + [7]=> + int(8) + [8]=> + int(9) + [9]=> + int(10) +} + +Decreasing range +array(10) { + [0]=> + int(10) + [1]=> + int(9) + [2]=> + int(8) + [3]=> + int(7) + [4]=> + int(6) + [5]=> + int(5) + [6]=> + int(4) + [7]=> + int(3) + [8]=> + int(2) + [9]=> + int(1) +} + +Boundaries are equal +array(1) { + [0]=> + int(5) +} + +Passing int step +array(4) { + [0]=> + int(1) + [1]=> + int(4) + [2]=> + int(7) + [3]=> + int(10) +} +array(4) { + [0]=> + int(10) + [1]=> + int(7) + [2]=> + int(4) + [3]=> + int(1) +} +array(4) { + [0]=> + int(1) + [1]=> + int(4) + [2]=> + int(7) + [3]=> + int(10) +} + +Passing float step +array(11) { + [0]=> + float(1) + [1]=> + float(1.1) + [2]=> + float(1.2) + [3]=> + float(1.3) + [4]=> + float(1.4) + [5]=> + float(1.5) + [6]=> + float(1.6) + [7]=> + float(1.7) + [8]=> + float(1.8) + [9]=> + float(1.9) + [10]=> + float(2) +} +array(11) { + [0]=> + float(2) + [1]=> + float(1.9) + [2]=> + float(1.8) + [3]=> + float(1.7) + [4]=> + float(1.6) + [5]=> + float(1.5) + [6]=> + float(1.4) + [7]=> + float(1.3) + [8]=> + float(1.2) + [9]=> + float(1.1) + [10]=> + float(1) +} +array(11) { + [0]=> + float(1) + [1]=> + float(1.1) + [2]=> + float(1.2) + [3]=> + float(1.3) + [4]=> + float(1.4) + [5]=> + float(1.5) + [6]=> + float(1.6) + [7]=> + float(1.7) + [8]=> + float(1.8) + [9]=> + float(1.9) + [10]=> + float(2) +} +Done diff --git a/tests/std/array/range/range_inputs_int_with_float_step.phpt b/tests/std/array/range/range_inputs_int_with_float_step.phpt new file mode 100644 index 00000000..2d479ac4 --- /dev/null +++ b/tests/std/array/range/range_inputs_int_with_float_step.phpt @@ -0,0 +1,17 @@ +--TEST-- +Test range() function with integer inputs and float step +--INI-- +serialize_precision=14 +--FILE-- + +--EXPECT-- +array(3) { + [0]=> + int(1) + [1]=> + int(3) + [2]=> + int(5) +} diff --git a/tests/std/array/range/range_inputs_null_variations.phpt b/tests/std/array/range/range_inputs_null_variations.phpt new file mode 100644 index 00000000..a3ff352c --- /dev/null +++ b/tests/std/array/range/range_inputs_null_variations.phpt @@ -0,0 +1,98 @@ +--TEST-- +Test range() function with null as argument. +--INI-- +serialize_precision=14 +--FILE-- + +--EXPECTF-- +range(null, null) +array(1) { + [0]=> + int(0) +} +null with int boundary +array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) +} +array(6) { + [0]=> + int(5) + [1]=> + int(4) + [2]=> + int(3) + [3]=> + int(2) + [4]=> + int(1) + [5]=> + int(0) +} +null with float boundary +array(5) { + [0]=> + float(0) + [1]=> + float(1) + [2]=> + float(2) + [3]=> + float(3) + [4]=> + float(4) +} +array(5) { + [0]=> + float(4.5) + [1]=> + float(3.5) + [2]=> + float(2.5) + [3]=> + float(1.5) + [4]=> + float(0.5) +} +null with string boundary + +Warning:%S Argument #1 ($start) must be a single byte string if argument #2 ($end) is a single byte string, argument #2 ($end) converted to 0 in %s on line %d +array(1) { + [0]=> + int(0) +} + +Warning:%S Argument #2 ($end) must be a single byte string if argument #1 ($start) is a single byte string, argument #1 ($start) converted to 0 in %s on line %d +array(1) { + [0]=> + int(0) +} +Done diff --git a/tests/std/array/range/range_inputs_numeric_basic.phpt b/tests/std/array/range/range_inputs_numeric_basic.phpt new file mode 100644 index 00000000..09e9e415 --- /dev/null +++ b/tests/std/array/range/range_inputs_numeric_basic.phpt @@ -0,0 +1,74 @@ +--TEST-- +range(): mixed numeric types boundary inputs +--INI-- +serialize_precision=14 +--FILE-- + +--EXPECT-- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) +} +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) +} +array(4) { + [0]=> + float(1.5) + [1]=> + float(2.5) + [2]=> + float(3.5) + [3]=> + float(4.5) +} +array(4) { + [0]=> + float(1.5) + [1]=> + float(2.5) + [2]=> + float(3.5) + [3]=> + float(4.5) +} +array(4) { + [0]=> + int(9) + [1]=> + int(10) + [2]=> + int(11) + [3]=> + int(12) +} +array(4) { + [0]=> + int(9) + [1]=> + int(10) + [2]=> + int(11) + [3]=> + int(12) +} diff --git a/tests/std/array/range/range_inputs_string_basic.phpt b/tests/std/array/range/range_inputs_string_basic.phpt new file mode 100644 index 00000000..00ce49e6 --- /dev/null +++ b/tests/std/array/range/range_inputs_string_basic.phpt @@ -0,0 +1,153 @@ +--TEST-- +Test range() function with basic/expected string inputs +--INI-- +serialize_precision=14 +--FILE-- + +--EXPECT-- +-- Chars as Low and High -- +-- An array of elements from low to high -- +array(26) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + [3]=> + string(1) "d" + [4]=> + string(1) "e" + [5]=> + string(1) "f" + [6]=> + string(1) "g" + [7]=> + string(1) "h" + [8]=> + string(1) "i" + [9]=> + string(1) "j" + [10]=> + string(1) "k" + [11]=> + string(1) "l" + [12]=> + string(1) "m" + [13]=> + string(1) "n" + [14]=> + string(1) "o" + [15]=> + string(1) "p" + [16]=> + string(1) "q" + [17]=> + string(1) "r" + [18]=> + string(1) "s" + [19]=> + string(1) "t" + [20]=> + string(1) "u" + [21]=> + string(1) "v" + [22]=> + string(1) "w" + [23]=> + string(1) "x" + [24]=> + string(1) "y" + [25]=> + string(1) "z" +} + +-- An array of elements from high to low -- +array(26) { + [0]=> + string(1) "z" + [1]=> + string(1) "y" + [2]=> + string(1) "x" + [3]=> + string(1) "w" + [4]=> + string(1) "v" + [5]=> + string(1) "u" + [6]=> + string(1) "t" + [7]=> + string(1) "s" + [8]=> + string(1) "r" + [9]=> + string(1) "q" + [10]=> + string(1) "p" + [11]=> + string(1) "o" + [12]=> + string(1) "n" + [13]=> + string(1) "m" + [14]=> + string(1) "l" + [15]=> + string(1) "k" + [16]=> + string(1) "j" + [17]=> + string(1) "i" + [18]=> + string(1) "h" + [19]=> + string(1) "g" + [20]=> + string(1) "f" + [21]=> + string(1) "e" + [22]=> + string(1) "d" + [23]=> + string(1) "c" + [24]=> + string(1) "b" + [25]=> + string(1) "a" +} + +-- Low and High are equal -- +array(1) { + [0]=> + string(1) "q" +} + +-- Testing basic string with step -- +array(4) { + [0]=> + string(1) "a" + [1]=> + string(1) "c" + [2]=> + string(1) "e" + [3]=> + string(1) "g" +} +Done diff --git a/tests/std/array/range/range_inputs_string_digits.phpt b/tests/std/array/range/range_inputs_string_digits.phpt new file mode 100644 index 00000000..b218c582 --- /dev/null +++ b/tests/std/array/range/range_inputs_string_digits.phpt @@ -0,0 +1,97 @@ +--TEST-- +Test range() function with string digits +--FILE-- + +--EXPECT-- +Only digits +array(9) { + [0]=> + string(1) "1" + [1]=> + string(1) "2" + [2]=> + string(1) "3" + [3]=> + string(1) "4" + [4]=> + string(1) "5" + [5]=> + string(1) "6" + [6]=> + string(1) "7" + [7]=> + string(1) "8" + [8]=> + string(1) "9" +} +array(9) { + [0]=> + string(1) "9" + [1]=> + string(1) "8" + [2]=> + string(1) "7" + [3]=> + string(1) "6" + [4]=> + string(1) "5" + [5]=> + string(1) "4" + [6]=> + string(1) "3" + [7]=> + string(1) "2" + [8]=> + string(1) "1" +} +Only digits and char +array(9) { + [0]=> + string(1) "9" + [1]=> + string(1) ":" + [2]=> + string(1) ";" + [3]=> + string(1) "<" + [4]=> + string(1) "=" + [5]=> + string(1) ">" + [6]=> + string(1) "?" + [7]=> + string(1) "@" + [8]=> + string(1) "A" +} +array(9) { + [0]=> + string(1) "A" + [1]=> + string(1) "@" + [2]=> + string(1) "?" + [3]=> + string(1) ">" + [4]=> + string(1) "=" + [5]=> + string(1) "<" + [6]=> + string(1) ";" + [7]=> + string(1) ":" + [8]=> + string(1) "9" +} +Done diff --git a/tests/std/array/range/range_inputs_string_digits_float_step.phpt b/tests/std/array/range/range_inputs_string_digits_float_step.phpt new file mode 100644 index 00000000..45a53827 --- /dev/null +++ b/tests/std/array/range/range_inputs_string_digits_float_step.phpt @@ -0,0 +1,34 @@ +--TEST-- +Test range() function where boundary are string digits and step is a float +--INI-- +serialize_precision=14 +--FILE-- + +--EXPECT-- +array(11) { + [0]=> + float(1) + [1]=> + float(1.1) + [2]=> + float(1.2) + [3]=> + float(1.3) + [4]=> + float(1.4) + [5]=> + float(1.5) + [6]=> + float(1.6) + [7]=> + float(1.7) + [8]=> + float(1.8) + [9]=> + float(1.9) + [10]=> + float(2) +} diff --git a/tests/std/array/range/range_inputs_string_invalid.phpt b/tests/std/array/range/range_inputs_string_invalid.phpt new file mode 100644 index 00000000..f86d1670 --- /dev/null +++ b/tests/std/array/range/range_inputs_string_invalid.phpt @@ -0,0 +1,85 @@ +--TEST-- +Test range() function with unexpected string inputs +--INI-- +serialize_precision=14 +--FILE-- + +--EXPECTF-- +Range will ignore any byte after the first one + +Warning:%S Argument #1 ($start) must be a single byte, subsequent bytes are ignored in %s on line %d + +Warning:%S Argument #2 ($end) must be a single byte, subsequent bytes are ignored in %s on line %d +array(2) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" +} +Range cannot operate on an empty string + +Warning:%S Argument #2 ($end) must not be empty, casted to 0 in %s on line %d + +Warning:%S Argument #2 ($end) must be a single byte string if argument #1 ($start) is a single byte string, argument #1 ($start) converted to 0 in %s on line %d +array(1) { + [0]=> + int(0) +} + +Warning:%S Argument #1 ($start) must not be empty, casted to 0 in %s on line %d + +Warning:%S Argument #1 ($start) must be a single byte string if argument #2 ($end) is a single byte string, argument #2 ($end) converted to 0 in %s on line %d +array(1) { + [0]=> + int(0) +} +Mixing numeric float string and character + +Warning:%S Argument #1 ($start) must be a single byte string if argument #2 ($end) is a single byte string, argument #2 ($end) converted to 0 in %s on line %d +array(4) { + [0]=> + float(3.5) + [1]=> + float(2.5) + [2]=> + float(1.5) + [3]=> + float(0.5) +} + +Warning:%S Argument #2 ($end) must be a single byte string if argument #1 ($start) is a single byte string, argument #1 ($start) converted to 0 in %s on line %d +array(4) { + [0]=> + float(0) + [1]=> + float(1) + [2]=> + float(2) + [3]=> + float(3) +} +Fractional step cannot be used on character ranges + +Warning:%S Argument #3 ($step) must be of type int when generating an array of characters, inputs converted to 0 in %s on line %d +array(1) { + [0]=> + float(0) +} +Done diff --git a/tests/std/array/range/range_inputs_string_numeric.phpt b/tests/std/array/range/range_inputs_string_numeric.phpt new file mode 100644 index 00000000..fc45811a --- /dev/null +++ b/tests/std/array/range/range_inputs_string_numeric.phpt @@ -0,0 +1,189 @@ +--TEST-- +range(): numeric string boundary inputs +--INI-- +serialize_precision=14 +--FILE-- + +--EXPECT-- +Increasing Range +array(10) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + [6]=> + int(7) + [7]=> + int(8) + [8]=> + int(9) + [9]=> + int(10) +} + +Decreasing range +array(10) { + [0]=> + int(10) + [1]=> + int(9) + [2]=> + int(8) + [3]=> + int(7) + [4]=> + int(6) + [5]=> + int(5) + [6]=> + int(4) + [7]=> + int(3) + [8]=> + int(2) + [9]=> + int(1) +} + +Boundaries are equal +array(1) { + [0]=> + string(1) "5" +} + +Passing int step +array(4) { + [0]=> + int(1) + [1]=> + int(4) + [2]=> + int(7) + [3]=> + int(10) +} +array(4) { + [0]=> + int(10) + [1]=> + int(7) + [2]=> + int(4) + [3]=> + int(1) +} +array(4) { + [0]=> + int(1) + [1]=> + int(4) + [2]=> + int(7) + [3]=> + int(10) +} + +Passing float step +array(11) { + [0]=> + float(1) + [1]=> + float(1.1) + [2]=> + float(1.2) + [3]=> + float(1.3) + [4]=> + float(1.4) + [5]=> + float(1.5) + [6]=> + float(1.6) + [7]=> + float(1.7) + [8]=> + float(1.8) + [9]=> + float(1.9) + [10]=> + float(2) +} +array(11) { + [0]=> + float(2) + [1]=> + float(1.9) + [2]=> + float(1.8) + [3]=> + float(1.7) + [4]=> + float(1.6) + [5]=> + float(1.5) + [6]=> + float(1.4) + [7]=> + float(1.3) + [8]=> + float(1.2) + [9]=> + float(1.1) + [10]=> + float(1) +} +array(11) { + [0]=> + float(1) + [1]=> + float(1.1) + [2]=> + float(1.2) + [3]=> + float(1.3) + [4]=> + float(1.4) + [5]=> + float(1.5) + [6]=> + float(1.6) + [7]=> + float(1.7) + [8]=> + float(1.8) + [9]=> + float(1.9) + [10]=> + float(2) +} +Done diff --git a/tests/std/array/range/range_inputs_string_variations.phpt b/tests/std/array/range/range_inputs_string_variations.phpt new file mode 100644 index 00000000..27dd535f --- /dev/null +++ b/tests/std/array/range/range_inputs_string_variations.phpt @@ -0,0 +1,148 @@ +--TEST-- +Test range() function with unexpected string input variations or unusual step. +--INI-- +serialize_precision=14 +--FILE-- + +--EXPECT-- +int compatible float as step +array(4) { + [0]=> + string(1) "a" + [1]=> + string(1) "c" + [2]=> + string(1) "e" + [3]=> + string(1) "g" +} +A to z range() +array(58) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + [2]=> + string(1) "C" + [3]=> + string(1) "D" + [4]=> + string(1) "E" + [5]=> + string(1) "F" + [6]=> + string(1) "G" + [7]=> + string(1) "H" + [8]=> + string(1) "I" + [9]=> + string(1) "J" + [10]=> + string(1) "K" + [11]=> + string(1) "L" + [12]=> + string(1) "M" + [13]=> + string(1) "N" + [14]=> + string(1) "O" + [15]=> + string(1) "P" + [16]=> + string(1) "Q" + [17]=> + string(1) "R" + [18]=> + string(1) "S" + [19]=> + string(1) "T" + [20]=> + string(1) "U" + [21]=> + string(1) "V" + [22]=> + string(1) "W" + [23]=> + string(1) "X" + [24]=> + string(1) "Y" + [25]=> + string(1) "Z" + [26]=> + string(1) "[" + [27]=> + string(1) "\" + [28]=> + string(1) "]" + [29]=> + string(1) "^" + [30]=> + string(1) "_" + [31]=> + string(1) "`" + [32]=> + string(1) "a" + [33]=> + string(1) "b" + [34]=> + string(1) "c" + [35]=> + string(1) "d" + [36]=> + string(1) "e" + [37]=> + string(1) "f" + [38]=> + string(1) "g" + [39]=> + string(1) "h" + [40]=> + string(1) "i" + [41]=> + string(1) "j" + [42]=> + string(1) "k" + [43]=> + string(1) "l" + [44]=> + string(1) "m" + [45]=> + string(1) "n" + [46]=> + string(1) "o" + [47]=> + string(1) "p" + [48]=> + string(1) "q" + [49]=> + string(1) "r" + [50]=> + string(1) "s" + [51]=> + string(1) "t" + [52]=> + string(1) "u" + [53]=> + string(1) "v" + [54]=> + string(1) "w" + [55]=> + string(1) "x" + [56]=> + string(1) "y" + [57]=> + string(1) "z" +} +Done diff --git a/tests/std/array/range/range_negative_step_decreasing_ranges.phpt b/tests/std/array/range/range_negative_step_decreasing_ranges.phpt new file mode 100644 index 00000000..6a9ff3a7 --- /dev/null +++ b/tests/std/array/range/range_negative_step_decreasing_ranges.phpt @@ -0,0 +1,33 @@ +--TEST-- +range() allows $step parameter to be negative for decreasing ranges +--INI-- +precision=14 +--FILE-- + +--EXPECT-- +array(3) { + [0]=> + string(1) "c" + [1]=> + string(1) "b" + [2]=> + string(1) "a" +} +array(3) { + [0]=> + int(3) + [1]=> + int(2) + [2]=> + int(1) +} +array(2) { + [0]=> + float(3.5) + [1]=> + float(2) +} diff --git a/tests/std/array/range/range_step_errors.phpt b/tests/std/array/range/range_step_errors.phpt new file mode 100644 index 00000000..e950c527 --- /dev/null +++ b/tests/std/array/range/range_step_errors.phpt @@ -0,0 +1,134 @@ +--TEST-- +range() programattic errors for the $step parameter +--INI-- +precision=14 +--FILE-- +getMessage(), "\n"; +} +try { + var_dump( range(1, 7, 0) ); +} catch (\ValueError $e) { + echo $e->getMessage(), "\n"; +} +try { + var_dump( range('A', 'H', 0) ); +} catch (\ValueError $e) { + echo $e->getMessage(), "\n"; +} +try { + var_dump( range('A', 'H', 0.0) ); +} catch (\ValueError $e) { + echo $e->getMessage(), "\n"; +} +echo "Step cannot be INF\n"; +try { + var_dump( range(1.0, 7.0, 10.0**400) ); +} catch (\ValueError $e) { + echo $e->getMessage(), "\n"; +} +try { + var_dump( range(1, 7, 10.0**400) ); +} catch (\ValueError $e) { + echo $e->getMessage(), "\n"; +} +try { + var_dump( range('A', 'H', 10.0**400) ); +} catch (\ValueError $e) { + echo $e->getMessage(), "\n"; +} +echo "Step cannot be NAN\n"; +try { + var_dump( range(1.0, 7.0, fdiv(0, 0)) ); +} catch (\ValueError $e) { + echo $e->getMessage(), "\n"; +} +try { + var_dump( range(1, 7, fdiv(0, 0)) ); +} catch (\ValueError $e) { + echo $e->getMessage(), "\n"; +} +try { + var_dump( range('A', 'H', fdiv(0, 0)) ); +} catch (\ValueError $e) { + echo $e->getMessage(), "\n"; +} + +echo "Step must be within the range of input parameters\n"; +echo "-- Testing ( (low < high) && (high-low < step) ) --\n"; +try { + var_dump( range(1.0, 7.0, 6.5) ); +} catch (\ValueError $e) { + echo $e->getMessage(), "\n"; +} + +echo "-- Testing ( (low > high) && (low-high < step) ) --\n"; +try { + var_dump( range(7.0, 1.0, 6.5) ); +} catch (\ValueError $e) { + echo $e->getMessage(), "\n"; +} + +echo "-- Testing ( (low < high) && (high-low < step) ) for characters --\n"; +try { + var_dump(range('a', 'z', 100)); +} catch (\ValueError $e) { + echo $e->getMessage(), "\n"; +} + +echo "-- Testing ( (low > high) && (low-high < step) ) for characters --\n"; +try { + var_dump(range('z', 'a', 100)); +} catch (\ValueError $e) { + echo $e->getMessage(), "\n"; +} + +echo "Step must not be negative for increasing ranges\n"; +try { + var_dump(range('a', 'c', -1)); +} catch (\ValueError $e) { + echo $e->getMessage(), "\n"; +} +try { + var_dump(range(1, 3, -1)); +} catch (\ValueError $e) { + echo $e->getMessage(), "\n"; +} +try { + var_dump(range(1.5, 3.5, -1.5)); +} catch (\ValueError $e) { + echo $e->getMessage(), "\n"; +} + +?> +--EXPECTF-- +Step cannot be 0 +range(): Argument #3 ($step) cannot be 0 +range(): Argument #3 ($step) cannot be 0 +range(): Argument #3 ($step) cannot be 0 +range(): Argument #3 ($step) cannot be 0 +Step cannot be INF +range(): Argument #3 ($step) must be a finite number, INF provided +range(): Argument #3 ($step) must be a finite number, INF provided +range(): Argument #3 ($step) must be a finite number, INF provided +Step cannot be NAN +range(): Argument #3 ($step) must be a finite number, NAN provided +range(): Argument #3 ($step) must be a finite number, NAN provided +range(): Argument #3 ($step) must be a finite number, NAN provided +Step must be within the range of input parameters +-- Testing ( (low < high) && (high-low < step) ) -- +range(): Argument #3 ($step) must be less than the range spanned by argument #1 ($start) and argument #2 ($end) +-- Testing ( (low > high) && (low-high < step) ) -- +range(): Argument #3 ($step) must be less than the range spanned by argument #1 ($start) and argument #2 ($end) +-- Testing ( (low < high) && (high-low < step) ) for characters -- +range(): Argument #3 ($step) must be less than the range spanned by argument #1 ($start) and argument #2 ($end) +-- Testing ( (low > high) && (low-high < step) ) for characters -- +range(): Argument #3 ($step) must be less than the range spanned by argument #1 ($start) and argument #2 ($end) +Step must not be negative for increasing ranges +range(): Argument #3 ($step) must be greater than 0 for increasing ranges +range(): Argument #3 ($step) must be greater than 0 for increasing ranges +range(): Argument #3 ($step) must be greater than 0 for increasing ranges diff --git a/tests/std/array/range/range_variation1.phpt b/tests/std/array/range/range_variation1.phpt new file mode 100644 index 00000000..0747fab3 --- /dev/null +++ b/tests/std/array/range/range_variation1.phpt @@ -0,0 +1,60 @@ +--TEST-- +Test range() function (variation-2) +--INI-- +precision=14 +--SKIPIF-- + +--FILE-- + +--EXPECT-- +*** Testing max/outof range values *** +array(2) { + [0]=> + int(2147483645) + [1]=> + int(2147483646) +} +array(3) { + [0]=> + float(2147483646) + [1]=> + float(2147483647) + [2]=> + float(2147483648) +} +array(2) { + [0]=> + int(-2147483647) + [1]=> + int(-2147483646) +} +array(2) { + [0]=> + float(-2147483648) + [1]=> + float(-2147483647) +} +array(3) { + [0]=> + float(-2147483649) + [1]=> + float(-2147483648) + [2]=> + float(-2147483647) +} + +Done diff --git a/tests/std/array/range/range_variation1_64bit.phpt b/tests/std/array/range/range_variation1_64bit.phpt new file mode 100644 index 00000000..555dbc2e --- /dev/null +++ b/tests/std/array/range/range_variation1_64bit.phpt @@ -0,0 +1,60 @@ +--TEST-- +Test range() function (variation-2) +--INI-- +precision=14 +--SKIPIF-- + +--FILE-- + +--EXPECT-- +*** Testing max/outof range values *** +array(2) { + [0]=> + int(2147483645) + [1]=> + int(2147483646) +} +array(3) { + [0]=> + int(2147483646) + [1]=> + int(2147483647) + [2]=> + int(2147483648) +} +array(2) { + [0]=> + int(-2147483647) + [1]=> + int(-2147483646) +} +array(2) { + [0]=> + int(-2147483648) + [1]=> + int(-2147483647) +} +array(3) { + [0]=> + int(-2147483649) + [1]=> + int(-2147483648) + [2]=> + int(-2147483647) +} + +Done diff --git a/tests/std/array/rcn_in_place.phpt b/tests/std/array/rcn_in_place.phpt new file mode 100644 index 00000000..e6a7b5b6 --- /dev/null +++ b/tests/std/array/rcn_in_place.phpt @@ -0,0 +1,57 @@ +--TEST-- +RCN check for in-place array modifications +--FILE-- + 0)); +var_dump(array_intersect(range(0, 1), [])); +var_dump(array_uintersect(range(0, 1), [], fn () => 0)); +var_dump(array_intersect_uassoc(range(0, 1), [], fn () => 0)); +var_dump(array_uintersect_uassoc(range(0, 1), [], fn () => 0, fn () => 0)); +?> +--EXPECT-- +array(2) { + [0]=> + int(0) + [1]=> + int(1) +} +array(2) { + [0]=> + int(0) + [1]=> + int(1) +} +array(2) { + [0]=> + int(0) + [1]=> + int(1) +} +array(2) { + [0]=> + int(0) + [1]=> + int(1) +} +array(2) { + [0]=> + int(0) + [1]=> + int(1) +} +array(0) { +} +array(0) { +} +array(0) { +} +array(0) { +} +array(0) { +} diff --git a/tests/std/array/reset_basic.phpt b/tests/std/array/reset_basic.phpt new file mode 100644 index 00000000..d533d28d --- /dev/null +++ b/tests/std/array/reset_basic.phpt @@ -0,0 +1,38 @@ +--TEST-- +Test reset() function : basic functionality +--FILE-- + 'two'); + +echo "\n-- Initial Position: --\n"; +echo key($array) . " => " . current($array) . "\n"; + +echo "\n-- Call to next() --\n"; +var_dump(next($array)); + +echo "\n-- Current Position: --\n"; +echo key($array) . " => " . current($array) . "\n"; + +echo "\n-- Call to reset() --\n"; +var_dump(reset($array)); +?> +--EXPECT-- +*** Testing reset() : basic functionality *** + +-- Initial Position: -- +0 => zero + +-- Call to next() -- +string(3) "one" + +-- Current Position: -- +1 => one + +-- Call to reset() -- +string(4) "zero" diff --git a/tests/std/array/reset_variation2.phpt b/tests/std/array/reset_variation2.phpt new file mode 100644 index 00000000..13d1347f --- /dev/null +++ b/tests/std/array/reset_variation2.phpt @@ -0,0 +1,27 @@ +--TEST-- +Test reset() function : usage variations - unset first element +--FILE-- + " . key($array) . "\n"; + +echo "\n-- Unset First element in array and check reset() --\n"; +unset($array[0]); +var_dump(reset($array)); +?> +--EXPECT-- +*** Testing reset() : usage variations *** + +-- Initial Position: -- +a => 0 + +-- Unset First element in array and check reset() -- +string(1) "b" diff --git a/tests/std/array/reset_variation3.phpt b/tests/std/array/reset_variation3.phpt new file mode 100644 index 00000000..9bfc290b --- /dev/null +++ b/tests/std/array/reset_variation3.phpt @@ -0,0 +1,49 @@ +--TEST-- +Test reset() function : usage variations - Referenced variables +--FILE-- + +--EXPECT-- +*** Testing reset() : usage variations *** + +-- Initial position of internal pointer -- +string(4) "zero" + +-- Position after calling next() -- +$array1: string(3) "one" +$array2: string(3) "one" + +-- Position after calling reset() -- +string(4) "zero" +$array1: string(4) "zero" +$array2: string(4) "zero" diff --git a/tests/std/array/rsort_basic.phpt b/tests/std/array/rsort_basic.phpt new file mode 100644 index 00000000..a7ad5f37 --- /dev/null +++ b/tests/std/array/rsort_basic.phpt @@ -0,0 +1,235 @@ +--TEST-- +Test rsort() function : basic functionality +--FILE-- + "lemon", "o" => "orange", + "O" => "Orange", "O1" => "Orange1", "o2" => "orange2", "O3" => "Orange3", "o20" => "orange20", + "b" => "banana", +); + +// array with default keys containing unsorted numeric values +$unsorted_numerics = array( 100, 33, 555, 22 ); + +echo "\n-- Testing rsort() by supplying string array, 'flag' value is default --\n"; +$temp_array = $unsorted_strings; +var_dump( rsort($temp_array) ); +var_dump( $temp_array); + +echo "\n-- Testing rsort() by supplying numeric array, 'flag' value is default --\n"; +$temp_array = $unsorted_numerics; +var_dump( rsort($temp_array) ); +var_dump( $temp_array); + +echo "\n-- Testing rsort() by supplying string array, 'flag' = SORT_REGULAR --\n"; +$temp_array = $unsorted_strings; +var_dump( rsort($temp_array, SORT_REGULAR) ); +var_dump( $temp_array); + +echo "\n-- Testing rsort() by supplying numeric array, 'flag' = SORT_REGULAR --\n"; +$temp_array = $unsorted_numerics; +var_dump( rsort($temp_array, SORT_REGULAR) ); +var_dump( $temp_array); + +echo "\n-- Testing rsort() by supplying string array, 'flag' = SORT_STRING --\n"; +$temp_array = $unsorted_strings; +var_dump( rsort($temp_array, SORT_STRING) ); +var_dump( $temp_array); + +echo "\n-- Testing rsort() by supplying string array (case insensitive), 'flag' = SORT_STRING|SORT_FLAG_CASE --\n"; +$temp_array = $unsorted_strings; +var_dump( rsort($temp_array, SORT_STRING|SORT_FLAG_CASE) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing rsort() by supplying string array (natural), 'flag' = SORT_NATURAL --\n"; +$temp_array = $unsorted_strings; +var_dump( rsort($temp_array, SORT_NATURAL) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing rsort() by supplying string array (natural, case insensitive), 'flag' = SORT_NATURAL|SORT_FLAG_CASE --\n"; +$temp_array = $unsorted_strings; +var_dump( rsort($temp_array, SORT_NATURAL|SORT_FLAG_CASE) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing rsort() by supplying numeric array, 'flag' = SORT_NUMERIC --\n"; +$temp_array = $unsorted_numerics; +var_dump( rsort($temp_array, SORT_NUMERIC) ); +var_dump( $temp_array); + +echo "Done"; +?> +--EXPECT-- +*** Testing rsort() : basic functionality *** + +-- Testing rsort() by supplying string array, 'flag' value is default -- +bool(true) +array(8) { + [0]=> + string(8) "orange20" + [1]=> + string(7) "orange2" + [2]=> + string(6) "orange" + [3]=> + string(5) "lemon" + [4]=> + string(6) "banana" + [5]=> + string(7) "Orange3" + [6]=> + string(7) "Orange1" + [7]=> + string(6) "Orange" +} + +-- Testing rsort() by supplying numeric array, 'flag' value is default -- +bool(true) +array(4) { + [0]=> + int(555) + [1]=> + int(100) + [2]=> + int(33) + [3]=> + int(22) +} + +-- Testing rsort() by supplying string array, 'flag' = SORT_REGULAR -- +bool(true) +array(8) { + [0]=> + string(8) "orange20" + [1]=> + string(7) "orange2" + [2]=> + string(6) "orange" + [3]=> + string(5) "lemon" + [4]=> + string(6) "banana" + [5]=> + string(7) "Orange3" + [6]=> + string(7) "Orange1" + [7]=> + string(6) "Orange" +} + +-- Testing rsort() by supplying numeric array, 'flag' = SORT_REGULAR -- +bool(true) +array(4) { + [0]=> + int(555) + [1]=> + int(100) + [2]=> + int(33) + [3]=> + int(22) +} + +-- Testing rsort() by supplying string array, 'flag' = SORT_STRING -- +bool(true) +array(8) { + [0]=> + string(8) "orange20" + [1]=> + string(7) "orange2" + [2]=> + string(6) "orange" + [3]=> + string(5) "lemon" + [4]=> + string(6) "banana" + [5]=> + string(7) "Orange3" + [6]=> + string(7) "Orange1" + [7]=> + string(6) "Orange" +} + +-- Testing rsort() by supplying string array (case insensitive), 'flag' = SORT_STRING|SORT_FLAG_CASE -- +bool(true) +array(8) { + [0]=> + string(7) "Orange3" + [1]=> + string(8) "orange20" + [2]=> + string(7) "orange2" + [3]=> + string(7) "Orange1" + [4]=> + string(6) "orange" + [5]=> + string(6) "Orange" + [6]=> + string(5) "lemon" + [7]=> + string(6) "banana" +} + +-- Testing rsort() by supplying string array (natural), 'flag' = SORT_NATURAL -- +bool(true) +array(8) { + [0]=> + string(8) "orange20" + [1]=> + string(7) "orange2" + [2]=> + string(6) "orange" + [3]=> + string(5) "lemon" + [4]=> + string(6) "banana" + [5]=> + string(7) "Orange3" + [6]=> + string(7) "Orange1" + [7]=> + string(6) "Orange" +} + +-- Testing rsort() by supplying string array (natural, case insensitive), 'flag' = SORT_NATURAL|SORT_FLAG_CASE -- +bool(true) +array(8) { + [0]=> + string(8) "orange20" + [1]=> + string(7) "Orange3" + [2]=> + string(7) "orange2" + [3]=> + string(7) "Orange1" + [4]=> + string(6) "orange" + [5]=> + string(6) "Orange" + [6]=> + string(5) "lemon" + [7]=> + string(6) "banana" +} + +-- Testing rsort() by supplying numeric array, 'flag' = SORT_NUMERIC -- +bool(true) +array(4) { + [0]=> + int(555) + [1]=> + int(100) + [2]=> + int(33) + [3]=> + int(22) +} +Done diff --git a/tests/std/array/rsort_object1.phpt b/tests/std/array/rsort_object1.phpt new file mode 100644 index 00000000..4dc1feeb --- /dev/null +++ b/tests/std/array/rsort_object1.phpt @@ -0,0 +1,218 @@ +--TEST-- +Test rsort() function : object functionality +--FILE-- +class_value = $value; + } +} +// class declaration for string objects +class for_string_rsort +{ + public $class_value; + // initializing object member value + function __construct($value) + { + $this->class_value = $value; + } + // return string value + function __tostring(): string { + return (string) $this->value; + } +} +function main() +{ + /* + * Test basic functionality of rsort() with objects + */ + echo "*** Testing rsort() : object functionality ***\n"; + // array of integer objects + $unsorted_int_obj = array(new for_integer_rsort(11), new for_integer_rsort(66), new for_integer_rsort(23), new for_integer_rsort(-5), new for_integer_rsort(0.001), new for_integer_rsort(0)); + // array of string objects + $unsorted_str_obj = array(new for_string_rsort("axx"), new for_string_rsort("t"), new for_string_rsort("w"), new for_string_rsort("py"), new for_string_rsort("apple"), new for_string_rsort("Orange"), new for_string_rsort("Lemon"), new for_string_rsort("aPPle")); + echo "\n-- Sort flag = default --\n"; + // testing rsort() function by supplying integer object array, flag value is default + $temp_array = $unsorted_int_obj; + var_dump(rsort($temp_array)); + var_dump($temp_array); + // testing rsort() function by supplying string object array, flag value is default + $temp_array = $unsorted_str_obj; + var_dump(rsort($temp_array)); + var_dump($temp_array); + echo "\n-- Sort flag = SORT_REGULAR --\n"; + // testing rsort() function by supplying integer object array, flag value = SORT_REGULAR + $temp_array = $unsorted_int_obj; + var_dump(rsort($temp_array, SORT_REGULAR)); + var_dump($temp_array); + // testing rsort() function by supplying string object array, flag value = SORT_REGULAR + $temp_array = $unsorted_str_obj; + var_dump(rsort($temp_array, SORT_REGULAR)); + var_dump($temp_array); + echo "Done"; +} +?> +--EXPECTF-- +*** Testing rsort() : object functionality *** + +-- Sort flag = default -- +bool(true) +array(6) { + [0]=> + object(for_integer_rsort)#%d (1) { + ["class_value"]=> + int(66) + } + [1]=> + object(for_integer_rsort)#%d (1) { + ["class_value"]=> + int(23) + } + [2]=> + object(for_integer_rsort)#%d (1) { + ["class_value"]=> + int(11) + } + [3]=> + object(for_integer_rsort)#%d (1) { + ["class_value"]=> + float(0.001) + } + [4]=> + object(for_integer_rsort)#%d (1) { + ["class_value"]=> + int(0) + } + [5]=> + object(for_integer_rsort)#%d (1) { + ["class_value"]=> + int(-5) + } +} +bool(true) +array(8) { + [0]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(1) "w" + } + [1]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(1) "t" + } + [2]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(2) "py" + } + [3]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(3) "axx" + } + [4]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(5) "apple" + } + [5]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(5) "aPPle" + } + [6]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(6) "Orange" + } + [7]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(5) "Lemon" + } +} + +-- Sort flag = SORT_REGULAR -- +bool(true) +array(6) { + [0]=> + object(for_integer_rsort)#%d (1) { + ["class_value"]=> + int(66) + } + [1]=> + object(for_integer_rsort)#%d (1) { + ["class_value"]=> + int(23) + } + [2]=> + object(for_integer_rsort)#%d (1) { + ["class_value"]=> + int(11) + } + [3]=> + object(for_integer_rsort)#%d (1) { + ["class_value"]=> + float(0.001) + } + [4]=> + object(for_integer_rsort)#%d (1) { + ["class_value"]=> + int(0) + } + [5]=> + object(for_integer_rsort)#%d (1) { + ["class_value"]=> + int(-5) + } +} +bool(true) +array(8) { + [0]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(1) "w" + } + [1]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(1) "t" + } + [2]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(2) "py" + } + [3]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(3) "axx" + } + [4]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(5) "apple" + } + [5]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(5) "aPPle" + } + [6]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(6) "Orange" + } + [7]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(5) "Lemon" + } +} +Done diff --git a/tests/std/array/rsort_object2.phpt b/tests/std/array/rsort_object2.phpt new file mode 100644 index 00000000..a7e4fde7 --- /dev/null +++ b/tests/std/array/rsort_object2.phpt @@ -0,0 +1,230 @@ +--TEST-- +Test rsort() function : object functionality - different visibilities +--FILE-- +public_class_value = $value1; + $this->private_class_value = $value2; + $this->protected_class_value = $value3; + } +} +// class declaration for string objects +class for_string_rsort +{ + public $public_class_value; + private $private_class_value; + protected $protected_class_value; + // initializing object member value + function __construct($value1, $value2, $value3) + { + $this->public_class_value = $value1; + $this->private_class_value = $value2; + $this->protected_class_value = $value3; + } + // return string value + function __tostring(): string { + return (string) $this->value; + } +} +function main() +{ + /* + * Test functionality of rsort() with objects where properties have different visibilities + */ + echo "*** Testing rsort() : object functionality ***\n"; + // array of integer objects + $unsorted_int_obj = array(new for_integer_rsort(11, 33, 30), new for_integer_rsort(66, 44, 4), new for_integer_rsort(-88, -5, 5), new for_integer_rsort(0.001, 99.5, 0.1)); + // array of string objects + $unsorted_str_obj = array(new for_string_rsort("axx", "AXX", "ass"), new for_string_rsort("t", "eee", "abb"), new for_string_rsort("w", "W", "c"), new for_string_rsort("py", "PY", "pt")); + echo "\n-- Sort flag = default --\n"; + // testing rsort() function by supplying integer object array, flag value is default + $temp_array = $unsorted_int_obj; + var_dump(rsort($temp_array)); + var_dump($temp_array); + // testing rsort() function by supplying string object array, flag value is default + $temp_array = $unsorted_str_obj; + var_dump(rsort($temp_array)); + var_dump($temp_array); + echo "\n-- Sort flag = SORT_REGULAR --\n"; + // testing rsort() function by supplying integer object array, flag value = SORT_REGULAR + $temp_array = $unsorted_int_obj; + var_dump(rsort($temp_array, SORT_REGULAR)); + var_dump($temp_array); + // testing rsort() function by supplying string object array, flag value = SORT_REGULAR + $temp_array = $unsorted_str_obj; + var_dump(rsort($temp_array, SORT_REGULAR)); + var_dump($temp_array); + echo "Done"; +} +?> +--EXPECTF-- +*** Testing rsort() : object functionality *** + +-- Sort flag = default -- +bool(true) +array(4) { + [0]=> + object(for_integer_rsort)#%d (3) { + ["public_class_value"]=> + int(66) + ["private_class_value":"for_integer_rsort":private]=> + int(44) + ["protected_class_value":protected]=> + int(4) + } + [1]=> + object(for_integer_rsort)#%d (3) { + ["public_class_value"]=> + int(11) + ["private_class_value":"for_integer_rsort":private]=> + int(33) + ["protected_class_value":protected]=> + int(30) + } + [2]=> + object(for_integer_rsort)#%d (3) { + ["public_class_value"]=> + float(0.001) + ["private_class_value":"for_integer_rsort":private]=> + float(99.5) + ["protected_class_value":protected]=> + float(0.1) + } + [3]=> + object(for_integer_rsort)#%d (3) { + ["public_class_value"]=> + int(-88) + ["private_class_value":"for_integer_rsort":private]=> + int(-5) + ["protected_class_value":protected]=> + int(5) + } +} +bool(true) +array(4) { + [0]=> + object(for_string_rsort)#%d (3) { + ["public_class_value"]=> + string(1) "w" + ["private_class_value":"for_string_rsort":private]=> + string(1) "W" + ["protected_class_value":protected]=> + string(1) "c" + } + [1]=> + object(for_string_rsort)#%d (3) { + ["public_class_value"]=> + string(1) "t" + ["private_class_value":"for_string_rsort":private]=> + string(3) "eee" + ["protected_class_value":protected]=> + string(3) "abb" + } + [2]=> + object(for_string_rsort)#%d (3) { + ["public_class_value"]=> + string(2) "py" + ["private_class_value":"for_string_rsort":private]=> + string(2) "PY" + ["protected_class_value":protected]=> + string(2) "pt" + } + [3]=> + object(for_string_rsort)#%d (3) { + ["public_class_value"]=> + string(3) "axx" + ["private_class_value":"for_string_rsort":private]=> + string(3) "AXX" + ["protected_class_value":protected]=> + string(3) "ass" + } +} + +-- Sort flag = SORT_REGULAR -- +bool(true) +array(4) { + [0]=> + object(for_integer_rsort)#%d (3) { + ["public_class_value"]=> + int(66) + ["private_class_value":"for_integer_rsort":private]=> + int(44) + ["protected_class_value":protected]=> + int(4) + } + [1]=> + object(for_integer_rsort)#%d (3) { + ["public_class_value"]=> + int(11) + ["private_class_value":"for_integer_rsort":private]=> + int(33) + ["protected_class_value":protected]=> + int(30) + } + [2]=> + object(for_integer_rsort)#%d (3) { + ["public_class_value"]=> + float(0.001) + ["private_class_value":"for_integer_rsort":private]=> + float(99.5) + ["protected_class_value":protected]=> + float(0.1) + } + [3]=> + object(for_integer_rsort)#%d (3) { + ["public_class_value"]=> + int(-88) + ["private_class_value":"for_integer_rsort":private]=> + int(-5) + ["protected_class_value":protected]=> + int(5) + } +} +bool(true) +array(4) { + [0]=> + object(for_string_rsort)#%d (3) { + ["public_class_value"]=> + string(1) "w" + ["private_class_value":"for_string_rsort":private]=> + string(1) "W" + ["protected_class_value":protected]=> + string(1) "c" + } + [1]=> + object(for_string_rsort)#%d (3) { + ["public_class_value"]=> + string(1) "t" + ["private_class_value":"for_string_rsort":private]=> + string(3) "eee" + ["protected_class_value":protected]=> + string(3) "abb" + } + [2]=> + object(for_string_rsort)#%d (3) { + ["public_class_value"]=> + string(2) "py" + ["private_class_value":"for_string_rsort":private]=> + string(2) "PY" + ["protected_class_value":protected]=> + string(2) "pt" + } + [3]=> + object(for_string_rsort)#%d (3) { + ["public_class_value"]=> + string(3) "axx" + ["private_class_value":"for_string_rsort":private]=> + string(3) "AXX" + ["protected_class_value":protected]=> + string(3) "ass" + } +} +Done diff --git a/tests/std/array/rsort_variation10.phpt b/tests/std/array/rsort_variation10.phpt new file mode 100644 index 00000000..6f9248c1 --- /dev/null +++ b/tests/std/array/rsort_variation10.phpt @@ -0,0 +1,102 @@ +--TEST-- +Test rsort() function : usage variations - Octal values +--FILE-- + +--EXPECT-- +*** Testing rsort() : variation *** + +-- Sort flag = default -- +bool(true) +array(9) { + [0]=> + int(669) + [1]=> + int(506) + [2]=> + int(229) + [3]=> + int(209) + [4]=> + int(63) + [5]=> + int(54) + [6]=> + int(0) + [7]=> + int(-54) + [8]=> + int(-229) +} + +-- Sort flag = SORT_REGULAR -- +bool(true) +array(9) { + [0]=> + int(669) + [1]=> + int(506) + [2]=> + int(229) + [3]=> + int(209) + [4]=> + int(63) + [5]=> + int(54) + [6]=> + int(0) + [7]=> + int(-54) + [8]=> + int(-229) +} + +-- Sort flag = SORT_NUMERIC -- +bool(true) +array(9) { + [0]=> + int(669) + [1]=> + int(506) + [2]=> + int(229) + [3]=> + int(209) + [4]=> + int(63) + [5]=> + int(54) + [6]=> + int(0) + [7]=> + int(-54) + [8]=> + int(-229) +} +Done diff --git a/tests/std/array/rsort_variation11.phpt b/tests/std/array/rsort_variation11.phpt new file mode 100644 index 00000000..fe91f79e --- /dev/null +++ b/tests/std/array/rsort_variation11.phpt @@ -0,0 +1,187 @@ +--TEST-- +Test rsort() function : usage variations - mixed array +--FILE-- + +--EXPECTF-- +*** Testing rsort() : variation *** + +-- Sort flag = default -- +bool(true) +array(22) { + [0]=> + array(4) { + [0]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } + [1]=> + array(1) { + [0]=> + int(11) + } + [2]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + [3]=> + array(0) { + } + } + [1]=> + array(0) { + } + [2]=> + string(1) "b" + [3]=> + string(14) "abcd%0abcd%0abcd" + [4]=> + string(4) "abcd" + [5]=> + string(2) "ab" + [6]=> + string(4) "True" + [7]=> + string(1) "5" + [8]=> + string(1) "4" + [9]=> + float(4) + [10]=> + string(3) "-.9" + [11]=> + int(-2) + [12]=> + float(-2) + [13]=> + float(-2.98989) + [14]=> + bool(true) + [15]=> + string(0) "" + [16]=> + NULL + [17]=> + float(0) + [18]=> + int(0) + [19]=> + int(-4) + [20]=> + string(0) "" + [21]=> + bool(false) +} + +-- Sort flag = SORT_REGULAR -- +bool(true) +array(22) { + [0]=> + array(4) { + [0]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } + [1]=> + array(1) { + [0]=> + int(11) + } + [2]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + [3]=> + array(0) { + } + } + [1]=> + array(0) { + } + [2]=> + string(1) "b" + [3]=> + string(14) "abcd%0abcd%0abcd" + [4]=> + string(4) "abcd" + [5]=> + string(2) "ab" + [6]=> + string(4) "True" + [7]=> + string(1) "5" + [8]=> + string(1) "4" + [9]=> + float(4) + [10]=> + string(3) "-.9" + [11]=> + int(-2) + [12]=> + float(-2) + [13]=> + float(-2.98989) + [14]=> + bool(true) + [15]=> + string(0) "" + [16]=> + NULL + [17]=> + float(0) + [18]=> + int(0) + [19]=> + int(-4) + [20]=> + string(0) "" + [21]=> + bool(false) +} +Done diff --git a/tests/std/array/rsort_variation3.phpt b/tests/std/array/rsort_variation3.phpt new file mode 100644 index 00000000..f2648f04 --- /dev/null +++ b/tests/std/array/rsort_variation3.phpt @@ -0,0 +1,319 @@ +--TEST-- +Test rsort() function : usage variations - numeric values +--SKIPIF-- + +--FILE-- + SORT_REGULAR, "SORT_NUMERIC" => SORT_NUMERIC); + +$count = 1; + +// loop through to test rsort() with different arrays +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With Default sort flag -\n"; + $temp_array = $array; + var_dump(rsort($temp_array) ); + var_dump($temp_array); + + // loop through $flag_value array and setting all possible flag values + foreach($flag_value as $key => $flag){ + echo "- Sort flag = $key -\n"; + $temp_array = $array; + var_dump(rsort($temp_array, $flag) ); + var_dump($temp_array); + } + $count++; +} + +echo "Done"; +?> +--EXPECT-- +*** Testing rsort() : variation *** + +-- Iteration 1 -- +- With Default sort flag - +bool(true) +array(9) { + [0]=> + int(41) + [1]=> + int(31) + [2]=> + int(21) + [3]=> + int(11) + [4]=> + int(0) + [5]=> + int(-11) + [6]=> + int(-21) + [7]=> + int(-31) + [8]=> + int(-41) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(9) { + [0]=> + int(41) + [1]=> + int(31) + [2]=> + int(21) + [3]=> + int(11) + [4]=> + int(0) + [5]=> + int(-11) + [6]=> + int(-21) + [7]=> + int(-31) + [8]=> + int(-41) +} +- Sort flag = SORT_NUMERIC - +bool(true) +array(9) { + [0]=> + int(41) + [1]=> + int(31) + [2]=> + int(21) + [3]=> + int(11) + [4]=> + int(0) + [5]=> + int(-11) + [6]=> + int(-21) + [7]=> + int(-31) + [8]=> + int(-41) +} + +-- Iteration 2 -- +- With Default sort flag - +bool(true) +array(7) { + [0]=> + float(1050) + [1]=> + float(10.5) + [2]=> + float(0.5) + [3]=> + float(0.106) + [4]=> + float(0.01) + [5]=> + float(-0.1) + [6]=> + float(-10.5) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(7) { + [0]=> + float(1050) + [1]=> + float(10.5) + [2]=> + float(0.5) + [3]=> + float(0.106) + [4]=> + float(0.01) + [5]=> + float(-0.1) + [6]=> + float(-10.5) +} +- Sort flag = SORT_NUMERIC - +bool(true) +array(7) { + [0]=> + float(1050) + [1]=> + float(10.5) + [2]=> + float(0.5) + [3]=> + float(0.106) + [4]=> + float(0.01) + [5]=> + float(-0.1) + [6]=> + float(-10.5) +} + +-- Iteration 3 -- +- With Default sort flag - +bool(true) +array(11) { + [0]=> + int(33) + [1]=> + int(2) + [2]=> + float(0.106) + [3]=> + float(0.09) + [4]=> + float(0.0021) + [5]=> + float(0.0001) + [6]=> + int(0) + [7]=> + float(-0.01) + [8]=> + float(-0.106) + [9]=> + float(-0.9) + [10]=> + int(-1) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(11) { + [0]=> + int(33) + [1]=> + int(2) + [2]=> + float(0.106) + [3]=> + float(0.09) + [4]=> + float(0.0021) + [5]=> + float(0.0001) + [6]=> + int(0) + [7]=> + float(-0.01) + [8]=> + float(-0.106) + [9]=> + float(-0.9) + [10]=> + int(-1) +} +- Sort flag = SORT_NUMERIC - +bool(true) +array(11) { + [0]=> + int(33) + [1]=> + int(2) + [2]=> + float(0.106) + [3]=> + float(0.09) + [4]=> + float(0.0021) + [5]=> + float(0.0001) + [6]=> + int(0) + [7]=> + float(-0.01) + [8]=> + float(-0.106) + [9]=> + float(-0.9) + [10]=> + int(-1) +} + +-- Iteration 4 -- +- With Default sort flag - +bool(true) +array(7) { + [0]=> + float(2147483648) + [1]=> + int(2147483647) + [2]=> + int(0) + [3]=> + int(0) + [4]=> + int(-2147483647) + [5]=> + float(-2147483648) + [6]=> + float(-2147483649) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(7) { + [0]=> + float(2147483648) + [1]=> + int(2147483647) + [2]=> + int(0) + [3]=> + int(0) + [4]=> + int(-2147483647) + [5]=> + float(-2147483648) + [6]=> + float(-2147483649) +} +- Sort flag = SORT_NUMERIC - +bool(true) +array(7) { + [0]=> + float(2147483648) + [1]=> + int(2147483647) + [2]=> + int(0) + [3]=> + int(0) + [4]=> + int(-2147483647) + [5]=> + float(-2147483648) + [6]=> + float(-2147483649) +} +Done diff --git a/tests/std/array/rsort_variation4.phpt b/tests/std/array/rsort_variation4.phpt new file mode 100644 index 00000000..baea5484 --- /dev/null +++ b/tests/std/array/rsort_variation4.phpt @@ -0,0 +1,62 @@ +--TEST-- +Test rsort() function : usage variations - referenced variables +--SKIPIF-- + + +--FILE-- + +--EXPECT-- +*** Testing rsort() : variation *** + +-- 'flag' value is default -- +bool(true) +array(3) { + [0]=> + &int(555) + [1]=> + &int(100) + [2]=> + &int(33) +} + +-- 'flag' = SORT_REGULAR -- +bool(true) +array(3) { + [0]=> + &int(555) + [1]=> + &int(100) + [2]=> + &int(33) +} +Done diff --git a/tests/std/array/rsort_variation5.phpt b/tests/std/array/rsort_variation5.phpt new file mode 100644 index 00000000..6b05443b --- /dev/null +++ b/tests/std/array/rsort_variation5.phpt @@ -0,0 +1,215 @@ +--TEST-- +Test rsort() function : usage variations - String values +--FILE-- + SORT_REGULAR, "SORT_STRING" => SORT_STRING); + +$count = 1; +// loop through to test rsort() with different arrays +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With Default sort flag -\n"; + $temp_array = $array; + var_dump(rsort($temp_array) ); + var_dump($temp_array); + + // loop through $flags array and setting all possible flag values + foreach($flags as $key => $flag){ + echo "- Sort flag = $key -\n"; + + $temp_array = $array; + var_dump(rsort($temp_array, $flag) ); + var_dump($temp_array); + } + $count++; +} + +echo "Done"; +?> +--EXPECT-- +*** Testing rsort() : variation *** + +-- Iteration 1 -- +- With Default sort flag - +bool(true) +array(11) { + [0]=> + string(4) "\xhh" + [1]=> + string(4) "\ddd" + [2]=> + string(3) "\cx" + [3]=> + string(2) "\a" + [4]=> + string(1) "" + [5]=> + string(1) " " + [6]=> + string(1) " " + [7]=> + string(1) " +" + [8]=> + string(1) " " + [9]=> + NULL + [10]=> + NULL +} +- Sort flag = SORT_REGULAR - +bool(true) +array(11) { + [0]=> + string(4) "\xhh" + [1]=> + string(4) "\ddd" + [2]=> + string(3) "\cx" + [3]=> + string(2) "\a" + [4]=> + string(1) "" + [5]=> + string(1) " " + [6]=> + string(1) " " + [7]=> + string(1) " +" + [8]=> + string(1) " " + [9]=> + NULL + [10]=> + NULL +} +- Sort flag = SORT_STRING - +bool(true) +array(11) { + [0]=> + string(4) "\xhh" + [1]=> + string(4) "\ddd" + [2]=> + string(3) "\cx" + [3]=> + string(2) "\a" + [4]=> + string(1) "" + [5]=> + string(1) " " + [6]=> + string(1) " " + [7]=> + string(1) " +" + [8]=> + string(1) " " + [9]=> + NULL + [10]=> + NULL +} + +-- Iteration 2 -- +- With Default sort flag - +bool(true) +array(12) { + [0]=> + string(1) "x" + [1]=> + string(2) "ww" + [2]=> + string(3) "ttt" + [3]=> + string(6) "oraNGe" + [4]=> + string(5) "lemoN" + [5]=> + string(6) "banana" + [6]=> + string(5) "apple" + [7]=> + string(1) "X" + [8]=> + string(4) "Test" + [9]=> + string(4) "TTTT" + [10]=> + string(6) "Orange" + [11]=> + string(6) "BANANA" +} +- Sort flag = SORT_REGULAR - +bool(true) +array(12) { + [0]=> + string(1) "x" + [1]=> + string(2) "ww" + [2]=> + string(3) "ttt" + [3]=> + string(6) "oraNGe" + [4]=> + string(5) "lemoN" + [5]=> + string(6) "banana" + [6]=> + string(5) "apple" + [7]=> + string(1) "X" + [8]=> + string(4) "Test" + [9]=> + string(4) "TTTT" + [10]=> + string(6) "Orange" + [11]=> + string(6) "BANANA" +} +- Sort flag = SORT_STRING - +bool(true) +array(12) { + [0]=> + string(1) "x" + [1]=> + string(2) "ww" + [2]=> + string(3) "ttt" + [3]=> + string(6) "oraNGe" + [4]=> + string(5) "lemoN" + [5]=> + string(6) "banana" + [6]=> + string(5) "apple" + [7]=> + string(1) "X" + [8]=> + string(4) "Test" + [9]=> + string(4) "TTTT" + [10]=> + string(6) "Orange" + [11]=> + string(6) "BANANA" +} +Done diff --git a/tests/std/array/rsort_variation6.phpt b/tests/std/array/rsort_variation6.phpt new file mode 100644 index 00000000..3394402e --- /dev/null +++ b/tests/std/array/rsort_variation6.phpt @@ -0,0 +1,114 @@ +--TEST-- +Test rsort() function : usage variations - Hexadecimal vales +--FILE-- + +--EXPECT-- +*** Testing rsort() : variation *** + +-- 'flag' value is default -- +bool(true) +array(11) { + [0]=> + int(4095) + [1]=> + int(682) + [2]=> + int(427) + [3]=> + int(427) + [4]=> + int(255) + [5]=> + int(255) + [6]=> + int(187) + [7]=> + int(15) + [8]=> + int(0) + [9]=> + int(-255) + [10]=> + int(-682) +} + +-- 'flag' value is SORT_REGULAR -- +bool(true) +array(11) { + [0]=> + int(4095) + [1]=> + int(682) + [2]=> + int(427) + [3]=> + int(427) + [4]=> + int(255) + [5]=> + int(255) + [6]=> + int(187) + [7]=> + int(15) + [8]=> + int(0) + [9]=> + int(-255) + [10]=> + int(-682) +} + +-- 'flag' value is SORT_NUMERIC -- +bool(true) +array(11) { + [0]=> + int(4095) + [1]=> + int(682) + [2]=> + int(427) + [3]=> + int(427) + [4]=> + int(255) + [5]=> + int(255) + [6]=> + int(187) + [7]=> + int(15) + [8]=> + int(0) + [9]=> + int(-255) + [10]=> + int(-682) +} +Done diff --git a/tests/std/array/rsort_variation7.phpt b/tests/std/array/rsort_variation7.phpt new file mode 100644 index 00000000..28b02a74 --- /dev/null +++ b/tests/std/array/rsort_variation7.phpt @@ -0,0 +1,90 @@ +--TEST-- +Test rsort() function : usage variations - boolean values +--FILE-- + +--EXPECT-- +*** Testing rsort() : variation *** + +-- 'flag' value is default -- +bool(true) +array(4) { + [0]=> + bool(true) + [1]=> + bool(true) + [2]=> + bool(false) + [3]=> + bool(false) +} + +-- 'flag' value is SORT_REGULAR -- +bool(true) +array(4) { + [0]=> + bool(true) + [1]=> + bool(true) + [2]=> + bool(false) + [3]=> + bool(false) +} + +-- 'flag' value is SORT_NUMERIC -- +bool(true) +array(4) { + [0]=> + bool(true) + [1]=> + bool(true) + [2]=> + bool(false) + [3]=> + bool(false) +} + +-- 'flag' value is SORT_STRING -- +bool(true) +array(4) { + [0]=> + bool(true) + [1]=> + bool(true) + [2]=> + bool(false) + [3]=> + bool(false) +} +Done diff --git a/tests/std/array/rsort_variation8.phpt b/tests/std/array/rsort_variation8.phpt new file mode 100644 index 00000000..8d8aa15f --- /dev/null +++ b/tests/std/array/rsort_variation8.phpt @@ -0,0 +1,174 @@ +--TEST-- +Test rsort() function : usage variations - multi-dimensional arrays +--FILE-- + +--EXPECT-- +*** Testing rsort() : variation *** + +-- Iteration 1 -- + +-- 'flag' value is default -- +bool(true) +array(0) { +} + +-- 'flag' value is SORT_REGULAR -- +bool(true) +array(0) { +} + +-- Iteration 2 -- + +-- 'flag' value is default -- +bool(true) +array(1) { + [0]=> + array(0) { + } +} + +-- 'flag' value is SORT_REGULAR -- +bool(true) +array(1) { + [0]=> + array(0) { + } +} + +-- Iteration 3 -- + +-- 'flag' value is default -- +bool(true) +array(3) { + [0]=> + array(2) { + [0]=> + int(64) + [1]=> + int(61) + } + [1]=> + int(44) + [2]=> + int(11) +} + +-- 'flag' value is SORT_REGULAR -- +bool(true) +array(3) { + [0]=> + array(2) { + [0]=> + int(64) + [1]=> + int(61) + } + [1]=> + int(44) + [2]=> + int(11) +} + +-- Iteration 4 -- + +-- 'flag' value is default -- +bool(true) +array(4) { + [0]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } + [1]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + [2]=> + array(1) { + [0]=> + int(11) + } + [3]=> + array(0) { + } +} + +-- 'flag' value is SORT_REGULAR -- +bool(true) +array(4) { + [0]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } + [1]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + [2]=> + array(1) { + [0]=> + int(11) + } + [3]=> + array(0) { + } +} +Done diff --git a/tests/std/array/rsort_variation9.phpt b/tests/std/array/rsort_variation9.phpt new file mode 100644 index 00000000..f46c2270 --- /dev/null +++ b/tests/std/array/rsort_variation9.phpt @@ -0,0 +1,254 @@ +--TEST-- +Test rsort() function : usage variations - mixed associative arrays +--FILE-- + 55, 6 => 66, 2 => 22, 3 => 33, 1 => 11), + + // two-dimensional assoc. and default key array + array("fruits" => array("a" => "orange", "b" => "banana", "c" => "apple"), + "numbers" => array(1, 2, 3, 4, 5, 6), + "holes" => array("first", 5 => "second", "third")), + + // numeric assoc. and default key array + array(1, 1, 8 => 1, 4 => 1, 19, 3 => 13), + + // mixed assoc. array + array('bar' => 'baz', "foo" => 1), + + // assoc. only multi-dimensional array + array('a' => 1,'b' => array('e' => 2,'f' => 3),'c' => array('g' => 4),'d' => 5), +); + +$count = 1; + +// loop through to test rsort() with different arrays, +// to test the new keys for the elements in the sorted array +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "-- Sort flag = default --\n"; + $temp_array = $array; + var_dump(rsort($temp_array) ); + var_dump($temp_array); + + echo "-- Sort flag = SORT_REGULAR --\n"; + $temp_array = $array; + var_dump(rsort($temp_array, SORT_REGULAR) ); + var_dump($temp_array); + $count++; +} + +echo "Done"; +?> +--EXPECT-- +*** Testing rsort() : variation *** + +-- Iteration 1 -- +-- Sort flag = default -- +bool(true) +array(5) { + [0]=> + int(66) + [1]=> + int(55) + [2]=> + int(33) + [3]=> + int(22) + [4]=> + int(11) +} +-- Sort flag = SORT_REGULAR -- +bool(true) +array(5) { + [0]=> + int(66) + [1]=> + int(55) + [2]=> + int(33) + [3]=> + int(22) + [4]=> + int(11) +} + +-- Iteration 2 -- +-- Sort flag = default -- +bool(true) +array(3) { + [0]=> + array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + } + [1]=> + array(3) { + ["a"]=> + string(6) "orange" + ["b"]=> + string(6) "banana" + ["c"]=> + string(5) "apple" + } + [2]=> + array(3) { + [0]=> + string(5) "first" + [5]=> + string(6) "second" + [6]=> + string(5) "third" + } +} +-- Sort flag = SORT_REGULAR -- +bool(true) +array(3) { + [0]=> + array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + } + [1]=> + array(3) { + ["a"]=> + string(6) "orange" + ["b"]=> + string(6) "banana" + ["c"]=> + string(5) "apple" + } + [2]=> + array(3) { + [0]=> + string(5) "first" + [5]=> + string(6) "second" + [6]=> + string(5) "third" + } +} + +-- Iteration 3 -- +-- Sort flag = default -- +bool(true) +array(6) { + [0]=> + int(19) + [1]=> + int(13) + [2]=> + int(1) + [3]=> + int(1) + [4]=> + int(1) + [5]=> + int(1) +} +-- Sort flag = SORT_REGULAR -- +bool(true) +array(6) { + [0]=> + int(19) + [1]=> + int(13) + [2]=> + int(1) + [3]=> + int(1) + [4]=> + int(1) + [5]=> + int(1) +} + +-- Iteration 4 -- +-- Sort flag = default -- +bool(true) +array(2) { + [0]=> + string(3) "baz" + [1]=> + int(1) +} +-- Sort flag = SORT_REGULAR -- +bool(true) +array(2) { + [0]=> + string(3) "baz" + [1]=> + int(1) +} + +-- Iteration 5 -- +-- Sort flag = default -- +bool(true) +array(4) { + [0]=> + array(2) { + ["e"]=> + int(2) + ["f"]=> + int(3) + } + [1]=> + array(1) { + ["g"]=> + int(4) + } + [2]=> + int(5) + [3]=> + int(1) +} +-- Sort flag = SORT_REGULAR -- +bool(true) +array(4) { + [0]=> + array(2) { + ["e"]=> + int(2) + ["f"]=> + int(3) + } + [1]=> + array(1) { + ["g"]=> + int(4) + } + [2]=> + int(5) + [3]=> + int(1) +} +Done diff --git a/tests/std/array/shuffle_basic1.phpt b/tests/std/array/shuffle_basic1.phpt new file mode 100644 index 00000000..d2af45db --- /dev/null +++ b/tests/std/array/shuffle_basic1.phpt @@ -0,0 +1,144 @@ +--TEST-- +Test shuffle() function : basic functionality - array with default keys +--FILE-- + +--EXPECTF-- +*** Testing shuffle() : with arrays having default keys *** + +-- input array of integers before shuffle() function is applied -- +array(9) { + [0]=> + int(0) + [1]=> + int(10) + [2]=> + int(20) + [3]=> + int(30) + [4]=> + int(40) + [5]=> + int(50) + [6]=> + int(60) + [7]=> + int(70) + [8]=> + int(80) +} + +-- return value from shuffle() function -- +bool(true) + +-- resultant array after shuffle() function is applied -- +array(9) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + [3]=> + int(%d) + [4]=> + int(%d) + [5]=> + int(%d) + [6]=> + int(%d) + [7]=> + int(%d) + [8]=> + int(%d) +} + +-- input array of strings before shuffle() function is applied -- +array(9) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + [2]=> + string(5) "three" + [3]=> + string(4) "four" + [4]=> + string(4) "five" + [5]=> + string(1) " " + [6]=> + string(3) "six" + [7]=> + string(1) " " + [8]=> + string(5) "seven" +} + +-- return value from shuffle() function -- +bool(true) + +-- resultant array after shuffle() function is applied -- +array(9) { + [0]=> + string(%d) "%s" + [1]=> + string(%d) "%s" + [2]=> + string(%d) "%s" + [3]=> + string(%d) "%s" + [4]=> + string(%d) "%s" + [5]=> + string(%d) "%s" + [6]=> + string(%d) "%s" + [7]=> + string(%d) "%s" + [8]=> + string(%d) "%s" +} +Done diff --git a/tests/std/array/shuffle_basic2.phpt b/tests/std/array/shuffle_basic2.phpt new file mode 100644 index 00000000..b6c86cb4 --- /dev/null +++ b/tests/std/array/shuffle_basic2.phpt @@ -0,0 +1,83 @@ +--TEST-- +Test shuffle() function : basic functionality - with associative array +--FILE-- + 1, 2 => 02, 'three' => 3, + 4 => 4, '#5' => 5, 'SIX' => 6, + "seven" => 0x7, "#8" => 012, "nine" => 9 +); + +// printing the input array before the shuffle operation +echo "\n-- input array before shuffle() function is applied --\n"; +var_dump( $array_arg ); + +// applying shuffle() function on the input array +echo "\n-- return value from shuffle() function --\n"; +var_dump( shuffle($array_arg) ); // prints the return value from shuffle() function + +echo "\n-- resultant array after shuffle() function is applied --\n"; +var_dump( $array_arg ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing shuffle() : with associative array *** + +-- input array before shuffle() function is applied -- +array(9) { + ["one"]=> + int(1) + [2]=> + int(2) + ["three"]=> + int(3) + [4]=> + int(4) + ["#5"]=> + int(5) + ["SIX"]=> + int(6) + ["seven"]=> + int(7) + ["#8"]=> + int(10) + ["nine"]=> + int(9) +} + +-- return value from shuffle() function -- +bool(true) + +-- resultant array after shuffle() function is applied -- +array(9) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + [3]=> + int(%d) + [4]=> + int(%d) + [5]=> + int(%d) + [6]=> + int(%d) + [7]=> + int(%d) + [8]=> + int(%d) +} +Done diff --git a/tests/std/array/shuffle_variation2.phpt b/tests/std/array/shuffle_variation2.phpt new file mode 100644 index 00000000..ab90db3f --- /dev/null +++ b/tests/std/array/shuffle_variation2.phpt @@ -0,0 +1,206 @@ +--TEST-- +Test shuffle() function : usage variation - with MultiDimensional array +--FILE-- + +--EXPECTF-- +*** Testing shuffle() : with multi-dimensional array *** +bool(true) + +The output array is: +array(7) { + [0]=> + array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + } + [1]=> + array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + } + [2]=> + array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + } + [3]=> + array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + } + [4]=> + array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + } + [5]=> + array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + } + [6]=> + array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + } +} + +*** Testing shuffle() with arrays having different types of values *** + +-- Iteration 1 -- +bool(true) + +The output array is: +array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) +} + +-- Iteration 2 -- +bool(true) + +The output array is: +array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) +} + +-- Iteration 3 -- +bool(true) + +The output array is: +array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) +} + +-- Iteration 4 -- +bool(true) + +The output array is: +array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) +} + +-- Iteration 5 -- +bool(true) + +The output array is: +array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) +} + +-- Iteration 6 -- +bool(true) + +The output array is: +array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) +} + +-- Iteration 7 -- +bool(true) + +The output array is: +array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) +} +Done diff --git a/tests/std/array/shuffle_variation3.phpt b/tests/std/array/shuffle_variation3.phpt new file mode 100644 index 00000000..87abe349 --- /dev/null +++ b/tests/std/array/shuffle_variation3.phpt @@ -0,0 +1,227 @@ +--TEST-- +Test shuffle() function : usage variation - arrays with diff types of values +--FILE-- + +--EXPECTF-- +*** Testing shuffle() : arrays with diff types of values *** + +*** Testing shuffle() with arrays having different types of values *** + +-- Iteration 1 -- +bool(true) + +The output array is: +array(4) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + [3]=> + int(%d) +} + +-- Iteration 2 -- +bool(true) + +The output array is: +array(3) { + [0]=> + int(-%d) + [1]=> + int(-%d) + [2]=> + int(-%d) +} + +-- Iteration 3 -- +bool(true) + +The output array is: +array(7) { + [0]=> + float(%f) + [1]=> + float(%f) + [2]=> + float(%f) + [3]=> + float(%f) + [4]=> + float(%f) + [5]=> + float(%f) + [6]=> + float(%f) +} + +-- Iteration 4 -- +bool(true) + +The output array is: +array(6) { + [0]=> + float(-%f) + [1]=> + float(-%f) + [2]=> + float(-%f) + [3]=> + float(-%f) + [4]=> + float(-%f) + [5]=> + float(-%f) +} + +-- Iteration 5 -- +bool(true) + +The output array is: +array(5) { + [0]=> + string(%d) "%s" + [1]=> + string(%d) "%s" + [2]=> + string(%d) "%s" + [3]=> + string(%d) "%s" + [4]=> + string(%d) "%s" +} + +-- Iteration 6 -- +bool(true) + +The output array is: +array(4) { + [0]=> + bool(%s) + [1]=> + bool(%s) + [2]=> + bool(%s) + [3]=> + bool(%s) +} + +-- Iteration 7 -- +bool(true) + +The output array is: +array(6) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + [3]=> + int(%d) + [4]=> + int(%d) + [5]=> + int(%d) +} + +-- Iteration 8 -- +bool(true) + +The output array is: +array(5) { + [0]=> + int(-%d) + [1]=> + int(-%d) + [2]=> + int(-%d) + [3]=> + int(-%d) + [4]=> + int(-%d) +} + +-- Iteration 9 -- +bool(true) + +The output array is: +array(4) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + [3]=> + int(%d) +} + +-- Iteration 10 -- +bool(true) + +The output array is: +array(3) { + [0]=> + int(-%d) + [1]=> + int(-%d) + [2]=> + int(-%d) +} +Done diff --git a/tests/std/array/shuffle_variation4.phpt b/tests/std/array/shuffle_variation4.phpt new file mode 100644 index 00000000..1d3269e7 --- /dev/null +++ b/tests/std/array/shuffle_variation4.phpt @@ -0,0 +1,225 @@ +--TEST-- +Test shuffle() function : usage variation - associative arrays with diff types of values +--FILE-- + 0, 1 => 1, "two" => 2, "max_int" => 2147483647 ), + + // array with negative int values + array("minus_one" => -1, 'minus_two' => -2, "min_int" => -2147483647 ), + + // array with positive float values +/*3*/ array("float1" => 0.23, 'float2' => 1.34, "exp1" => 0e2, 'exp2' => 200e-2, "exp3" => 10e0), + + // array with negative float values + array(-0 => -0.23, -1 => -1.34, -200 => -200e-2, -30 => -30e0, -2147473649.80), + + // array with single and double quoted strings +/*5*/ array('1' => 'one', "str1" => "123numbers", '' => 'hello\tworld', "" => "hello world\0", "12.34floatnum"), + + // array with bool values + array('1' => TRUE, "1" => TRUE, "0" => FALSE, '0' => FALSE), + + // array with positive hexa values +/*7*/ array("hex1" => 0x123, 'hex2' => 0xabc, "hex\t3" => 0xABC, "hex\04" => 0xAb1), + + // array with negative hexa values + array(NULL => -0x123, "NULL" => -0xabc, "-ABC" => -0xABC, -0xAB1 => -0xAb1), + + // array with positive octal values +/*9*/ array(0123 => 0123, "0234" => 0234, '034' => 034, 00 => 00), + + // array with negative octal values + array(-0123 => -0123, "-0234" => -0234, '-034' => -034), + + // array with null values +/*11*/ array(NULL => NULL, "null" => NULL, "NULL" => NULL) + +); + +// looping to test shuffle() with each sub-array in the $array_arg array +echo "\n*** Testing shuffle() with arrays having different types of values ***\n"; +$counter = 1; +foreach($array_arg as $arr) { + echo "\n-- Iteration $counter --\n"; + var_dump( shuffle($arr) ); + echo "\nThe output array is:\n"; + var_dump( $arr ); + $counter++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing shuffle() : associative arrays with diff types of values *** + +*** Testing shuffle() with arrays having different types of values *** + +-- Iteration 1 -- +bool(true) + +The output array is: +array(4) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + [3]=> + int(%d) +} + +-- Iteration 2 -- +bool(true) + +The output array is: +array(3) { + [0]=> + int(-%d) + [1]=> + int(-%d) + [2]=> + int(-%d) +} + +-- Iteration 3 -- +bool(true) + +The output array is: +array(5) { + [0]=> + float(%f) + [1]=> + float(%f) + [2]=> + float(%f) + [3]=> + float(%f) + [4]=> + float(%f) +} + +-- Iteration 4 -- +bool(true) + +The output array is: +array(5) { + [0]=> + float(-%f) + [1]=> + float(-%f) + [2]=> + float(-%f) + [3]=> + float(-%f) + [4]=> + float(-%f) +} + +-- Iteration 5 -- +bool(true) + +The output array is: +array(4) { + [0]=> + string(%d) "%s" + [1]=> + string(%d) "%s" + [2]=> + string(%d) "%s" + [3]=> + string(%d) "%s" +} + +-- Iteration 6 -- +bool(true) + +The output array is: +array(2) { + [0]=> + bool(%s) + [1]=> + bool(%s) +} + +-- Iteration 7 -- +bool(true) + +The output array is: +array(4) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + [3]=> + int(%d) +} + +-- Iteration 8 -- +bool(true) + +The output array is: +array(4) { + [0]=> + int(-%d) + [1]=> + int(-%d) + [2]=> + int(-%d) + [3]=> + int(-%d) +} + +-- Iteration 9 -- +bool(true) + +The output array is: +array(4) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + [3]=> + int(%d) +} + +-- Iteration 10 -- +bool(true) + +The output array is: +array(3) { + [0]=> + int(-%d) + [1]=> + int(-%d) + [2]=> + int(-%d) +} + +-- Iteration 11 -- +bool(true) + +The output array is: +array(3) { + [0]=> + NULL + [1]=> + NULL + [2]=> + NULL +} +Done diff --git a/tests/std/array/shuffle_variation5.phpt b/tests/std/array/shuffle_variation5.phpt new file mode 100644 index 00000000..7ad0c016 --- /dev/null +++ b/tests/std/array/shuffle_variation5.phpt @@ -0,0 +1,114 @@ +--TEST-- +Test shuffle() function : usage variation - arrays with diff heredoc strings +--FILE-- + "heredoc1", + $heredoc_with_newline => "heredoc2", + $heredoc_with_characters => "heredoc3", + $heredoc_with_newline_and_tabs => "heredoc3", + $heredoc_with_alphanumerics => "heredoc4", + $heredoc_with_embedded_nulls => "heredoc5" +); + +// test shuffle() with array containing heredoc strings as values +echo "\n-- with array of heredoc strings --\n"; +var_dump( shuffle($heredoc_array) ); +echo "\nThe output array is:\n"; +var_dump( $heredoc_array ); + +// test shuffle() with array containing heredoc strings as its keys +echo "\n-- with array having heredoc strings as keys --\n"; +var_dump( shuffle($heredoc_asso_array) ); +echo "\nThe output array is:\n"; +var_dump( $heredoc_asso_array ); + +echo "Done"; +?> +--EXPECTREGEX-- +\*\*\* Testing shuffle\(\) : with array containing heredoc strings \*\*\* + +-- with array of heredoc strings -- +bool\(true\) + +The output array is: +array\(6\) { + \[0\]=> + string\([0-9]*\) "[0-9 a-z \n \0 \t]*" + \[1\]=> + string\([0-9]*\) "[0-9 a-z \n \0 \t]*" + \[2\]=> + string\([0-9]*\) "[0-9 a-z \n \0 \t]*" + \[3\]=> + string\([0-9]*\) "[0-9 a-z \n \0 \t]*" + \[4\]=> + string\([0-9]*\) "[0-9 a-z \n \0 \t]*" + \[5\]=> + string\([0-9]*\) "[0-9 a-z \n \0 \t]*" +} + +-- with array having heredoc strings as keys -- +bool\(true\) + +The output array is: +array\(6\) { + \[0\]=> + string\(8\) "[heredoc 1-5]*" + \[1\]=> + string\(8\) "[heredoc 1-5]*" + \[2\]=> + string\(8\) "[heredoc 1-5]*" + \[3\]=> + string\(8\) "[heredoc 1-5]*" + \[4\]=> + string\(8\) "[heredoc 1-5]*" + \[5\]=> + string\(8\) "[heredoc 1-5]*" +} +Done diff --git a/tests/std/array/sizeof_basic2.phpt b/tests/std/array/sizeof_basic2.phpt new file mode 100644 index 00000000..e77a0d6a --- /dev/null +++ b/tests/std/array/sizeof_basic2.phpt @@ -0,0 +1,92 @@ +--TEST-- +Test sizeof() function : basic functionality - for non-scalar type(array) +--FILE-- + "Saffron", "Peace" => "White", "Growth" => "Green"); +$mixed_array = array(1, 2, "Aggression" => "Saffron", 10 => "Ten", "Ten" => 10); + +echo "-- Testing sizeof() with integer array in default, COUNT_NORMAL, COUNT_RECURSIVE modes --\n"; +echo "default mode: "; +var_dump( sizeof($int_array) ); +echo "\n"; +echo "COUNT_NORMAL mode: "; +var_dump( sizeof($int_array, COUNT_NORMAL) ); +echo "\n"; +echo "COUNT_RECURSIVE mode: "; +var_dump( sizeof($int_array, COUNT_RECURSIVE) ); +echo "\n"; + +echo "-- Testing sizeof() with string array in default, COUNT_NORMAL, COUNT_RECURSIVE modes --\n"; +echo "default mode: "; +var_dump( sizeof($string_array) ); +echo "\n"; +echo "COUNT_NORMAL mode: "; +var_dump( sizeof($string_array, COUNT_NORMAL) ); +echo "\n"; +echo "COUNT_RECURSIVE mode: "; +var_dump( sizeof($string_array, COUNT_RECURSIVE) ); +echo "\n"; + +echo "-- Testing sizeof() with indexed array in default, COUNT_NORMAL, COUNT_RECURSIVE modes --\n"; +echo "default mode: "; +var_dump( sizeof($indexed_array) ); +echo "\n"; +echo "COUNT_NORMAL mode: "; +var_dump( sizeof($indexed_array, COUNT_NORMAL) ); +echo "\n"; +echo "COUNT_RECURSIVE mode: "; +var_dump( sizeof($indexed_array, COUNT_RECURSIVE) ); +echo "\n"; + +echo "-- Testing sizeof() with mixed array in default, COUNT_NORMAL, COUNT_RECURSIVE modes --\n"; +echo "default mode: "; +var_dump( sizeof($mixed_array) ); +echo "\n"; +echo "COUNT_NORMAL mode: "; +var_dump( sizeof($mixed_array, COUNT_NORMAL) ); +echo "\n"; +echo "COUNT_RECURSIVE mode: "; +var_dump( sizeof($mixed_array, COUNT_RECURSIVE) ); + +echo "Done"; +?> +--EXPECT-- +*** Testing sizeof() : basic functionality *** +-- Testing sizeof() with integer array in default, COUNT_NORMAL, COUNT_RECURSIVE modes -- +default mode: int(4) + +COUNT_NORMAL mode: int(4) + +COUNT_RECURSIVE mode: int(4) + +-- Testing sizeof() with string array in default, COUNT_NORMAL, COUNT_RECURSIVE modes -- +default mode: int(3) + +COUNT_NORMAL mode: int(3) + +COUNT_RECURSIVE mode: int(3) + +-- Testing sizeof() with indexed array in default, COUNT_NORMAL, COUNT_RECURSIVE modes -- +default mode: int(3) + +COUNT_NORMAL mode: int(3) + +COUNT_RECURSIVE mode: int(3) + +-- Testing sizeof() with mixed array in default, COUNT_NORMAL, COUNT_RECURSIVE modes -- +default mode: int(5) + +COUNT_NORMAL mode: int(5) + +COUNT_RECURSIVE mode: int(5) +Done diff --git a/tests/std/array/sizeof_object1.phpt b/tests/std/array/sizeof_object1.phpt new file mode 100644 index 00000000..681f28f3 --- /dev/null +++ b/tests/std/array/sizeof_object1.phpt @@ -0,0 +1,39 @@ +--TEST-- +Test sizeof() function : object functionality - object with Countable interface +--FILE-- + +--EXPECT-- +*** Testing sizeof() : object functionality *** +-- Testing sizeof() with an object which implements Countable interface -- +-- Testing sizeof() in default mode -- +int(3) +-- Testing sizeof() in COUNT_NORMAL mode -- +int(3) +-- Testing sizeof() in COUNT_RECURSIVE mode -- +int(3) +Done diff --git a/tests/std/array/sizeof_object2.phpt b/tests/std/array/sizeof_object2.phpt new file mode 100644 index 00000000..675ebcab --- /dev/null +++ b/tests/std/array/sizeof_object2.phpt @@ -0,0 +1,112 @@ +--TEST-- +Test sizeof() function : object functionality - objects without Countable interface +--FILE-- +getMessage() . \PHP_EOL; + } + echo "COUNT_NORMAL Mode: "; + try { + var_dump(sizeof($var, COUNT_NORMAL)); + } catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; + } + echo "COUNT_RECURSIVE Mode: "; + try { + var_dump(sizeof($var, COUNT_RECURSIVE)); + } catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; + } + $counter++; + } + echo "Done"; +} +?> +--EXPECT-- +*** Testing sizeof() : object functionality *** +--- Testing sizeof() with objects which doesn't implement Countable interface --- +-- Iteration 1 -- +Default Mode: sizeof(): Argument #1 ($value) must be of type Countable|array, test given +COUNT_NORMAL Mode: sizeof(): Argument #1 ($value) must be of type Countable|array, test given +COUNT_RECURSIVE Mode: sizeof(): Argument #1 ($value) must be of type Countable|array, test given +-- Iteration 2 -- +Default Mode: sizeof(): Argument #1 ($value) must be of type Countable|array, test1 given +COUNT_NORMAL Mode: sizeof(): Argument #1 ($value) must be of type Countable|array, test1 given +COUNT_RECURSIVE Mode: sizeof(): Argument #1 ($value) must be of type Countable|array, test1 given +-- Iteration 3 -- +Default Mode: sizeof(): Argument #1 ($value) must be of type Countable|array, test2 given +COUNT_NORMAL Mode: sizeof(): Argument #1 ($value) must be of type Countable|array, test2 given +COUNT_RECURSIVE Mode: sizeof(): Argument #1 ($value) must be of type Countable|array, test2 given +-- Iteration 4 -- +Default Mode: sizeof(): Argument #1 ($value) must be of type Countable|array, child_test2 given +COUNT_NORMAL Mode: sizeof(): Argument #1 ($value) must be of type Countable|array, child_test2 given +COUNT_RECURSIVE Mode: sizeof(): Argument #1 ($value) must be of type Countable|array, child_test2 given +-- Iteration 5 -- +Default Mode: sizeof(): Argument #1 ($value) must be of type Countable|array, concrete_class given +COUNT_NORMAL Mode: sizeof(): Argument #1 ($value) must be of type Countable|array, concrete_class given +COUNT_RECURSIVE Mode: sizeof(): Argument #1 ($value) must be of type Countable|array, concrete_class given +Done diff --git a/tests/std/array/sizeof_variation2.phpt b/tests/std/array/sizeof_variation2.phpt new file mode 100644 index 00000000..baa917a2 --- /dev/null +++ b/tests/std/array/sizeof_variation2.phpt @@ -0,0 +1,156 @@ +--TEST-- +Test sizeof() function : usage variations - different array values for 'var' argument +--FILE-- + $fp), + array(1, array(3, 4, array(6, array(8)))), + array("a" => 1, 'b' => 2, array( "c" =>3, array( "d" => 5))), + array(), + /* 5 */ array(1, 2, 3, 4), + array("Saffron", "White", "Green"), + array('saffron', 'white', 'green'), + array(1 => "Hi", 2 => "Hello" ), + array("color" => "red", "item" => "pen"), + /* 10 */ array('color' => 'red', 'item' => 'pen'), + array(TRUE => "red", FALSE => "pen" ), + array(false => 'red', true => 'pen' ), + array('color' => "red", "item" => 'pen', 1 => "Hi", "" => "Hello" ), + /* 14 */ array($fp, "resource1" => $fp, 'resource2' => $fp, array( $fp, 'type' => $fp) ) +); + +// loop through each element of the values array for 'var' argument +// check the working of sizeof() +$counter = 1; +for($i = 0; $i < count($values); $i++) +{ + echo "-- Iteration $counter --\n"; + $var = $values[$i]; + + echo "Default Mode: "; + var_dump( sizeof($var) ); + echo "\n"; + + echo "COUNT_NORMAL Mode: "; + var_dump( sizeof($var, COUNT_NORMAL) ); + echo "\n"; + + echo "COUNT_RECURSIVE Mode: "; + var_dump( sizeof($var, COUNT_RECURSIVE) ); + echo "\n"; + + $counter++; +} + +echo "Done"; +?> +--EXPECT-- +*** Testing sizeof() : usage variations *** +--- Testing sizeof() with different array values for 'var' argument --- +-- Iteration 1 -- +Default Mode: int(2) + +COUNT_NORMAL Mode: int(2) + +COUNT_RECURSIVE Mode: int(2) + +-- Iteration 2 -- +Default Mode: int(2) + +COUNT_NORMAL Mode: int(2) + +COUNT_RECURSIVE Mode: int(8) + +-- Iteration 3 -- +Default Mode: int(3) + +COUNT_NORMAL Mode: int(3) + +COUNT_RECURSIVE Mode: int(6) + +-- Iteration 4 -- +Default Mode: int(0) + +COUNT_NORMAL Mode: int(0) + +COUNT_RECURSIVE Mode: int(0) + +-- Iteration 5 -- +Default Mode: int(4) + +COUNT_NORMAL Mode: int(4) + +COUNT_RECURSIVE Mode: int(4) + +-- Iteration 6 -- +Default Mode: int(3) + +COUNT_NORMAL Mode: int(3) + +COUNT_RECURSIVE Mode: int(3) + +-- Iteration 7 -- +Default Mode: int(3) + +COUNT_NORMAL Mode: int(3) + +COUNT_RECURSIVE Mode: int(3) + +-- Iteration 8 -- +Default Mode: int(2) + +COUNT_NORMAL Mode: int(2) + +COUNT_RECURSIVE Mode: int(2) + +-- Iteration 9 -- +Default Mode: int(2) + +COUNT_NORMAL Mode: int(2) + +COUNT_RECURSIVE Mode: int(2) + +-- Iteration 10 -- +Default Mode: int(2) + +COUNT_NORMAL Mode: int(2) + +COUNT_RECURSIVE Mode: int(2) + +-- Iteration 11 -- +Default Mode: int(2) + +COUNT_NORMAL Mode: int(2) + +COUNT_RECURSIVE Mode: int(2) + +-- Iteration 12 -- +Default Mode: int(2) + +COUNT_NORMAL Mode: int(2) + +COUNT_RECURSIVE Mode: int(2) + +-- Iteration 13 -- +Default Mode: int(4) + +COUNT_NORMAL Mode: int(4) + +COUNT_RECURSIVE Mode: int(4) + +-- Iteration 14 -- +Default Mode: int(4) + +COUNT_NORMAL Mode: int(4) + +COUNT_RECURSIVE Mode: int(6) + +Done diff --git a/tests/std/array/sizeof_variation3.phpt b/tests/std/array/sizeof_variation3.phpt new file mode 100644 index 00000000..4b4a3d7b --- /dev/null +++ b/tests/std/array/sizeof_variation3.phpt @@ -0,0 +1,32 @@ +--TEST-- +Test sizeof() function : usage variations - checking for infinite recursion in COUNT_RECURSIVE mode +--SKIPIF-- + + +--FILE-- + +--EXPECT-- +*** Testing sizeof() : usage variations *** +-- Testing sizeof() for infinite recursion with arrays as argument in COUNT_RECURSIVE mode -- +int(13) + +int(2) +Done diff --git a/tests/std/array/sort_basic.phpt b/tests/std/array/sort_basic.phpt new file mode 100644 index 00000000..8f50c6e1 --- /dev/null +++ b/tests/std/array/sort_basic.phpt @@ -0,0 +1,240 @@ +--TEST-- +Test sort() function : basic functionality +--FILE-- + "lemon", "o" => "orange", + "O" => "Orange", "O1" => "Orange1", "o2" => "orange2", "O3" => "Orange3", "o20" => "orange20", + "b" => "banana", +); + +// array with default keys containing unsorted numeric values +$unsorted_numerics = array( 100, 33, 555, 22 ); + +echo "\n-- Testing sort() by supplying string array, 'flag' value is default --\n"; +$temp_array = $unsorted_strings; +var_dump( sort($temp_array) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing sort() by supplying numeric array, 'flag' value is default --\n"; +$temp_array = $unsorted_numerics; +var_dump( sort($temp_array) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing sort() by supplying string array, 'flag' = SORT_REGULAR --\n"; +$temp_array = $unsorted_strings; +var_dump( sort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing sort() by supplying numeric array, 'flag' = SORT_REGULAR --\n"; +$temp_array = $unsorted_numerics; +var_dump( sort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing sort() by supplying string array, 'flag' = SORT_STRING --\n"; +$temp_array = $unsorted_strings; +var_dump( sort($temp_array, SORT_STRING) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing sort() by supplying string array (case insensitive), 'flag' = SORT_STRING|SORT_FLAG_CASE --\n"; +$temp_array = $unsorted_strings; +var_dump( sort($temp_array, SORT_STRING|SORT_FLAG_CASE) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing sort() by supplying string array (natural), 'flag' = SORT_NATURAL --\n"; +$temp_array = $unsorted_strings; +var_dump( sort($temp_array, SORT_NATURAL) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing sort() by supplying string array (natural, case insensitive), 'flag' = SORT_NATURAL|SORT_FLAG_CASE --\n"; +$temp_array = $unsorted_strings; +var_dump( sort($temp_array, SORT_NATURAL|SORT_FLAG_CASE) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing sort() by supplying numeric array, 'flag' = SORT_NUMERIC --\n"; +$temp_array = $unsorted_numerics; +var_dump( sort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "Done\n"; +?> +--EXPECT-- +*** Testing sort() : basic functionality *** + +-- Testing sort() by supplying string array, 'flag' value is default -- +bool(true) +array(8) { + [0]=> + string(6) "Orange" + [1]=> + string(7) "Orange1" + [2]=> + string(7) "Orange3" + [3]=> + string(6) "banana" + [4]=> + string(5) "lemon" + [5]=> + string(6) "orange" + [6]=> + string(7) "orange2" + [7]=> + string(8) "orange20" +} + +-- Testing sort() by supplying numeric array, 'flag' value is default -- +bool(true) +array(4) { + [0]=> + int(22) + [1]=> + int(33) + [2]=> + int(100) + [3]=> + int(555) +} + +-- Testing sort() by supplying string array, 'flag' = SORT_REGULAR -- +bool(true) +array(8) { + [0]=> + string(6) "Orange" + [1]=> + string(7) "Orange1" + [2]=> + string(7) "Orange3" + [3]=> + string(6) "banana" + [4]=> + string(5) "lemon" + [5]=> + string(6) "orange" + [6]=> + string(7) "orange2" + [7]=> + string(8) "orange20" +} + +-- Testing sort() by supplying numeric array, 'flag' = SORT_REGULAR -- +bool(true) +array(4) { + [0]=> + int(22) + [1]=> + int(33) + [2]=> + int(100) + [3]=> + int(555) +} + +-- Testing sort() by supplying string array, 'flag' = SORT_STRING -- +bool(true) +array(8) { + [0]=> + string(6) "Orange" + [1]=> + string(7) "Orange1" + [2]=> + string(7) "Orange3" + [3]=> + string(6) "banana" + [4]=> + string(5) "lemon" + [5]=> + string(6) "orange" + [6]=> + string(7) "orange2" + [7]=> + string(8) "orange20" +} + +-- Testing sort() by supplying string array (case insensitive), 'flag' = SORT_STRING|SORT_FLAG_CASE -- +bool(true) +array(8) { + [0]=> + string(6) "banana" + [1]=> + string(5) "lemon" + [2]=> + string(6) "orange" + [3]=> + string(6) "Orange" + [4]=> + string(7) "Orange1" + [5]=> + string(7) "orange2" + [6]=> + string(8) "orange20" + [7]=> + string(7) "Orange3" +} + +-- Testing sort() by supplying string array (natural), 'flag' = SORT_NATURAL -- +bool(true) +array(8) { + [0]=> + string(6) "Orange" + [1]=> + string(7) "Orange1" + [2]=> + string(7) "Orange3" + [3]=> + string(6) "banana" + [4]=> + string(5) "lemon" + [5]=> + string(6) "orange" + [6]=> + string(7) "orange2" + [7]=> + string(8) "orange20" +} + +-- Testing sort() by supplying string array (natural, case insensitive), 'flag' = SORT_NATURAL|SORT_FLAG_CASE -- +bool(true) +array(8) { + [0]=> + string(6) "banana" + [1]=> + string(5) "lemon" + [2]=> + string(6) "orange" + [3]=> + string(6) "Orange" + [4]=> + string(7) "Orange1" + [5]=> + string(7) "orange2" + [6]=> + string(7) "Orange3" + [7]=> + string(8) "orange20" +} + +-- Testing sort() by supplying numeric array, 'flag' = SORT_NUMERIC -- +bool(true) +array(4) { + [0]=> + int(22) + [1]=> + int(33) + [2]=> + int(100) + [3]=> + int(555) +} +Done diff --git a/tests/std/array/sort_object1.phpt b/tests/std/array/sort_object1.phpt new file mode 100644 index 00000000..3a9f2a14 --- /dev/null +++ b/tests/std/array/sort_object1.phpt @@ -0,0 +1,218 @@ +--TEST-- +Test sort() function : object functionality - sorting objects, 'sort_flags' as default/SORT_REGULAR +--FILE-- +class_value = $value; + } +} +// class declaration for string objects +class for_string_sort +{ + public $class_value; + // initializing object member value + function __construct($value) + { + $this->class_value = $value; + } + // return string value + function __tostring(): string { + return (string) $this->value; + } +} +function main() +{ + /* + * testing sort() by providing integer/string object arrays with flag values are default, SORT_REGULAR + */ + echo "*** Testing sort() : object functionality ***\n"; + // array of integer objects + $unsorted_int_obj = array(new for_integer_sort(11), new for_integer_sort(66), new for_integer_sort(23), new for_integer_sort(-5), new for_integer_sort(0.001), new for_integer_sort(0)); + // array of string objects + $unsorted_str_obj = array(new for_string_sort("axx"), new for_string_sort("t"), new for_string_sort("w"), new for_string_sort("py"), new for_string_sort("apple"), new for_string_sort("Orange"), new for_string_sort("Lemon"), new for_string_sort("aPPle")); + echo "\n-- Testing sort() by supplying various object arrays, 'flag' value is default --\n"; + // testing sort() function by supplying integer object array, flag value is default + $temp_array = $unsorted_int_obj; + var_dump(sort($temp_array)); + var_dump($temp_array); + // testing sort() function by supplying string object array, flag value is default + $temp_array = $unsorted_str_obj; + var_dump(sort($temp_array)); + var_dump($temp_array); + echo "\n-- Testing sort() by supplying various object arrays, 'flag' value is SORT_REGULAR --\n"; + // testing sort() function by supplying integer object array, flag value = SORT_REGULAR + $temp_array = $unsorted_int_obj; + var_dump(sort($temp_array, SORT_REGULAR)); + var_dump($temp_array); + // testing sort() function by supplying string object array, flag value = SORT_REGULAR + $temp_array = $unsorted_str_obj; + var_dump(sort($temp_array, SORT_REGULAR)); + var_dump($temp_array); + echo "Done\n"; +} +?> +--EXPECTF-- +*** Testing sort() : object functionality *** + +-- Testing sort() by supplying various object arrays, 'flag' value is default -- +bool(true) +array(6) { + [0]=> + object(for_integer_sort)#%d (1) { + ["class_value"]=> + int(-5) + } + [1]=> + object(for_integer_sort)#%d (1) { + ["class_value"]=> + int(0) + } + [2]=> + object(for_integer_sort)#%d (1) { + ["class_value"]=> + float(0.001) + } + [3]=> + object(for_integer_sort)#%d (1) { + ["class_value"]=> + int(11) + } + [4]=> + object(for_integer_sort)#%d (1) { + ["class_value"]=> + int(23) + } + [5]=> + object(for_integer_sort)#%d (1) { + ["class_value"]=> + int(66) + } +} +bool(true) +array(8) { + [0]=> + object(for_string_sort)#%d (1) { + ["class_value"]=> + string(5) "Lemon" + } + [1]=> + object(for_string_sort)#%d (1) { + ["class_value"]=> + string(6) "Orange" + } + [2]=> + object(for_string_sort)#%d (1) { + ["class_value"]=> + string(5) "aPPle" + } + [3]=> + object(for_string_sort)#%d (1) { + ["class_value"]=> + string(5) "apple" + } + [4]=> + object(for_string_sort)#%d (1) { + ["class_value"]=> + string(3) "axx" + } + [5]=> + object(for_string_sort)#%d (1) { + ["class_value"]=> + string(2) "py" + } + [6]=> + object(for_string_sort)#%d (1) { + ["class_value"]=> + string(1) "t" + } + [7]=> + object(for_string_sort)#%d (1) { + ["class_value"]=> + string(1) "w" + } +} + +-- Testing sort() by supplying various object arrays, 'flag' value is SORT_REGULAR -- +bool(true) +array(6) { + [0]=> + object(for_integer_sort)#%d (1) { + ["class_value"]=> + int(-5) + } + [1]=> + object(for_integer_sort)#%d (1) { + ["class_value"]=> + int(0) + } + [2]=> + object(for_integer_sort)#%d (1) { + ["class_value"]=> + float(0.001) + } + [3]=> + object(for_integer_sort)#%d (1) { + ["class_value"]=> + int(11) + } + [4]=> + object(for_integer_sort)#%d (1) { + ["class_value"]=> + int(23) + } + [5]=> + object(for_integer_sort)#%d (1) { + ["class_value"]=> + int(66) + } +} +bool(true) +array(8) { + [0]=> + object(for_string_sort)#%d (1) { + ["class_value"]=> + string(5) "Lemon" + } + [1]=> + object(for_string_sort)#%d (1) { + ["class_value"]=> + string(6) "Orange" + } + [2]=> + object(for_string_sort)#%d (1) { + ["class_value"]=> + string(5) "aPPle" + } + [3]=> + object(for_string_sort)#%d (1) { + ["class_value"]=> + string(5) "apple" + } + [4]=> + object(for_string_sort)#%d (1) { + ["class_value"]=> + string(3) "axx" + } + [5]=> + object(for_string_sort)#%d (1) { + ["class_value"]=> + string(2) "py" + } + [6]=> + object(for_string_sort)#%d (1) { + ["class_value"]=> + string(1) "t" + } + [7]=> + object(for_string_sort)#%d (1) { + ["class_value"]=> + string(1) "w" + } +} +Done diff --git a/tests/std/array/sort_object2.phpt b/tests/std/array/sort_object2.phpt new file mode 100644 index 00000000..294078da --- /dev/null +++ b/tests/std/array/sort_object2.phpt @@ -0,0 +1,230 @@ +--TEST-- +Test sort() function : object functionality - sorting objects with diff. accessibility of member vars +--FILE-- +public_class_value = $value1; + $this->private_class_value = $value2; + $this->protected_class_value = $value3; + } +} +// class declaration for string objects +class for_string_sort +{ + public $public_class_value; + private $private_class_value; + protected $protected_class_value; + // initializing object member value + function __construct($value1, $value2, $value3) + { + $this->public_class_value = $value1; + $this->private_class_value = $value2; + $this->protected_class_value = $value3; + } + // return string value + function __tostring(): string { + return (string) $this->value; + } +} +function main() +{ + /* + * testing sort() by providing integer/string object arrays with flag values are default, SORT_REGULAR + */ + echo "*** Testing sort() : object functionality ***\n"; + // array of integer objects + $unsorted_int_obj = array(new for_integer_sort(11, 33, 30), new for_integer_sort(66, 44, 4), new for_integer_sort(-88, -5, 5), new for_integer_sort(0.001, 99.5, 0.1)); + // array of string objects + $unsorted_str_obj = array(new for_string_sort("axx", "AXX", "ass"), new for_string_sort("t", "eee", "abb"), new for_string_sort("w", "W", "c"), new for_string_sort("py", "PY", "pt")); + echo "\n-- Testing sort() by supplying various object arrays, 'flag' value is default --\n"; + // testing sort() function by supplying integer object array, flag value is default + $temp_array = $unsorted_int_obj; + var_dump(sort($temp_array)); + var_dump($temp_array); + // testing sort() function by supplying string object array, flag value is default + $temp_array = $unsorted_str_obj; + var_dump(sort($temp_array)); + var_dump($temp_array); + echo "\n-- Testing sort() by supplying various object arrays, 'flag' value is SORT_REGULAR --\n"; + // testing sort() function by supplying integer object array, flag value = SORT_REGULAR + $temp_array = $unsorted_int_obj; + var_dump(sort($temp_array, SORT_REGULAR)); + var_dump($temp_array); + // testing sort() function by supplying string object array, flag value = SORT_REGULAR + $temp_array = $unsorted_str_obj; + var_dump(sort($temp_array, SORT_REGULAR)); + var_dump($temp_array); + echo "Done\n"; +} +?> +--EXPECTF-- +*** Testing sort() : object functionality *** + +-- Testing sort() by supplying various object arrays, 'flag' value is default -- +bool(true) +array(4) { + [0]=> + object(for_integer_sort)#%d (3) { + ["public_class_value"]=> + int(-88) + ["private_class_value":"for_integer_sort":private]=> + int(-5) + ["protected_class_value":protected]=> + int(5) + } + [1]=> + object(for_integer_sort)#%d (3) { + ["public_class_value"]=> + float(0.001) + ["private_class_value":"for_integer_sort":private]=> + float(99.5) + ["protected_class_value":protected]=> + float(0.1) + } + [2]=> + object(for_integer_sort)#%d (3) { + ["public_class_value"]=> + int(11) + ["private_class_value":"for_integer_sort":private]=> + int(33) + ["protected_class_value":protected]=> + int(30) + } + [3]=> + object(for_integer_sort)#%d (3) { + ["public_class_value"]=> + int(66) + ["private_class_value":"for_integer_sort":private]=> + int(44) + ["protected_class_value":protected]=> + int(4) + } +} +bool(true) +array(4) { + [0]=> + object(for_string_sort)#%d (3) { + ["public_class_value"]=> + string(3) "axx" + ["private_class_value":"for_string_sort":private]=> + string(3) "AXX" + ["protected_class_value":protected]=> + string(3) "ass" + } + [1]=> + object(for_string_sort)#%d (3) { + ["public_class_value"]=> + string(2) "py" + ["private_class_value":"for_string_sort":private]=> + string(2) "PY" + ["protected_class_value":protected]=> + string(2) "pt" + } + [2]=> + object(for_string_sort)#%d (3) { + ["public_class_value"]=> + string(1) "t" + ["private_class_value":"for_string_sort":private]=> + string(3) "eee" + ["protected_class_value":protected]=> + string(3) "abb" + } + [3]=> + object(for_string_sort)#%d (3) { + ["public_class_value"]=> + string(1) "w" + ["private_class_value":"for_string_sort":private]=> + string(1) "W" + ["protected_class_value":protected]=> + string(1) "c" + } +} + +-- Testing sort() by supplying various object arrays, 'flag' value is SORT_REGULAR -- +bool(true) +array(4) { + [0]=> + object(for_integer_sort)#%d (3) { + ["public_class_value"]=> + int(-88) + ["private_class_value":"for_integer_sort":private]=> + int(-5) + ["protected_class_value":protected]=> + int(5) + } + [1]=> + object(for_integer_sort)#%d (3) { + ["public_class_value"]=> + float(0.001) + ["private_class_value":"for_integer_sort":private]=> + float(99.5) + ["protected_class_value":protected]=> + float(0.1) + } + [2]=> + object(for_integer_sort)#%d (3) { + ["public_class_value"]=> + int(11) + ["private_class_value":"for_integer_sort":private]=> + int(33) + ["protected_class_value":protected]=> + int(30) + } + [3]=> + object(for_integer_sort)#%d (3) { + ["public_class_value"]=> + int(66) + ["private_class_value":"for_integer_sort":private]=> + int(44) + ["protected_class_value":protected]=> + int(4) + } +} +bool(true) +array(4) { + [0]=> + object(for_string_sort)#%d (3) { + ["public_class_value"]=> + string(3) "axx" + ["private_class_value":"for_string_sort":private]=> + string(3) "AXX" + ["protected_class_value":protected]=> + string(3) "ass" + } + [1]=> + object(for_string_sort)#%d (3) { + ["public_class_value"]=> + string(2) "py" + ["private_class_value":"for_string_sort":private]=> + string(2) "PY" + ["protected_class_value":protected]=> + string(2) "pt" + } + [2]=> + object(for_string_sort)#%d (3) { + ["public_class_value"]=> + string(1) "t" + ["private_class_value":"for_string_sort":private]=> + string(3) "eee" + ["protected_class_value":protected]=> + string(3) "abb" + } + [3]=> + object(for_string_sort)#%d (3) { + ["public_class_value"]=> + string(1) "w" + ["private_class_value":"for_string_sort":private]=> + string(1) "W" + ["protected_class_value":protected]=> + string(1) "c" + } +} +Done diff --git a/tests/std/array/sort_variation10.phpt b/tests/std/array/sort_variation10.phpt new file mode 100644 index 00000000..36dfcb85 --- /dev/null +++ b/tests/std/array/sort_variation10.phpt @@ -0,0 +1,106 @@ +--TEST-- +Test sort() function : usage variations - sort octal values +--FILE-- + +--EXPECT-- +*** Testing sort() : usage variations *** + +-- Testing sort() by supplying octal value array, 'flag' value is default -- +bool(true) +array(9) { + [0]=> + int(-229) + [1]=> + int(-54) + [2]=> + int(0) + [3]=> + int(54) + [4]=> + int(63) + [5]=> + int(209) + [6]=> + int(229) + [7]=> + int(506) + [8]=> + int(669) +} + +-- Testing sort() by supplying octal value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(9) { + [0]=> + int(-229) + [1]=> + int(-54) + [2]=> + int(0) + [3]=> + int(54) + [4]=> + int(63) + [5]=> + int(209) + [6]=> + int(229) + [7]=> + int(506) + [8]=> + int(669) +} + +-- Testing sort() by supplying octal value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(9) { + [0]=> + int(-229) + [1]=> + int(-54) + [2]=> + int(0) + [3]=> + int(54) + [4]=> + int(63) + [5]=> + int(209) + [6]=> + int(229) + [7]=> + int(506) + [8]=> + int(669) +} +Done diff --git a/tests/std/array/sort_variation11.phpt b/tests/std/array/sort_variation11.phpt new file mode 100644 index 00000000..909a5546 --- /dev/null +++ b/tests/std/array/sort_variation11.phpt @@ -0,0 +1,185 @@ +--TEST-- +Test sort() function : usage variations - sort mixed values, 'sort_flag' as default/SORT_REGULAR (OK to fail as result is unpredectable) +--FILE-- + +--EXPECTF-- +*** Testing sort() : usage variations *** + +-- Testing sort() by supplying mixed value array, 'flag' value is default -- +bool(true) +array(22) { + [0]=> + string(0) "" + [1]=> + NULL + [2]=> + string(0) "" + [3]=> + float(0) + [4]=> + bool(false) + [5]=> + int(-4) + [6]=> + float(-2.98989) + [7]=> + int(-2) + [8]=> + float(-2) + [9]=> + string(3) "-.9" + [10]=> + int(0) + [11]=> + string(1) "4" + [12]=> + float(4) + [13]=> + string(1) "5" + [14]=> + string(4) "True" + [15]=> + string(2) "ab" + [16]=> + string(4) "abcd" + [17]=> + string(14) "abcd%0abcd%0abcd" + [18]=> + string(1) "b" + [19]=> + array(0) { + } + [20]=> + array(4) { + [0]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } + [1]=> + array(1) { + [0]=> + int(11) + } + [2]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + [3]=> + array(0) { + } + } + [21]=> + bool(true) +} + +-- Testing sort() by supplying mixed value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(22) { + [0]=> + string(0) "" + [1]=> + NULL + [2]=> + string(0) "" + [3]=> + float(0) + [4]=> + bool(false) + [5]=> + int(-4) + [6]=> + float(-2.98989) + [7]=> + int(-2) + [8]=> + float(-2) + [9]=> + string(3) "-.9" + [10]=> + int(0) + [11]=> + string(1) "4" + [12]=> + float(4) + [13]=> + string(1) "5" + [14]=> + string(4) "True" + [15]=> + string(2) "ab" + [16]=> + string(4) "abcd" + [17]=> + string(14) "abcd%0abcd%0abcd" + [18]=> + string(1) "b" + [19]=> + array(0) { + } + [20]=> + array(4) { + [0]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } + [1]=> + array(1) { + [0]=> + int(11) + } + [2]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + [3]=> + array(0) { + } + } + [21]=> + bool(true) +} +Done diff --git a/tests/std/array/sort_variation3.phpt b/tests/std/array/sort_variation3.phpt new file mode 100644 index 00000000..194d2b9f --- /dev/null +++ b/tests/std/array/sort_variation3.phpt @@ -0,0 +1,322 @@ +--TEST-- +Test sort() function : usage variations - sort integer/float values +--FILE-- + SORT_REGULAR, "SORT_NUMERIC" => SORT_NUMERIC); + +$count = 1; +echo "\n-- Testing sort() by supplying various integer/float arrays --\n"; + +// loop through to test sort() with different arrays +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With Default sort flag -\n"; + $temp_array = $array; + var_dump(sort($temp_array) ); + var_dump($temp_array); + + // loop through $flag_value array and setting all possible flag values + foreach($flag_value as $key => $flag){ + echo "- Sort flag = $key -\n"; + $temp_array = $array; + var_dump(sort($temp_array, $flag) ); + var_dump($temp_array); + } + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing sort() : usage variations *** + +-- Testing sort() by supplying various integer/float arrays -- + +-- Iteration 1 -- +- With Default sort flag - +bool(true) +array(9) { + [0]=> + int(-41) + [1]=> + int(-31) + [2]=> + int(-21) + [3]=> + int(-11) + [4]=> + int(0) + [5]=> + int(11) + [6]=> + int(21) + [7]=> + int(31) + [8]=> + int(41) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(9) { + [0]=> + int(-41) + [1]=> + int(-31) + [2]=> + int(-21) + [3]=> + int(-11) + [4]=> + int(0) + [5]=> + int(11) + [6]=> + int(21) + [7]=> + int(31) + [8]=> + int(41) +} +- Sort flag = SORT_NUMERIC - +bool(true) +array(9) { + [0]=> + int(-41) + [1]=> + int(-31) + [2]=> + int(-21) + [3]=> + int(-11) + [4]=> + int(0) + [5]=> + int(11) + [6]=> + int(21) + [7]=> + int(31) + [8]=> + int(41) +} + +-- Iteration 2 -- +- With Default sort flag - +bool(true) +array(7) { + [0]=> + float(-10.5) + [1]=> + float(-0.1) + [2]=> + float(0.01) + [3]=> + float(0.106) + [4]=> + float(0.5) + [5]=> + float(10.5) + [6]=> + float(1050) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(7) { + [0]=> + float(-10.5) + [1]=> + float(-0.1) + [2]=> + float(0.01) + [3]=> + float(0.106) + [4]=> + float(0.5) + [5]=> + float(10.5) + [6]=> + float(1050) +} +- Sort flag = SORT_NUMERIC - +bool(true) +array(7) { + [0]=> + float(-10.5) + [1]=> + float(-0.1) + [2]=> + float(0.01) + [3]=> + float(0.106) + [4]=> + float(0.5) + [5]=> + float(10.5) + [6]=> + float(1050) +} + +-- Iteration 3 -- +- With Default sort flag - +bool(true) +array(11) { + [0]=> + int(-1) + [1]=> + float(-0.9) + [2]=> + float(-0.106) + [3]=> + float(-0.01) + [4]=> + int(0) + [5]=> + float(0.0001) + [6]=> + float(0.0021) + [7]=> + float(0.09) + [8]=> + float(0.106) + [9]=> + int(2) + [10]=> + int(33) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(11) { + [0]=> + int(-1) + [1]=> + float(-0.9) + [2]=> + float(-0.106) + [3]=> + float(-0.01) + [4]=> + int(0) + [5]=> + float(0.0001) + [6]=> + float(0.0021) + [7]=> + float(0.09) + [8]=> + float(0.106) + [9]=> + int(2) + [10]=> + int(33) +} +- Sort flag = SORT_NUMERIC - +bool(true) +array(11) { + [0]=> + int(-1) + [1]=> + float(-0.9) + [2]=> + float(-0.106) + [3]=> + float(-0.01) + [4]=> + int(0) + [5]=> + float(0.0001) + [6]=> + float(0.0021) + [7]=> + float(0.09) + [8]=> + float(0.106) + [9]=> + int(2) + [10]=> + int(33) +} + +-- Iteration 4 -- +- With Default sort flag - +bool(true) +array(7) { + [0]=> + %s(-2147483649) + [1]=> + %s(-2147483648) + [2]=> + int(-2147483647) + [3]=> + int(0) + [4]=> + int(0) + [5]=> + int(2147483647) + [6]=> + %s(2147483648) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(7) { + [0]=> + %s(-2147483649) + [1]=> + %s(-2147483648) + [2]=> + int(-2147483647) + [3]=> + int(0) + [4]=> + int(0) + [5]=> + int(2147483647) + [6]=> + %s(2147483648) +} +- Sort flag = SORT_NUMERIC - +bool(true) +array(7) { + [0]=> + %s(-2147483649) + [1]=> + %s(-2147483648) + [2]=> + int(-2147483647) + [3]=> + int(0) + [4]=> + int(0) + [5]=> + int(2147483647) + [6]=> + %s(2147483648) +} +Done diff --git a/tests/std/array/sort_variation4.phpt b/tests/std/array/sort_variation4.phpt new file mode 100644 index 00000000..9a355065 --- /dev/null +++ b/tests/std/array/sort_variation4.phpt @@ -0,0 +1,78 @@ +--TEST-- +Test sort() function : usage variations - sort reference values +--SKIPIF-- + + +--FILE-- + +--EXPECT-- +*** Testing sort() :usage variations *** + +-- Testing sort() by supplying reference variable array, 'flag' value is default -- +bool(true) +array(3) { + [0]=> + &int(33) + [1]=> + &int(100) + [2]=> + &int(555) +} + +-- Testing sort() by supplying reference variable array, 'flag' = SORT_REGULAR -- +bool(true) +array(3) { + [0]=> + &int(33) + [1]=> + &int(100) + [2]=> + &int(555) +} + +-- Testing sort() by supplying reference variable array, 'flag' = SORT_NUMERIC -- +bool(true) +array(3) { + [0]=> + &int(33) + [1]=> + &int(100) + [2]=> + &int(555) +} +Done diff --git a/tests/std/array/sort_variation5.phpt b/tests/std/array/sort_variation5.phpt new file mode 100644 index 00000000..6c49342d --- /dev/null +++ b/tests/std/array/sort_variation5.phpt @@ -0,0 +1,227 @@ +--TEST-- +Test sort() function : usage variations - sort strings +--FILE-- + SORT_REGULAR, "SORT_STRING" => SORT_STRING); + +$count = 1; +echo "\n-- Testing sort() by supplying various string arrays --\n"; + +// loop through to test sort() with different arrays +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With Default sort flag -\n"; + $temp_array = $array; + var_dump(sort($temp_array) ); // expecting : bool(true) + var_dump($temp_array); + + // loop through $flags array and setting all possible flag values + foreach($flags as $key => $flag){ + echo "- Sort flag = $key -\n"; + $temp_array = $array; + var_dump(sort($temp_array, $flag) ); // expecting : bool(true) + var_dump($temp_array); + } + $count++; +} + +echo "Done\n"; +?> +--EXPECT-- +*** Testing sort() : usage variations *** + +-- Testing sort() by supplying various string arrays -- + +-- Iteration 1 -- +- With Default sort flag - +bool(true) +array(12) { + [0]=> + NULL + [1]=> + NULL + [2]=> + string(1) " " + [3]=> + string(1) " +" + [4]=> + string(1) " " + [5]=> + string(1) " " + [6]=> + string(1) " " + [7]=> + string(1) "" + [8]=> + string(2) "\a" + [9]=> + string(3) "\cx" + [10]=> + string(4) "\ddd" + [11]=> + string(4) "\xhh" +} +- Sort flag = SORT_REGULAR - +bool(true) +array(12) { + [0]=> + NULL + [1]=> + NULL + [2]=> + string(1) " " + [3]=> + string(1) " +" + [4]=> + string(1) " " + [5]=> + string(1) " " + [6]=> + string(1) " " + [7]=> + string(1) "" + [8]=> + string(2) "\a" + [9]=> + string(3) "\cx" + [10]=> + string(4) "\ddd" + [11]=> + string(4) "\xhh" +} +- Sort flag = SORT_STRING - +bool(true) +array(12) { + [0]=> + NULL + [1]=> + NULL + [2]=> + string(1) " " + [3]=> + string(1) " +" + [4]=> + string(1) " " + [5]=> + string(1) " " + [6]=> + string(1) " " + [7]=> + string(1) "" + [8]=> + string(2) "\a" + [9]=> + string(3) "\cx" + [10]=> + string(4) "\ddd" + [11]=> + string(4) "\xhh" +} + +-- Iteration 2 -- +- With Default sort flag - +bool(true) +array(12) { + [0]=> + string(6) "BANANA" + [1]=> + string(6) "Orange" + [2]=> + string(4) "TTTT" + [3]=> + string(4) "Test" + [4]=> + string(1) "X" + [5]=> + string(5) "apple" + [6]=> + string(6) "banana" + [7]=> + string(5) "lemoN" + [8]=> + string(6) "oraNGe" + [9]=> + string(3) "ttt" + [10]=> + string(2) "ww" + [11]=> + string(1) "x" +} +- Sort flag = SORT_REGULAR - +bool(true) +array(12) { + [0]=> + string(6) "BANANA" + [1]=> + string(6) "Orange" + [2]=> + string(4) "TTTT" + [3]=> + string(4) "Test" + [4]=> + string(1) "X" + [5]=> + string(5) "apple" + [6]=> + string(6) "banana" + [7]=> + string(5) "lemoN" + [8]=> + string(6) "oraNGe" + [9]=> + string(3) "ttt" + [10]=> + string(2) "ww" + [11]=> + string(1) "x" +} +- Sort flag = SORT_STRING - +bool(true) +array(12) { + [0]=> + string(6) "BANANA" + [1]=> + string(6) "Orange" + [2]=> + string(4) "TTTT" + [3]=> + string(4) "Test" + [4]=> + string(1) "X" + [5]=> + string(5) "apple" + [6]=> + string(6) "banana" + [7]=> + string(5) "lemoN" + [8]=> + string(6) "oraNGe" + [9]=> + string(3) "ttt" + [10]=> + string(2) "ww" + [11]=> + string(1) "x" +} +Done diff --git a/tests/std/array/sort_variation6.phpt b/tests/std/array/sort_variation6.phpt new file mode 100644 index 00000000..fcde3b3d --- /dev/null +++ b/tests/std/array/sort_variation6.phpt @@ -0,0 +1,117 @@ +--TEST-- +Test sort() function : usage variations - sort hexadecimal values +--FILE-- + +--EXPECT-- +*** Testing sort() : usage variations *** + +-- Testing sort() by supplying hexadecimal value array, 'flag' value is default -- +bool(true) +array(11) { + [0]=> + int(-682) + [1]=> + int(-255) + [2]=> + int(0) + [3]=> + int(15) + [4]=> + int(187) + [5]=> + int(255) + [6]=> + int(255) + [7]=> + int(427) + [8]=> + int(427) + [9]=> + int(682) + [10]=> + int(4095) +} + +-- Testing sort() by supplying hexadecimal value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(11) { + [0]=> + int(-682) + [1]=> + int(-255) + [2]=> + int(0) + [3]=> + int(15) + [4]=> + int(187) + [5]=> + int(255) + [6]=> + int(255) + [7]=> + int(427) + [8]=> + int(427) + [9]=> + int(682) + [10]=> + int(4095) +} + +-- Testing sort() by supplying hexadecimal value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(11) { + [0]=> + int(-682) + [1]=> + int(-255) + [2]=> + int(0) + [3]=> + int(15) + [4]=> + int(187) + [5]=> + int(255) + [6]=> + int(255) + [7]=> + int(427) + [8]=> + int(427) + [9]=> + int(682) + [10]=> + int(4095) +} +Done diff --git a/tests/std/array/sort_variation7.phpt b/tests/std/array/sort_variation7.phpt new file mode 100644 index 00000000..75d2dd16 --- /dev/null +++ b/tests/std/array/sort_variation7.phpt @@ -0,0 +1,92 @@ +--TEST-- +Test sort() function : usage variations - sort boolean values +--FILE-- + +--EXPECT-- +*** Testing sort() : usage variations *** + +-- Testing sort() by supplying bool value array, 'flag' value is default -- +bool(true) +array(4) { + [0]=> + bool(false) + [1]=> + bool(false) + [2]=> + bool(true) + [3]=> + bool(true) +} + +-- Testing sort() by supplying bool value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(4) { + [0]=> + bool(false) + [1]=> + bool(false) + [2]=> + bool(true) + [3]=> + bool(true) +} + +-- Testing sort() by supplying bool value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(4) { + [0]=> + bool(false) + [1]=> + bool(false) + [2]=> + bool(true) + [3]=> + bool(true) +} + +-- Testing sort() by supplying bool value array, 'flag' value is SORT_STRING -- +bool(true) +array(4) { + [0]=> + bool(false) + [1]=> + bool(false) + [2]=> + bool(true) + [3]=> + bool(true) +} +Done diff --git a/tests/std/array/sort_variation8.phpt b/tests/std/array/sort_variation8.phpt new file mode 100644 index 00000000..562766e7 --- /dev/null +++ b/tests/std/array/sort_variation8.phpt @@ -0,0 +1,172 @@ +--TEST-- +Test sort() function : usage variations - sort array with diff. sub arrays, 'sort_flags' as default/SORT_REGULAR +--FILE-- + +--EXPECT-- +*** Testing sort() : usage variations *** + +-- Testing sort() by supplying various arrays containing sub arrays -- + +-- Iteration 1 -- +- With Default sort flag - +bool(true) +array(0) { +} +- Sort flag = SORT_REGULAR - +bool(true) +array(0) { +} + +-- Iteration 2 -- +- With Default sort flag - +bool(true) +array(1) { + [0]=> + array(0) { + } +} +- Sort flag = SORT_REGULAR - +bool(true) +array(1) { + [0]=> + array(0) { + } +} + +-- Iteration 3 -- +- With Default sort flag - +bool(true) +array(3) { + [0]=> + int(11) + [1]=> + int(44) + [2]=> + array(2) { + [0]=> + int(64) + [1]=> + int(61) + } +} +- Sort flag = SORT_REGULAR - +bool(true) +array(3) { + [0]=> + int(11) + [1]=> + int(44) + [2]=> + array(2) { + [0]=> + int(64) + [1]=> + int(61) + } +} + +-- Iteration 4 -- +- With Default sort flag - +bool(true) +array(4) { + [0]=> + array(0) { + } + [1]=> + array(1) { + [0]=> + int(11) + } + [2]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + [3]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } +} +- Sort flag = SORT_REGULAR - +bool(true) +array(4) { + [0]=> + array(0) { + } + [1]=> + array(1) { + [0]=> + int(11) + } + [2]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + [3]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } +} +Done diff --git a/tests/std/array/sort_variation9.phpt b/tests/std/array/sort_variation9.phpt new file mode 100644 index 00000000..7791a81c --- /dev/null +++ b/tests/std/array/sort_variation9.phpt @@ -0,0 +1,253 @@ +--TEST-- +Test sort() function : usage variations - sort diff. associative arrays, 'sort_flags' as default/SORT_REGULAR +--FILE-- + 55, 6 => 66, 2 => 22, 3 => 33, 1 => 11), + array ("fruits" => array("a" => "orange", "b" => "banana", "c" => "apple"), + "numbers" => array(1, 2, 3, 4, 5, 6), + "holes" => array("first", 5 => "second", "third") + ), + array(1, 1, 8 => 1, 4 => 1, 19, 3 => 13), + array('bar' => 'baz', "foo" => 1), + array('a' => 1,'b' => array('e' => 2,'f' => 3),'c' => array('g' => 4),'d' => 5), +); + +$count = 1; +echo "\n-- Testing sort() by supplying various arrays with key values --\n"; + +// loop through to test sort() with different arrays, +// to test the new keys for the elements in the sorted array +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With Default sort flag -\n"; + $temp_array = $array; + var_dump(sort($temp_array) ); + var_dump($temp_array); + + echo "- Sort flag = SORT_REGULAR -\n"; + $temp_array = $array; + var_dump(sort($temp_array, SORT_REGULAR) ); + var_dump($temp_array); + $count++; +} + +echo "Done\n"; +?> +--EXPECT-- +*** Testing sort() : usage variations *** + +-- Testing sort() by supplying various arrays with key values -- + +-- Iteration 1 -- +- With Default sort flag - +bool(true) +array(5) { + [0]=> + int(11) + [1]=> + int(22) + [2]=> + int(33) + [3]=> + int(55) + [4]=> + int(66) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(5) { + [0]=> + int(11) + [1]=> + int(22) + [2]=> + int(33) + [3]=> + int(55) + [4]=> + int(66) +} + +-- Iteration 2 -- +- With Default sort flag - +bool(true) +array(3) { + [0]=> + array(3) { + [0]=> + string(5) "first" + [5]=> + string(6) "second" + [6]=> + string(5) "third" + } + [1]=> + array(3) { + ["a"]=> + string(6) "orange" + ["b"]=> + string(6) "banana" + ["c"]=> + string(5) "apple" + } + [2]=> + array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + } +} +- Sort flag = SORT_REGULAR - +bool(true) +array(3) { + [0]=> + array(3) { + [0]=> + string(5) "first" + [5]=> + string(6) "second" + [6]=> + string(5) "third" + } + [1]=> + array(3) { + ["a"]=> + string(6) "orange" + ["b"]=> + string(6) "banana" + ["c"]=> + string(5) "apple" + } + [2]=> + array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + } +} + +-- Iteration 3 -- +- With Default sort flag - +bool(true) +array(6) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + int(1) + [3]=> + int(1) + [4]=> + int(13) + [5]=> + int(19) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(6) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + int(1) + [3]=> + int(1) + [4]=> + int(13) + [5]=> + int(19) +} + +-- Iteration 4 -- +- With Default sort flag - +bool(true) +array(2) { + [0]=> + int(1) + [1]=> + string(3) "baz" +} +- Sort flag = SORT_REGULAR - +bool(true) +array(2) { + [0]=> + int(1) + [1]=> + string(3) "baz" +} + +-- Iteration 5 -- +- With Default sort flag - +bool(true) +array(4) { + [0]=> + int(1) + [1]=> + int(5) + [2]=> + array(1) { + ["g"]=> + int(4) + } + [3]=> + array(2) { + ["e"]=> + int(2) + ["f"]=> + int(3) + } +} +- Sort flag = SORT_REGULAR - +bool(true) +array(4) { + [0]=> + int(1) + [1]=> + int(5) + [2]=> + array(1) { + ["g"]=> + int(4) + } + [3]=> + array(2) { + ["e"]=> + int(2) + ["f"]=> + int(3) + } +} +Done diff --git a/tests/std/array/uasort_basic1.phpt b/tests/std/array/uasort_basic1.phpt new file mode 100644 index 00000000..9ff9d33d --- /dev/null +++ b/tests/std/array/uasort_basic1.phpt @@ -0,0 +1,106 @@ +--TEST-- +Test uasort() function : basic functionality +--FILE-- + $value2) { + return 1; + } + else + return -1; +} + +function main() { +echo "*** Testing uasort() : basic functionality ***\n"; + +// Int array with default keys +$int_values = array(1, 8, 9, 3, 2, 6, 7); +echo "-- Numeric array with default keys --\n"; +var_dump( uasort($int_values, 'cmp') ); +var_dump($int_values); + +// String array with default keys +$string_values = array("This", "is", 'a', "test"); +echo "-- String array with default keys --\n"; +var_dump( uasort($string_values, 'cmp') ); +var_dump($string_values); + +// Associative array with numeric keys +$numeric_key_arg = array(1=> 1, 2 => 2, 3 => 7, 5 => 4, 4 => 9); +echo "-- Associative array with numeric keys --\n"; +var_dump( uasort($numeric_key_arg, 'cmp') ); +var_dump($numeric_key_arg); + +// Associative array with string keys +$string_key_arg = array('one' => 4, 'two' => 2, 'three' => 1, 'four' => 10); +echo "-- Associative array with string keys --\n"; +var_dump( uasort($string_key_arg, 'cmp') ); +var_dump($string_key_arg); + +echo "Done"; +} +?> +--EXPECT-- +*** Testing uasort() : basic functionality *** +-- Numeric array with default keys -- +bool(true) +array(7) { + [0]=> + int(1) + [4]=> + int(2) + [3]=> + int(3) + [5]=> + int(6) + [6]=> + int(7) + [1]=> + int(8) + [2]=> + int(9) +} +-- String array with default keys -- +bool(true) +array(4) { + [0]=> + string(4) "This" + [2]=> + string(1) "a" + [1]=> + string(2) "is" + [3]=> + string(4) "test" +} +-- Associative array with numeric keys -- +bool(true) +array(5) { + [1]=> + int(1) + [2]=> + int(2) + [5]=> + int(4) + [3]=> + int(7) + [4]=> + int(9) +} +-- Associative array with string keys -- +bool(true) +array(4) { + ["three"]=> + int(1) + ["two"]=> + int(2) + ["one"]=> + int(4) + ["four"]=> + int(10) +} +Done diff --git a/tests/std/array/uasort_basic2.phpt b/tests/std/array/uasort_basic2.phpt new file mode 100644 index 00000000..49708b30 --- /dev/null +++ b/tests/std/array/uasort_basic2.phpt @@ -0,0 +1,92 @@ +--TEST-- +Test uasort() function : basic functionality - duplicate values +--FILE-- + $value2) { + return 1; + } + else + return -1; +} + +function main() { +echo "*** Testing uasort() : basic functionality with duplicate values ***\n"; + +// increasing values +$int_values1 = array(1, 1, 2, 2, 3, 3); +echo "-- Numeric array with increasing values --\n"; +var_dump( uasort($int_values1, 'cmp') ); +var_dump($int_values1); + +// decreasing values +$int_values2 = array(3, 3, 2, 2, 1, 1); +echo "-- Numeric array with decreasing values --\n"; +var_dump( uasort($int_values2, 'cmp') ); +var_dump($int_values2); + +// increasing and decreasing values +$int_values3 = array(1, 2, 3, 3, 2, 1); +echo "-- Numeric array with increasing and decreasing values --\n"; +var_dump( uasort($int_values3, 'cmp') ); +var_dump($int_values3); + +echo "Done"; +} +?> +--EXPECT-- +*** Testing uasort() : basic functionality with duplicate values *** +-- Numeric array with increasing values -- +bool(true) +array(6) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(2) + [4]=> + int(3) + [5]=> + int(3) +} +-- Numeric array with decreasing values -- +bool(true) +array(6) { + [4]=> + int(1) + [5]=> + int(1) + [2]=> + int(2) + [3]=> + int(2) + [0]=> + int(3) + [1]=> + int(3) +} +-- Numeric array with increasing and decreasing values -- +bool(true) +array(6) { + [0]=> + int(1) + [5]=> + int(1) + [1]=> + int(2) + [4]=> + int(2) + [2]=> + int(3) + [3]=> + int(3) +} +Done diff --git a/tests/std/array/uasort_object1.phpt b/tests/std/array/uasort_object1.phpt new file mode 100644 index 00000000..972418fd --- /dev/null +++ b/tests/std/array/uasort_object1.phpt @@ -0,0 +1,140 @@ +--TEST-- +Test uasort() function : object functionality +--FILE-- + $value2) { + return 1; + } + else + return -1; +} + +// comparison function for SimpleClass2 objects which has more than one members +function multiple_cmp($value1, $value2) +{ + if($value1->getValue() == $value2->getValue()) + return 0; + else if($value1->getValue() > $value2->getValue()) + return 1; + else + return -1; +} + +// Simple class with single member variable +class SimpleClass1 +{ + private $int_value; + + public function __construct($value) { + $this->int_value = $value; + } +} + +// Simple class with more than one member variables +class SimpleClass2 +{ + private $int_value; + protected $float_value; + public $string_value; + public function __construct($int, $float, $str) { + $this->int_value = $int; + $this->float_value = $float; + $this->string_value = $str; + } + public function getValue() { + return $this->int_value; + } +} + +function main() { +echo "*** Testing uasort() : object functionality ***\n"; + +// array of SimpleClass objects with only one member +$array_arg = array( + 0 => new SimpleClass1(10), + 1 => new SimpleClass1(1), + 2 => new SimpleClass1(100), + 3 => new SimpleClass1(50) +); +var_dump( uasort($array_arg, 'simple_cmp') ); +var_dump($array_arg); + +// array of SimpleClass objects having more than one members +$array_arg = array( + 0 => new SimpleClass2(2, 3.4, "mango"), + 1 => new SimpleClass2(10, 1.2, "apple"), + 2 => new SimpleClass2(5, 2.5, "orange"), +); +var_dump( uasort($array_arg, 'multiple_cmp') ); +var_dump($array_arg); + +echo "Done"; +} +?> +--EXPECT-- +*** Testing uasort() : object functionality *** +bool(true) +array(4) { + [1]=> + object(SimpleClass1)#2 (1) { + ["int_value":"SimpleClass1":private]=> + int(1) + } + [0]=> + object(SimpleClass1)#1 (1) { + ["int_value":"SimpleClass1":private]=> + int(10) + } + [3]=> + object(SimpleClass1)#4 (1) { + ["int_value":"SimpleClass1":private]=> + int(50) + } + [2]=> + object(SimpleClass1)#3 (1) { + ["int_value":"SimpleClass1":private]=> + int(100) + } +} +bool(true) +array(3) { + [0]=> + object(SimpleClass2)#5 (3) { + ["int_value":"SimpleClass2":private]=> + int(2) + ["float_value":protected]=> + float(3.4) + ["string_value"]=> + string(5) "mango" + } + [2]=> + object(SimpleClass2)#7 (3) { + ["int_value":"SimpleClass2":private]=> + int(5) + ["float_value":protected]=> + float(2.5) + ["string_value"]=> + string(6) "orange" + } + [1]=> + object(SimpleClass2)#6 (3) { + ["int_value":"SimpleClass2":private]=> + int(10) + ["float_value":protected]=> + float(1.2) + ["string_value"]=> + string(5) "apple" + } +} +Done diff --git a/tests/std/array/uasort_object2.phpt b/tests/std/array/uasort_object2.phpt new file mode 100644 index 00000000..bb4672db --- /dev/null +++ b/tests/std/array/uasort_object2.phpt @@ -0,0 +1,175 @@ +--TEST-- +Test uasort() function : object functionality - sort diff. objects +--FILE-- + $value2) { + return 1; + } + else + return -1; +} + +// Simple class with single member variable +class SimpleClass +{ + private $int_value; + + public function __construct($value) { + $this->int_value = $value; + } +} + +// Class without any member +class EmptyClass +{ +} + +// Class with static member +class StaticClass +{ + public static $static_value; + public function __construct($value) { + StaticClass::$static_value = $value; + } +} + +// Abstract class +abstract class AbstractClass +{ + public $pub_value; + public abstract function abstractMethod(); +} + +// Child class extending abstract class +class ChildClass extends AbstractClass +{ + public $child_value = 100; + public function abstractMethod() { + $pub_value = 5; + } + public function __construct($value) { + $this->child_value = $value; + } +} + +function main() { +echo "*** Testing uasort() : object functionality ***\n"; + +// Testing uasort with StaticClass objects as elements of 'array_arg' +echo "-- Testing uasort() with StaticClass objects --\n"; +$array_arg = array( + 0 => new StaticClass(20), + 1 => new StaticClass(50), + 2 => new StaticClass(15), + 3 => new StaticClass(70), +); +var_dump( uasort($array_arg, 'cmp_function') ); +var_dump($array_arg); + +// Testing uasort with EmptyClass objects as elements of 'array_arg' +echo "-- Testing uasort() with EmptyClass objects --\n"; +$array_arg = array( + 0 => new EmptyClass(), + 1 => new EmptyClass(), + 2 => new EmptyClass(), + 3 => new EmptyClass(), +); +var_dump( uasort($array_arg, 'cmp_function') ); +var_dump($array_arg); + +// Testing uasort with ChildClass objects as elements of 'array_arg' +echo "-- Testing uasort() with ChildClass objects --\n"; +$array_arg = array( + 0 => new ChildClass(20), + 1 => new ChildClass(500), + 2 => new ChildClass(15), + 3 => new ChildClass(700), +); +var_dump( uasort($array_arg, 'cmp_function') ); +var_dump($array_arg); + +echo "Done"; +} +?> +--EXPECTF-- +*** Testing uasort() : object functionality *** +-- Testing uasort() with StaticClass objects -- +bool(true) +array(4) { + [0]=> + object(StaticClass)#%d (0) { + } + [1]=> + object(StaticClass)#%d (0) { + } + [2]=> + object(StaticClass)#%d (0) { + } + [3]=> + object(StaticClass)#%d (0) { + } +} +-- Testing uasort() with EmptyClass objects -- +bool(true) +array(4) { + [0]=> + object(EmptyClass)#%d (0) { + } + [1]=> + object(EmptyClass)#%d (0) { + } + [2]=> + object(EmptyClass)#%d (0) { + } + [3]=> + object(EmptyClass)#%d (0) { + } +} +-- Testing uasort() with ChildClass objects -- +bool(true) +array(4) { + [2]=> + object(ChildClass)#%d (2) { + ["pub_value"]=> + NULL + ["child_value"]=> + int(15) + } + [0]=> + object(ChildClass)#%d (2) { + ["pub_value"]=> + NULL + ["child_value"]=> + int(20) + } + [1]=> + object(ChildClass)#%d (2) { + ["pub_value"]=> + NULL + ["child_value"]=> + int(500) + } + [3]=> + object(ChildClass)#%d (2) { + ["pub_value"]=> + NULL + ["child_value"]=> + int(700) + } +} +Done diff --git a/tests/std/array/uasort_variation10.phpt b/tests/std/array/uasort_variation10.phpt new file mode 100644 index 00000000..507ce5b0 --- /dev/null +++ b/tests/std/array/uasort_variation10.phpt @@ -0,0 +1,68 @@ +--TEST-- +Test uasort() function : usage variations - sort array with reference variables +--SKIPIF-- + +--FILE-- + $value2) { + return 1; + } + else { + return -1; + } +} + +function main() { +echo "*** Testing uasort() : 'array_arg' with elements as reference ***\n"; + +// different variables which are used as elements of 'array_arg' +$value1 = -5; +$value2 = 100; +$value3 = 0; +$value4 = &$value1; + +// array_args an array containing elements with reference variables +$array_arg = array( + 0 => 10, + 1 => &$value4, + 2 => &$value2, + 3 => 200, + 4 => &$value3, +); + +echo "-- Sorting 'array_arg' containing different references --\n"; +var_dump( uasort($array_arg, 'cmp_function') ); // expecting: bool(true) +var_dump($array_arg); + +echo "Done"; +} +?> +--EXPECT-- +*** Testing uasort() : 'array_arg' with elements as reference *** +-- Sorting 'array_arg' containing different references -- +bool(true) +array(5) { + [1]=> + &int(-5) + [4]=> + &int(0) + [0]=> + int(10) + [2]=> + &int(100) + [3]=> + int(200) +} +Done diff --git a/tests/std/array/uasort_variation11.phpt b/tests/std/array/uasort_variation11.phpt new file mode 100644 index 00000000..aa8ec3d9 --- /dev/null +++ b/tests/std/array/uasort_variation11.phpt @@ -0,0 +1,72 @@ +--TEST-- +Test uasort() function : usage variations - different associative arrays +--FILE-- + $value2) { + return 1; + } + else + return -1; +} + +function main() { +echo "*** Testing uasort() : sorting different associative arrays ***\n"; + +// Array with duplicate string and integer keys +$array_arg = array(0 => 2, "a" => 8, "d" => 9, 3 => 3, 5 => 2, "o" => 6, "z" => -99, 0 => 1, "z" => 3); +echo "-- Array with duplicate keys --\n"; +var_dump( uasort($array_arg, 'cmp') ); +var_dump($array_arg); + +// Array with default and assigned keys +$array_arg = array(0 => "Banana", 1 => "Mango", "Orange", 2 => "Apple", "Pineapple"); +echo "-- Array with default/assigned keys --\n"; +var_dump( uasort($array_arg, 'cmp') ); +var_dump($array_arg); + +echo "Done"; +} +?> +--EXPECT-- +*** Testing uasort() : sorting different associative arrays *** +-- Array with duplicate keys -- +bool(true) +array(7) { + [0]=> + int(1) + [5]=> + int(2) + [3]=> + int(3) + ["z"]=> + int(3) + ["o"]=> + int(6) + ["a"]=> + int(8) + ["d"]=> + int(9) +} +-- Array with default/assigned keys -- +bool(true) +array(4) { + [2]=> + string(5) "Apple" + [0]=> + string(6) "Banana" + [1]=> + string(5) "Mango" + [3]=> + string(9) "Pineapple" +} +Done diff --git a/tests/std/array/uasort_variation3.phpt b/tests/std/array/uasort_variation3.phpt new file mode 100644 index 00000000..f287841b --- /dev/null +++ b/tests/std/array/uasort_variation3.phpt @@ -0,0 +1,127 @@ +--TEST-- +Test uasort() function : usage variations - sort array with all possible keys +--SKIPIF-- + +--FILE-- + $value2) { + return -1; + } + else { + return 1; + } +} + +function main() { +echo "*** Testing uasort() : Sorting array with all possible keys ***\n"; + +// different heredoc strings +//empty heredoc string +$empty_heredoc = << 10, // expecting: value will be replaced by 'TRUE' + -2 => 9, + 012 => 7, + 0x34 => 6, + + // string keys + 'key' => 5, //single quoted key + "two" => 4, //double quoted key + '' => 3, + "" => 2, + " " => 0, // space as key + + // bool keys + true => 15, + false => 5, + TRUE => 100, + FALSE => 25, + + // null keys + null => 20, // expecting: value will be replaced by 'NULL' + NULL => 35, + + // binary key + "a".chr(0)."b" => 45, + b"binary" => 30, + + //heredoc keys + $empty_heredoc => 90, + $simple_heredoc => 75, + $multiline_heredoc => 200, +); + +var_dump( uasort($array_arg, 'cmp_function') ); +echo "-- Sorted array after uasort() function call --\n"; +var_dump($array_arg); + +echo "Done"; +} +?> +--EXPECTF-- +*** Testing uasort() : Sorting array with all possible keys *** +bool(true) +-- Sorted array after uasort() function call -- +array(15) { + ["multiline heredoc with 123 +and speci@! ch@r.. +check also"]=> + int(200) + [1]=> + int(100) + [""]=> + int(90) + ["simple"]=> + int(75) + ["a%0b"]=> + int(45) + [54]=> + int(35) + ["binary"]=> + int(30) + [0]=> + int(25) + [53]=> + int(20) + [-2]=> + int(9) + [10]=> + int(7) + [52]=> + int(6) + ["key"]=> + int(5) + ["two"]=> + int(4) + [" "]=> + int(0) +} +Done diff --git a/tests/std/array/uasort_variation4.phpt b/tests/std/array/uasort_variation4.phpt new file mode 100644 index 00000000..20febefd --- /dev/null +++ b/tests/std/array/uasort_variation4.phpt @@ -0,0 +1,140 @@ +--TEST-- +Test uasort() function : usage variations - sort different numeric values +--FILE-- + $value2) { + return 1; + } + else { + return -1; + } +} + +function main() { +echo "*** Testing uasort() : different numeric arrays as 'array_arg' ***\n"; + +// Int array +$int_values = array(0 => 3, 1 => 2, 3 => 100, 4 => 150, 5 => 25, 6 => 350, 7 => 0, 8 => -3, 9 => -1200); +echo "-- Sorting Integer array --\n"; +var_dump( uasort($int_values, 'cmp_function') ); // expecting: bool(true) +var_dump($int_values); + +// Octal array +$octal_values = array(0 => 056, 1 => 023, 2 => 00, 3 => 015, 4 => -045, 5 => 01, 6 => -07); +echo "-- Sorting Octal array --\n"; +var_dump( uasort($octal_values, 'cmp_function') ); // expecting: bool(true) +var_dump($octal_values); + +// Hexadecimal array +$hex_values = array(0 => 0xAE, 1 => 0x2B, 2 => 0X10, 3 => -0xCF, 4 => 0X12, 5 => -0XF2); +echo "-- Sorting Hex array --\n"; +var_dump( uasort($hex_values, 'cmp_function') ); // expecting: bool(true) +var_dump($hex_values); + +// Float array +$float_values = array( 0 => 10.2, 1 => 2.4, 2 => -3.4, 3 => 0, 4 => 0.5, 5 => 7.3e3, 6 => -9.34E-2); +echo "-- Sorting Float array --\n"; +var_dump( uasort($float_values, 'cmp_function') ); // expecting: bool(true) +var_dump($float_values); + +// empty array +$empty_array = array(); +echo "-- Sorting empty array --\n"; +var_dump( uasort($empty_array, 'cmp_function') ); // expecting: bool(true) +var_dump($empty_array); + +echo "Done"; +} +?> +--EXPECT-- +*** Testing uasort() : different numeric arrays as 'array_arg' *** +-- Sorting Integer array -- +bool(true) +array(9) { + [9]=> + int(-1200) + [8]=> + int(-3) + [7]=> + int(0) + [1]=> + int(2) + [0]=> + int(3) + [5]=> + int(25) + [3]=> + int(100) + [4]=> + int(150) + [6]=> + int(350) +} +-- Sorting Octal array -- +bool(true) +array(7) { + [4]=> + int(-37) + [6]=> + int(-7) + [2]=> + int(0) + [5]=> + int(1) + [3]=> + int(13) + [1]=> + int(19) + [0]=> + int(46) +} +-- Sorting Hex array -- +bool(true) +array(6) { + [5]=> + int(-242) + [3]=> + int(-207) + [2]=> + int(16) + [4]=> + int(18) + [1]=> + int(43) + [0]=> + int(174) +} +-- Sorting Float array -- +bool(true) +array(7) { + [2]=> + float(-3.4) + [6]=> + float(-0.0934) + [3]=> + int(0) + [4]=> + float(0.5) + [1]=> + float(2.4) + [0]=> + float(10.2) + [5]=> + float(7300) +} +-- Sorting empty array -- +bool(true) +array(0) { +} +Done diff --git a/tests/std/array/uasort_variation5.phpt b/tests/std/array/uasort_variation5.phpt new file mode 100644 index 00000000..26521981 --- /dev/null +++ b/tests/std/array/uasort_variation5.phpt @@ -0,0 +1,135 @@ +--TEST-- +Test uasort() function : usage variations - sort diff. strings +--FILE-- + $value2) { + return 1; + } + else { + return -1; + } +} + +function main() { +// Different heredoc strings to be sorted +$empty_heredoc =<< ' ', 1 => 'test', 3 => 'Hello', 4 => 'HELLO', + 5 => '', 6 => '\t', 7 => '0', 8 => '123Hello', 9 => '\'', 10 => '@#$%' +); +echo "-- Sorting Single Quoted String values --\n"; +var_dump( uasort($single_quoted_values, 'cmp_function') ); // expecting: bool(true) +var_dump($single_quoted_values); + +// Double quoted strings +$double_quoted_values = array( + 0 => " ", 1 => "test", 3 => "Hello", 4 => "HELLO", + 5 => "", 6 => "\t", 7 => "0", 8 => "123Hello", 9 => "\"", 10 => "@#$%" +); +echo "-- Sorting Double Quoted String values --\n"; +var_dump( uasort($double_quoted_values, 'cmp_function') ); // expecting: bool(true) +var_dump($double_quoted_values); + +// Heredoc strings +$heredoc_values = array(0 => $empty_heredoc, 1 => $simple_heredoc1, 2 => $simple_heredoc2, 3 => $multiline_heredoc); +echo "-- Sorting Heredoc String values --\n"; +var_dump( uasort($heredoc_values, 'cmp_function') ); // expecting: bool(true) +var_dump($heredoc_values); + +echo "Done"; +} +?> +--EXPECTF-- +*** Testing uasort() : different string arrays as 'array_arg' *** +-- Sorting Single Quoted String values -- +bool(true) +array(10) { + [5]=> + string(0) "" + [0]=> + string(1) " " + [9]=> + string(1) "'" + [7]=> + string(1) "0" + [8]=> + string(8) "123Hello" + [10]=> + string(4) "@#$%" + [4]=> + string(5) "HELLO" + [3]=> + string(5) "Hello" + [6]=> + string(2) "\t" + [1]=> + string(4) "test" +} +-- Sorting Double Quoted String values -- +bool(true) +array(10) { + [5]=> + string(0) "" + [6]=> + string(1) " " + [0]=> + string(1) " " + [9]=> + string(1) """ + [7]=> + string(1) "0" + [8]=> + string(8) "123Hello" + [10]=> + string(4) "@#$%" + [4]=> + string(5) "HELLO" + [3]=> + string(5) "Hello" + [1]=> + string(4) "test" +} +-- Sorting Heredoc String values -- +bool(true) +array(4) { + [0]=> + string(0) "" + [2]=> + string(7) "HEREDOC" + [1]=> + string(7) "Heredoc" + [3]=> + string(4%d) "heredoc string with!@# and 123 +Test this!!!" +} +Done diff --git a/tests/std/array/uasort_variation6.phpt b/tests/std/array/uasort_variation6.phpt new file mode 100644 index 00000000..23acfc8e --- /dev/null +++ b/tests/std/array/uasort_variation6.phpt @@ -0,0 +1,92 @@ +--TEST-- +Test uasort() function : usage variations - sort array having subarrays +--FILE-- + $value2) { + return 1; + } else { + return -1; + } +} +function main() +{ + echo "*** Testing uasort() : sorting array having different subarrays ***\n"; + $array_args = array(0 => array(2, 10, -1), 1 => array(100), 2 => array(), 3 => array(0), 4 => array(-1), 5 => array(-9, 34, 54, 0, 20), 6 => array(''), 7 => array("apple", "Apple", "APPLE", "aPPle", "aPpLe")); + $temp_array = $array_args; + // sorting array_arg as whole array + var_dump(uasort($temp_array, 'cmp_function')); + // expecting: bool(true) + var_dump($temp_array); +} +?> +--EXPECT-- +*** Testing uasort() : sorting array having different subarrays *** +bool(true) +array(8) { + [2]=> + array(0) { + } + [6]=> + array(1) { + [0]=> + string(0) "" + } + [4]=> + array(1) { + [0]=> + int(-1) + } + [3]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [0]=> + int(100) + } + [0]=> + array(3) { + [0]=> + int(2) + [1]=> + int(10) + [2]=> + int(-1) + } + [5]=> + array(5) { + [0]=> + int(-9) + [1]=> + int(34) + [2]=> + int(54) + [3]=> + int(0) + [4]=> + int(20) + } + [7]=> + array(5) { + [0]=> + string(5) "apple" + [1]=> + string(5) "Apple" + [2]=> + string(5) "APPLE" + [3]=> + string(5) "aPPle" + [4]=> + string(5) "aPpLe" + } +} diff --git a/tests/std/array/uasort_variation7.phpt b/tests/std/array/uasort_variation7.phpt new file mode 100644 index 00000000..5340dd90 --- /dev/null +++ b/tests/std/array/uasort_variation7.phpt @@ -0,0 +1,86 @@ +--TEST-- +Test uasort() function : usage variations - anonymous function as 'cmp_function' +--SKIPIF-- + + +--FILE-- + $value2) { return 1; } + else { return -1; } +}; + +$array_arg = array(0 => 100, 1 => 3, 2 => -70, 3 => 24, 4 => 90); +echo "-- Anonymous 'cmp_function' with parameters passed by value --\n"; +var_dump( uasort($array_arg, $cmp_function) ); +var_dump($array_arg); + +$cmp_function = function(&$value1, &$value2) { + if ($value1 == $value2) { return 0; } + else if ($value1 > $value2) { return 1; } + else { return -1; } +}; + +$array_arg = array("b" => "Banana", "m" => "Mango", "a" => "Apple", "p" => "Pineapple"); +echo "-- Anonymous 'cmp_function' with parameters passed by reference --\n"; +var_dump( uasort($array_arg, $cmp_function ) ); +var_dump($array_arg); + +echo "Done"; +?> +--EXPECTF-- +*** Testing uasort() : anonymous function as 'cmp_function' *** +-- Anonymous 'cmp_function' with parameters passed by value -- +bool(true) +array(5) { + [2]=> + int(-70) + [1]=> + int(3) + [3]=> + int(24) + [4]=> + int(90) + [0]=> + int(100) +} +-- Anonymous 'cmp_function' with parameters passed by reference -- + +Warning: {closure:%s:%d}(): Argument #1 ($value1) must be passed by reference, value given in %s on line %d + +Warning: {closure:%s:%d}(): Argument #2 ($value2) must be passed by reference, value given in %s on line %d + +Warning: {closure:%s:%d}(): Argument #1 ($value1) must be passed by reference, value given in %s on line %d + +Warning: {closure:%s:%d}(): Argument #2 ($value2) must be passed by reference, value given in %s on line %d + +Warning: {closure:%s:%d}(): Argument #1 ($value1) must be passed by reference, value given in %s on line %d + +Warning: {closure:%s:%d}(): Argument #2 ($value2) must be passed by reference, value given in %s on line %d + +Warning: {closure:%s:%d}(): Argument #1 ($value1) must be passed by reference, value given in %s on line %d + +Warning: {closure:%s:%d}(): Argument #2 ($value2) must be passed by reference, value given in %s on line %d +bool(true) +array(4) { + ["a"]=> + string(5) "Apple" + ["b"]=> + string(6) "Banana" + ["m"]=> + string(5) "Mango" + ["p"]=> + string(9) "Pineapple" +} +Done diff --git a/tests/std/array/uasort_variation8.phpt b/tests/std/array/uasort_variation8.phpt new file mode 100644 index 00000000..9250af55 --- /dev/null +++ b/tests/std/array/uasort_variation8.phpt @@ -0,0 +1,57 @@ +--TEST-- +Test uasort() function : usage variations - built-in function as 'cmp_function' +--FILE-- + "Banana", "m" => "Mango", "a" => "apple", "p" => "Pineapple", "o" => "orange"); +$builtin_fun_arg = $array_arg; +$languageConstruct_fun_arg = $array_arg; + +// Testing library functions as comparison function +echo "-- Testing uasort() with built-in 'cmp_function': strcasecmp() --\n"; +var_dump( uasort($builtin_fun_arg, 'strcasecmp') ); // expecting: bool(true) +var_dump($builtin_fun_arg); + +echo "-- Testing uasort() with built-in 'cmp_function': strcmp() --\n"; +var_dump( uasort($array_arg, 'strcmp') ); // expecting: bool(true) +var_dump($array_arg); + +echo "Done"; +?> +--EXPECT-- +*** Testing uasort() : built in function as 'cmp_function' *** +-- Testing uasort() with built-in 'cmp_function': strcasecmp() -- +bool(true) +array(5) { + ["a"]=> + string(5) "apple" + ["b"]=> + string(6) "Banana" + ["m"]=> + string(5) "Mango" + ["o"]=> + string(6) "orange" + ["p"]=> + string(9) "Pineapple" +} +-- Testing uasort() with built-in 'cmp_function': strcmp() -- +bool(true) +array(5) { + ["b"]=> + string(6) "Banana" + ["m"]=> + string(5) "Mango" + ["p"]=> + string(9) "Pineapple" + ["a"]=> + string(5) "apple" + ["o"]=> + string(6) "orange" +} +Done diff --git a/tests/std/array/uksort_basic.phpt b/tests/std/array/uksort_basic.phpt new file mode 100644 index 00000000..12b8c0bc --- /dev/null +++ b/tests/std/array/uksort_basic.phpt @@ -0,0 +1,29 @@ +--TEST-- +Test uksort(): basic functionality +--FILE-- + $value) { + echo "{$key}: {$value}\n"; + } +} +?> +--EXPECT-- +4: 1 +1: 2 +0: 3 +2: 5 +3: 6 diff --git a/tests/std/array/unexpected_array_mod_bug.phpt b/tests/std/array/unexpected_array_mod_bug.phpt new file mode 100644 index 00000000..f211e898 --- /dev/null +++ b/tests/std/array/unexpected_array_mod_bug.phpt @@ -0,0 +1,31 @@ +--TEST-- +Crash when function parameter modified via reference +--SKIPIF-- + +--FILE-- + $b; +} +function main() +{ + $my_var = array(1 => "entry_1", 2 => "entry_2", 3 => "entry_3", 4 => "entry_4", 5 => "entry_5"); + usort($my_var, "usercompare"); + var_dump($my_var); +} +?> +--EXPECT-- +array(5) { + [0]=> + string(7) "entry_1" + [1]=> + string(7) "entry_2" + [2]=> + string(7) "entry_3" + [3]=> + string(7) "entry_4" + [4]=> + string(7) "entry_5" +} diff --git a/tests/std/array/unexpected_array_mod_bug_variation1.phpt b/tests/std/array/unexpected_array_mod_bug_variation1.phpt new file mode 100644 index 00000000..b5a1ee24 --- /dev/null +++ b/tests/std/array/unexpected_array_mod_bug_variation1.phpt @@ -0,0 +1,33 @@ +--TEST-- +Crash when function parameter modified via reference while keeping orig refcount +--FILE-- + "entry_1", + 2 => "entry_2", + 3 => "entry_3", + 4 => "entry_4", + 5 => "entry_5" +); +usort($array, function($a, $b) use (&$array, &$ref) { + unset($array[2]); + $ref = $array; + return $a <=> $b; +}); +var_dump($array); + +?> +--EXPECT-- +array(5) { + [0]=> + string(7) "entry_1" + [1]=> + string(7) "entry_2" + [2]=> + string(7) "entry_3" + [3]=> + string(7) "entry_4" + [4]=> + string(7) "entry_5" +} diff --git a/tests/std/array/usort_basic.phpt b/tests/std/array/usort_basic.phpt new file mode 100644 index 00000000..2c98a6de --- /dev/null +++ b/tests/std/array/usort_basic.phpt @@ -0,0 +1,104 @@ +--TEST-- +Test usort() function : basic functionality +--FILE-- + $value2) { + return 1; + } else { + return -1; + } +} +function main() +{ + /* + * Test basic functionality of usort() with indexed and associative arrays + */ + echo "*** Testing usort() : basic functionality ***\n"; + // Int array with default keys + $int_values = array(1, 8, 9, 3, 2, 6, 7); + echo "\n-- Numeric array with default keys --\n"; + var_dump(usort($int_values, 'cmp')); + var_dump($int_values); + // String array with default keys + $string_values = array("This", "is", 'a', "test"); + echo "\n-- String array with default keys --\n"; + var_dump(usort($string_values, 'cmp')); + var_dump($string_values); + // Associative array with numeric keys + $numeric_key_arg = array(1 => 1, 2 => 2, 3 => 7, 5 => 4, 4 => 9); + echo "\n-- Associative array with numeric keys --\n"; + var_dump(usort($numeric_key_arg, 'cmp')); + var_dump($numeric_key_arg); + // Associative array with string keys + $string_key_arg = array('one' => 4, 'two' => 2, 'three' => 1, 'four' => 10); + echo "\n-- Associative array with string keys --\n"; + var_dump(usort($string_key_arg, 'cmp')); + var_dump($string_key_arg); +} +?> +--EXPECT-- +*** Testing usort() : basic functionality *** + +-- Numeric array with default keys -- +bool(true) +array(7) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(6) + [4]=> + int(7) + [5]=> + int(8) + [6]=> + int(9) +} + +-- String array with default keys -- +bool(true) +array(4) { + [0]=> + string(4) "This" + [1]=> + string(1) "a" + [2]=> + string(2) "is" + [3]=> + string(4) "test" +} + +-- Associative array with numeric keys -- +bool(true) +array(5) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(4) + [3]=> + int(7) + [4]=> + int(9) +} + +-- Associative array with string keys -- +bool(true) +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(4) + [3]=> + int(10) +} diff --git a/tests/std/array/usort_object1.phpt b/tests/std/array/usort_object1.phpt new file mode 100644 index 00000000..5c338852 --- /dev/null +++ b/tests/std/array/usort_object1.phpt @@ -0,0 +1,123 @@ +--TEST-- +Test usort() function : object functionality - different number of properties +--FILE-- + $value2) { + return 1; + } else { + return -1; + } +} +// comparison function for SimpleClass2 objects which has more than one member +function multiple_cmp($value1, $value2) +{ + if ($value1->getValue() == $value2->getValue()) { + return 0; + } else if ($value1->getValue() > $value2->getValue()) { + return 1; + } else { + return -1; + } +} +// Simple class with single property +class SimpleClass1 +{ + private $int_value; + public function __construct($value) + { + $this->int_value = $value; + } +} +// Simple class with more than one property +class SimpleClass2 +{ + private $int_value; + protected $float_value; + public $string_value; + public function __construct($int, $float, $str) + { + $this->int_value = $int; + $this->float_value = $float; + $this->string_value = $str; + } + public function getValue() + { + return $this->int_value; + } +} +function main() +{ + /* + * Pass an array of objects which have a different number of properties + * to test behaviour of usort() + */ + echo "*** Testing usort() : object functionality ***\n"; + // array of SimpleClass objects with only one property + $array_arg = array(0 => new SimpleClass1(10), 1 => new SimpleClass1(1), 2 => new SimpleClass1(100), 3 => new SimpleClass1(50)); + var_dump(usort($array_arg, 'simple_cmp')); + var_dump($array_arg); + // array of SimpleClass objects having more than one properties + $array_arg = array(0 => new SimpleClass2(2, 3.4, "mango"), 1 => new SimpleClass2(10, 1.2, "apple"), 2 => new SimpleClass2(5, 2.5, "orange")); + var_dump(usort($array_arg, 'multiple_cmp')); + var_dump($array_arg); +} +?> +--EXPECTF-- +*** Testing usort() : object functionality *** +bool(true) +array(4) { + [0]=> + object(SimpleClass1)#%d (1) { + ["int_value":"SimpleClass1":private]=> + int(1) + } + [1]=> + object(SimpleClass1)#%d (1) { + ["int_value":"SimpleClass1":private]=> + int(10) + } + [2]=> + object(SimpleClass1)#%d (1) { + ["int_value":"SimpleClass1":private]=> + int(50) + } + [3]=> + object(SimpleClass1)#%d (1) { + ["int_value":"SimpleClass1":private]=> + int(100) + } +} +bool(true) +array(3) { + [0]=> + object(SimpleClass2)#%d (3) { + ["int_value":"SimpleClass2":private]=> + int(2) + ["float_value":protected]=> + float(3.4) + ["string_value"]=> + string(5) "mango" + } + [1]=> + object(SimpleClass2)#%d (3) { + ["int_value":"SimpleClass2":private]=> + int(5) + ["float_value":protected]=> + float(2.5) + ["string_value"]=> + string(6) "orange" + } + [2]=> + object(SimpleClass2)#%d (3) { + ["int_value":"SimpleClass2":private]=> + int(10) + ["float_value":protected]=> + float(1.2) + ["string_value"]=> + string(5) "apple" + } +} diff --git a/tests/std/array/usort_object2.phpt b/tests/std/array/usort_object2.phpt new file mode 100644 index 00000000..661d8390 --- /dev/null +++ b/tests/std/array/usort_object2.phpt @@ -0,0 +1,139 @@ +--TEST-- +Test usort() function : object functionality - Different types of classes +--FILE-- + $value2) { + return 1; + } else { + return -1; + } +} +// Class without any member +class EmptyClass +{ +} +// Class with static member +class StaticClass +{ + public static $static_value; + public function __construct($value) + { + StaticClass::$static_value = $value; + } +} +// Abstract class +abstract class AbstractClass +{ + public $pub_value; + abstract public function abstractMethod(); +} +// Child class extending abstract class +class ChildClass extends AbstractClass +{ + public $child_value = 100; + public function abstractMethod() + { + $pub_value = 5; + } + public function __construct($value) + { + $this->child_value = $value; + } +} +function main() +{ + /* + * Pass an array of objects which are either: + * 1. Empty + * 2. Static + * 2. Inherited + * to test behaviour of usort() + */ + echo "*** Testing usort() : object functionality ***\n"; + // Testing uasort with StaticClass objects as elements of 'array_arg' + echo "-- Testing usort() with StaticClass objects --\n"; + $array_arg = array(0 => new StaticClass(20), 1 => new StaticClass(50), 2 => new StaticClass(15), 3 => new StaticClass(70)); + var_dump(usort($array_arg, 'cmp_function')); + var_dump($array_arg); + // Testing uasort with EmptyClass objects as elements of 'array_arg' + echo "-- Testing usort() with EmptyClass objects --\n"; + $array_arg = array(0 => new EmptyClass(), 1 => new EmptyClass(), 2 => new EmptyClass(), 3 => new EmptyClass()); + var_dump(usort($array_arg, 'cmp_function')); + var_dump($array_arg); + // Testing uasort with ChildClass objects as elements of 'array_arg' + echo "-- Testing usort() with ChildClass objects --\n"; + $array_arg = array(0 => new ChildClass(20), 1 => new ChildClass(500), 2 => new ChildClass(15), 3 => new ChildClass(700)); + var_dump(usort($array_arg, 'cmp_function')); + var_dump($array_arg); +} +?> +--EXPECTF-- +*** Testing usort() : object functionality *** +-- Testing usort() with StaticClass objects -- +bool(true) +array(4) { + [0]=> + object(StaticClass)#%d (0) { + } + [1]=> + object(StaticClass)#%d (0) { + } + [2]=> + object(StaticClass)#%d (0) { + } + [3]=> + object(StaticClass)#%d (0) { + } +} +-- Testing usort() with EmptyClass objects -- +bool(true) +array(4) { + [0]=> + object(EmptyClass)#%d (0) { + } + [1]=> + object(EmptyClass)#%d (0) { + } + [2]=> + object(EmptyClass)#%d (0) { + } + [3]=> + object(EmptyClass)#%d (0) { + } +} +-- Testing usort() with ChildClass objects -- +bool(true) +array(4) { + [0]=> + object(ChildClass)#%d (2) { + ["pub_value"]=> + NULL + ["child_value"]=> + int(15) + } + [1]=> + object(ChildClass)#%d (2) { + ["pub_value"]=> + NULL + ["child_value"]=> + int(20) + } + [2]=> + object(ChildClass)#%d (2) { + ["pub_value"]=> + NULL + ["child_value"]=> + int(500) + } + [3]=> + object(ChildClass)#%d (2) { + ["pub_value"]=> + NULL + ["child_value"]=> + int(700) + } +} diff --git a/tests/std/array/usort_stability.phpt b/tests/std/array/usort_stability.phpt new file mode 100644 index 00000000..e3ca4e16 --- /dev/null +++ b/tests/std/array/usort_stability.phpt @@ -0,0 +1,15 @@ +--TEST-- +usort() is stable +--FILE-- + +--EXPECT-- +bool(true) diff --git a/tests/std/array/usort_variation10.phpt b/tests/std/array/usort_variation10.phpt new file mode 100644 index 00000000..6085e6fb --- /dev/null +++ b/tests/std/array/usort_variation10.phpt @@ -0,0 +1,66 @@ +--TEST-- +Test usort() function : usage variations - duplicate keys and values +--FILE-- + $value2) { + return 1; + } else { + return -1; + } +} +function main() +{ + /* + * Pass an array with duplicate keys and values to usort() to test behaviour + */ + echo "*** Testing usort() : usage variation ***\n"; + // Array with duplicate string and integer keys and values + $array_arg = array(0 => 2, "a" => 8, "d" => 9, 3 => 3, 5 => 2, "o" => 6, "z" => -99, 0 => 1, "z" => 3); + echo "\n-- Array with duplicate keys --\n"; + var_dump(usort($array_arg, 'cmp')); + var_dump($array_arg); + // Array with default and assigned keys + $array_arg = array(0 => "Banana", 1 => "Mango", "Orange", 2 => "Apple", "Pineapple"); + echo "\n-- Array with default/assigned keys --\n"; + var_dump(usort($array_arg, 'cmp')); + var_dump($array_arg); +} +?> +--EXPECT-- +*** Testing usort() : usage variation *** + +-- Array with duplicate keys -- +bool(true) +array(7) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(3) + [4]=> + int(6) + [5]=> + int(8) + [6]=> + int(9) +} + +-- Array with default/assigned keys -- +bool(true) +array(4) { + [0]=> + string(5) "Apple" + [1]=> + string(6) "Banana" + [2]=> + string(5) "Mango" + [3]=> + string(9) "Pineapple" +} diff --git a/tests/std/array/usort_variation11.phpt b/tests/std/array/usort_variation11.phpt new file mode 100644 index 00000000..fef77fc4 --- /dev/null +++ b/tests/std/array/usort_variation11.phpt @@ -0,0 +1,87 @@ +--TEST-- +Test usort() function : usage variations - malformed comparison function returning boolean +--SKIPIF-- + +--FILE-- + $b; +} +function main() +{ + $range = array(2, 4, 8, 16, 32, 64, 128); + foreach ($range as $r) { + $backup = $array = range(0, $r); + shuffle($array); + usort($array, "ucmp"); + if ($array != $backup) { + var_dump($array); + var_dump($backup); + die("Array not sorted (usort)"); + } + shuffle($array); + $array = array_flip($array); + uksort($array, "ucmp"); + $array = array_keys($array); + if ($array != $backup) { + var_dump($array); + var_dump($backup); + die("Array not sorted (uksort)"); + } + shuffle($array); + $array = array_combine($array, $array); + uasort($array, "ucmp"); + $array = array_keys($array); + if ($array != $backup) { + var_dump($array); + var_dump($backup); + die("Array not sorted (uasort)"); + } + } + echo "okey"; +} +?> +--EXPECTF-- +Deprecated: usort(): Returning bool from comparison function is deprecated, return an integer less than, equal to, or greater than zero in %s on line %d + +Deprecated: uksort(): Returning bool from comparison function is deprecated, return an integer less than, equal to, or greater than zero in %s on line %d + +Deprecated: uasort(): Returning bool from comparison function is deprecated, return an integer less than, equal to, or greater than zero in %s on line %d + +Deprecated: usort(): Returning bool from comparison function is deprecated, return an integer less than, equal to, or greater than zero in %s on line %d + +Deprecated: uksort(): Returning bool from comparison function is deprecated, return an integer less than, equal to, or greater than zero in %s on line %d + +Deprecated: uasort(): Returning bool from comparison function is deprecated, return an integer less than, equal to, or greater than zero in %s on line %d + +Deprecated: usort(): Returning bool from comparison function is deprecated, return an integer less than, equal to, or greater than zero in %s on line %d + +Deprecated: uksort(): Returning bool from comparison function is deprecated, return an integer less than, equal to, or greater than zero in %s on line %d + +Deprecated: uasort(): Returning bool from comparison function is deprecated, return an integer less than, equal to, or greater than zero in %s on line %d + +Deprecated: usort(): Returning bool from comparison function is deprecated, return an integer less than, equal to, or greater than zero in %s on line %d + +Deprecated: uksort(): Returning bool from comparison function is deprecated, return an integer less than, equal to, or greater than zero in %s on line %d + +Deprecated: uasort(): Returning bool from comparison function is deprecated, return an integer less than, equal to, or greater than zero in %s on line %d + +Deprecated: usort(): Returning bool from comparison function is deprecated, return an integer less than, equal to, or greater than zero in %s on line %d + +Deprecated: uksort(): Returning bool from comparison function is deprecated, return an integer less than, equal to, or greater than zero in %s on line %d + +Deprecated: uasort(): Returning bool from comparison function is deprecated, return an integer less than, equal to, or greater than zero in %s on line %d + +Deprecated: usort(): Returning bool from comparison function is deprecated, return an integer less than, equal to, or greater than zero in %s on line %d + +Deprecated: uksort(): Returning bool from comparison function is deprecated, return an integer less than, equal to, or greater than zero in %s on line %d + +Deprecated: uasort(): Returning bool from comparison function is deprecated, return an integer less than, equal to, or greater than zero in %s on line %d + +Deprecated: usort(): Returning bool from comparison function is deprecated, return an integer less than, equal to, or greater than zero in %s on line %d + +Deprecated: uksort(): Returning bool from comparison function is deprecated, return an integer less than, equal to, or greater than zero in %s on line %d + +Deprecated: uasort(): Returning bool from comparison function is deprecated, return an integer less than, equal to, or greater than zero in %s on line %d +okey diff --git a/tests/std/array/usort_variation3.phpt b/tests/std/array/usort_variation3.phpt new file mode 100644 index 00000000..54db46e4 --- /dev/null +++ b/tests/std/array/usort_variation3.phpt @@ -0,0 +1,100 @@ +--TEST-- +Test usort() function : usage variations - diff. array values +--FILE-- + $value2) { + return -1; + } else { + return 1; + } +} +function main() +{ + /* + * Pass an array with different data types as keys to usort() to test how it is re-ordered + */ + echo "*** Testing usort() : usage variation ***\n"; + // different heredoc strings + // single line heredoc string + $simple_heredoc = << 9, + 8 => 8, + 012 => 7, + 0x34 => 6, + // string keys + 'key' => 5, + //single quoted key + "two" => 4, + //double quoted key + " " => 0, + // space as key + // bool keys + TRUE => 100, + FALSE => 25, + // null keys + NULL => 35, + // binary key + "a" . chr(0) . "b" => 45, + "binary" => 30, + //heredoc keys + $simple_heredoc => 75, + $multiline_heredoc => 200, + // default key + 1, + ); + var_dump(usort($array_arg, 'cmp_function')); + echo "\n-- Sorted array after usort() function call --\n"; + var_dump($array_arg); +} +?> +--EXPECT-- +*** Testing usort() : usage variation *** +bool(true) + +-- Sorted array after usort() function call -- +array(15) { + [0]=> + int(200) + [1]=> + int(100) + [2]=> + int(75) + [3]=> + int(45) + [4]=> + int(35) + [5]=> + int(30) + [6]=> + int(25) + [7]=> + int(9) + [8]=> + int(8) + [9]=> + int(7) + [10]=> + int(6) + [11]=> + int(5) + [12]=> + int(4) + [13]=> + int(1) + [14]=> + int(0) +} diff --git a/tests/std/array/usort_variation4.phpt b/tests/std/array/usort_variation4.phpt new file mode 100644 index 00000000..b8f86003 --- /dev/null +++ b/tests/std/array/usort_variation4.phpt @@ -0,0 +1,132 @@ +--TEST-- +Test usort() function : usage variations - numeric data +--FILE-- + $value2) { + return 1; + } else { + return -1; + } +} +function main() +{ + /* + * Pass arrays of numeric data to usort() to test how it is re-ordered + */ + echo "*** Testing usort() : usage variation ***\n"; + // Int array + $int_values = array(0 => 3, 1 => 2, 3 => 100, 4 => 150, 5 => 25, 6 => 350, 7 => 0, 8 => -3, 9 => -1200); + echo "\n-- Sorting Integer array --\n"; + var_dump(usort($int_values, 'cmp_function')); + var_dump($int_values); + // Octal array + $octal_values = array(0 => 056, 1 => 023, 2 => 00, 3 => 015, 4 => -045, 5 => 01, 6 => -07); + echo "\n-- Sorting Octal array --\n"; + var_dump(usort($octal_values, 'cmp_function')); + var_dump($octal_values); + // Hexadecimal array + $hex_values = array(0 => 0xae, 1 => 0x2b, 2 => 0x10, 3 => -0xcf, 4 => 0x12, 5 => -0xf2); + echo "\n-- Sorting Hex array --\n"; + var_dump(usort($hex_values, 'cmp_function')); + var_dump($hex_values); + // Float array + $float_values = array(0 => 10.2, 1 => 2.4, 2 => -3.4, 3 => 0, 4 => 0.5, 5 => 7300.0, 6 => -0.0934); + echo "\n-- Sorting Float array --\n"; + var_dump(usort($float_values, 'cmp_function')); + var_dump($float_values); + // empty array + $empty_array = array(); + echo "\n-- Sorting empty array --\n"; + var_dump(usort($empty_array, 'cmp_function')); + var_dump($empty_array); +} +?> +--EXPECT-- +*** Testing usort() : usage variation *** + +-- Sorting Integer array -- +bool(true) +array(9) { + [0]=> + int(-1200) + [1]=> + int(-3) + [2]=> + int(0) + [3]=> + int(2) + [4]=> + int(3) + [5]=> + int(25) + [6]=> + int(100) + [7]=> + int(150) + [8]=> + int(350) +} + +-- Sorting Octal array -- +bool(true) +array(7) { + [0]=> + int(-37) + [1]=> + int(-7) + [2]=> + int(0) + [3]=> + int(1) + [4]=> + int(13) + [5]=> + int(19) + [6]=> + int(46) +} + +-- Sorting Hex array -- +bool(true) +array(6) { + [0]=> + int(-242) + [1]=> + int(-207) + [2]=> + int(16) + [3]=> + int(18) + [4]=> + int(43) + [5]=> + int(174) +} + +-- Sorting Float array -- +bool(true) +array(7) { + [0]=> + float(-3.4) + [1]=> + float(-0.0934) + [2]=> + int(0) + [3]=> + float(0.5) + [4]=> + float(2.4) + [5]=> + float(10.2) + [6]=> + float(7300) +} + +-- Sorting empty array -- +bool(true) +array(0) { +} diff --git a/tests/std/array/usort_variation5.phpt b/tests/std/array/usort_variation5.phpt new file mode 100644 index 00000000..b0b93e20 --- /dev/null +++ b/tests/std/array/usort_variation5.phpt @@ -0,0 +1,116 @@ +--TEST-- +Test usort() function : usage variations - string data +--FILE-- + $value2) { + return 1; + } else { + return -1; + } +} +function main() +{ + /* + * Pass arrays of string data to usort() to test how it is re-ordered + */ + echo "*** Testing usort() : usage variation ***\n"; + // Different heredoc strings to be sorted + $empty_heredoc = << ' ', 1 => 'test', 3 => 'Hello', 4 => 'HELLO', 5 => '', 6 => '\t', 7 => '0', 8 => '123Hello', 9 => '\'', 10 => '@#$%'); + echo "\n-- Sorting Single Quoted String values --\n"; + var_dump(usort($single_quoted_values, 'cmp_function')); + var_dump($single_quoted_values); + // Double quoted strings + $double_quoted_values = array(0 => " ", 1 => "test", 3 => "Hello", 4 => "HELLO", 5 => "", 6 => "\t", 7 => "0", 8 => "123Hello", 9 => "\"", 10 => "@#\$%"); + echo "\n-- Sorting Double Quoted String values --\n"; + var_dump(usort($double_quoted_values, 'cmp_function')); + var_dump($double_quoted_values); + // Heredoc strings + $heredoc_values = array(0 => $empty_heredoc, 1 => $simple_heredoc1, 2 => $simple_heredoc2, 3 => $multiline_heredoc); + echo "\n-- Sorting Heredoc String values --\n"; + var_dump(usort($heredoc_values, 'cmp_function')); + var_dump($heredoc_values); +} +?> +--EXPECTF-- +*** Testing usort() : usage variation *** + +-- Sorting Single Quoted String values -- +bool(true) +array(10) { + [0]=> + string(0) "" + [1]=> + string(1) " " + [2]=> + string(1) "'" + [3]=> + string(1) "0" + [4]=> + string(8) "123Hello" + [5]=> + string(4) "@#$%" + [6]=> + string(5) "HELLO" + [7]=> + string(5) "Hello" + [8]=> + string(2) "\t" + [9]=> + string(4) "test" +} + +-- Sorting Double Quoted String values -- +bool(true) +array(10) { + [0]=> + string(0) "" + [1]=> + string(1) " " + [2]=> + string(1) " " + [3]=> + string(1) """ + [4]=> + string(1) "0" + [5]=> + string(8) "123Hello" + [6]=> + string(4) "@#$%" + [7]=> + string(5) "HELLO" + [8]=> + string(5) "Hello" + [9]=> + string(4) "test" +} + +-- Sorting Heredoc String values -- +bool(true) +array(4) { + [0]=> + string(0) "" + [1]=> + string(7) "HEREDOC" + [2]=> + string(7) "Heredoc" + [3]=> + string(%d) "heredoc string with!@# and 123 +Test this!!!" +} diff --git a/tests/std/array/usort_variation6.phpt b/tests/std/array/usort_variation6.phpt new file mode 100644 index 00000000..b1024907 --- /dev/null +++ b/tests/std/array/usort_variation6.phpt @@ -0,0 +1,116 @@ +--TEST-- +Test usort() function : usage variations - multi-dimensional arrays +--FILE-- + $value2) { + return 1; + } else { + return -1; + } +} +function main() +{ + /* + * Pass a multi-dimensional array as $array_arg argument to usort() + * to test how array is re-ordered + */ + echo "*** Testing usort() : usage variation ***\n"; + $array_args = array(0 => array(2, 10, -1), 1 => array(100), 2 => array(), 3 => array(0), 4 => array(-1), 5 => array(-9, 34, 54, 0, 20), 6 => array(''), 7 => array("apple", "Apple", "APPLE", "aPPle", "aPpLe")); + $temp_array = $array_args; + echo "\n-- Pass usort() a two-dimensional array --\n"; + // sorting array_arg as whole array + var_dump(usort($temp_array, 'cmp_function')); + echo "-- Array after call to usort() --\n"; + var_dump($temp_array); + echo "\n-- Pass usort() a sub-array --\n"; + var_dump(usort($array_args[5], 'cmp_function')); + echo "-- Array after call to usort() --\n"; + var_dump($array_args[5]); +} +?> +--EXPECT-- +*** Testing usort() : usage variation *** + +-- Pass usort() a two-dimensional array -- +bool(true) +-- Array after call to usort() -- +array(8) { + [0]=> + array(0) { + } + [1]=> + array(1) { + [0]=> + string(0) "" + } + [2]=> + array(1) { + [0]=> + int(-1) + } + [3]=> + array(1) { + [0]=> + int(0) + } + [4]=> + array(1) { + [0]=> + int(100) + } + [5]=> + array(3) { + [0]=> + int(2) + [1]=> + int(10) + [2]=> + int(-1) + } + [6]=> + array(5) { + [0]=> + int(-9) + [1]=> + int(34) + [2]=> + int(54) + [3]=> + int(0) + [4]=> + int(20) + } + [7]=> + array(5) { + [0]=> + string(5) "apple" + [1]=> + string(5) "Apple" + [2]=> + string(5) "APPLE" + [3]=> + string(5) "aPPle" + [4]=> + string(5) "aPpLe" + } +} + +-- Pass usort() a sub-array -- +bool(true) +-- Array after call to usort() -- +array(5) { + [0]=> + int(-9) + [1]=> + int(0) + [2]=> + int(20) + [3]=> + int(34) + [4]=> + int(54) +} diff --git a/tests/std/array/usort_variation7.phpt b/tests/std/array/usort_variation7.phpt new file mode 100644 index 00000000..ae036a58 --- /dev/null +++ b/tests/std/array/usort_variation7.phpt @@ -0,0 +1,85 @@ +--TEST-- +Test usort() function : usage variations - Anonymous comparison function +--SKIPIF-- + + +--FILE-- + $value2) { return 1; } + else { return -1; } +}; + +$array_arg = array(0 => 100, 1 => 3, 2 => -70, 3 => 24, 4 => 90); + +echo "\n-- Anonymous 'cmp_function' with parameters passed by value --\n"; +var_dump( usort($array_arg, $cmp_function) ); +var_dump($array_arg); + +$array_arg = array("b" => "Banana", "m" => "Mango", "a" => "Apple", "p" => "Pineapple"); + +$cmp_function = function(&$value1, &$value2) { + if ($value1 == $value2) { return 0; } + else if ($value1 > $value2) { return 1; } + else { return -1; } +}; + +echo "\n-- Anonymous 'cmp_function' with parameters passed by reference --\n"; +var_dump( usort($array_arg, $cmp_function) ); +var_dump($array_arg); +?> +--EXPECTF-- +*** Testing usort() : usage variation *** + +-- Anonymous 'cmp_function' with parameters passed by value -- +bool(true) +array(5) { + [0]=> + int(-70) + [1]=> + int(3) + [2]=> + int(24) + [3]=> + int(90) + [4]=> + int(100) +} + +-- Anonymous 'cmp_function' with parameters passed by reference -- + +Warning: {closure:%s:%d}(): Argument #1 ($value1) must be passed by reference, value given in %s on line %d + +Warning: {closure:%s:%d}(): Argument #2 ($value2) must be passed by reference, value given in %s on line %d + +Warning: {closure:%s:%d}(): Argument #1 ($value1) must be passed by reference, value given in %s on line %d + +Warning: {closure:%s:%d}(): Argument #2 ($value2) must be passed by reference, value given in %s on line %d + +Warning: {closure:%s:%d}(): Argument #1 ($value1) must be passed by reference, value given in %s on line %d + +Warning: {closure:%s:%d}(): Argument #2 ($value2) must be passed by reference, value given in %s on line %d + +Warning: {closure:%s:%d}(): Argument #1 ($value1) must be passed by reference, value given in %s on line %d + +Warning: {closure:%s:%d}(): Argument #2 ($value2) must be passed by reference, value given in %s on line %d +bool(true) +array(4) { + [0]=> + string(5) "Apple" + [1]=> + string(6) "Banana" + [2]=> + string(5) "Mango" + [3]=> + string(9) "Pineapple" +} diff --git a/tests/std/array/usort_variation8.phpt b/tests/std/array/usort_variation8.phpt new file mode 100644 index 00000000..2775e097 --- /dev/null +++ b/tests/std/array/usort_variation8.phpt @@ -0,0 +1,60 @@ +--TEST-- +Test usort() function : usage variations - use built in functions as $cmp_function arg +--FILE-- + "Banana", "m" => "Mango", "a" => "apple", + "p" => "Pineapple", "o" => "orange"); + +// Testing library functions as comparison function +echo "\n-- Testing usort() with built-in 'cmp_function': strcasecmp() --\n"; +$temp_array1 = $array_arg; +var_dump( usort($temp_array1, 'strcasecmp') ); +var_dump($temp_array1); + +echo "\n-- Testing usort() with built-in 'cmp_function': strcmp() --\n"; +$temp_array2 = $array_arg; +var_dump( usort($temp_array2, 'strcmp') ); +var_dump($temp_array2); + +?> +--EXPECT-- +*** Testing usort() : usage variation *** + +-- Testing usort() with built-in 'cmp_function': strcasecmp() -- +bool(true) +array(5) { + [0]=> + string(5) "apple" + [1]=> + string(6) "Banana" + [2]=> + string(5) "Mango" + [3]=> + string(6) "orange" + [4]=> + string(9) "Pineapple" +} + +-- Testing usort() with built-in 'cmp_function': strcmp() -- +bool(true) +array(5) { + [0]=> + string(6) "Banana" + [1]=> + string(5) "Mango" + [2]=> + string(9) "Pineapple" + [3]=> + string(5) "apple" + [4]=> + string(6) "orange" +} diff --git a/tests/std/array/usort_variation9.phpt b/tests/std/array/usort_variation9.phpt new file mode 100644 index 00000000..a28bb4a4 --- /dev/null +++ b/tests/std/array/usort_variation9.phpt @@ -0,0 +1,51 @@ +--TEST-- +Test usort() function : usage variations - referenced variables +--SKIPIF-- + +--FILE-- + $value2) { + return 1; + } else { + return -1; + } +} +function main() +{ + /* + * Pass an array of referenced variables as $array_arg to test behaviour + */ + echo "*** Testing usort() : usage variation ***\n"; + // different variables which are used as elements of $array_arg + $value1 = -5; + $value2 = 100; + $value3 = 0; + $value4 =& $value1; + // array_args an array containing elements with reference variables + $array_arg = array(0 => 10, 1 => &$value4, 2 => &$value2, 3 => 200, 4 => &$value3); + echo "\n-- Sorting \$array_arg containing different references --\n"; + var_dump(usort($array_arg, 'cmp_function')); + var_dump($array_arg); +} +?> +--EXPECT-- +*** Testing usort() : usage variation *** + +-- Sorting $array_arg containing different references -- +bool(true) +array(5) { + [0]=> + &int(-5) + [1]=> + &int(0) + [2]=> + int(10) + [3]=> + &int(100) + [4]=> + int(200) +} diff --git a/tests/std/array/var_export.phpt b/tests/std/array/var_export.phpt new file mode 100644 index 00000000..5c23ad26 --- /dev/null +++ b/tests/std/array/var_export.phpt @@ -0,0 +1,13 @@ +--TEST-- +var_export() and objects with numeric indexes properties +--FILE-- + "bar"); +var_export($a); +?> +--EXPECT-- +(object) array( + '0' => 1, + '1' => 3, + 'foo' => 'bar', +) diff --git a/tests/std/array/var_export2.phpt b/tests/std/array/var_export2.phpt new file mode 100644 index 00000000..6db44d5c --- /dev/null +++ b/tests/std/array/var_export2.phpt @@ -0,0 +1,13 @@ +--TEST-- +var_export() and empty array keys +--FILE-- + 'null', "" => 'empty', "0" => 'nul'); +var_export($a); +?> +--EXPECT-- +array ( + '' . "\0" . '' => 'null', + '' => 'empty', + 0 => 'nul', +) diff --git a/tests/std/array/var_export3.phpt b/tests/std/array/var_export3.phpt new file mode 100644 index 00000000..76c40155 --- /dev/null +++ b/tests/std/array/var_export3.phpt @@ -0,0 +1,25 @@ +--TEST-- +var_export() and classes +--FILE-- +mann = 42; + $this->kvinne = 43; + } +} +function main() +{ + $kake = new kake(); + var_export($kake); +} +?> +--EXPECT-- +\kake::__set_state(array( + 'mann' => 42, + 'kvinne' => 43, +))