diff options
author | Rodrigo Prado de Jesus <royopa@gmail.com> | 2014-09-28 20:30:52 -0300 |
---|---|---|
committer | Rogerio Prado de Jesus <rogeriopradoj@gmail.com> | 2014-09-28 20:30:52 -0300 |
commit | d89b1dad8a3e98c09ed2f96e3ee4dd85dc9bcb8a (patch) | |
tree | 1a48ae37cc38fd11f2898c8b925b8bce9baf9d81 | |
parent | 813830e763514a0b716c4813c4c57c8e82401be7 (diff) | |
download | php-git-d89b1dad8a3e98c09ed2f96e3ee4dd85dc9bcb8a.tar.gz |
added some tests to datetime and dateinterval functions
12 files changed, 237 insertions, 0 deletions
diff --git a/ext/date/tests/date_interval_create_from_date_string.phpt b/ext/date/tests/date_interval_create_from_date_string.phpt new file mode 100644 index 0000000000..9a1745c9ac --- /dev/null +++ b/ext/date/tests/date_interval_create_from_date_string.phpt @@ -0,0 +1,34 @@ +--TEST-- +Test date_interval_create_from_date_string() function : basic functionality +--CREDITS-- +Rodrigo Prado de Jesus <royopa [at] gmail [dot] com> +--FILE-- +<?php +$string = '1 day'; //P1D +$i = date_interval_create_from_date_string($string); +var_dump($i->d); + +$string = '2 weeks'; //14 days +$i = date_interval_create_from_date_string($string); +var_dump($i->d); + +$string = '3 months'; +$i = date_interval_create_from_date_string($string); +var_dump($i->m); + +$string = '4 years'; +$i = date_interval_create_from_date_string($string); +var_dump($i->y); + +$string = '1 year + 1 day'; +$i = date_interval_create_from_date_string($string); +var_dump($i->y); +var_dump($i->d); +?> +--EXPECTF-- +int(1) +int(14) +int(3) +int(4) +int(1) +int(1)
\ No newline at end of file diff --git a/ext/date/tests/date_interval_create_from_date_string_nullparam.phpt b/ext/date/tests/date_interval_create_from_date_string_nullparam.phpt new file mode 100644 index 0000000000..369db5714a --- /dev/null +++ b/ext/date/tests/date_interval_create_from_date_string_nullparam.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test date_interval_create_from_date_string() function : null parameter +--CREDITS-- +Rodrigo Prado de Jesus <royopa [at] gmail [dot] com> +--FILE-- +<?php +$i = date_interval_create_from_date_string(null); //returns a empty object +var_dump($i); +?> +--EXPECTF-- +object(DateInterval)#1 (15) { + ["y"]=> + int(0) + ["m"]=> + int(0) + ["d"]=> + int(0) + ["h"]=> + int(0) + ["i"]=> + int(0) + ["s"]=> + int(0) + ["weekday"]=> + int(0) + ["weekday_behavior"]=> + int(0) + ["first_last_day_of"]=> + int(0) + ["invert"]=> + int(0) + ["days"]=> + int(0) + ["special_type"]=> + int(0) + ["special_amount"]=> + int(0) + ["have_weekday_relative"]=> + int(0) + ["have_special_relative"]=> + int(0) +}
\ No newline at end of file diff --git a/ext/date/tests/date_interval_create_from_date_string_wrongparam_001.phpt b/ext/date/tests/date_interval_create_from_date_string_wrongparam_001.phpt new file mode 100644 index 0000000000..15db956553 --- /dev/null +++ b/ext/date/tests/date_interval_create_from_date_string_wrongparam_001.phpt @@ -0,0 +1,11 @@ +--TEST-- +Test date_interval_create_from_date_string() function : wrong parameter (array) +--CREDITS-- +Rodrigo Prado de Jesus <royopa [at] gmail [dot] com> +--FILE-- +<?php +$wrong_parameter = array(); +$i = date_interval_create_from_date_string($wrong_parameter); +?> +--EXPECTF-- +Warning: date_interval_create_from_date_string() expects parameter 1 to be string, array given in %s on line %d
\ No newline at end of file diff --git a/ext/date/tests/date_interval_create_from_date_string_wrongparam_002.phpt b/ext/date/tests/date_interval_create_from_date_string_wrongparam_002.phpt new file mode 100644 index 0000000000..a3407c3967 --- /dev/null +++ b/ext/date/tests/date_interval_create_from_date_string_wrongparam_002.phpt @@ -0,0 +1,9 @@ +--TEST-- +Test date_interval_create_from_date_string() function : with 2 parameters (wrong). +Rodrigo Prado de Jesus <royopa [at] gmail [dot] com> +--FILE-- +<?php +$i = date_interval_create_from_date_string('1 year', 'wrong'); +?> +--EXPECTF-- +Warning: date_interval_create_from_date_string() expects exactly 1 parameter, 2 given in %s on line %d
\ No newline at end of file diff --git a/ext/date/tests/date_timestamp_set.phpt b/ext/date/tests/date_timestamp_set.phpt new file mode 100644 index 0000000000..e01660193f --- /dev/null +++ b/ext/date/tests/date_timestamp_set.phpt @@ -0,0 +1,19 @@ +--TEST-- +Test the basics to function date_timestamp_set(). +--CREDITS-- +Rodrigo Prado de Jesus <royopa [at] gmail [dot] com> +--INI-- +date.timezone = UTC; +date_default_timezone_set("America/Sao_Paulo"); +--FILE-- +<?php +$dftz021 = date_default_timezone_get(); //UTC + +$dtms021 = date_create(); + +date_timestamp_set($dtms021, 1234567890); + +var_dump(date_format($dtms021, 'B => (U) => T Y-M-d H:i:s')); +?> +--EXPECTF-- +string(47) "021 => (1234567890) => UTC 2009-Feb-13 23:31:30"
\ No newline at end of file diff --git a/ext/date/tests/date_timestamp_set_nullparam.phpt b/ext/date/tests/date_timestamp_set_nullparam.phpt new file mode 100644 index 0000000000..1bcb800242 --- /dev/null +++ b/ext/date/tests/date_timestamp_set_nullparam.phpt @@ -0,0 +1,17 @@ +--TEST-- +Test the function date_timestamp_set() with first null parameter. +--CREDITS-- +Rodrigo Prado de Jesus <royopa [at] gmail [dot] com> +--INI-- +date.timezone = UTC; +date_default_timezone_set("America/Sao_Paulo"); +--FILE-- +<?php +$dftz021 = date_default_timezone_get(); //UTC + +$dtms021 = date_create(); + +date_timestamp_set(null, 1234567890); +?> +--EXPECTF-- +Warning: date_timestamp_set() expects parameter 1 to be DateTime, null given in %s on line %d
\ No newline at end of file diff --git a/ext/date/tests/date_timestamp_set_nullparam2.phpt b/ext/date/tests/date_timestamp_set_nullparam2.phpt new file mode 100644 index 0000000000..1442da4426 --- /dev/null +++ b/ext/date/tests/date_timestamp_set_nullparam2.phpt @@ -0,0 +1,24 @@ +--TEST-- +Test the function date_timestamp_set() with second null parameter. +--CREDITS-- +Rodrigo Prado de Jesus <royopa [at] gmail [dot] com> +--INI-- +date.timezone = UTC; +date_default_timezone_set("America/Sao_Paulo"); +--FILE-- +<?php +$dftz021 = date_default_timezone_get(); //UTC + +$dtms021 = date_create(); + +var_dump(date_timestamp_set($dtms021, null)); +?> +--EXPECTF-- +object(DateTime)#1 (3) { + ["date"]=> + string(26) "1970-01-01 00:00:00.000000" + ["timezone_type"]=> + int(3) + ["timezone"]=> + string(3) "UTC" +}
\ No newline at end of file diff --git a/ext/date/tests/date_timestamp_set_wrongparam_001.phpt b/ext/date/tests/date_timestamp_set_wrongparam_001.phpt new file mode 100644 index 0000000000..9a0fca99c1 --- /dev/null +++ b/ext/date/tests/date_timestamp_set_wrongparam_001.phpt @@ -0,0 +1,17 @@ +--TEST-- +Check the function date_timestamp_set() with first parameter wrong (array). +--CREDITS-- +Rodrigo Prado de Jesus <royopa [at] gmail [dot] com> +--INI-- +date.timezone = UTC; +date_default_timezone_set("America/Sao_Paulo"); +--FILE-- +<?php +$dftz021 = date_default_timezone_get(); //UTC + +$dtms021 = array(); + +date_timestamp_set($dtms021, 123456789); +?> +--EXPECTF-- +Warning: date_timestamp_set() expects parameter 1 to be DateTime, array given in %s on line %d
\ No newline at end of file diff --git a/ext/date/tests/date_timestamp_set_wrongparam_002.phpt b/ext/date/tests/date_timestamp_set_wrongparam_002.phpt new file mode 100644 index 0000000000..ed31cb217d --- /dev/null +++ b/ext/date/tests/date_timestamp_set_wrongparam_002.phpt @@ -0,0 +1,15 @@ +--TEST-- +Check the function date_timestamp_set() with first parameter wrong (integer). +--CREDITS-- +Rodrigo Prado de Jesus <royopa [at] gmail [dot] com> +--INI-- +date.timezone = UTC; +date_default_timezone_set("America/Sao_Paulo"); +--FILE-- +<?php +$dftz021 = date_default_timezone_get(); //UTC + +date_timestamp_set(987654321, 123456789); +?> +--EXPECTF-- +Warning: date_timestamp_set() expects parameter 1 to be DateTime, integer given in %s on line %d
\ No newline at end of file diff --git a/ext/date/tests/date_timestamp_set_wrongparam_003.phpt b/ext/date/tests/date_timestamp_set_wrongparam_003.phpt new file mode 100644 index 0000000000..f965334d9d --- /dev/null +++ b/ext/date/tests/date_timestamp_set_wrongparam_003.phpt @@ -0,0 +1,19 @@ +--TEST-- +Check the function date_timestamp_set() with second parameter wrong (array). +--CREDITS-- +Rodrigo Prado de Jesus <royopa [at] gmail [dot] com> +--INI-- +date.timezone = UTC; +date_default_timezone_set("America/Sao_Paulo"); +--FILE-- +<?php +$dftz021 = date_default_timezone_get(); //UTC + +$dtms021 = new DateTime(); + +$wrong_parameter = array(); + +date_timestamp_set($dtms021, $wrong_parameter); +?> +--EXPECTF-- +Warning: date_timestamp_set() expects parameter 2 to be long, array given in %s on line %d
\ No newline at end of file diff --git a/ext/date/tests/date_timestamp_set_wrongparam_004.phpt b/ext/date/tests/date_timestamp_set_wrongparam_004.phpt new file mode 100644 index 0000000000..b171e98bd4 --- /dev/null +++ b/ext/date/tests/date_timestamp_set_wrongparam_004.phpt @@ -0,0 +1,17 @@ +--TEST-- +Check the function date_timestamp_set() with 3 parameters. +--CREDITS-- +Rodrigo Prado de Jesus <royopa [at] gmail [dot] com> +--INI-- +date.timezone = UTC; +date_default_timezone_set("America/Sao_Paulo"); +--FILE-- +<?php +$dftz021 = date_default_timezone_get(); //UTC + +$dtms021 = new DateTime(); + +date_timestamp_set($dtms021, 123456789, 'error'); +?> +--EXPECTF-- +Warning: date_timestamp_set() expects exactly 2 parameters, 3 given in %s on line %d
\ No newline at end of file diff --git a/ext/date/tests/timezone_version_get.phpt b/ext/date/tests/timezone_version_get.phpt new file mode 100644 index 0000000000..e076004289 --- /dev/null +++ b/ext/date/tests/timezone_version_get.phpt @@ -0,0 +1,13 @@ +--TEST-- +Test the basics to function timezone_version_get(). +--CREDITS-- +Rodrigo Prado de Jesus <royopa [at] gmail [dot] com> +--INI-- +date.timezone = UTC; +date_default_timezone_set("America/Sao_Paulo"); +--FILE-- +<?php +var_dump(timezone_version_get()); +?> +--EXPECTREGEX-- +string\([6-7]\) \"20[0-9][0-9]\.[1-9][0-9]?\"
\ No newline at end of file |