php-src/ext/date/tests/localtime_variation2.phpt
2009-01-09 05:09:40 +00:00

644 lines
8.4 KiB
PHP

--TEST--
Test localtime() function : usage variation - Passing unexpected values to second argument 'associative_array'.
--FILE--
<?php
/* Prototype : array localtime([int timestamp [, bool associative_array]])
* Description: Returns the results of the C system call localtime as an associative array
* if the associative_array argument is set to 1 other wise it is a regular array
* Source code: ext/date/php_date.c
* Alias to functions:
*/
echo "*** Testing localtime() : usage variation ***\n";
date_default_timezone_set("UTC");
// Initialise function arguments not being substituted (if any)
$timestamp = 10;
//get an unset variable
$unset_var = 10;
unset ($unset_var);
// define some classes
class classWithToString
{
public function __toString() {
return "Class A object";
}
}
class classWithoutToString
{
}
// heredoc string
$heredoc = <<<EOT
hello world
EOT;
// add arrays
$index_array = array (1, 2, 3);
$assoc_array = array ('one' => 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' => 12.3456789000e10,
'float -12.3456789000e10' => -12.3456789000e10,
'float .5' => .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 associative_array
foreach($inputs as $key =>$value) {
echo "\n--$key--\n";
var_dump( localtime($timestamp, $value) );
};
?>
===DONE===
--EXPECTF--
*** Testing localtime() : usage variation ***
--int 0--
array(9) {
[0]=>
int(10)
[1]=>
int(0)
[2]=>
int(0)
[3]=>
int(1)
[4]=>
int(0)
[5]=>
int(70)
[6]=>
int(4)
[7]=>
int(0)
[8]=>
int(0)
}
--int 1--
array(9) {
["tm_sec"]=>
int(10)
["tm_min"]=>
int(0)
["tm_hour"]=>
int(0)
["tm_mday"]=>
int(1)
["tm_mon"]=>
int(0)
["tm_year"]=>
int(70)
["tm_wday"]=>
int(4)
["tm_yday"]=>
int(0)
["tm_isdst"]=>
int(0)
}
--int 12345--
array(9) {
["tm_sec"]=>
int(10)
["tm_min"]=>
int(0)
["tm_hour"]=>
int(0)
["tm_mday"]=>
int(1)
["tm_mon"]=>
int(0)
["tm_year"]=>
int(70)
["tm_wday"]=>
int(4)
["tm_yday"]=>
int(0)
["tm_isdst"]=>
int(0)
}
--int -12345--
array(9) {
["tm_sec"]=>
int(10)
["tm_min"]=>
int(0)
["tm_hour"]=>
int(0)
["tm_mday"]=>
int(1)
["tm_mon"]=>
int(0)
["tm_year"]=>
int(70)
["tm_wday"]=>
int(4)
["tm_yday"]=>
int(0)
["tm_isdst"]=>
int(0)
}
--float 10.5--
array(9) {
["tm_sec"]=>
int(10)
["tm_min"]=>
int(0)
["tm_hour"]=>
int(0)
["tm_mday"]=>
int(1)
["tm_mon"]=>
int(0)
["tm_year"]=>
int(70)
["tm_wday"]=>
int(4)
["tm_yday"]=>
int(0)
["tm_isdst"]=>
int(0)
}
--float -10.5--
array(9) {
["tm_sec"]=>
int(10)
["tm_min"]=>
int(0)
["tm_hour"]=>
int(0)
["tm_mday"]=>
int(1)
["tm_mon"]=>
int(0)
["tm_year"]=>
int(70)
["tm_wday"]=>
int(4)
["tm_yday"]=>
int(0)
["tm_isdst"]=>
int(0)
}
--float 12.3456789000e10--
array(9) {
["tm_sec"]=>
int(10)
["tm_min"]=>
int(0)
["tm_hour"]=>
int(0)
["tm_mday"]=>
int(1)
["tm_mon"]=>
int(0)
["tm_year"]=>
int(70)
["tm_wday"]=>
int(4)
["tm_yday"]=>
int(0)
["tm_isdst"]=>
int(0)
}
--float -12.3456789000e10--
array(9) {
["tm_sec"]=>
int(10)
["tm_min"]=>
int(0)
["tm_hour"]=>
int(0)
["tm_mday"]=>
int(1)
["tm_mon"]=>
int(0)
["tm_year"]=>
int(70)
["tm_wday"]=>
int(4)
["tm_yday"]=>
int(0)
["tm_isdst"]=>
int(0)
}
--float .5--
array(9) {
["tm_sec"]=>
int(10)
["tm_min"]=>
int(0)
["tm_hour"]=>
int(0)
["tm_mday"]=>
int(1)
["tm_mon"]=>
int(0)
["tm_year"]=>
int(70)
["tm_wday"]=>
int(4)
["tm_yday"]=>
int(0)
["tm_isdst"]=>
int(0)
}
--empty array--
Warning: localtime() expects parameter 2 to be boolean, array given in %s on line %d
bool(false)
--int indexed array--
Warning: localtime() expects parameter 2 to be boolean, array given in %s on line %d
bool(false)
--associative array--
Warning: localtime() expects parameter 2 to be boolean, array given in %s on line %d
bool(false)
--nested arrays--
Warning: localtime() expects parameter 2 to be boolean, array given in %s on line %d
bool(false)
--uppercase NULL--
array(9) {
[0]=>
int(10)
[1]=>
int(0)
[2]=>
int(0)
[3]=>
int(1)
[4]=>
int(0)
[5]=>
int(70)
[6]=>
int(4)
[7]=>
int(0)
[8]=>
int(0)
}
--lowercase null--
array(9) {
[0]=>
int(10)
[1]=>
int(0)
[2]=>
int(0)
[3]=>
int(1)
[4]=>
int(0)
[5]=>
int(70)
[6]=>
int(4)
[7]=>
int(0)
[8]=>
int(0)
}
--lowercase true--
array(9) {
["tm_sec"]=>
int(10)
["tm_min"]=>
int(0)
["tm_hour"]=>
int(0)
["tm_mday"]=>
int(1)
["tm_mon"]=>
int(0)
["tm_year"]=>
int(70)
["tm_wday"]=>
int(4)
["tm_yday"]=>
int(0)
["tm_isdst"]=>
int(0)
}
--lowercase false--
array(9) {
[0]=>
int(10)
[1]=>
int(0)
[2]=>
int(0)
[3]=>
int(1)
[4]=>
int(0)
[5]=>
int(70)
[6]=>
int(4)
[7]=>
int(0)
[8]=>
int(0)
}
--uppercase TRUE--
array(9) {
["tm_sec"]=>
int(10)
["tm_min"]=>
int(0)
["tm_hour"]=>
int(0)
["tm_mday"]=>
int(1)
["tm_mon"]=>
int(0)
["tm_year"]=>
int(70)
["tm_wday"]=>
int(4)
["tm_yday"]=>
int(0)
["tm_isdst"]=>
int(0)
}
--uppercase FALSE--
array(9) {
[0]=>
int(10)
[1]=>
int(0)
[2]=>
int(0)
[3]=>
int(1)
[4]=>
int(0)
[5]=>
int(70)
[6]=>
int(4)
[7]=>
int(0)
[8]=>
int(0)
}
--empty string DQ--
array(9) {
[0]=>
int(10)
[1]=>
int(0)
[2]=>
int(0)
[3]=>
int(1)
[4]=>
int(0)
[5]=>
int(70)
[6]=>
int(4)
[7]=>
int(0)
[8]=>
int(0)
}
--empty string SQ--
array(9) {
[0]=>
int(10)
[1]=>
int(0)
[2]=>
int(0)
[3]=>
int(1)
[4]=>
int(0)
[5]=>
int(70)
[6]=>
int(4)
[7]=>
int(0)
[8]=>
int(0)
}
--string DQ--
array(9) {
["tm_sec"]=>
int(10)
["tm_min"]=>
int(0)
["tm_hour"]=>
int(0)
["tm_mday"]=>
int(1)
["tm_mon"]=>
int(0)
["tm_year"]=>
int(70)
["tm_wday"]=>
int(4)
["tm_yday"]=>
int(0)
["tm_isdst"]=>
int(0)
}
--string SQ--
array(9) {
["tm_sec"]=>
int(10)
["tm_min"]=>
int(0)
["tm_hour"]=>
int(0)
["tm_mday"]=>
int(1)
["tm_mon"]=>
int(0)
["tm_year"]=>
int(70)
["tm_wday"]=>
int(4)
["tm_yday"]=>
int(0)
["tm_isdst"]=>
int(0)
}
--mixed case string--
array(9) {
["tm_sec"]=>
int(10)
["tm_min"]=>
int(0)
["tm_hour"]=>
int(0)
["tm_mday"]=>
int(1)
["tm_mon"]=>
int(0)
["tm_year"]=>
int(70)
["tm_wday"]=>
int(4)
["tm_yday"]=>
int(0)
["tm_isdst"]=>
int(0)
}
--heredoc--
array(9) {
["tm_sec"]=>
int(10)
["tm_min"]=>
int(0)
["tm_hour"]=>
int(0)
["tm_mday"]=>
int(1)
["tm_mon"]=>
int(0)
["tm_year"]=>
int(70)
["tm_wday"]=>
int(4)
["tm_yday"]=>
int(0)
["tm_isdst"]=>
int(0)
}
--instance of classWithToString--
Warning: localtime() expects parameter 2 to be boolean, object given in %s on line %d
bool(false)
--instance of classWithoutToString--
Warning: localtime() expects parameter 2 to be boolean, object given in %s on line %d
bool(false)
--undefined var--
array(9) {
[0]=>
int(10)
[1]=>
int(0)
[2]=>
int(0)
[3]=>
int(1)
[4]=>
int(0)
[5]=>
int(70)
[6]=>
int(4)
[7]=>
int(0)
[8]=>
int(0)
}
--unset var--
array(9) {
[0]=>
int(10)
[1]=>
int(0)
[2]=>
int(0)
[3]=>
int(1)
[4]=>
int(0)
[5]=>
int(70)
[6]=>
int(4)
[7]=>
int(0)
[8]=>
int(0)
}
===DONE===