diff options
author | Raghubansh Kumar <kraghuba@php.net> | 2007-10-19 18:31:16 +0000 |
---|---|---|
committer | Raghubansh Kumar <kraghuba@php.net> | 2007-10-19 18:31:16 +0000 |
commit | dd465b457ca6da798a8fc742c0a0ca3098eb5385 (patch) | |
tree | 7b838daac8be8bd9ba176d11a5a751229fd61bc2 /ext/standard/tests | |
parent | 63b1e9fb866b6a6b182b60b040046464108f7c95 (diff) | |
download | php-git-dd465b457ca6da798a8fc742c0a0ca3098eb5385.tar.gz |
New testcases for array_fill() function
Diffstat (limited to 'ext/standard/tests')
-rw-r--r-- | ext/standard/tests/array/array_fill_basic.phpt | 97 | ||||
-rw-r--r-- | ext/standard/tests/array/array_fill_error.phpt | 61 | ||||
-rw-r--r-- | ext/standard/tests/array/array_fill_object.phpt | 432 | ||||
-rw-r--r-- | ext/standard/tests/array/array_fill_variation1.phpt | 255 | ||||
-rw-r--r-- | ext/standard/tests/array/array_fill_variation2.phpt | 213 | ||||
-rw-r--r-- | ext/standard/tests/array/array_fill_variation3.phpt | 110 | ||||
-rw-r--r-- | ext/standard/tests/array/array_fill_variation4.phpt | 168 | ||||
-rw-r--r-- | ext/standard/tests/array/array_fill_variation5.phpt | 291 |
8 files changed, 1627 insertions, 0 deletions
diff --git a/ext/standard/tests/array/array_fill_basic.phpt b/ext/standard/tests/array/array_fill_basic.phpt new file mode 100644 index 0000000000..415bbf606a --- /dev/null +++ b/ext/standard/tests/array/array_fill_basic.phpt @@ -0,0 +1,97 @@ +--TEST-- +Test array_fill() function : basic functionality +--FILE-- +<?php +/* Prototype : array array_fill(int $start_key, int $num, mixed $val) + * Description: Create an array containing num elements starting with index start_key each initialized to val + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_fill() : basic functionality ***\n"; + +// calling the array_fill with all possible valid values for 'val' argument + +$start_key = 0 ; +$num = 2; +$heredoc = <<<HERE_DOC +Hello +HERE_DOC; + +// array of possible valid values for 'val' arugment +$values = array ( + + /* 1 */ NULL, + 0, + 1, + /* 4 */ 1.5, + 'hi', + "hi", + /* 7 */ $heredoc + +); + +$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"; +?> +--EXPECTF-- +*** 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/ext/standard/tests/array/array_fill_error.phpt b/ext/standard/tests/array/array_fill_error.phpt new file mode 100644 index 0000000000..9992009f09 --- /dev/null +++ b/ext/standard/tests/array/array_fill_error.phpt @@ -0,0 +1,61 @@ +--TEST-- +Test array_fill() function : error conditions +--FILE-- +<?php +/* Prototype : array array_fill(int $start_key, int $num, mixed $val) + * Description: Create an array containing num elements starting with index start_key each initialized to val + * Source code: ext/standard/array.c + */ + + +echo "*** Testing array_fill() : error conditions ***\n"; + +// Zero arguments +echo "-- Testing array_fill() function with Zero arguments --\n"; +var_dump( array_fill() ); + +// More than expected number of arguments +echo "-- Testing array_fill() function with more than expected no. of arguments --\n"; +$start_key = 0; +$num = 2; +$val = 1; +$extra_arg = 10; +var_dump( array_fill($start_key, $num,$val, $extra_arg) ); + +// Less than the expected number of arguments +echo "-- Testing array_fill() function with less than expected no. of arguments --\n"; +$start_key = 0; +$num = 2; +var_dump( array_fill($start_key, $num) ); + +//calling array_fill with negative values for 'num' parameter +$num = -1; +var_dump( array_fill($start_key, $num, $val) ); + +//callin array_fill with 'num' equal to zero value +$num = 0; +var_dump( array_fill($start_key, $num, $val) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_fill() : error conditions *** +-- Testing array_fill() function with Zero arguments -- + +Warning: Wrong parameter count for array_fill() in %s on line %d +NULL +-- Testing array_fill() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for array_fill() in %s on line %d +NULL +-- Testing array_fill() function with less than expected no. of arguments -- + +Warning: Wrong parameter count for array_fill() in %s on line %d +NULL + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/array/array_fill_object.phpt b/ext/standard/tests/array/array_fill_object.phpt new file mode 100644 index 0000000000..0714962c1c --- /dev/null +++ b/ext/standard/tests/array/array_fill_object.phpt @@ -0,0 +1,432 @@ +--TEST-- +Test array_fill() function : usage variations - various object values for 'val' argument +--FILE-- +<?php +/* Prototype : array array_fill(int $start_key, int $num, mixed $val) + * Description: Create an array containing num elements starting with index start_key each initialized to val + * Source code: ext/standard/array.c + */ + +/* + * 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; + +// class without a member +class Test +{ +} + +//class with public, static, constant members and consturctor to initialize the public member +class Test1 +{ + const test1_constant = "test1"; + public static $test1_static = 0; + public $member1; + var $var1 = 30; + var $var2; + + function __construct($value1, $value2) + { + $this->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, static, constant members 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, static, constant members 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"; + } +} + +//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) { + ["member2"]=> + int(102) + ["member1"]=> + int(100) + ["var1"]=> + int(30) + ["var2"]=> + int(101) + } + [1]=> + object(Child_test1)#%d (4) { + ["member2"]=> + int(102) + ["member1"]=> + int(100) + ["var1"]=> + int(30) + ["var2"]=> + int(101) + } +} +-- Iteration 4 -- +array(2) { + [0]=> + object(Test2)#%d (3) { + ["member1:private"]=> + int(100) + ["var1"]=> + int(30) + ["var2"]=> + int(101) + } + [1]=> + object(Test2)#%d (3) { + ["member1:private"]=> + int(100) + ["var1"]=> + int(30) + ["var2"]=> + int(101) + } +} +-- Iteration 5 -- +array(2) { + [0]=> + object(Child_test2)#%d (4) { + ["member1:private"]=> + int(102) + ["member1:private"]=> + int(100) + ["var1"]=> + int(30) + ["var2"]=> + int(101) + } + [1]=> + object(Child_test2)#%d (4) { + ["member1:private"]=> + int(102) + ["member1:private"]=> + int(100) + ["var1"]=> + int(30) + ["var2"]=> + int(101) + } +} +-- 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:private"]=> + int(101) + ["member3:protected"]=> + int(102) + } + [1]=> + object(Test4)#%d (3) { + ["member1"]=> + int(100) + ["member2:private"]=> + int(101) + ["member3:protected"]=> + int(102) + } +} +-- Iteration 9 -- +array(2) { + [0]=> + object(Child_test4)#%d (4) { + ["var1"]=> + int(103) + ["member1"]=> + int(100) + ["member2:private"]=> + int(101) + ["member3:protected"]=> + int(102) + } + [1]=> + object(Child_test4)#%d (4) { + ["var1"]=> + int(103) + ["member1"]=> + int(100) + ["member2:private"]=> + int(101) + ["member3:protected"]=> + int(102) + } +} +-- Iteration 10 -- +array(2) { + [0]=> + object(ConcreteClass1)#%d (4) { + ["member1"]=> + NULL + ["member2:private"]=> + NULL + ["member3:protected"]=> + NULL + ["var1"]=> + int(30) + } + [1]=> + object(ConcreteClass1)#%d (4) { + ["member1"]=> + NULL + ["member2:private"]=> + NULL + ["member3:protected"]=> + NULL + ["var1"]=> + int(30) + } +} +-- Iteration 11 -- +array(2) { + [0]=> + object(Template1)#%d (0) { + } + [1]=> + object(Template1)#%d (0) { + } +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_fill_variation1.phpt b/ext/standard/tests/array/array_fill_variation1.phpt new file mode 100644 index 0000000000..b265f63834 --- /dev/null +++ b/ext/standard/tests/array/array_fill_variation1.phpt @@ -0,0 +1,255 @@ +--TEST-- +Test array_fill() function : usage variations - unexpected values for 'start_key' argument(Bug#43017) +--FILE-- +<?php +/* Prototype : array array_fill(int $start_key, int $num, mixed $val) + * Description: Create an array containing num elements starting with index start_key each initialized to val + * Source code: ext/standard/array.c + */ + +/* + * testing array_fill() by passing different unexpected value for 'start_key' argument + */ + +echo "*** Testing array_fill() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$num = 2; +$val = 100; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//get a resource variable +$fp = fopen(__FILE__, "r"); + +//define a class +class test +{ + var $t = 10; + function __toString() + { + return "testObject"; + } +} + + +//array of different values for 'start_key' argument +$values = array( + + // float values + /* 1 */ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // array values + /* 6 */ array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null values + /* 11 */ NULL, + null, + + // boolean values + /* 13 */ true, + false, + TRUE, + FALSE, + + // empty string + /* 17 */ "", + '', + + // string values + /* 19 */ "string", + 'string', + + // objects + /* 21 */ new test(), + + // undefined variable + @$undefined_var, + + // unset variable + @$unset_var, + + // resource variable + /* 24 */ $fp +); + +// loop through each element of the array for start_key +// check the working of array_fill() +echo "--- Testing array_fill() with different values for 'start_key' arg ---\n"; +$counter = 1; +for($index = 0; $index < count($values); $index ++) +{ + echo "-- Iteration $counter --\n"; + $start_key = $values[$index]; + + var_dump( array_fill($start_key,$num,$val) ); + + $counter ++; +} + +// close the resource used +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_fill() : usage variations *** +--- Testing array_fill() with different values for 'start_key' arg --- +-- Iteration 1 -- +array(2) { + [10]=> + int(100) + [11]=> + int(100) +} +-- Iteration 2 -- +array(2) { + [-10]=> + int(100) + [0]=> + int(100) +} +-- Iteration 3 -- +array(2) { + [-1097262584]=> + int(100) + [0]=> + int(100) +} +-- Iteration 4 -- +array(2) { + [0]=> + int(100) + [1]=> + int(100) +} +-- Iteration 5 -- +array(2) { + [0]=> + int(100) + [1]=> + int(100) +} +-- Iteration 6 -- + +Warning: array_fill(): Wrong data type for start key in %s on line %d +bool(false) +-- Iteration 7 -- + +Warning: array_fill(): Wrong data type for start key in %s on line %d +bool(false) +-- Iteration 8 -- + +Warning: array_fill(): Wrong data type for start key in %s on line %d +bool(false) +-- Iteration 9 -- + +Warning: array_fill(): Wrong data type for start key in %s on line %d +bool(false) +-- Iteration 10 -- + +Warning: array_fill(): Wrong data type for start key in %s on line %d +bool(false) +-- Iteration 11 -- + +array(2) { + [0]=> + int(100) + [1]=> + int(100) +} +-- Iteration 12 -- + +array(2) { + [0]=> + int(100) + [1]=> + int(100) +} +-- Iteration 13 -- + +array(2) { + [1]=> + int(100) + [2]=> + int(100) +} +-- Iteration 14 -- + +array(2) { + [0]=> + int(100) + [1]=> + int(100) +} +-- Iteration 15 -- + +array(2) { + [1]=> + int(100) + [2]=> + int(100) +} +-- Iteration 16 -- + +array(2) { + [0]=> + int(100) + [1]=> + int(100) +} +-- Iteration 17 -- +array(2) { + [0]=> + int(100) + [1]=> + int(100) +} +-- Iteration 18 -- +array(2) { + [0]=> + int(100) + [1]=> + int(100) +} +-- Iteration 19 -- +array(2) { + [0]=> + int(100) + [1]=> + int(100) +} +-- Iteration 20 -- +array(2) { + [0]=> + int(100) + [1]=> + int(100) +} +-- Iteration 21 -- + +Warning: array_fill(): Wrong data type for start key in %s on line %d +bool(false) +-- Iteration 22 -- + +Warning: array_fill(): Wrong data type for start key in %s on line %d +bool(false) +-- Iteration 23 -- + +Warning: array_fill(): Wrong data type for start key in %s on line %d +bool(false) +-- Iteration 24 -- + +Warning: array_fill(): Wrong data type for start key in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/array/array_fill_variation2.phpt b/ext/standard/tests/array/array_fill_variation2.phpt new file mode 100644 index 0000000000..9eb635fded --- /dev/null +++ b/ext/standard/tests/array/array_fill_variation2.phpt @@ -0,0 +1,213 @@ +--TEST-- +Test array_fill() function : usage variations - unexpected values for 'num' argument +--FILE-- +<?php +/* Prototype : array array_fill(int $start_key, int $num, mixed $val) + * Description: Create an array containing num elements starting with index start_key each initialized to val + * Source code: ext/standard/array.c + */ + +/* + * testing array_fill() by passing different unexpected values for 'num' argument + */ + +echo "*** Testing array_fill() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$start_key = 0; +$val = 100; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//define a class +class test +{ + var $t = 10; + function __toString() + { + return "testObject"; + } +} + + +//array of different values for 'num' argument +$values = array( + + // float values + /* 1 */ 2.5, + -2.5, + 0.5e1, + 0.5E-1, + .5, + + // array values + /* 6 */ array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null values + /* 11 */ NULL, + null, + + // boolean values + /* 13 */ true, + false, + TRUE, + FALSE, + + // empty string + /* 17 */ "", + '', + + // string values + /* 19 */ "string", + 'string', + + // objects + /* 21 */ new test(), + + // undefined variable + @$undefined_var, + + // unset variable + /* 23 */ @$unset_var, + +); + +// loop through each element of the array for num +// check the working of array_fill +echo "--- Testing array_fill() with different values for 'num' arg ---\n"; +$counter = 1; +for($index = 0; $index < count($values); $index ++) +{ + echo "-- Iteration $counter --\n"; + $num = $values[$index]; + + var_dump( array_fill($start_key, $num, $val) ); + + $counter ++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_fill() : usage variations *** +--- Testing array_fill() with different values for 'num' arg --- +-- Iteration 1 -- +array(2) { + [0]=> + int(100) + [1]=> + int(100) +} +-- Iteration 2 -- + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) +-- Iteration 3 -- +array(5) { + [0]=> + int(100) + [1]=> + int(100) + [2]=> + int(100) + [3]=> + int(100) + [4]=> + int(100) +} +-- Iteration 4 -- + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) +-- Iteration 5 -- + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) +-- Iteration 6 -- + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) +-- Iteration 7 -- +array(1) { + [0]=> + int(100) +} +-- Iteration 8 -- +array(1) { + [0]=> + int(100) +} +-- Iteration 9 -- +array(1) { + [0]=> + int(100) +} +-- Iteration 10 -- +array(1) { + [0]=> + int(100) +} +-- Iteration 11 -- + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) +-- Iteration 12 -- + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) +-- Iteration 13 -- +array(1) { + [0]=> + int(100) +} +-- Iteration 14 -- + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) +-- Iteration 15 -- +array(1) { + [0]=> + int(100) +} +-- Iteration 16 -- + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) +-- Iteration 17 -- + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) +-- Iteration 18 -- + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) +-- Iteration 19 -- + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) +-- Iteration 20 -- + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) +-- Iteration 21 -- + +Notice: Object of class test could not be converted to int in %s on line %d +array(1) { + [0]=> + int(100) +} +-- Iteration 22 -- + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) +-- Iteration 23 -- + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/array/array_fill_variation3.phpt b/ext/standard/tests/array/array_fill_variation3.phpt new file mode 100644 index 0000000000..fbb22d8696 --- /dev/null +++ b/ext/standard/tests/array/array_fill_variation3.phpt @@ -0,0 +1,110 @@ +--TEST-- +Test array_fill() function : usage variations - unexpected values for 'val' argument +--FILE-- +<?php +/* Prototype : array array_fill(int $start_key, int $num, mixed $val) + * Description: Create an array containing num elements starting with index start_key each initialized to val + * Source code: ext/standard/array.c + */ + +/* + * testing array_fill() by passing different unexpected values for 'val' argument + */ + +echo "*** Testing array_fill() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$start_key = 0; +$num = 2; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define a class +class test +{ + var $t = 10; + function __toString() + { + return "testObject"; + } +} + + +//array of different values for 'val' argument +$values = array( + // empty string + /* 1 */ "", + '', + // objects + /* 3 */ new test(), + + // undefined variable + @$undefined_var, + + // unset variable + /* 5 */ @$unset_var, +); + +// loop through each element of the array for 'val' argument +// check the working of array_fill() +echo "--- Testing array_fill() with different values for 'val' argument ---\n"; +$counter = 1; +for($index = 0; $index < count($values); $index ++) +{ + echo "-- Iteration $counter --\n"; + $val = $values[$index]; + + var_dump( array_fill($start_key, $num, $val) ); + + $counter++; +} + +echo"Done"; +?> +--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
\ No newline at end of file diff --git a/ext/standard/tests/array/array_fill_variation4.phpt b/ext/standard/tests/array/array_fill_variation4.phpt new file mode 100644 index 0000000000..247761db37 --- /dev/null +++ b/ext/standard/tests/array/array_fill_variation4.phpt @@ -0,0 +1,168 @@ +--TEST-- +Test array_fill() function : usage variations - using return value of array_fill as 'val' arugment +--FILE-- +<?php +/* Prototype : array array_fill(int $start_key, int $num, mixed $val) + * Description: Create an array containing num elements starting with index start_key each initialized to val + * Source code: ext/standard/array.c + */ + +/* passing array_fill() as the 'val' argument in array_fill() function */ + +echo "*** Testing array_fill() : variation ***\n"; + +$start_key = 0; +$num = 2; +$heredoc = <<<HERE_DOC +Hello +HERE_DOC; + +// array of possible valid values for 'val' arugment +$values = array ( + + /* 1 */ NULL, + 0, + 1, + /* 4 */ 1.0, + 'hi', + "hi", + /* 7 */ $heredoc +); + +echo "*** Filling 2 dimensional array with all basic valid values ***\n"; +$counter = 1; +for($i =0; $i < count($values); $i ++) +{ + echo "-- Iteration $counter --\n"; + $val = $values[$i]; + + var_dump( array_fill($start_key, $num, array_fill($start_key, $num, $val)) ); + + $counter++; +} + +echo "Done"; +?> +--EXPECTF-- +*** 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/ext/standard/tests/array/array_fill_variation5.phpt b/ext/standard/tests/array/array_fill_variation5.phpt new file mode 100644 index 0000000000..6260c36bd6 --- /dev/null +++ b/ext/standard/tests/array/array_fill_variation5.phpt @@ -0,0 +1,291 @@ +--TEST-- +Test array_fill() function : usage variations - different types of array values for 'val' argument +--FILE-- +<?php +/* Prototype : array array_fill(int $start_key, int $num, mixed $val) + * Description: Create an array containing num elements starting with index start_key each initialized to val + * Source code: ext/standard/array.c + */ + +/* + * testing array_fill() by passing different types of array values for 'val' argument + */ + +echo "*** Testing array_fill() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$start_key = 0; +$num = 2; + + +//array of different types of array values for 'val' argument +$values = array( + + /* 1 */ array(), + array(1 , 2 , 3 , 4), + array(1 => "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"; +?> +--EXPECTF-- +*** 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 |