From: andy wharmby Date: Wed, 18 Mar 2009 11:32:56 +0000 (+0000) Subject: New tests for date extension DateTime methods Tested on Windows, Linux and linux 64 X-Git-Tag: php-5.4.0alpha1~191^2~4111 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=124fc28089fa01616b0253fdd35a8809224dce26;p=php New tests for date extension DateTime methods Tested on Windows, Linux and linux 64 --- diff --git a/ext/date/tests/DateTime_clone_basic1.phpt b/ext/date/tests/DateTime_clone_basic1.phpt new file mode 100644 index 0000000000..cef6621a75 --- /dev/null +++ b/ext/date/tests/DateTime_clone_basic1.phpt @@ -0,0 +1,29 @@ +--TEST-- +Test clone on DateTime objects +--FILE-- +setTime(22, 41, 50); + +echo "Original: " . $orig->format("H:i:s") . "\n"; +echo "Clone: " . $clone->format("H:i:s") . "\n"; + +?> +===DONE=== +--EXPECTF-- +*** Testing clone on DateTime objects *** +Original: 22:41:50 +Clone: 14:25:41 +===DONE=== diff --git a/ext/date/tests/DateTime_clone_basic2.phpt b/ext/date/tests/DateTime_clone_basic2.phpt new file mode 100644 index 0000000000..01385c93dc --- /dev/null +++ b/ext/date/tests/DateTime_clone_basic2.phpt @@ -0,0 +1,90 @@ +--TEST-- +Test clone of objects whoose class derived from DateTime class +--FILE-- + +===DONE=== +--EXPECTF-- +*** Testing clone on objects whoose class derived from DateTime class *** +object(DateTimeExt1)#%d (5) { + [u"property1"]=> + int(99) + [u"property2"]=> + unicode(5) "Hello" + [u"date"]=> + unicode(19) "2009-02-03 12:34:41" + [u"timezone_type"]=> + int(2) + [u"timezone"]=> + unicode(3) "GMT" +} +object(DateTimeExt1)#%d (5) { + [u"property1"]=> + int(99) + [u"property2"]=> + unicode(5) "Hello" + [u"date"]=> + unicode(19) "2009-02-03 12:34:41" + [u"timezone_type"]=> + int(2) + [u"timezone"]=> + unicode(3) "GMT" +} +object(DateTimeExt2)#%d (7) { + [u"property3"]=> + bool(true) + [u"property4"]=> + float(10.5) + [u"property1"]=> + int(99) + [u"property2"]=> + unicode(5) "Hello" + [u"date"]=> + unicode(19) "2009-02-03 12:34:41" + [u"timezone_type"]=> + int(2) + [u"timezone"]=> + unicode(3) "GMT" +} +object(DateTimeExt2)#%d (7) { + [u"property3"]=> + bool(true) + [u"property4"]=> + float(10.5) + [u"property1"]=> + int(99) + [u"property2"]=> + unicode(5) "Hello" + [u"date"]=> + unicode(19) "2009-02-03 12:34:41" + [u"timezone_type"]=> + int(2) + [u"timezone"]=> + unicode(3) "GMT" +} +===DONE=== diff --git a/ext/date/tests/DateTime_clone_basic3.phpt b/ext/date/tests/DateTime_clone_basic3.phpt new file mode 100644 index 0000000000..9d33978fdc --- /dev/null +++ b/ext/date/tests/DateTime_clone_basic3.phpt @@ -0,0 +1,105 @@ +--TEST-- +Test clone of DateTime objects +--FILE-- +property1 = 99; +$d1->property2 = "Hello"; +var_dump($d1); +echo "\n-- clone it --\n"; +$d1_clone = clone $d1; +var_dump($d1_clone); +echo "\n-- Add some more properties --\n"; +$d1_clone->property3 = true; +$d1_clone->property4 = 10.5; +var_dump($d1_clone); +echo "\n-- clone it --\n"; +$d2_clone = clone $d1_clone; +var_dump($d2_clone); +?> +===DONE=== +--EXPECTF-- +*** Testing clone on DateTime objects *** + +-- Create a DateTime object -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-02-03 12:34:41" + [u"timezone_type"]=> + int(2) + [u"timezone"]=> + unicode(3) "GMT" +} + +-- Add some properties -- +object(DateTime)#%d (5) { + [u"date"]=> + unicode(19) "2009-02-03 12:34:41" + [u"timezone_type"]=> + int(2) + [u"timezone"]=> + unicode(3) "GMT" + [u"property1"]=> + int(99) + [u"property2"]=> + unicode(5) "Hello" +} + +-- clone it -- +object(DateTime)#%d (5) { + [u"date"]=> + unicode(19) "2009-02-03 12:34:41" + [u"timezone_type"]=> + int(2) + [u"timezone"]=> + unicode(3) "GMT" + [u"property1"]=> + int(99) + [u"property2"]=> + unicode(5) "Hello" +} + +-- Add some more properties -- +object(DateTime)#%d (7) { + [u"date"]=> + unicode(19) "2009-02-03 12:34:41" + [u"timezone_type"]=> + int(2) + [u"timezone"]=> + unicode(3) "GMT" + [u"property1"]=> + int(99) + [u"property2"]=> + unicode(5) "Hello" + [u"property3"]=> + bool(true) + [u"property4"]=> + float(10.5) +} + +-- clone it -- +object(DateTime)#%d (7) { + [u"date"]=> + unicode(19) "2009-02-03 12:34:41" + [u"timezone_type"]=> + int(2) + [u"timezone"]=> + unicode(3) "GMT" + [u"property1"]=> + int(99) + [u"property2"]=> + unicode(5) "Hello" + [u"property3"]=> + bool(true) + [u"property4"]=> + float(10.5) +} +===DONE=== \ No newline at end of file diff --git a/ext/date/tests/DateTime_clone_basic4.phpt b/ext/date/tests/DateTime_clone_basic4.phpt new file mode 100644 index 0000000000..bba45081f5 --- /dev/null +++ b/ext/date/tests/DateTime_clone_basic4.phpt @@ -0,0 +1,31 @@ +--TEST-- +Test clone of DateTime derived objects with __clone magic method +--FILE-- +format( "m.d.y") ); + +?> +===DONE=== +--EXPECTF-- +*** Testing clone of objects derived from DateTime class with __clone magic method*** +-- DateTimeExt1 __clone magic method called -- +unicode(8) "02.03.09" +===DONE=== diff --git a/ext/date/tests/DateTime_compare_basic1.phpt b/ext/date/tests/DateTime_compare_basic1.phpt new file mode 100644 index 0000000000..313dab1c25 --- /dev/null +++ b/ext/date/tests/DateTime_compare_basic1.phpt @@ -0,0 +1,77 @@ +--TEST-- +Test of compare object handler for DateTime objects +--FILE-- + +===DONE=== +--EXPECT-- +Simple test for DateTime compare object handler + +-- All the following tests should compare equal -- +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +-- The following test should still compare equal -- +bool(true) + +-- All the following tests should now compare NOT equal -- +bool(false) +bool(false) +bool(false) + +-- All the following tests should again compare equal -- +bool(true) +bool(true) +bool(true) +===DONE=== \ No newline at end of file diff --git a/ext/date/tests/DateTime_construct_basic1.phpt b/ext/date/tests/DateTime_construct_basic1.phpt new file mode 100644 index 0000000000..78faf05208 --- /dev/null +++ b/ext/date/tests/DateTime_construct_basic1.phpt @@ -0,0 +1,58 @@ +--TEST-- +Test new DateTime() : basic functionality +--FILE-- + +===DONE=== +--EXPECTF-- +*** Testing new DateTime() : basic functionality *** +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "%s" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "%s" + [u"timezone_type"]=> + int(2) + [u"timezone"]=> + unicode(3) "GMT" +} +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2005-07-14 22:30:41" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2005-07-14 22:30:41" + [u"timezone_type"]=> + int(2) + [u"timezone"]=> + unicode(3) "GMT" +} +===DONE=== diff --git a/ext/date/tests/DateTime_construct_error.phpt b/ext/date/tests/DateTime_construct_error.phpt new file mode 100644 index 0000000000..ef79eb4554 --- /dev/null +++ b/ext/date/tests/DateTime_construct_error.phpt @@ -0,0 +1,32 @@ +--TEST-- +Test new DateTime() : error conditions +--FILE-- + +===DONE=== +--EXPECTF-- +*** Testing date_create() : error conditions *** + +-- Testing new DateTime() with more than expected no. of arguments -- + +Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct() expects at most 2 parameters, 3 given' in %s:%d +Stack trace: +#0 %s(%d): DateTime->__construct('GMT', Object(DateTimeZone), 99) +#1 {main} + thrown in %s on line %d \ No newline at end of file diff --git a/ext/date/tests/DateTime_construct_variation1.phpt b/ext/date/tests/DateTime_construct_variation1.phpt new file mode 100644 index 0000000000..7211fe5dde --- /dev/null +++ b/ext/date/tests/DateTime_construct_variation1.phpt @@ -0,0 +1,377 @@ +--TEST-- +Test new DateTime() function : usage variation - Passing unexpected values to first argument $time. +--FILE-- + 1, 'two' => 2); + +// resource +$file_handle = fopen(__FILE__, 'r'); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -12345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + '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, + + // resource + 'resource' => $file_handle +); + +$timezone = new DateTimeZone("Europe/London"); + +foreach($inputs as $variation =>$time) { + echo "\n-- $variation --\n"; + + try { + var_dump( new DateTime($time) ); + } catch(Exception $e) { + $msg = $e->getMessage(); + echo "FAILED: " . $msg . "\n"; + } + + try { + var_dump( new DateTime($time, $timezone) ); + } catch(Exception$e) { + $msg = $e->getMessage(); + echo "FAILED: " . $msg . "\n"; + } +}; + +// closing the resource +fclose( $file_handle); + +?> +===DONE=== +--EXPECTF-- +*** Testing new DateTime(): usage variation - unexpected values to first argument $time*** + +-- int 0 -- +FAILED: DateTime::__construct(): Failed to parse time string (0) at position 0 (0): Unexpected character +FAILED: DateTime::__construct(): Failed to parse time string (0) at position 0 (0): Unexpected character + +-- int 1 -- +FAILED: DateTime::__construct(): Failed to parse time string (1) at position 0 (1): Unexpected character +FAILED: DateTime::__construct(): Failed to parse time string (1) at position 0 (1): Unexpected character + +-- int 12345 -- +FAILED: DateTime::__construct(): Failed to parse time string (12345) at position 4 (5): Unexpected character +FAILED: DateTime::__construct(): Failed to parse time string (12345) at position 4 (5): Unexpected character + +-- int -12345 -- +FAILED: DateTime::__construct(): Failed to parse time string (-12345) at position 5 (5): Unexpected character +FAILED: DateTime::__construct(): Failed to parse time string (-12345) at position 5 (5): Unexpected character + +-- float 10.5 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "%s" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "%s" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- float -10.5 -- +FAILED: DateTime::__construct(): Failed to parse time string (-10.5) at position 4 (5): Unexpected character +FAILED: DateTime::__construct(): Failed to parse time string (-10.5) at position 4 (5): Unexpected character + +-- float .5 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "%s" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "%s" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- empty array -- +FAILED: DateTime::__construct() expects parameter 1 to be binary string, array given +FAILED: DateTime::__construct() expects parameter 1 to be binary string, array given + +-- int indexed array -- +FAILED: DateTime::__construct() expects parameter 1 to be binary string, array given +FAILED: DateTime::__construct() expects parameter 1 to be binary string, array given + +-- associative array -- +FAILED: DateTime::__construct() expects parameter 1 to be binary string, array given +FAILED: DateTime::__construct() expects parameter 1 to be binary string, array given + +-- nested arrays -- +FAILED: DateTime::__construct() expects parameter 1 to be binary string, array given +FAILED: DateTime::__construct() expects parameter 1 to be binary string, array given + +-- uppercase NULL -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "%s" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} +object(DateTime)#6 (3) { + [u"date"]=> + unicode(19) "%s" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- lowercase null -- +object(DateTime)#6 (3) { + [u"date"]=> + unicode(19) "%s" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} +object(DateTime)#6 (3) { + [u"date"]=> + unicode(19) "%s" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- lowercase true -- +FAILED: DateTime::__construct(): Failed to parse time string (1) at position 0 (1): Unexpected character +FAILED: DateTime::__construct(): Failed to parse time string (1) at position 0 (1): Unexpected character + +-- lowercase false -- +object(DateTime)#5 (3) { + [u"date"]=> + unicode(19) "%s" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} +object(DateTime)#5 (3) { + [u"date"]=> + unicode(19) "%s" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- uppercase TRUE -- +FAILED: DateTime::__construct(): Failed to parse time string (1) at position 0 (1): Unexpected character +FAILED: DateTime::__construct(): Failed to parse time string (1) at position 0 (1): Unexpected character + +-- uppercase FALSE -- +object(DateTime)#4 (3) { + [u"date"]=> + unicode(19) "%s" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} +object(DateTime)#4 (3) { + [u"date"]=> + unicode(19) "%s" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- empty string DQ -- +object(DateTime)#4 (3) { + [u"date"]=> + unicode(19) "%s" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} +object(DateTime)#4 (3) { + [u"date"]=> + unicode(19) "%s" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- empty string SQ -- +object(DateTime)#4 (3) { + [u"date"]=> + unicode(19) "%s" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "%s" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- string DQ -- +FAILED: DateTime::__construct(): Failed to parse time string (string) at position 0 (s): The timezone could not be found in the database +FAILED: DateTime::__construct(): Failed to parse time string (string) at position 0 (s): The timezone could not be found in the database + +-- string SQ -- +FAILED: DateTime::__construct(): Failed to parse time string (string) at position 0 (s): The timezone could not be found in the database +FAILED: DateTime::__construct(): Failed to parse time string (string) at position 0 (s): The timezone could not be found in the database + +-- mixed case string -- +FAILED: DateTime::__construct(): Failed to parse time string (sTrInG) at position 0 (s): The timezone could not be found in the database +FAILED: DateTime::__construct(): Failed to parse time string (sTrInG) at position 0 (s): The timezone could not be found in the database + +-- heredoc -- +FAILED: DateTime::__construct(): Failed to parse time string (hello world) at position 0 (h): The timezone could not be found in the database +FAILED: DateTime::__construct(): Failed to parse time string (hello world) at position 0 (h): The timezone could not be found in the database + +-- instance of classWithToString -- +FAILED: DateTime::__construct(): Failed to parse time string (Class A object) at position 0 (C): The timezone could not be found in the database +FAILED: DateTime::__construct(): Failed to parse time string (Class A object) at position 0 (C): The timezone could not be found in the database + +-- instance of classWithoutToString -- +FAILED: DateTime::__construct() expects parameter 1 to be binary string, object given +FAILED: DateTime::__construct() expects parameter 1 to be binary string, object given + +-- undefined var -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "%s" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "%s" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- unset var -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "%s" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "%s" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- resource -- +FAILED: DateTime::__construct() expects parameter 1 to be binary string, resource given +FAILED: DateTime::__construct() expects parameter 1 to be binary string, resource given +===DONE=== diff --git a/ext/date/tests/DateTime_construct_variation2.phpt b/ext/date/tests/DateTime_construct_variation2.phpt new file mode 100644 index 0000000000..c69b88ca5c --- /dev/null +++ b/ext/date/tests/DateTime_construct_variation2.phpt @@ -0,0 +1,203 @@ +--TEST-- +Test new DateTime() function : usage variation - Passing unexpected values to second argument $timezone. +--FILE-- + 1, 'two' => 2); + +// resource +$file_handle = fopen(__FILE__, 'r'); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -12345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + '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, + + // resource + 'resource' => $file_handle +); + +$time = "2005-07-14 22:30:41"; + +foreach($inputs as $variation =>$timezone) { + echo "\n-- $variation --\n"; + + try { + var_dump( new DateTime($time, $timezone) ); + } catch(Exception $e) { + $msg = $e->getMessage(); + echo "FAILED: " . $msg . "\n"; + } + +}; + +// closing the resource +fclose( $file_handle); + +?> +===DONE=== +--EXPECT-- +*** Testing new DateTime() : usage variation - unexpected values to second argument $timezone*** + +-- int 0 -- +FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, integer given + +-- int 1 -- +FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, integer given + +-- int 12345 -- +FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, integer given + +-- int -12345 -- +FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, integer given + +-- float 10.5 -- +FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, double given + +-- float -10.5 -- +FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, double given + +-- float .5 -- +FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, double given + +-- empty array -- +FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, array given + +-- int indexed array -- +FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, array given + +-- associative array -- +FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, array given + +-- nested arrays -- +FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, array given + +-- uppercase NULL -- +FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, null given + +-- lowercase null -- +FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, null given + +-- lowercase true -- +FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, boolean given + +-- lowercase false -- +FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, boolean given + +-- uppercase TRUE -- +FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, boolean given + +-- uppercase FALSE -- +FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, boolean given + +-- empty string DQ -- +FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, Unicode string given + +-- empty string SQ -- +FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, Unicode string given + +-- string DQ -- +FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, Unicode string given + +-- string SQ -- +FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, Unicode string given + +-- mixed case string -- +FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, Unicode string given + +-- heredoc -- +FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, Unicode string given + +-- instance of classWithToString -- +FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, object given + +-- instance of classWithoutToString -- +FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, object given + +-- undefined var -- +FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, null given + +-- unset var -- +FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, null given + +-- resource -- +FAILED: DateTime::__construct() expects parameter 2 to be DateTimeZone, resource given +===DONE=== diff --git a/ext/date/tests/DateTime_extends_basic1.phpt b/ext/date/tests/DateTime_extends_basic1.phpt new file mode 100644 index 0000000000..8fe53d69f8 --- /dev/null +++ b/ext/date/tests/DateTime_extends_basic1.phpt @@ -0,0 +1,49 @@ +--TEST-- +Test DateTime class inheritance +--FILE-- +setDate(1963, 7, 2); +$d->setTime(10, 45, 30); + +echo "\n-- Invoke __toString again --\n"; +echo $d . "\n"; + +?> +===DONE=== +--EXPECTF-- +*** Testing basic DateTime inheritance() *** + +-- Create an instance of DateTimeExt -- + +-- Invoke __toString -- +May 1, 1967, 10:30:41 pm + + -- modify date and time -- + +-- Invoke __toString again -- +July 2, 1963, 10:45:30 am +===DONE=== diff --git a/ext/date/tests/DateTime_extends_basic2.phpt b/ext/date/tests/DateTime_extends_basic2.phpt new file mode 100644 index 0000000000..a4bf4aa27f --- /dev/null +++ b/ext/date/tests/DateTime_extends_basic2.phpt @@ -0,0 +1,31 @@ +--TEST-- +Test DateTime class inheritance : with user space __construct magic method +--FILE-- +format("F j, Y, g:i:s a") . "\n"; + +?> +===DONE=== +--EXPECTF-- +*** Testing new DateTime() : with user space __construct magic method *** +May 1, 1967, 10:30:41 pm +===DONE=== \ No newline at end of file diff --git a/ext/date/tests/DateTime_extends_basic3.phpt b/ext/date/tests/DateTime_extends_basic3.phpt new file mode 100644 index 0000000000..bee395aa96 --- /dev/null +++ b/ext/date/tests/DateTime_extends_basic3.phpt @@ -0,0 +1,26 @@ +--TEST-- +Test DateTime class inheritance : with user space fromat() method +--FILE-- +format() . "\n"; + +?> +===DONE=== +--EXPECTF-- +*** Testing new DateTime() : with user format() method *** +May 1, 1967, 10:30:41 pm +===DONE=== diff --git a/ext/date/tests/DateTime_format_basic1.phpt b/ext/date/tests/DateTime_format_basic1.phpt new file mode 100644 index 0000000000..63fec823f0 --- /dev/null +++ b/ext/date/tests/DateTime_format_basic1.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test DateTime::format() function : basic functionality +--FILE-- +format( "F j, Y, g:i a") ); +var_dump( $date->format( "m.d.y") ); +var_dump( $date->format( "j, n, Y") ); +var_dump( $date->format( "Ymd") ); +var_dump( $date->format( 'h-i-s, j-m-y, it is w Day') ); +var_dump( $date->format( '\i\t \i\s \t\h\e jS \d\a\y.') ); +var_dump( $date->format( "D M j G:i:s T Y") ); +var_dump( $date->format( 'H:m:s \m \i\s\ \m\o\n\t\h') ); +var_dump( $date->format( "H:i:s") ); + +?> +===DONE=== +--EXPECT-- +*** Testing DateTime::format() : basic functionality *** +unicode(23) "July 14, 2005, 10:30 pm" +unicode(8) "07.14.05" +unicode(11) "14, 7, 2005" +unicode(8) "20050714" +unicode(39) "10-30-41, 14-07-05, 3031 3041 4 Thupm05" +unicode(19) "it is the 14th day." +unicode(28) "Thu Jul 14 22:30:41 BST 2005" +unicode(19) "22:07:41 m is month" +unicode(8) "22:30:41" +===DONE=== \ No newline at end of file diff --git a/ext/date/tests/DateTime_format_basic2.phpt b/ext/date/tests/DateTime_format_basic2.phpt new file mode 100644 index 0000000000..8f144cfc96 --- /dev/null +++ b/ext/date/tests/DateTime_format_basic2.phpt @@ -0,0 +1,44 @@ +--TEST-- +Test date_format() function : basic functionality +--FILE-- +format( DateTime::ATOM) ) ; +var_dump( $date->format( DateTime::COOKIE) ) ; +var_dump( $date->format( DateTime::ISO8601) ) ; +var_dump( $date->format( DateTime::RFC822) ) ; +var_dump( $date->format( DateTime::RFC850) ) ; +var_dump( $date->format( DateTime::RFC1036) ) ; +var_dump( $date->format( DateTime::RFC1123) ) ; +var_dump( $date->format( DateTime:: RFC2822) ) ; +var_dump( $date->format( DateTime::RFC3339) ) ; +var_dump( $date->format( DateTime::RSS) ) ; +var_dump( $date->format( DateTime::W3C) ) ; + +?> +===DONE=== +--EXPECT-- +*** Testing date_format() : basic functionality - formatting coinstants *** +unicode(25) "2005-07-14T22:30:41+01:00" +unicode(32) "Thursday, 14-Jul-05 22:30:41 BST" +unicode(24) "2005-07-14T22:30:41+0100" +unicode(29) "Thu, 14 Jul 05 22:30:41 +0100" +unicode(32) "Thursday, 14-Jul-05 22:30:41 BST" +unicode(29) "Thu, 14 Jul 05 22:30:41 +0100" +unicode(31) "Thu, 14 Jul 2005 22:30:41 +0100" +unicode(31) "Thu, 14 Jul 2005 22:30:41 +0100" +unicode(25) "2005-07-14T22:30:41+01:00" +unicode(31) "Thu, 14 Jul 2005 22:30:41 +0100" +unicode(25) "2005-07-14T22:30:41+01:00" +===DONE=== diff --git a/ext/date/tests/DateTime_format_error.phpt b/ext/date/tests/DateTime_format_error.phpt new file mode 100644 index 0000000000..db1be92290 --- /dev/null +++ b/ext/date/tests/DateTime_format_error.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test DateTime::format() function : error conditions +--FILE-- +format() ); + +echo "\n-- Testing date_date_formatcreate() function with more than expected no. of arguments --\n"; +$format = "F j, Y, g:i a"; +$extra_arg = 10; +var_dump( $date->format($format, $extra_arg) ); + +?> +===DONE=== +--EXPECTF-- +*** Testing DateTime::format() : error conditions *** + +-- Testing date_date_formatcreate() function with zero arguments -- + +Warning: DateTime::format() expects exactly 1 parameter, 0 given in %s on line %d +bool(false) + +-- Testing date_date_formatcreate() function with more than expected no. of arguments -- + +Warning: DateTime::format() expects exactly 1 parameter, 2 given in %s on line %d +bool(false) +===DONE=== diff --git a/ext/date/tests/DateTime_getOffset_basic1.phpt b/ext/date/tests/DateTime_getOffset_basic1.phpt new file mode 100644 index 0000000000..41b1a78d75 --- /dev/null +++ b/ext/date/tests/DateTime_getOffset_basic1.phpt @@ -0,0 +1,28 @@ +--TEST-- +Test DateTime::getOffset() function : basic functionality +--FILE-- +getOffset() / 3600 . " hours\n"; +echo "Summer offset: " . $summer->getOffset() / 3600 . " hours\n"; + +?> +===DONE=== +--EXPECTF-- +*** Testing DateTime::getOffset() : basic functionality *** +Winter offset: 0 hours +Summer offset: 1 hours +===DONE=== diff --git a/ext/date/tests/DateTime_getOffset_error.phpt b/ext/date/tests/DateTime_getOffset_error.phpt new file mode 100644 index 0000000000..6e9c3f411d --- /dev/null +++ b/ext/date/tests/DateTime_getOffset_error.phpt @@ -0,0 +1,33 @@ +--TEST-- +Test DateTime::getOffset() function : error conditions +--FILE-- +getOffset($extra_arg) ); + +?> +===DONE=== +--EXPECTF-- +*** Testing DateTime::getOffset() : error conditions *** + +-- Testing DateTime::getOffset() function with more than expected no. of arguments -- + +Warning: DateTime::getOffset() expects exactly 0 parameters, 1 given in %s on line %d +bool(false) +===DONE=== + diff --git a/ext/date/tests/DateTime_getTimeZone_basic1.phpt b/ext/date/tests/DateTime_getTimeZone_basic1.phpt new file mode 100644 index 0000000000..fe8e83a495 --- /dev/null +++ b/ext/date/tests/DateTime_getTimeZone_basic1.phpt @@ -0,0 +1,33 @@ +--TEST-- +Test DateTime::getTimezone() function : basic functionality +--FILE-- +getTimeZone()->getName() ); + + +date_default_timezone_set("America/New_York"); +$object = new DateTime("2009-01-30 17:57:32"); +var_dump( $object->getTimeZone()->getName() ); + +$la_time = new DateTimeZone("America/Los_Angeles"); +$object->setTimeZone($la_time); +var_dump( $object->getTimeZone()->getName() ); + +?> +===DONE=== +--EXPECTF-- +*** Testing DateTime::getTimezone() : basic functionality *** +unicode(13) "Europe/London" +unicode(16) "America/New_York" +unicode(19) "America/Los_Angeles" +===DONE=== diff --git a/ext/date/tests/DateTime_modify_basic1.phpt b/ext/date/tests/DateTime_modify_basic1.phpt new file mode 100644 index 0000000000..052524d5a4 --- /dev/null +++ b/ext/date/tests/DateTime_modify_basic1.phpt @@ -0,0 +1,39 @@ +--TEST-- +Test DateTime::modify() function : basic functionality +--FILE-- +modify("+1 day"); +echo "After modification 1: " . $datetime->format("D, d M Y") . "\n"; + +$datetime->modify("+1 week 2 days 4 hours 2 seconds"); +echo "After modification 2: " . $datetime->format("D, d M Y H:i:s") . "\n"; + +$datetime->modify("next Thursday"); +echo "After modification 3: " . $datetime->format("D, d M Y") . "\n"; + +$datetime->modify("last Sunday"); +echo "After modification 4: " . $datetime->format("D, d M Y") . "\n"; + +?> +===DONE=== +--EXPECTF-- +*** Testing DateTime::modify() : basic functionality *** +After modification 1: Sun, 01 Feb 2009 +After modification 2: Tue, 10 Feb 2009 18:28:43 +After modification 3: Thu, 12 Feb 2009 +After modification 4: Sun, 08 Feb 2009 +===DONE=== diff --git a/ext/date/tests/DateTime_modify_error.phpt b/ext/date/tests/DateTime_modify_error.phpt new file mode 100644 index 0000000000..bc4f2423f4 --- /dev/null +++ b/ext/date/tests/DateTime_modify_error.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test DateTime::modify() function : error conditions +--FILE-- +modify() ); + +echo "\n-- Testing DateTime::modify() function with more than expected no. of arguments --\n"; +$modify = "+1 day"; +$extra_arg = 99; +var_dump( $object->modify($modify, $extra_arg) ); + +?> +===DONE=== +--EXPECTF-- +*** Testing DateTime::modify() : error conditions *** + +-- Testing DateTime::modify() function with less than expected no. of arguments -- + +Warning: DateTime::modify() expects exactly 1 parameter, 0 given in %s on line %d +bool(false) + +-- Testing DateTime::modify() function with more than expected no. of arguments -- + +Warning: DateTime::modify() expects exactly 1 parameter, 2 given in %s on line %d +bool(false) +===DONE=== + diff --git a/ext/date/tests/DateTime_modify_variation1.phpt b/ext/date/tests/DateTime_modify_variation1.phpt new file mode 100644 index 0000000000..29b1403c27 --- /dev/null +++ b/ext/date/tests/DateTime_modify_variation1.phpt @@ -0,0 +1,362 @@ +--TEST-- +Test DateTime::modify() function : usage variation - Passing unexpected values to first argument $modify. +--FILE-- + 1, 'two' => 2); + +// resource +$file_handle = fopen(__FILE__, 'r'); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -12345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + '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, + + // resource + 'resource' => $file_handle +); + +$object = new DateTime("2009-01-31 14:28:41"); + +foreach($inputs as $variation =>$format) { + echo "\n-- $variation --\n"; + var_dump( $object->modify($format) ); +}; + +// closing the resource +fclose( $file_handle ); + +?> +===DONE=== +--EXPECTF-- +*** Testing DateTime::modify() : usage variation - unexpected values to first argument $modify*** + +-- int 0 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-31 14:28:41" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- int 1 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-31 14:28:41" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- int 12345 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-31 14:28:41" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- int -12345 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-31 14:28:41" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- float 10.5 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-31 14:28:41" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- float -10.5 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-31 14:28:41" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- float .5 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-31 14:28:41" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- empty array -- + +Warning: DateTime::modify() expects parameter 1 to be binary string, array given in %s on line %d +bool(false) + +-- int indexed array -- + +Warning: DateTime::modify() expects parameter 1 to be binary string, array given in %s on line %d +bool(false) + +-- associative array -- + +Warning: DateTime::modify() expects parameter 1 to be binary string, array given in %s on line %d +bool(false) + +-- nested arrays -- + +Warning: DateTime::modify() expects parameter 1 to be binary string, array given in %s on line %d +bool(false) + +-- uppercase NULL -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-31 14:28:41" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- lowercase null -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-31 14:28:41" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- lowercase true -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-31 14:28:41" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- lowercase false -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-31 14:28:41" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- uppercase TRUE -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-31 14:28:41" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- uppercase FALSE -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-31 14:28:41" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- empty string DQ -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-31 14:28:41" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- empty string SQ -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-31 14:28:41" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- string DQ -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-31 14:28:41" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- string SQ -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-31 14:28:41" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- mixed case string -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-31 14:28:41" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- heredoc -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-31 14:28:41" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- instance of classWithToString -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-31 14:28:41" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- instance of classWithoutToString -- + +Warning: DateTime::modify() expects parameter 1 to be binary string, object given in %s on line %d +bool(false) + +-- undefined var -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-31 14:28:41" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- unset var -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-31 14:28:41" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- resource -- + +Warning: DateTime::modify() expects parameter 1 to be binary string, resource given in %s on line %d +bool(false) +===DONE=== diff --git a/ext/date/tests/DateTime_serialize.phpt b/ext/date/tests/DateTime_serialize.phpt new file mode 100644 index 0000000000..d9b6b0a517 --- /dev/null +++ b/ext/date/tests/DateTime_serialize.phpt @@ -0,0 +1,39 @@ +--TEST-- +Test serialization of DateTime objects +--FILE-- +format( "F j, Y, g:i a") ); + +?> +===DONE=== +--EXPECTF-- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2005-07-14 22:30:41" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} +unicode(118) "O:8:"DateTime":3:{U:4:"date";U:19:"2005-07-14 22:30:41";U:13:"timezone_type";i:3;U:8:"timezone";U:13:"Europe/London";}" +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2005-07-14 22:30:41" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} +unicode(23) "July 14, 2005, 10:30 pm" +===DONE=== \ No newline at end of file diff --git a/ext/date/tests/DateTime_setDate_basic1.phpt b/ext/date/tests/DateTime_setDate_basic1.phpt new file mode 100644 index 0000000000..7989470cda --- /dev/null +++ b/ext/date/tests/DateTime_setDate_basic1.phpt @@ -0,0 +1,30 @@ +--TEST-- +Test DateTime::setDate() function : basic functionality +--FILE-- +format(DATE_RFC2822) . "\n"; + +$datetime->setDate(2008, 02, 01); + +echo $datetime->format(DATE_RFC2822) . "\n"; + +?> +===DONE=== +--EXPECTF-- +*** Testing DateTime::setDate() : basic functionality *** +Fri, 30 Jan 2009 19:34:10 +0000 +Fri, 01 Feb 2008 19:34:10 +0000 +===DONE=== \ No newline at end of file diff --git a/ext/date/tests/DateTime_setDate_error.phpt b/ext/date/tests/DateTime_setDate_error.phpt new file mode 100644 index 0000000000..29c019a262 --- /dev/null +++ b/ext/date/tests/DateTime_setDate_error.phpt @@ -0,0 +1,53 @@ +--TEST-- +Test DateTime::setDate() function : error conditions +--FILE-- +setDate() ); + +echo "\n-- Testing DateTime::setDate() function with less than expected no. of arguments --\n"; +$year = 2009; +$month = 1; +$day = 30; +var_dump( $datetime->setDate($year) ); +var_dump( $datetime->setDate($year, $month) ); + +echo "\n-- Testing DateTime::setDate() function with more than expected no. of arguments --\n"; +$extra_arg = 10; +var_dump( $datetime->setDate($year, $month, $day, $extra_arg) ); + +?> +===DONE=== +--EXPECTF-- +*** Testing DateTime::setDate() : error conditions *** + +-- Testing DateTime::setDate() function with zero arguments -- + +Warning: DateTime::setDate() expects exactly 3 parameters, 0 given in %s on line %d +bool(false) + +-- Testing DateTime::setDate() function with less than expected no. of arguments -- + +Warning: DateTime::setDate() expects exactly 3 parameters, 1 given in %s on line %d +bool(false) + +Warning: DateTime::setDate() expects exactly 3 parameters, 2 given in %s on line %d +bool(false) + +-- Testing DateTime::setDate() function with more than expected no. of arguments -- + +Warning: DateTime::setDate() expects exactly 3 parameters, 4 given in %s on line %d +bool(false) +===DONE=== diff --git a/ext/date/tests/DateTime_setDate_variation1.phpt b/ext/date/tests/DateTime_setDate_variation1.phpt new file mode 100644 index 0000000000..a74d149043 --- /dev/null +++ b/ext/date/tests/DateTime_setDate_variation1.phpt @@ -0,0 +1,329 @@ +--TEST-- +Test DateTime::setDate() function : usage variation - Passing unexpected values to first argument $year. +--FILE-- + 1, 'two' => 2); + +// resource +$file_handle = fopen(__FILE__, 'r'); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -12345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + '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, + + // resource + 'resource' => $file_handle +); + +$object = new DateTime("2009-02-27 08:34:10"); +$day = 2; +$month = 7; + +foreach($inputs as $variation =>$year) { + echo "\n-- $variation --\n"; + var_dump( $object->setDate($year, $month, $day) ); +}; + +// closing the resource +fclose( $file_handle ); + +?> +===DONE=== +--EXPECTF-- +*** Testing DateTime::setDate() : usage variation - unexpected values to first argument $year*** + +-- int 0 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "0000-07-02 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- int 1 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "0001-07-02 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- int 12345 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(20) "12345-07-02 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- int -12345 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(21) "-12345-07-02 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- float 10.5 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "0010-07-02 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- float -10.5 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(20) "-0010-07-02 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- float .5 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "0000-07-02 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- empty array -- + +Warning: DateTime::setDate() expects parameter 1 to be long, array given in %s on line %d +bool(false) + +-- int indexed array -- + +Warning: DateTime::setDate() expects parameter 1 to be long, array given in %s on line %d +bool(false) + +-- associative array -- + +Warning: DateTime::setDate() expects parameter 1 to be long, array given in %s on line %d +bool(false) + +-- nested arrays -- + +Warning: DateTime::setDate() expects parameter 1 to be long, array given in %s on line %d +bool(false) + +-- uppercase NULL -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "0000-07-02 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- lowercase null -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "0000-07-02 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- lowercase true -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "0001-07-02 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- lowercase false -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "0000-07-02 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- uppercase TRUE -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "0001-07-02 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- uppercase FALSE -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "0000-07-02 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- empty string DQ -- + +Warning: DateTime::setDate() expects parameter 1 to be long, Unicode string given in %s on line %d +bool(false) + +-- empty string SQ -- + +Warning: DateTime::setDate() expects parameter 1 to be long, Unicode string given in %s on line %d +bool(false) + +-- string DQ -- + +Warning: DateTime::setDate() expects parameter 1 to be long, Unicode string given in %s on line %d +bool(false) + +-- string SQ -- + +Warning: DateTime::setDate() expects parameter 1 to be long, Unicode string given in %s on line %d +bool(false) + +-- mixed case string -- + +Warning: DateTime::setDate() expects parameter 1 to be long, Unicode string given in %s on line %d +bool(false) + +-- heredoc -- + +Warning: DateTime::setDate() expects parameter 1 to be long, Unicode string given in %s on line %d +bool(false) + +-- instance of classWithToString -- + +Warning: DateTime::setDate() expects parameter 1 to be long, object given in %s on line %d +bool(false) + +-- instance of classWithoutToString -- + +Warning: DateTime::setDate() expects parameter 1 to be long, object given in %s on line %d +bool(false) + +-- undefined var -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "0000-07-02 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- unset var -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "0000-07-02 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- resource -- + +Warning: DateTime::setDate() expects parameter 1 to be long, resource given in %s on line %d +bool(false) +===DONE=== diff --git a/ext/date/tests/DateTime_setDate_variation2.phpt b/ext/date/tests/DateTime_setDate_variation2.phpt new file mode 100644 index 0000000000..b533691e86 --- /dev/null +++ b/ext/date/tests/DateTime_setDate_variation2.phpt @@ -0,0 +1,330 @@ +--TEST-- +Test DateTime::setDate() function : usage variation - Passing unexpected values to second argument $month. +--FILE-- + 1, 'two' => 2); + +// resource +$file_handle = fopen(__FILE__, 'r'); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -12345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + '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, + + // resource + 'resource' => $file_handle +); + +$object = new DateTime("2009-02-27 08:34:10"); +$day = 2; +$year = 1963; + +foreach($inputs as $variation =>$month) { + echo "\n-- $variation --\n"; + var_dump( $object->setDate($year, $month, $day) ); +}; + +// closing the resource +fclose( $file_handle ); + +?> +===DONE=== +--EXPECTF-- + +*** Testing DateTime::setDate() : usage variation - unexpected values to second argument $month*** + +-- int 0 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1962-12-02 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- int 1 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1963-01-02 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- int 12345 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2991-09-02 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- int -12345 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "0934-03-02 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- float 10.5 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1963-10-02 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- float -10.5 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1962-02-02 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- float .5 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1962-12-02 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- empty array -- + +Warning: DateTime::setDate() expects parameter 2 to be long, array given in %s on line %d +bool(false) + +-- int indexed array -- + +Warning: DateTime::setDate() expects parameter 2 to be long, array given in %s on line %d +bool(false) + +-- associative array -- + +Warning: DateTime::setDate() expects parameter 2 to be long, array given in %s on line %d +bool(false) + +-- nested arrays -- + +Warning: DateTime::setDate() expects parameter 2 to be long, array given in %s on line %d +bool(false) + +-- uppercase NULL -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1962-12-02 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- lowercase null -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1962-12-02 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- lowercase true -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1963-01-02 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- lowercase false -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1962-12-02 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- uppercase TRUE -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1963-01-02 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- uppercase FALSE -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1962-12-02 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- empty string DQ -- + +Warning: DateTime::setDate() expects parameter 2 to be long, Unicode string given in %s on line %d +bool(false) + +-- empty string SQ -- + +Warning: DateTime::setDate() expects parameter 2 to be long, Unicode string given in %s on line %d +bool(false) + +-- string DQ -- + +Warning: DateTime::setDate() expects parameter 2 to be long, Unicode string given in %s on line %d +bool(false) + +-- string SQ -- + +Warning: DateTime::setDate() expects parameter 2 to be long, Unicode string given in %s on line %d +bool(false) + +-- mixed case string -- + +Warning: DateTime::setDate() expects parameter 2 to be long, Unicode string given in %s on line %d +bool(false) + +-- heredoc -- + +Warning: DateTime::setDate() expects parameter 2 to be long, Unicode string given in %s on line %d +bool(false) + +-- instance of classWithToString -- + +Warning: DateTime::setDate() expects parameter 2 to be long, object given in %s on line %d +bool(false) + +-- instance of classWithoutToString -- + +Warning: DateTime::setDate() expects parameter 2 to be long, object given in %s on line %d +bool(false) + +-- undefined var -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1962-12-02 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- unset var -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1962-12-02 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- resource -- + +Warning: DateTime::setDate() expects parameter 2 to be long, resource given in %s on line %d +bool(false) +===DONE=== diff --git a/ext/date/tests/DateTime_setDate_variation3.phpt b/ext/date/tests/DateTime_setDate_variation3.phpt new file mode 100644 index 0000000000..79b54f8176 --- /dev/null +++ b/ext/date/tests/DateTime_setDate_variation3.phpt @@ -0,0 +1,329 @@ +--TEST-- +Test DateTime::setDate() function : usage variation - Passing unexpected values to third argument $day. +--FILE-- + 1, 'two' => 2); + +// resource +$file_handle = fopen(__FILE__, 'r'); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -12345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + '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, + + // resource + 'resource' => $file_handle +); + +$object = new DateTime("2009-02-27 08:34:10"); +$month = 7; +$year = 1963; + +foreach($inputs as $variation =>$day) { + echo "\n-- $variation --\n"; + var_dump( $object->setDate($year, $month, $day) ); +}; + +// closing the resource +fclose( $file_handle ); + +?> +===DONE=== +--EXPECTF-- +*** Testing DateTime::setDate() : usage variation - unexpected values to third argument $day*** + +-- int 0 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1963-06-30 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- int 1 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1963-07-01 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- int 12345 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1997-04-17 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- int -12345 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1929-09-11 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- float 10.5 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1963-07-10 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- float -10.5 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1963-06-20 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- float .5 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1963-06-30 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- empty array -- + +Warning: DateTime::setDate() expects parameter 3 to be long, array given in %s on line %d +bool(false) + +-- int indexed array -- + +Warning: DateTime::setDate() expects parameter 3 to be long, array given in %s on line %d +bool(false) + +-- associative array -- + +Warning: DateTime::setDate() expects parameter 3 to be long, array given in %s on line %d +bool(false) + +-- nested arrays -- + +Warning: DateTime::setDate() expects parameter 3 to be long, array given in %s on line %d +bool(false) + +-- uppercase NULL -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1963-06-30 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- lowercase null -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1963-06-30 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- lowercase true -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1963-07-01 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- lowercase false -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1963-06-30 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- uppercase TRUE -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1963-07-01 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- uppercase FALSE -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1963-06-30 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- empty string DQ -- + +Warning: DateTime::setDate() expects parameter 3 to be long, Unicode string given in %s on line %d +bool(false) + +-- empty string SQ -- + +Warning: DateTime::setDate() expects parameter 3 to be long, Unicode string given in %s on line %d +bool(false) + +-- string DQ -- + +Warning: DateTime::setDate() expects parameter 3 to be long, Unicode string given in %s on line %d +bool(false) + +-- string SQ -- + +Warning: DateTime::setDate() expects parameter 3 to be long, Unicode string given in %s on line %d +bool(false) + +-- mixed case string -- + +Warning: DateTime::setDate() expects parameter 3 to be long, Unicode string given in %s on line %d +bool(false) + +-- heredoc -- + +Warning: DateTime::setDate() expects parameter 3 to be long, Unicode string given in %s on line %d +bool(false) + +-- instance of classWithToString -- + +Warning: DateTime::setDate() expects parameter 3 to be long, object given in %s on line %d +bool(false) + +-- instance of classWithoutToString -- + +Warning: DateTime::setDate() expects parameter 3 to be long, object given in %s on line %d +bool(false) + +-- undefined var -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1963-06-30 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- unset var -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1963-06-30 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- resource -- + +Warning: DateTime::setDate() expects parameter 3 to be long, resource given in %s on line %d +bool(false) +===DONE=== diff --git a/ext/date/tests/DateTime_setISODate_basic1.phpt b/ext/date/tests/DateTime_setISODate_basic1.phpt new file mode 100644 index 0000000000..cdedb44e7a --- /dev/null +++ b/ext/date/tests/DateTime_setISODate_basic1.phpt @@ -0,0 +1,38 @@ +--TEST-- +Test DateTime::setISODate() function : basic functionality +--FILE-- +setISODate(2008, 40); +echo "Week 40 of 2009 is in \"" . $datetime->format("F") . "\"\n"; + +// What date is week week 30 day 3 ? +$datetime->setISODate(2009, 30, 3); +echo "Week 30 day 3 of 2009 is \"" . $datetime->format("D M j") . "\"\n"; + +// What date was is last year ? +$datetime->setISODate(2008, 30, 3); +echo "..same day last year was \"" . $datetime->format("D M j") . "\"\n"; + +?> +===DONE=== +--EXPECTF-- +*** Testing DateTime::setISODate() : basic functionality *** +Week 40 of 2009 is in "September" +Week 30 day 3 of 2009 is "Wed Jul 22" +..same day last year was "Wed Jul 23" +===DONE=== diff --git a/ext/date/tests/DateTime_setISODate_error.phpt b/ext/date/tests/DateTime_setISODate_error.phpt new file mode 100644 index 0000000000..af22581829 --- /dev/null +++ b/ext/date/tests/DateTime_setISODate_error.phpt @@ -0,0 +1,51 @@ +--TEST-- +Test DateTime::setISODate () function : error conditions +--FILE-- +setISODate() ); + +$year = 2009; +echo "\n-- Testing DateTime::setISODate() function with less than expected no. of arguments --\n"; +var_dump( $datetime->setISODate($year) ); + +echo "\n-- Testing date_isodate_set() function with more than expected no. of arguments --\n"; +$week = 30; +$day = 7; +$extra_arg = 30; +var_dump( $datetime->setISODate($year, $week, $day, $extra_arg) ); + +?> +===DONE=== +--EXPECTF-- +*** Testing DateTime::setISODate () : error conditions *** + +-- Testing DateTime::setISODate() function with zero arguments -- + +Warning: DateTime::setISODate() expects at least 2 parameters, 0 given in %s on line %d +bool(false) + +-- Testing DateTime::setISODate() function with less than expected no. of arguments -- + +Warning: DateTime::setISODate() expects at least 2 parameters, 1 given in %s on line %d +bool(false) + +-- Testing date_isodate_set() function with more than expected no. of arguments -- + +Warning: DateTime::setISODate() expects at most 3 parameters, 4 given in %s on line %d +bool(false) +===DONE=== diff --git a/ext/date/tests/DateTime_setISODate_variation1.phpt b/ext/date/tests/DateTime_setISODate_variation1.phpt new file mode 100644 index 0000000000..55c78803bd --- /dev/null +++ b/ext/date/tests/DateTime_setISODate_variation1.phpt @@ -0,0 +1,329 @@ +--TEST-- +Test DateTime::setISODate() function : usage variation - Passing unexpected values to first argument $year. +--FILE-- + 1, 'two' => 2); + +// resource +$file_handle = fopen(__FILE__, 'r'); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -12345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + '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, + + // resource + 'resource' => $file_handle +); + +$object = new DateTime("2009-02-27 08:34:10"); +$day = 2; +$month = 7; + +foreach($inputs as $variation =>$year) { + echo "\n-- $variation --\n"; + var_dump( $object->setISODate($year, $month, $day) ); +}; + +// closing the resource +fclose( $file_handle ); + +?> +===DONE=== +--EXPECTF-- +*** Testing DateTime::setISODate() : usage variation - unexpected values to first argument $year*** + +-- int 0 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "0000-02-15 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- int 1 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "0001-02-13 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- int 12345 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(20) "12345-02-13 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- int -12345 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(21) "-12345-02-15 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- float 10.5 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "0010-02-16 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- float -10.5 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(20) "-0010-02-19 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- float .5 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "0000-02-15 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- empty array -- + +Warning: DateTime::setISODate() expects parameter 1 to be long, array given in %s on line %d +bool(false) + +-- int indexed array -- + +Warning: DateTime::setISODate() expects parameter 1 to be long, array given in %s on line %d +bool(false) + +-- associative array -- + +Warning: DateTime::setISODate() expects parameter 1 to be long, array given in %s on line %d +bool(false) + +-- nested arrays -- + +Warning: DateTime::setISODate() expects parameter 1 to be long, array given in %s on line %d +bool(false) + +-- uppercase NULL -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "0000-02-15 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- lowercase null -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "0000-02-15 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- lowercase true -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "0001-02-13 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- lowercase false -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "0000-02-15 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- uppercase TRUE -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "0001-02-13 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- uppercase FALSE -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "0000-02-15 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- empty string DQ -- + +Warning: DateTime::setISODate() expects parameter 1 to be long, Unicode string given in %s on line %d +bool(false) + +-- empty string SQ -- + +Warning: DateTime::setISODate() expects parameter 1 to be long, Unicode string given in %s on line %d +bool(false) + +-- string DQ -- + +Warning: DateTime::setISODate() expects parameter 1 to be long, Unicode string given in %s on line %d +bool(false) + +-- string SQ -- + +Warning: DateTime::setISODate() expects parameter 1 to be long, Unicode string given in %s on line %d +bool(false) + +-- mixed case string -- + +Warning: DateTime::setISODate() expects parameter 1 to be long, Unicode string given in %s on line %d +bool(false) + +-- heredoc -- + +Warning: DateTime::setISODate() expects parameter 1 to be long, Unicode string given in %s on line %d +bool(false) + +-- instance of classWithToString -- + +Warning: DateTime::setISODate() expects parameter 1 to be long, object given in %s on line %d +bool(false) + +-- instance of classWithoutToString -- + +Warning: DateTime::setISODate() expects parameter 1 to be long, object given in %s on line %d +bool(false) + +-- undefined var -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "0000-02-15 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- unset var -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "0000-02-15 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- resource -- + +Warning: DateTime::setISODate() expects parameter 1 to be long, resource given in %s on line %d +bool(false) +===DONE=== diff --git a/ext/date/tests/DateTime_setISODate_variation2.phpt b/ext/date/tests/DateTime_setISODate_variation2.phpt new file mode 100644 index 0000000000..365b9a4753 --- /dev/null +++ b/ext/date/tests/DateTime_setISODate_variation2.phpt @@ -0,0 +1,329 @@ +--TEST-- +Test DateTime::setISODate() function : usage variation - Passing unexpected values to second argument $week. +--FILE-- + 1, 'two' => 2); + +// resource +$file_handle = fopen(__FILE__, 'r'); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -12345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + '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, + + // resource + 'resource' => $file_handle +); + +$object = date_create("2009-02-27 08:34:10"); +$day = 2; +$year = 1963; + +foreach($inputs as $variation =>$month) { + echo "\n-- $variation --\n"; + var_dump( $object->setISODate($year, $month, $day) ); +}; + +// closing the resource +fclose( $file_handle ); + +?> +===DONE=== +--EXPECTF-- +*** Testing DateTime::setISODate() : usage variation - unexpected values to second argument $week*** + +-- int 0 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1962-12-25 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- int 1 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1963-01-01 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- int 12345 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2199-07-30 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- int -12345 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1726-05-21 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- float 10.5 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1963-03-05 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- float -10.5 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1962-10-16 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- float .5 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1962-12-25 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- empty array -- + +Warning: DateTime::setISODate() expects parameter 2 to be long, array given in %s on line %d +bool(false) + +-- int indexed array -- + +Warning: DateTime::setISODate() expects parameter 2 to be long, array given in %s on line %d +bool(false) + +-- associative array -- + +Warning: DateTime::setISODate() expects parameter 2 to be long, array given in %s on line %d +bool(false) + +-- nested arrays -- + +Warning: DateTime::setISODate() expects parameter 2 to be long, array given in %s on line %d +bool(false) + +-- uppercase NULL -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1962-12-25 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- lowercase null -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1962-12-25 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- lowercase true -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1963-01-01 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- lowercase false -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1962-12-25 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- uppercase TRUE -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1963-01-01 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- uppercase FALSE -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1962-12-25 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- empty string DQ -- + +Warning: DateTime::setISODate() expects parameter 2 to be long, Unicode string given in %s on line %d +bool(false) + +-- empty string SQ -- + +Warning: DateTime::setISODate() expects parameter 2 to be long, Unicode string given in %s on line %d +bool(false) + +-- string DQ -- + +Warning: DateTime::setISODate() expects parameter 2 to be long, Unicode string given in %s on line %d +bool(false) + +-- string SQ -- + +Warning: DateTime::setISODate() expects parameter 2 to be long, Unicode string given in %s on line %d +bool(false) + +-- mixed case string -- + +Warning: DateTime::setISODate() expects parameter 2 to be long, Unicode string given in %s on line %d +bool(false) + +-- heredoc -- + +Warning: DateTime::setISODate() expects parameter 2 to be long, Unicode string given in %s on line %d +bool(false) + +-- instance of classWithToString -- + +Warning: DateTime::setISODate() expects parameter 2 to be long, object given in %s on line %d +bool(false) + +-- instance of classWithoutToString -- + +Warning: DateTime::setISODate() expects parameter 2 to be long, object given in %s on line %d +bool(false) + +-- undefined var -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1962-12-25 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- unset var -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1962-12-25 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- resource -- + +Warning: DateTime::setISODate() expects parameter 2 to be long, resource given in %s on line %d +bool(false) +===DONE=== \ No newline at end of file diff --git a/ext/date/tests/DateTime_setISODate_variation3.phpt b/ext/date/tests/DateTime_setISODate_variation3.phpt new file mode 100644 index 0000000000..b86caa891e --- /dev/null +++ b/ext/date/tests/DateTime_setISODate_variation3.phpt @@ -0,0 +1,329 @@ +--TEST-- +Test DateTime::setISODate() function : usage variation - Passing unexpected values to third argument $day. +--FILE-- + 1, 'two' => 2); + +// resource +$file_handle = fopen(__FILE__, 'r'); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -12345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + '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, + + // resource + 'resource' => $file_handle +); + +$object = date_create("2009-02-27 08:34:10"); +$year = 1963; +$month = 7; + +foreach($inputs as $variation =>$day) { + echo "\n-- $variation --\n"; + var_dump( $object->setISODate($year, $month, $day) ); +}; + +// closing the resource +fclose( $file_handle ); + +?> +===DONE=== +--EXPECTF-- +*** Testing DateTime::setISODate() : usage variation - unexpected values to third argument $day*** + +-- int 0 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1963-02-10 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- int 1 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1963-02-11 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- int 12345 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1996-11-28 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- int -12345 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1929-04-24 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- float 10.5 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1963-02-20 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- float -10.5 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1963-01-31 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- float .5 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1963-02-10 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- empty array -- + +Warning: DateTime::setISODate() expects parameter 3 to be long, array given in %s on line %d +bool(false) + +-- int indexed array -- + +Warning: DateTime::setISODate() expects parameter 3 to be long, array given in %s on line %d +bool(false) + +-- associative array -- + +Warning: DateTime::setISODate() expects parameter 3 to be long, array given in %s on line %d +bool(false) + +-- nested arrays -- + +Warning: DateTime::setISODate() expects parameter 3 to be long, array given in %s on line %d +bool(false) + +-- uppercase NULL -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1963-02-10 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- lowercase null -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1963-02-10 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- lowercase true -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1963-02-11 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- lowercase false -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1963-02-10 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- uppercase TRUE -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1963-02-11 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- uppercase FALSE -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1963-02-10 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- empty string DQ -- + +Warning: DateTime::setISODate() expects parameter 3 to be long, Unicode string given in %s on line %d +bool(false) + +-- empty string SQ -- + +Warning: DateTime::setISODate() expects parameter 3 to be long, Unicode string given in %s on line %d +bool(false) + +-- string DQ -- + +Warning: DateTime::setISODate() expects parameter 3 to be long, Unicode string given in %s on line %d +bool(false) + +-- string SQ -- + +Warning: DateTime::setISODate() expects parameter 3 to be long, Unicode string given in %s on line %d +bool(false) + +-- mixed case string -- + +Warning: DateTime::setISODate() expects parameter 3 to be long, Unicode string given in %s on line %d +bool(false) + +-- heredoc -- + +Warning: DateTime::setISODate() expects parameter 3 to be long, Unicode string given in %s on line %d +bool(false) + +-- instance of classWithToString -- + +Warning: DateTime::setISODate() expects parameter 3 to be long, object given in %s on line %d +bool(false) + +-- instance of classWithoutToString -- + +Warning: DateTime::setISODate() expects parameter 3 to be long, object given in %s on line %d +bool(false) + +-- undefined var -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1963-02-10 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- unset var -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "1963-02-10 08:34:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- resource -- + +Warning: DateTime::setISODate() expects parameter 3 to be long, resource given in %s on line %d +bool(false) +===DONE=== diff --git a/ext/date/tests/DateTime_setTime_basic1.phpt b/ext/date/tests/DateTime_setTime_basic1.phpt new file mode 100644 index 0000000000..bd95fecd08 --- /dev/null +++ b/ext/date/tests/DateTime_setTime_basic1.phpt @@ -0,0 +1,46 @@ +--TEST-- +Test DateTime::setTime() function : basic functionality +--FILE-- +format(DATE_RFC2822) . "\n"; + +$datetime->setTime(17, 20); +echo "After modification1 " . $datetime ->format(DATE_RFC2822) . "\n"; + +$datetime->setTime(19, 05, 59); +echo "After modification2 " . $datetime ->format(DATE_RFC2822) . "\n"; + +$datetime->setTime(24, 10); +echo "After modification3 " . $datetime ->format(DATE_RFC2822) . "\n"; + +$datetime->setTime(47, 35, 47); +echo "After modification4 " . $datetime ->format(DATE_RFC2822) . "\n"; + +$datetime->setTime(54, 25); +echo "After modification5 " . $datetime ->format(DATE_RFC2822) . "\n"; + +?> +===DONE=== +--EXPECTF-- +*** Testing DateTime::setTime() : basic functionality *** +Initial date: Sat, 31 Jan 2009 15:14:10 +0000 +After modification1 Sat, 31 Jan 2009 17:20:00 +0000 +After modification2 Sat, 31 Jan 2009 19:05:59 +0000 +After modification3 Sun, 01 Feb 2009 00:10:00 +0000 +After modification4 Mon, 02 Feb 2009 23:35:47 +0000 +After modification5 Wed, 04 Feb 2009 06:25:00 +0000 +===DONE=== diff --git a/ext/date/tests/DateTime_setTime_error.phpt b/ext/date/tests/DateTime_setTime_error.phpt new file mode 100644 index 0000000000..eaf1555d1d --- /dev/null +++ b/ext/date/tests/DateTime_setTime_error.phpt @@ -0,0 +1,49 @@ +--TEST-- +Test DateTime::setTime() function : error conditions +--FILE-- +setTime() ); + +echo "\n-- Testing DateTime::setTime() function with less than expected no. of arguments --\n"; +$hour = 18; +var_dump( $datetime->setTime($hour) ); + +echo "\n-- Testing DateTime::setTime() function with more than expected no. of arguments --\n"; +$min = 15; +$sec = 30; +$extra_arg = 10; +var_dump( $datetime->setTime($hour, $min, $sec, $extra_arg) ); + +?> +===DONE=== +--EXPECTF-- +*** Testing DateTime::setTime() : error conditions *** + +-- Testing DateTime::setTime() function with zero arguments -- + +Warning: DateTime::setTime() expects at least 2 parameters, 0 given in %s on line %d +bool(false) + +-- Testing DateTime::setTime() function with less than expected no. of arguments -- + +Warning: DateTime::setTime() expects at least 2 parameters, 1 given in %s on line %d +bool(false) + +-- Testing DateTime::setTime() function with more than expected no. of arguments -- + +Warning: DateTime::setTime() expects at most 3 parameters, 4 given in %s on line %d +bool(false) +===DONE=== diff --git a/ext/date/tests/DateTime_setTime_variation1.phpt b/ext/date/tests/DateTime_setTime_variation1.phpt new file mode 100644 index 0000000000..231eeeec44 --- /dev/null +++ b/ext/date/tests/DateTime_setTime_variation1.phpt @@ -0,0 +1,329 @@ +--TEST-- +Test DateTime::setTime() function : usage variation - Passing unexpected values to first argument $hour. +--FILE-- + 1, 'two' => 2); + +// resource +$file_handle = fopen(__FILE__, 'r'); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -12345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + '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, + + // resource + 'resource' => $file_handle +); + +$object = new DateTime("2009-01-31 15:14:10"); +$minute = 13; +$sec = 45; + +foreach($inputs as $variation =>$hour) { + echo "\n-- $variation --\n"; + var_dump( $object->setTime($hour, $minute, $sec) ); +}; + +// closing the resource +fclose( $file_handle ); + +?> +===DONE=== +--EXPECTF-- +*** Testing DateTime::setTime() : usage variation - unexpected values to first argument $hour*** + +-- int 0 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-31 00:13:45" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- int 1 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-31 01:13:45" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- int 12345 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2010-06-29 09:13:45" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- int -12345 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-30 15:13:45" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- float 10.5 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-30 10:13:45" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- float -10.5 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-29 14:13:45" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- float .5 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-29 00:13:45" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- empty array -- + +Warning: DateTime::setTime() expects parameter 1 to be long, array given in %s on line %d +bool(false) + +-- int indexed array -- + +Warning: DateTime::setTime() expects parameter 1 to be long, array given in %s on line %d +bool(false) + +-- associative array -- + +Warning: DateTime::setTime() expects parameter 1 to be long, array given in %s on line %d +bool(false) + +-- nested arrays -- + +Warning: DateTime::setTime() expects parameter 1 to be long, array given in %s on line %d +bool(false) + +-- uppercase NULL -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-29 00:13:45" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- lowercase null -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-29 00:13:45" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- lowercase true -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-29 01:13:45" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- lowercase false -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-29 00:13:45" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- uppercase TRUE -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-29 01:13:45" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- uppercase FALSE -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-29 00:13:45" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- empty string DQ -- + +Warning: DateTime::setTime() expects parameter 1 to be long, Unicode string given in %s on line %d +bool(false) + +-- empty string SQ -- + +Warning: DateTime::setTime() expects parameter 1 to be long, Unicode string given in %s on line %d +bool(false) + +-- string DQ -- + +Warning: DateTime::setTime() expects parameter 1 to be long, Unicode string given in %s on line %d +bool(false) + +-- string SQ -- + +Warning: DateTime::setTime() expects parameter 1 to be long, Unicode string given in %s on line %d +bool(false) + +-- mixed case string -- + +Warning: DateTime::setTime() expects parameter 1 to be long, Unicode string given in %s on line %d +bool(false) + +-- heredoc -- + +Warning: DateTime::setTime() expects parameter 1 to be long, Unicode string given in %s on line %d +bool(false) + +-- instance of classWithToString -- + +Warning: DateTime::setTime() expects parameter 1 to be long, object given in %s on line %d +bool(false) + +-- instance of classWithoutToString -- + +Warning: DateTime::setTime() expects parameter 1 to be long, object given in %s on line %d +bool(false) + +-- undefined var -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-29 00:13:45" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- unset var -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-29 00:13:45" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- resource -- + +Warning: DateTime::setTime() expects parameter 1 to be long, resource given in %s on line %d +bool(false) +===DONE=== diff --git a/ext/date/tests/DateTime_setTime_variation2.phpt b/ext/date/tests/DateTime_setTime_variation2.phpt new file mode 100644 index 0000000000..8d0d30df67 --- /dev/null +++ b/ext/date/tests/DateTime_setTime_variation2.phpt @@ -0,0 +1,329 @@ +--TEST-- +Test DateTime::setTime() function : usage variation - Passing unexpected values to second argument $minute. +--FILE-- + 1, 'two' => 2); + +// resource +$file_handle = fopen(__FILE__, 'r'); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -12345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + '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, + + // resource + 'resource' => $file_handle +); + +$object = new DateTime("2009-01-31 15:14:10"); +$hour = 10; +$sec = 45; + +foreach($inputs as $variation =>$minute) { + echo "\n-- $variation --\n"; + var_dump( $object->setTime($hour, $minute, $sec) ); +}; + +// closing the resource +fclose( $file_handle ); + +?> +===DONE=== +--EXPECTF-- +*** Testing DateTime::setTime() : usage variation - unexpected values to second argument $minute*** + +-- int 0 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-31 10:00:45" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- int 1 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-31 10:01:45" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- int 12345 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-02-08 23:45:45" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- int -12345 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-30 20:15:45" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- float 10.5 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-30 10:10:45" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- float -10.5 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-30 09:50:45" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- float .5 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-30 10:00:45" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- empty array -- + +Warning: DateTime::setTime() expects parameter 2 to be long, array given in %s on line %d +bool(false) + +-- int indexed array -- + +Warning: DateTime::setTime() expects parameter 2 to be long, array given in %s on line %d +bool(false) + +-- associative array -- + +Warning: DateTime::setTime() expects parameter 2 to be long, array given in %s on line %d +bool(false) + +-- nested arrays -- + +Warning: DateTime::setTime() expects parameter 2 to be long, array given in %s on line %d +bool(false) + +-- uppercase NULL -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-30 10:00:45" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- lowercase null -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-30 10:00:45" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- lowercase true -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-30 10:01:45" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- lowercase false -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-30 10:00:45" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- uppercase TRUE -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-30 10:01:45" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- uppercase FALSE -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-30 10:00:45" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- empty string DQ -- + +Warning: DateTime::setTime() expects parameter 2 to be long, Unicode string given in %s on line %d +bool(false) + +-- empty string SQ -- + +Warning: DateTime::setTime() expects parameter 2 to be long, Unicode string given in %s on line %d +bool(false) + +-- string DQ -- + +Warning: DateTime::setTime() expects parameter 2 to be long, Unicode string given in %s on line %d +bool(false) + +-- string SQ -- + +Warning: DateTime::setTime() expects parameter 2 to be long, Unicode string given in %s on line %d +bool(false) + +-- mixed case string -- + +Warning: DateTime::setTime() expects parameter 2 to be long, Unicode string given in %s on line %d +bool(false) + +-- heredoc -- + +Warning: DateTime::setTime() expects parameter 2 to be long, Unicode string given in %s on line %d +bool(false) + +-- instance of classWithToString -- + +Warning: DateTime::setTime() expects parameter 2 to be long, object given in %s on line %d +bool(false) + +-- instance of classWithoutToString -- + +Warning: DateTime::setTime() expects parameter 2 to be long, object given in %s on line %d +bool(false) + +-- undefined var -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-30 10:00:45" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- unset var -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-30 10:00:45" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- resource -- + +Warning: DateTime::setTime() expects parameter 2 to be long, resource given in %s on line %d +bool(false) +===DONE=== diff --git a/ext/date/tests/DateTime_setTime_variation3.phpt b/ext/date/tests/DateTime_setTime_variation3.phpt new file mode 100644 index 0000000000..9040b6c641 --- /dev/null +++ b/ext/date/tests/DateTime_setTime_variation3.phpt @@ -0,0 +1,329 @@ +--TEST-- +Test DateTime::setTime() function : usage variation - Passing unexpected values to third argument $second. +--FILE-- + 1, 'two' => 2); + +// resource +$file_handle = fopen(__FILE__, 'r'); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -12345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + '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, + + // resource + 'resource' => $file_handle +); + +$object = new DateTime("2009-01-31 15:14:10"); +$hour = 10; +$minute = 13; + +foreach($inputs as $variation =>$sec) { + echo "\n-- $variation --\n"; + var_dump( $object->setTime($hour, $minute, $sec) ); +}; + +// closing the resource +fclose( $file_handle ); + +?> +===DONE=== +--EXPECTF-- +*** Testing DateTime::setTime() : usage variation - unexpected values to third argument $second*** + +-- int 0 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-31 10:13:00" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- int 1 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-31 10:13:01" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- int 12345 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-31 13:38:45" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- int -12345 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-31 06:47:15" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- float 10.5 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-31 10:13:10" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- float -10.5 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-31 10:12:50" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- float .5 -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-31 10:13:00" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- empty array -- + +Warning: DateTime::setTime() expects parameter 3 to be long, array given in %s on line %d +bool(false) + +-- int indexed array -- + +Warning: DateTime::setTime() expects parameter 3 to be long, array given in %s on line %d +bool(false) + +-- associative array -- + +Warning: DateTime::setTime() expects parameter 3 to be long, array given in %s on line %d +bool(false) + +-- nested arrays -- + +Warning: DateTime::setTime() expects parameter 3 to be long, array given in %s on line %d +bool(false) + +-- uppercase NULL -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-31 10:13:00" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- lowercase null -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-31 10:13:00" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- lowercase true -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-31 10:13:01" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- lowercase false -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-31 10:13:00" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- uppercase TRUE -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-31 10:13:01" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- uppercase FALSE -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-31 10:13:00" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- empty string DQ -- + +Warning: DateTime::setTime() expects parameter 3 to be long, Unicode string given in %s on line %d +bool(false) + +-- empty string SQ -- + +Warning: DateTime::setTime() expects parameter 3 to be long, Unicode string given in %s on line %d +bool(false) + +-- string DQ -- + +Warning: DateTime::setTime() expects parameter 3 to be long, Unicode string given in %s on line %d +bool(false) + +-- string SQ -- + +Warning: DateTime::setTime() expects parameter 3 to be long, Unicode string given in %s on line %d +bool(false) + +-- mixed case string -- + +Warning: DateTime::setTime() expects parameter 3 to be long, Unicode string given in %s on line %d +bool(false) + +-- heredoc -- + +Warning: DateTime::setTime() expects parameter 3 to be long, Unicode string given in %s on line %d +bool(false) + +-- instance of classWithToString -- + +Warning: DateTime::setTime() expects parameter 3 to be long, object given in %s on line %d +bool(false) + +-- instance of classWithoutToString -- + +Warning: DateTime::setTime() expects parameter 3 to be long, object given in %s on line %d +bool(false) + +-- undefined var -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-31 10:13:00" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- unset var -- +object(DateTime)#%d (3) { + [u"date"]=> + unicode(19) "2009-01-31 10:13:00" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(13) "Europe/London" +} + +-- resource -- + +Warning: DateTime::setTime() expects parameter 3 to be long, resource given in %s on line %d +bool(false) +===DONE=== diff --git a/ext/date/tests/DateTime_setTimezone_basic1.phpt b/ext/date/tests/DateTime_setTimezone_basic1.phpt new file mode 100644 index 0000000000..f4f479fe04 --- /dev/null +++ b/ext/date/tests/DateTime_setTimezone_basic1.phpt @@ -0,0 +1,29 @@ +--TEST-- +Test DateTime::setTimezone() function : basic functionality +--FILE-- +getName() . "\n"; + +$la_time = new DateTimezone("America/Los_Angeles"); +$datetime->setTimezone($la_time); +echo "New timezone: " . date_timezone_get($datetime)->getName() . "\n"; + +?> +===DONE=== +--EXPECTF-- +*** Testing DateTime::setTimezone() : basic functionality *** +Default timezone: Europe/London +New timezone: America/Los_Angeles +===DONE=== diff --git a/ext/date/tests/DateTime_setTimezone_error.phpt b/ext/date/tests/DateTime_setTimezone_error.phpt new file mode 100644 index 0000000000..32d03fbec9 --- /dev/null +++ b/ext/date/tests/DateTime_setTimezone_error.phpt @@ -0,0 +1,39 @@ +--TEST-- +Test DateTime::setTimezone () function : error conditions +--FILE-- +setTimezone() ); + +echo "\n-- Testing DateTime::setTimezone () function with more than expected no. of arguments --\n"; +$timezone = new DateTimezone("GMT"); +$extra_arg = 99; +var_dump( $datetime->setTimezone($timezone, $extra_arg) ); + +?> +===DONE=== +--EXPECTF-- +*** Testing DateTime::setTimezone () : error conditions *** + +-- Testing DateTime::setTimezone () function with zero arguments -- + +Warning: DateTime::setTimezone() expects exactly 1 parameter, 0 given in %s on line %d +bool(false) + +-- Testing DateTime::setTimezone () function with more than expected no. of arguments -- + +Warning: DateTime::setTimezone() expects exactly 1 parameter, 2 given in %s on line %d +bool(false) +===DONE=== diff --git a/ext/date/tests/DateTime_setTimezone_variation1.phpt b/ext/date/tests/DateTime_setTimezone_variation1.phpt new file mode 100644 index 0000000000..bfc9e1d230 --- /dev/null +++ b/ext/date/tests/DateTime_setTimezone_variation1.phpt @@ -0,0 +1,252 @@ +--TEST-- +Test DateTime::setTimezone() function : usage variation - Passing unexpected values to first argument $timezone. +--FILE-- + 1, 'two' => 2); + +// resource +$file_handle = fopen(__FILE__, 'r'); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -12345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + '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, + + // resource + 'resource' => $file_handle +); + +$object = new DateTime("2009-01-30 17:57:32"); + +foreach($inputs as $variation =>$timezone) { + echo "\n-- $variation --\n"; + var_dump( $object->setTimezone($timezone) ); +}; + +// closing the resource +fclose( $file_handle ); + +?> +===DONE=== +--EXPECTF-- +*** Testing DateTime::setTimezone() : usage variation - unexpected values to first argument $timezone*** + +-- int 0 -- + +Warning: DateTime::setTimezone() expects parameter 1 to be DateTimeZone, integer given in %s on line %d +bool(false) + +-- int 1 -- + +Warning: DateTime::setTimezone() expects parameter 1 to be DateTimeZone, integer given in %s on line %d +bool(false) + +-- int 12345 -- + +Warning: DateTime::setTimezone() expects parameter 1 to be DateTimeZone, integer given in %s on line %d +bool(false) + +-- int -12345 -- + +Warning: DateTime::setTimezone() expects parameter 1 to be DateTimeZone, integer given in %s on line %d +bool(false) + +-- float 10.5 -- + +Warning: DateTime::setTimezone() expects parameter 1 to be DateTimeZone, double given in %s on line %d +bool(false) + +-- float -10.5 -- + +Warning: DateTime::setTimezone() expects parameter 1 to be DateTimeZone, double given in %s on line %d +bool(false) + +-- float .5 -- + +Warning: DateTime::setTimezone() expects parameter 1 to be DateTimeZone, double given in %s on line %d +bool(false) + +-- empty array -- + +Warning: DateTime::setTimezone() expects parameter 1 to be DateTimeZone, array given in %s on line %d +bool(false) + +-- int indexed array -- + +Warning: DateTime::setTimezone() expects parameter 1 to be DateTimeZone, array given in %s on line %d +bool(false) + +-- associative array -- + +Warning: DateTime::setTimezone() expects parameter 1 to be DateTimeZone, array given in %s on line %d +bool(false) + +-- nested arrays -- + +Warning: DateTime::setTimezone() expects parameter 1 to be DateTimeZone, array given in %s on line %d +bool(false) + +-- uppercase NULL -- + +Warning: DateTime::setTimezone() expects parameter 1 to be DateTimeZone, null given in %s on line %d +bool(false) + +-- lowercase null -- + +Warning: DateTime::setTimezone() expects parameter 1 to be DateTimeZone, null given in %s on line %d +bool(false) + +-- lowercase true -- + +Warning: DateTime::setTimezone() expects parameter 1 to be DateTimeZone, boolean given in %s on line %d +bool(false) + +-- lowercase false -- + +Warning: DateTime::setTimezone() expects parameter 1 to be DateTimeZone, boolean given in %s on line %d +bool(false) + +-- uppercase TRUE -- + +Warning: DateTime::setTimezone() expects parameter 1 to be DateTimeZone, boolean given in %s on line %d +bool(false) + +-- uppercase FALSE -- + +Warning: DateTime::setTimezone() expects parameter 1 to be DateTimeZone, boolean given in %s on line %d +bool(false) + +-- empty string DQ -- + +Warning: DateTime::setTimezone() expects parameter 1 to be DateTimeZone, Unicode string given in %s on line %d +bool(false) + +-- empty string SQ -- + +Warning: DateTime::setTimezone() expects parameter 1 to be DateTimeZone, Unicode string given in %s on line %d +bool(false) + +-- string DQ -- + +Warning: DateTime::setTimezone() expects parameter 1 to be DateTimeZone, Unicode string given in %s on line %d +bool(false) + +-- string SQ -- + +Warning: DateTime::setTimezone() expects parameter 1 to be DateTimeZone, Unicode string given in %s on line %d +bool(false) + +-- mixed case string -- + +Warning: DateTime::setTimezone() expects parameter 1 to be DateTimeZone, Unicode string given in %s on line %d +bool(false) + +-- heredoc -- + +Warning: DateTime::setTimezone() expects parameter 1 to be DateTimeZone, Unicode string given in %s on line %d +bool(false) + +-- instance of classWithToString -- + +Warning: DateTime::setTimezone() expects parameter 1 to be DateTimeZone, object given in %s on line %d +bool(false) + +-- instance of classWithoutToString -- + +Warning: DateTime::setTimezone() expects parameter 1 to be DateTimeZone, object given in %s on line %d +bool(false) + +-- undefined var -- + +Warning: DateTime::setTimezone() expects parameter 1 to be DateTimeZone, null given in %s on line %d +bool(false) + +-- unset var -- + +Warning: DateTime::setTimezone() expects parameter 1 to be DateTimeZone, null given in %s on line %d +bool(false) + +-- resource -- + +Warning: DateTime::setTimezone() expects parameter 1 to be DateTimeZone, resource given in %s on line %d +bool(false) +===DONE=== diff --git a/ext/date/tests/DateTime_verify.phpt b/ext/date/tests/DateTime_verify.phpt new file mode 100644 index 0000000000..1b5149fb9d --- /dev/null +++ b/ext/date/tests/DateTime_verify.phpt @@ -0,0 +1,183 @@ +--TEST-- +Test DateTime class registration +--FILE-- +getMethods(); +var_dump($methods); + +echo "..and get names of all its class constants\n"; +$constants = $class->getConstants(); +var_dump($constants); + +?> +===DONE=== +--EXPECTF-- +*** Verify DateTime class *** +Verify DateTime class registered OK +object(ReflectionClass)#%d (1) { + [u"name"]=> + unicode(8) "DateTime" +} +..and get names of all its methods +array(18) { + [0]=> + &object(ReflectionMethod)#%d (2) { + [u"name"]=> + unicode(11) "__construct" + [u"class"]=> + unicode(8) "DateTime" + } + [1]=> + &object(ReflectionMethod)#%d (2) { + [u"name"]=> + unicode(8) "__wakeup" + [u"class"]=> + unicode(8) "DateTime" + } + [2]=> + &object(ReflectionMethod)#%d (2) { + [u"name"]=> + unicode(11) "__set_state" + [u"class"]=> + unicode(8) "DateTime" + } + [3]=> + &object(ReflectionMethod)#%d (2) { + [u"name"]=> + unicode(16) "createFromFormat" + [u"class"]=> + unicode(8) "DateTime" + } + [4]=> + &object(ReflectionMethod)#%d (2) { + [u"name"]=> + unicode(13) "getLastErrors" + [u"class"]=> + unicode(8) "DateTime" + } + [5]=> + &object(ReflectionMethod)#%d (2) { + [u"name"]=> + unicode(6) "format" + [u"class"]=> + unicode(8) "DateTime" + } + [6]=> + &object(ReflectionMethod)#%d (2) { + [u"name"]=> + unicode(6) "modify" + [u"class"]=> + unicode(8) "DateTime" + } + [7]=> + &object(ReflectionMethod)#%d (2) { + [u"name"]=> + unicode(3) "add" + [u"class"]=> + unicode(8) "DateTime" + } + [8]=> + &object(ReflectionMethod)#%d (2) { + [u"name"]=> + unicode(3) "sub" + [u"class"]=> + unicode(8) "DateTime" + } + [9]=> + &object(ReflectionMethod)#%d (2) { + [u"name"]=> + unicode(11) "getTimezone" + [u"class"]=> + unicode(8) "DateTime" + } + [10]=> + &object(ReflectionMethod)#%d (2) { + [u"name"]=> + unicode(11) "setTimezone" + [u"class"]=> + unicode(8) "DateTime" + } + [11]=> + &object(ReflectionMethod)#%d (2) { + [u"name"]=> + unicode(9) "getOffset" + [u"class"]=> + unicode(8) "DateTime" + } + [12]=> + &object(ReflectionMethod)#%d (2) { + [u"name"]=> + unicode(7) "setTime" + [u"class"]=> + unicode(8) "DateTime" + } + [13]=> + &object(ReflectionMethod)#%d (2) { + [u"name"]=> + unicode(7) "setDate" + [u"class"]=> + unicode(8) "DateTime" + } + [14]=> + &object(ReflectionMethod)#%d (2) { + [u"name"]=> + unicode(10) "setISODate" + [u"class"]=> + unicode(8) "DateTime" + } + [15]=> + &object(ReflectionMethod)#%d (2) { + [u"name"]=> + unicode(12) "setTimestamp" + [u"class"]=> + unicode(8) "DateTime" + } + [16]=> + &object(ReflectionMethod)#%d (2) { + [u"name"]=> + unicode(12) "getTimestamp" + [u"class"]=> + unicode(8) "DateTime" + } + [17]=> + &object(ReflectionMethod)#%d (2) { + [u"name"]=> + unicode(4) "diff" + [u"class"]=> + unicode(8) "DateTime" + } +} +..and get names of all its class constants +array(11) { + [u"ATOM"]=> + unicode(13) "Y-m-d\TH:i:sP" + [u"COOKIE"]=> + unicode(16) "l, d-M-y H:i:s T" + [u"ISO8601"]=> + unicode(13) "Y-m-d\TH:i:sO" + [u"RFC822"]=> + unicode(16) "D, d M y H:i:s O" + [u"RFC850"]=> + unicode(16) "l, d-M-y H:i:s T" + [u"RFC1036"]=> + unicode(16) "D, d M y H:i:s O" + [u"RFC1123"]=> + unicode(16) "D, d M Y H:i:s O" + [u"RFC2822"]=> + unicode(16) "D, d M Y H:i:s O" + [u"RFC3339"]=> + unicode(13) "Y-m-d\TH:i:sP" + [u"RSS"]=> + unicode(16) "D, d M Y H:i:s O" + [u"W3C"]=> + unicode(13) "Y-m-d\TH:i:sP" +} +===DONE===