diff options
author | Josie Messa <jmessa@php.net> | 2008-02-13 14:20:58 +0000 |
---|---|---|
committer | Josie Messa <jmessa@php.net> | 2008-02-13 14:20:58 +0000 |
commit | 4546084866d69a0b7c6e54cef4a8b33334debd57 (patch) | |
tree | d22405616218cb90a2b355d62669887344a064d1 /ext/standard | |
parent | 6b522fdd5071b3d7c7772ac22ecb5a1e0b7eede4 (diff) | |
download | php-git-4546084866d69a0b7c6e54cef4a8b33334debd57.tar.gz |
- committing tests for array_merge() function
Diffstat (limited to 'ext/standard')
-rw-r--r-- | ext/standard/tests/array/array_merge_basic.phpt | 58 | ||||
-rw-r--r-- | ext/standard/tests/array/array_merge_error.phpt | 30 | ||||
-rw-r--r-- | ext/standard/tests/array/array_merge_variation1.phpt | 231 | ||||
-rw-r--r-- | ext/standard/tests/array/array_merge_variation10.phpt | 70 | ||||
-rw-r--r-- | ext/standard/tests/array/array_merge_variation2.phpt | 230 | ||||
-rw-r--r-- | ext/standard/tests/array/array_merge_variation3.phpt | 379 | ||||
-rw-r--r-- | ext/standard/tests/array/array_merge_variation4.phpt | 368 | ||||
-rw-r--r-- | ext/standard/tests/array/array_merge_variation5.phpt | 61 | ||||
-rw-r--r-- | ext/standard/tests/array/array_merge_variation6.phpt | 53 | ||||
-rw-r--r-- | ext/standard/tests/array/array_merge_variation7.phpt | 65 | ||||
-rw-r--r-- | ext/standard/tests/array/array_merge_variation8.phpt | 74 | ||||
-rw-r--r-- | ext/standard/tests/array/array_merge_variation9.phpt | 112 |
12 files changed, 1731 insertions, 0 deletions
diff --git a/ext/standard/tests/array/array_merge_basic.phpt b/ext/standard/tests/array/array_merge_basic.phpt new file mode 100644 index 0000000000..c4dc69638e --- /dev/null +++ b/ext/standard/tests/array/array_merge_basic.phpt @@ -0,0 +1,58 @@ +--TEST-- +Test array_merge() function : basic functionality +--FILE-- +<?php +/* Prototype : array array_merge(array $arr1, array $arr2 [, array $...]) + * Description: Merges elements from passed arrays into one array + * Source code: ext/standard/array.c + */ + +/* + * Test basic functionality of array_merge() + */ + +echo "*** Testing array_merge() : basic functionality ***\n"; + +//indexed array +$array1 = array ('zero', 'one', 'two'); +//associative array +$array2 = array ('a' => 1, 'b' => 2, 'c' => 3); + +var_dump(array_merge($array1, $array2)); + +var_dump(array_merge($array2, $array1)); + +echo "Done"; +?> + +--EXPECTF-- +*** 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
\ No newline at end of file diff --git a/ext/standard/tests/array/array_merge_error.phpt b/ext/standard/tests/array/array_merge_error.phpt new file mode 100644 index 0000000000..3a394bbb73 --- /dev/null +++ b/ext/standard/tests/array/array_merge_error.phpt @@ -0,0 +1,30 @@ +--TEST-- +Test array_merge() function : error conditions - Pass incorrect number of args +--FILE-- +<?php +/* Prototype : array array_merge(array $arr1, array $arr2 [, array $...]) + * Description: Merges elements from passed arrays into one array + * Source code: ext/standard/array.c + */ + +/* + * Pass incorrect number of arguments to array_merge() to test behaviour + */ + +echo "*** Testing array_merge() : error conditions ***\n"; + +// Testing array_merge with zero arguments +echo "\n-- Testing array_merge() function with less than expected no. of arguments --\n"; +$arr1 = array(1, 2); +var_dump( array_merge() ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_merge() : error conditions *** + +-- Testing array_merge() function with less than expected no. of arguments -- + +Warning: Wrong parameter count for array_merge() in %s on line %d +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_merge_variation1.phpt b/ext/standard/tests/array/array_merge_variation1.phpt new file mode 100644 index 0000000000..1ce71debb0 --- /dev/null +++ b/ext/standard/tests/array/array_merge_variation1.phpt @@ -0,0 +1,231 @@ +--TEST-- +Test array_merge() function : usage variations - Pass different data types to $arr1 arg +--FILE-- +<?php +/* Prototype : array array_merge(array $arr1, array $arr2 [, array $...]) + * Description: Merges elements from passed arrays into one array + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $arr1 argument to test behaviour + */ + +echo "*** Testing array_merge() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$arr2 = array (1, 2); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $arr1 argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of array_merge() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( array_merge($input, $arr2) ); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_merge() : usage variations *** + +-- Iteration 1 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 18 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + +-- Iteration 19 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_merge_variation10.phpt b/ext/standard/tests/array/array_merge_variation10.phpt new file mode 100644 index 0000000000..7f08a4bb78 --- /dev/null +++ b/ext/standard/tests/array/array_merge_variation10.phpt @@ -0,0 +1,70 @@ +--TEST-- +Test array_merge() function : usage variations - position of internal array pointer +--FILE-- +<?php +/* Prototype : array array_merge(array $arr1, array $arr2 [, array $...]) + * Description: Merges elements from passed arrays into one array + * Source code: ext/standard/array.c + */ + +/* + * Check the position of the internal array pointer after calling array_merge(). + * This test is also passing more than two arguments to array_merge(). + */ + +echo "*** Testing array_merge() : usage variations ***\n"; + +$arr1 = array ('zero', 'one', 'two'); +$arr2 = array ('zero', 'un', 'deux'); +$arr3 = array ('null', 'eins', 'zwei'); + +echo "\n-- Call array_merge() --\n"; +var_dump($result = array_merge($arr1, $arr2, $arr3)); + +echo "\n-- Position of Internal Pointer in Result: --\n"; +echo key($result) . " => " . 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"; +?> + +--EXPECTF-- +*** 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
\ No newline at end of file diff --git a/ext/standard/tests/array/array_merge_variation2.phpt b/ext/standard/tests/array/array_merge_variation2.phpt new file mode 100644 index 0000000000..4ebbeb92b9 --- /dev/null +++ b/ext/standard/tests/array/array_merge_variation2.phpt @@ -0,0 +1,230 @@ +--TEST-- +Test array_merge() function : usage variations - Pass different data types as $arr2 arg +--FILE-- +<?php +/* Prototype : array array_merge(array $arr1, array $arr2 [, array $...]) + * Description: Merges elements from passed arrays into one array + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $arr2 argument to array_merge() to test behaviour + */ + +echo "*** Testing array_merge() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$arr1 = array (1, 2); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $arr2 argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of array_merge() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( array_merge($arr1, $input) ); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_merge() : usage variations *** + +-- Iteration 1 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 18 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + +-- Iteration 19 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_merge_variation3.phpt b/ext/standard/tests/array/array_merge_variation3.phpt new file mode 100644 index 0000000000..717968adb8 --- /dev/null +++ b/ext/standard/tests/array/array_merge_variation3.phpt @@ -0,0 +1,379 @@ +--TEST-- +Test array_merge() function : usage variations - arrays of diff. data types +--FILE-- +<?php +/* Prototype : array array_merge(array $arr1, array $arr2 [, array $...]) + * Description: Merges elements from passed arrays into one array + * Source code: ext/standard/array.c + */ + +/* + * Pass arrays of different data types to test how array_merge adds them + * onto an existing array + */ + +echo "*** Testing array_merge() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$arr = array (1, 2); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// arrays of different data types to be passed as $input +$inputs = array( + + // int data +/*1*/ 'int' => array( + 0, + 1, + 12345, + -2345, + ), + + // float data +/*2*/ 'float' => array( + 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .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
\ No newline at end of file diff --git a/ext/standard/tests/array/array_merge_variation4.phpt b/ext/standard/tests/array/array_merge_variation4.phpt new file mode 100644 index 0000000000..e4eb2570cd --- /dev/null +++ b/ext/standard/tests/array/array_merge_variation4.phpt @@ -0,0 +1,368 @@ +--TEST-- +Test array_merge() function : usage variations - Diff. data types as array keys +--FILE-- +<?php +/* Prototype : array array_merge(array $arr1, array $arr2 [, array $...]) + * Description: Merges elements from passed arrays into one array + * Source code: ext/standard/array.c + */ + +/* + * Pass an array with different data types as keys to test how array_merge + * adds it onto an existing array + */ + +echo "*** Testing array_merge() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$arr = array ('one' => 1, 'two' => 2); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// arrays with keys as different data types to be passed as $input +$inputs = array( + + // int data +/*1*/ 'int' => array( + 0 => 'zero', + 1 => 'one', + 12345 => 'positive', + -2345 => 'negative', + ), + + // float data +/*2*/ 'float' => array( + 10.5 => 'positive', + -10.5 => 'negative', + .5 => 'half', + ), + +/*3*/ 'extreme floats' => array( + 12.3456789000e10 => 'large', + 12.3456789000E-10 => 'small', + ), + + // 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"; +?> +--EXPECTF-- +*** 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: float data -- +array(5) { + [0]=> + string(8) "positive" + [1]=> + string(8) "negative" + [2]=> + string(4) "half" + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(5) { + ["one"]=> + int(1) + ["two"]=> + int(2) + [0]=> + string(8) "positive" + [1]=> + string(8) "negative" + [2]=> + string(4) "half" +} + +-- Iteration 3: extreme floats data -- +array(4) { + [0]=> + string(5) "large" + [1]=> + string(5) "small" + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(4) { + ["one"]=> + int(1) + ["two"]=> + int(2) + [0]=> + string(5) "large" + [1]=> + string(5) "small" +} + +-- Iteration 4: 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 5: 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 6: 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 7: 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 8: 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 9: 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 10: 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 11: 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 12: 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
\ No newline at end of file diff --git a/ext/standard/tests/array/array_merge_variation5.phpt b/ext/standard/tests/array/array_merge_variation5.phpt new file mode 100644 index 0000000000..eca6078e6a --- /dev/null +++ b/ext/standard/tests/array/array_merge_variation5.phpt @@ -0,0 +1,61 @@ +--TEST-- +Test array_merge() function : usage variations - numeric keys +--FILE-- +<?php +/* Prototype : array array_merge(array $arr1, array $arr2 [, array $...]) + * Description: Merges elements from passed arrays into one array + * Source code: ext/standard/array.c + */ + +/* + * Pass array_merge() arrays with only numeric keys to test behaviour. + * $arr2 contains a duplicate element to $arr1. + */ + +echo "*** Testing array_merge() : usage variations ***\n"; + +//numeric keys +$arr1 = array('zero', 'one', 'two', 'three'); +$arr2 = array(1 => 'one', 20 => 'twenty', 30 => 'thirty'); + +var_dump(array_merge($arr1, $arr2)); +var_dump(array_merge($arr2, $arr1)); + +echo "Done"; +?> + +--EXPECTF-- +*** 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
\ No newline at end of file diff --git a/ext/standard/tests/array/array_merge_variation6.phpt b/ext/standard/tests/array/array_merge_variation6.phpt new file mode 100644 index 0000000000..13b346eb3f --- /dev/null +++ b/ext/standard/tests/array/array_merge_variation6.phpt @@ -0,0 +1,53 @@ +--TEST-- +Test array_merge() function : usage variations - string keys +--FILE-- +<?php +/* Prototype : array array_merge(array $arr1, array $arr2 [, array $...]) + * Description: Merges elements from passed arrays into one array + * Source code: ext/standard/array.c + */ + +/* + * Pass array_merge arrays with string keys to test behaviour. + * $arr2 has a duplicate key to $arr1 + */ + +echo "*** Testing array_merge() : usage variations ***\n"; + +//string keys +$arr1 = array('zero' => '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"; +?> + +--EXPECTF-- +*** 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
\ No newline at end of file diff --git a/ext/standard/tests/array/array_merge_variation7.phpt b/ext/standard/tests/array/array_merge_variation7.phpt new file mode 100644 index 0000000000..00943f3ea4 --- /dev/null +++ b/ext/standard/tests/array/array_merge_variation7.phpt @@ -0,0 +1,65 @@ +--TEST-- +Test array_merge() function : usage variations - Mixed keys +--FILE-- +<?php +/* Prototype : array array_merge(array $arr1, array $arr2 [, array $...]) + * Description: Merges elements from passed arrays into one array + * Source code: ext/standard/array.c + */ + +/* + * Pass array_merge() arrays with mixed keys to test how it attaches them to + * existing arrays + */ + +echo "*** Testing array_merge() : usage variations ***\n"; + +//mixed keys +$arr1 = array('zero', 20 => 'twenty', 'thirty' => 30, true => 'bool'); +$arr2 = array(0, 1, 2, null => 'null', 1.234E-10 => 'float'); + +var_dump(array_merge($arr1, $arr2)); +var_dump(array_merge($arr2, $arr1)); + +echo "Done"; +?> + +--EXPECTF-- +*** 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
\ No newline at end of file diff --git a/ext/standard/tests/array/array_merge_variation8.phpt b/ext/standard/tests/array/array_merge_variation8.phpt new file mode 100644 index 0000000000..a4cdea74fe --- /dev/null +++ b/ext/standard/tests/array/array_merge_variation8.phpt @@ -0,0 +1,74 @@ +--TEST-- +Test array_merge() function : usage variations - multi-dimensional arrays +--FILE-- +<?php +/* Prototype : array array_merge(array $arr1, array $arr2 [, array $...]) + * Description: Merges elements from passed arrays into one array + * Source code: ext/standard/array.c + */ + +/* + * Test array_merge() with multi-dimensional arrays + */ + +echo "*** Testing array_merge() : usage variations ***\n"; + +$arr1 = array('zero', 'one', 'two', array(0)); +$arr2 = array(1, 2, 3); + +echo "\n-- Merge a two-dimensional and a one-dimensional array --\n"; +var_dump(array_merge($arr1, $arr2)); + +echo "\n-- Merge an array and a sub-array --\n"; +var_dump(array_merge($arr1[3], $arr2)); +var_dump(array_merge($arr2, $arr1[3])); + +echo "Done"; +?> + +--EXPECTF-- +*** 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
\ No newline at end of file diff --git a/ext/standard/tests/array/array_merge_variation9.phpt b/ext/standard/tests/array/array_merge_variation9.phpt new file mode 100644 index 0000000000..34ab3e8218 --- /dev/null +++ b/ext/standard/tests/array/array_merge_variation9.phpt @@ -0,0 +1,112 @@ +--TEST-- +Test array_merge() function : usage variations - referenced variables +--FILE-- +<?php +/* Prototype : array array_merge(array $arr1, array $arr2 [, array $...]) + * Description: Merges elements from passed arrays into one array + * Source code: ext/standard/array.c + */ + +/* Test array_merge() when: + * 1. Passed an array made up of referenced variables + * 2. Passed an array as the first argument and a reference to that array as the second. + */ + +echo "*** Testing array_merge() : usage variations ***\n"; + +$val1 = 'foo'; +$val2 = 'bar'; +$val3 = 'baz'; + +$arr1 = array(&$val1, &$val2, &$val3); +$arr2 = array('key1' => '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 "\n-- Merge an array and a reference to the first array --\n"; +var_dump(array_merge($arr2, &$arr2)); + +echo "Done"; +?> + +--EXPECTF-- +*** 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" +} + +-- Merge an array and a reference to the first array -- +array(3) { + ["key1"]=> + string(4) "val1" + ["key2"]=> + string(4) "val2" + ["key3"]=> + string(4) "val3" +} +Done
\ No newline at end of file |