jmessa Thu Feb 14 16:49:17 2008 UTC
Added files: (Branch: PHP_5_2)
/php-src/ext/standard/tests/array count_variation2.phpt
count_variation3.phpt
count_error.phpt count_basic.phpt
count_variation1.phpt
Log:
- New tests for count() function
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/count_variation2.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/array/count_variation2.phpt
+++ php-src/ext/standard/tests/array/count_variation2.phpt
--TEST--
Test count() function : usage variations - Pass different data types as $mode
arg
--FILE--
<?php
/* Prototype : int count(mixed $var [, int $mode])
* Description: Count the number of elements in a variable (usually an array)
* Source code: ext/standard/array.c
*/
/*
* Pass different data types as $mode argument to count() to test behaviour
*/
echo "*** Testing count() : usage variations ***\n";
// Initialise function arguments not being substituted
$var = array(1, 2, array ('one', 'two'));
//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 $mode 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*/ "",
'',
// string data
/*18*/ "string",
'string',
$heredoc,
// object data
/*21*/ new classA(),
// undefined data
/*22*/ @$undefined_var,
// unset data
/*23*/ @$unset_var,
// resource variable
/*24*/ $fp
);
// loop through each element of $inputs to check the behavior of count()
$iterator = 1;
foreach($inputs as $input) {
echo "\n-- Iteration $iterator --\n";
var_dump( count($var, $input) );
$iterator++;
};
fclose($fp);
echo "Done";
?>
--EXPECTF--
*** Testing count() : usage variations ***
-- Iteration 1 --
int(3)
-- Iteration 2 --
int(5)
-- 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(5)
-- Iteration 13 --
int(3)
-- Iteration 14 --
int(5)
-- Iteration 15 --
int(3)
-- Iteration 16 --
Warning: count() expects parameter 2 to be long, string given in %s on line %d
NULL
-- Iteration 17 --
Warning: count() expects parameter 2 to be long, string given in %s on line %d
NULL
-- Iteration 18 --
Warning: count() expects parameter 2 to be long, string given in %s on line %d
NULL
-- Iteration 19 --
Warning: count() expects parameter 2 to be long, string given in %s on line %d
NULL
-- Iteration 20 --
Warning: count() expects parameter 2 to be long, string given in %s on line %d
NULL
-- Iteration 21 --
Warning: count() expects parameter 2 to be long, object given in %s on line %d
NULL
-- Iteration 22 --
int(3)
-- Iteration 23 --
int(3)
-- Iteration 24 --
Warning: count() expects parameter 2 to be long, resource given in %s on line %d
NULL
Done
--UEXPECTF--
*** Testing count() : usage variations ***
-- Iteration 1 --
int(3)
-- Iteration 2 --
int(5)
-- 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(5)
-- Iteration 13 --
int(3)
-- Iteration 14 --
int(5)
-- Iteration 15 --
int(3)
-- Iteration 16 --
Warning: count() expects parameter 2 to be long, Unicode string given in %s on
line %d
NULL
-- Iteration 17 --
Warning: count() expects parameter 2 to be long, Unicode string given in %s on
line %d
NULL
-- Iteration 18 --
Warning: count() expects parameter 2 to be long, Unicode string given in %s on
line %d
NULL
-- Iteration 19 --
Warning: count() expects parameter 2 to be long, Unicode string given in %s on
line %d
NULL
-- Iteration 20 --
Warning: count() expects parameter 2 to be long, Unicode string given in %s on
line %d
NULL
-- Iteration 21 --
Warning: count() expects parameter 2 to be long, object given in %s on line %d
NULL
-- Iteration 22 --
int(3)
-- Iteration 23 --
int(3)
-- Iteration 24 --
Warning: count() expects parameter 2 to be long, resource given in %s on line %d
NULL
Done
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/count_variation3.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/array/count_variation3.phpt
+++ php-src/ext/standard/tests/array/count_variation3.phpt
--TEST--
Test count() function : usage variations - Infinitely recursive array
--FILE--
<?php
/* Prototype : int count(mixed $var [, int $mode])
* Description: Count the number of elements in a variable (usually an array)
* Source code: ext/standard/array.c
*/
/*
* Pass count() an infinitely recursive array as $var argument
* This will stop the script before it reaches the end.
*/
echo "*** Testing count() : usage variations ***\n";
$array1 = array (1, 2, 'three');
// get an infinitely recursive array
$array1[] = &$array1;
echo "\n-- \$mode not set: --\n";
var_dump(count ($array1));
echo "\n-- \$mode = 1: --\n";
var_dump(count ($array1, 1));
echo "Done";
?>
--EXPECTF--
*** Testing count() : usage variations ***
-- $mode not set: --
int(4)
-- $mode = 1: --
--UEXPECTF--
*** Testing count() : usage variations ***
-- $mode not set: --
int(4)
-- $mode = 1: --
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/count_error.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/array/count_error.phpt
+++ php-src/ext/standard/tests/array/count_error.phpt
--TEST--
Test count() function : error conditions - pass incorrect number of args
--FILE--
<?php
/* Prototype : int count(mixed var [, int mode])
* Description: Count the number of elements in a variable (usually an array)
* Source code: ext/standard/array.c
*/
/*
* Pass incorrect number of arguments to count() to test behaviour
*/
echo "*** Testing count() : error conditions ***\n";
// Zero arguments
echo "\n-- Testing count() function with Zero arguments --\n";
var_dump( count() );
//Test count with one more than the expected number of arguments
echo "\n-- Testing count() function with more than expected no. of arguments
--\n";
$var = 1;
$mode = 10;
$extra_arg = 10;
var_dump( count($var, $mode, $extra_arg) );
echo "Done";
?>
--EXPECTF--
*** Testing count() : error conditions ***
-- Testing count() function with Zero arguments --
Warning: count() expects at least 1 parameter, 0 given in %s on line %d
NULL
-- Testing count() function with more than expected no. of arguments --
Warning: count() expects at most 2 parameters, 3 given in %s on line %d
NULL
Done
--UEXPECTF--
*** Testing count() : error conditions ***
-- Testing count() function with Zero arguments --
Warning: count() expects at least 1 parameter, 0 given in %s on line %d
NULL
-- Testing count() function with more than expected no. of arguments --
Warning: count() expects at most 2 parameters, 3 given in %s on line %d
NULL
Done
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/count_basic.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/array/count_basic.phpt
+++ php-src/ext/standard/tests/array/count_basic.phpt
--TEST--
Test count() function : basic functionality
--FILE--
<?php
/* Prototype : int count(mixed $var [, int $mode])
* Description: Count the number of elements in a variable (usually an array)
* Source code: ext/standard/array.c
*/
/*
* Test basic functionality of count() using an array as $var argument
* and different values as $mode argument.
*/
echo "*** Testing count() : basic functionality ***\n";
echo "\n-- One Dimensional Array: --\n";
$array = array('zero', 'one', 'two');
var_dump(count($array));
echo "\n-- Two Dimensional Array: --\n";
$array_multi = array('zero', array(1, 2, 3), 'two');
echo "\$mode = COUNT_NORMAL: ";
var_dump(count($array_multi, COUNT_NORMAL));
echo "\$mode = 0: ";
var_dump(count($array_multi, 0));
echo "\$mode = COUNT_RECURSIVE: ";
var_dump(count($array_multi, COUNT_RECURSIVE));
echo "\$mode = 1: ";
var_dump(count($array_multi, 1));
echo "Done";
?>
--EXPECTF--
*** 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
--UEXPECTF--
*** 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
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/count_variation1.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/array/count_variation1.phpt
+++ php-src/ext/standard/tests/array/count_variation1.phpt
--TEST--
Test count() function : usage variations - Pass different data types as $var arg
--FILE--
<?php
/* Prototype : int count(mixed $var [, int $mode])
* Description: Count the number of elements in a variable (usually an array)
* Source code: ext/standard/array.c
*/
/*
* aPass different data types as $var argument to count() to test behaviour
*/
echo "*** Testing count() : usage variations ***\n";
//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 $var 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*/ "",
'',
// string data
/*18*/ "string",
'string',
$heredoc,
// object data
/*21*/ new classA(),
// undefined data
/*22*/ @$undefined_var,
// unset data
/*23*/ @$unset_var,
// resource variable
/*24*/ $fp
);
// loop through each element of $inputs to check the behavior of count()
$iterator = 1;
foreach($inputs as $input) {
echo "\n-- Iteration $iterator --\n";
var_dump( count($input) );
$iterator++;
};
fclose($fp);
echo "Done";
?>
--EXPECTF--
*** Testing count() : usage variations ***
-- Iteration 1 --
int(1)
-- Iteration 2 --
int(1)
-- Iteration 3 --
int(1)
-- Iteration 4 --
int(1)
-- Iteration 5 --
int(1)
-- Iteration 6 --
int(1)
-- Iteration 7 --
int(1)
-- Iteration 8 --
int(1)
-- Iteration 9 --
int(1)
-- Iteration 10 --
int(0)
-- Iteration 11 --
int(0)
-- Iteration 12 --
int(1)
-- Iteration 13 --
int(1)
-- Iteration 14 --
int(1)
-- Iteration 15 --
int(1)
-- Iteration 16 --
int(1)
-- Iteration 17 --
int(1)
-- Iteration 18 --
int(1)
-- Iteration 19 --
int(1)
-- Iteration 20 --
int(1)
-- Iteration 21 --
int(1)
-- Iteration 22 --
int(0)
-- Iteration 23 --
int(0)
-- Iteration 24 --
int(1)
Done
--UEXPECTF--
*** Testing count() : usage variations ***
-- Iteration 1 --
int(1)
-- Iteration 2 --
int(1)
-- Iteration 3 --
int(1)
-- Iteration 4 --
int(1)
-- Iteration 5 --
int(1)
-- Iteration 6 --
int(1)
-- Iteration 7 --
int(1)
-- Iteration 8 --
int(1)
-- Iteration 9 --
int(1)
-- Iteration 10 --
int(0)
-- Iteration 11 --
int(0)
-- Iteration 12 --
int(1)
-- Iteration 13 --
int(1)
-- Iteration 14 --
int(1)
-- Iteration 15 --
int(1)
-- Iteration 16 --
int(1)
-- Iteration 17 --
int(1)
-- Iteration 18 --
int(1)
-- Iteration 19 --
int(1)
-- Iteration 20 --
int(1)
-- Iteration 21 --
int(1)
-- Iteration 22 --
int(0)
-- Iteration 23 --
int(0)
-- Iteration 24 --
int(1)
Done
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php