Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New testcases for array_flip() function
- Loading branch information
Raghubansh Kumar
committed
Oct 15, 2007
1 parent
92642d0
commit 7a97b74
Showing
7 changed files
with
455 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
--TEST-- | ||
Test array_flip() function : basic functionality | ||
--FILE-- | ||
<?php | ||
/* Prototype : array array_flip(array $input) | ||
* Description: Return array with key <-> value flipped | ||
* Source code: ext/standard/array.c | ||
*/ | ||
|
||
echo "*** Testing array_flip() : basic functionality ***\n"; | ||
|
||
// array with default keys - numeric values | ||
$input = array(1, 2); | ||
var_dump( array_flip($input) ); | ||
|
||
// array with default keys - string values | ||
$input = array('value1', "value2"); | ||
var_dump( array_flip($input) ); | ||
|
||
// associative arrays - key as string | ||
$input = array('key1' => 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" | ||
?> | ||
--EXPECTF-- | ||
*** 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--TEST-- | ||
Test array_flip() function : error conditions | ||
--FILE-- | ||
<?php | ||
/* Prototype : array array_flip(array $input) | ||
* Description: Return array with key <-> value flipped | ||
* Source code: ext/standard/array.c | ||
*/ | ||
|
||
echo "*** Testing array_flip() : error conditions ***\n"; | ||
|
||
// Zero arguments | ||
echo "-- Testing array_flip() function with Zero arguments --\n"; | ||
var_dump( array_flip() ); | ||
|
||
//one more than the expected number of arguments | ||
echo "-- Testing array_flip() function with more than expected no. of arguments --\n"; | ||
$input = array(1 => 'one', 2 => 'two'); | ||
$extra_arg = 10; | ||
var_dump( array_flip($input, $extra_arg) ); | ||
|
||
echo "Done" | ||
?> | ||
--EXPECTF-- | ||
*** Testing array_flip() : error conditions *** | ||
-- Testing array_flip() function with Zero arguments -- | ||
|
||
Warning: Wrong parameter count for array_flip() in %s on line %d | ||
NULL | ||
-- Testing array_flip() function with more than expected no. of arguments -- | ||
|
||
Warning: Wrong parameter count for array_flip() in %s on line %d | ||
NULL | ||
Done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
--TEST-- | ||
Test array_flip() function : usage variations - unexpected values for 'input' argument | ||
--FILE-- | ||
<?php | ||
/* Prototype : array array_flip(array $input) | ||
* Description: Return array with key <-> value flipped | ||
* Source code: ext/standard/array.c | ||
*/ | ||
|
||
echo "*** Testing array_flip() : usage variations - unexpected values for 'input' ***\n"; | ||
|
||
//get an unset variable | ||
$unset_var = 10; | ||
unset ($unset_var); | ||
|
||
//class definition for object variable | ||
class MyClass | ||
{ | ||
public function __toString() | ||
{ | ||
return 'object'; | ||
} | ||
} | ||
|
||
//resource variable | ||
$fp = fopen(__FILE__,'r'); | ||
|
||
//array of values for 'input' argument | ||
$values = array( | ||
// int data | ||
/*1*/ 0, | ||
1, | ||
12345, | ||
-2345, | ||
|
||
// float data | ||
/*5*/ 10.5, | ||
-10.5, | ||
10.5e10, | ||
10.6E-10, | ||
.5, | ||
|
||
// null data | ||
/*10*/ NULL, | ||
null, | ||
|
||
// boolean data | ||
/*12*/ true, | ||
false, | ||
TRUE, | ||
/*15*/ FALSE, | ||
|
||
// empty data | ||
"", | ||
'', | ||
|
||
// string data | ||
"string", | ||
'string', | ||
|
||
// object data | ||
/*20*/ new MyClass(), | ||
|
||
// undefined data | ||
@$undefined_var, | ||
|
||
// unset data | ||
@$unset_var, | ||
|
||
//resource data | ||
/*23*/ $fp | ||
); | ||
|
||
// loop through each element of $values for 'input' argument | ||
for($count = 0; $count < count($values); $count++) { | ||
echo "-- Iteration ".($count + 1). " --\n"; | ||
var_dump( array_flip($values[$count]) ); | ||
}; | ||
|
||
//closing resource | ||
fclose($fp); | ||
|
||
echo "Done" | ||
?> | ||
--EXPECTF-- | ||
*** Testing array_flip() : usage variations - unexpected values for 'input' *** | ||
-- Iteration 1 -- | ||
|
||
Warning: array_flip(): The argument should be an array in %s on line %d | ||
bool(false) | ||
-- Iteration 2 -- | ||
|
||
Warning: array_flip(): The argument should be an array in %s on line %d | ||
bool(false) | ||
-- Iteration 3 -- | ||
|
||
Warning: array_flip(): The argument should be an array in %s on line %d | ||
bool(false) | ||
-- Iteration 4 -- | ||
|
||
Warning: array_flip(): The argument should be an array in %s on line %d | ||
bool(false) | ||
-- Iteration 5 -- | ||
|
||
Warning: array_flip(): The argument should be an array in %s on line %d | ||
bool(false) | ||
-- Iteration 6 -- | ||
|
||
Warning: array_flip(): The argument should be an array in %s on line %d | ||
bool(false) | ||
-- Iteration 7 -- | ||
|
||
Warning: array_flip(): The argument should be an array in %s on line %d | ||
bool(false) | ||
-- Iteration 8 -- | ||
|
||
Warning: array_flip(): The argument should be an array in %s on line %d | ||
bool(false) | ||
-- Iteration 9 -- | ||
|
||
Warning: array_flip(): The argument should be an array in %s on line %d | ||
bool(false) | ||
-- Iteration 10 -- | ||
|
||
Warning: array_flip(): The argument should be an array in %s on line %d | ||
bool(false) | ||
-- Iteration 11 -- | ||
|
||
Warning: array_flip(): The argument should be an array in %s on line %d | ||
bool(false) | ||
-- Iteration 12 -- | ||
|
||
Warning: array_flip(): The argument should be an array in %s on line %d | ||
bool(false) | ||
-- Iteration 13 -- | ||
|
||
Warning: array_flip(): The argument should be an array in %s on line %d | ||
bool(false) | ||
-- Iteration 14 -- | ||
|
||
Warning: array_flip(): The argument should be an array in %s on line %d | ||
bool(false) | ||
-- Iteration 15 -- | ||
|
||
Warning: array_flip(): The argument should be an array in %s on line %d | ||
bool(false) | ||
-- Iteration 16 -- | ||
|
||
Warning: array_flip(): The argument should be an array in %s on line %d | ||
bool(false) | ||
-- Iteration 17 -- | ||
|
||
Warning: array_flip(): The argument should be an array in %s on line %d | ||
bool(false) | ||
-- Iteration 18 -- | ||
|
||
Warning: array_flip(): The argument should be an array in %s on line %d | ||
bool(false) | ||
-- Iteration 19 -- | ||
|
||
Warning: array_flip(): The argument should be an array in %s on line %d | ||
bool(false) | ||
-- Iteration 20 -- | ||
array(0) { | ||
} | ||
-- Iteration 21 -- | ||
|
||
Warning: array_flip(): The argument should be an array in %s on line %d | ||
bool(false) | ||
-- Iteration 22 -- | ||
|
||
Warning: array_flip(): The argument should be an array in %s on line %d | ||
bool(false) | ||
-- Iteration 23 -- | ||
|
||
Warning: array_flip(): The argument should be an array in %s on line %d | ||
bool(false) | ||
Done |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
--TEST-- | ||
Test array_flip() function : usage variations - 'input' argument with different invalid values for keys | ||
--FILE-- | ||
<?php | ||
/* Prototype : array array_flip(array $input) | ||
* Description: Return array with key <-> value flipped | ||
* Source code: ext/standard/array.c | ||
*/ | ||
|
||
/* | ||
* Trying different invalid values for 'input' array argument | ||
*/ | ||
|
||
echo "*** Testing array_flip() : different invalid values in 'input' array argument ***\n"; | ||
|
||
// class definition for object data | ||
class MyClass | ||
{ | ||
public function __toString() | ||
{ | ||
return 'object'; | ||
} | ||
} | ||
$obj = new MyClass(); | ||
|
||
// resource data | ||
$fp = fopen(__FILE__, 'r'); | ||
|
||
$input = array( | ||
// float values | ||
'float_value1' => 1.2, | ||
'float_value2' => 0.5, | ||
'float_value3' => 3.4E3, | ||
'float_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: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d | ||
|
||
Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d | ||
|
||
Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d | ||
|
||
Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d | ||
|
||
Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d | ||
|
||
Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d | ||
|
||
Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d | ||
|
||
Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d | ||
|
||
Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d | ||
|
||
Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d | ||
|
||
Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d | ||
|
||
Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d | ||
array(0) { | ||
} | ||
Done |
Oops, something went wrong.