Annotation of embedaddon/php/ext/date/tests/gmdate_variation2.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test gmdate() function : usage variation - Passing unexpected values to timestamp argument.
                      3: --FILE--
                      4: <?php
                      5: /* Prototype  : string gmdate(string format [, long timestamp])
                      6:  * Description: Format a GMT date/time 
                      7:  * Source code: ext/date/php_date.c
                      8:  * Alias to functions: 
                      9:  */
                     10: 
                     11: echo "*** Testing gmdate() : usage variation ***\n";
                     12: 
                     13: 
                     14: // Initialise all required variables
                     15: date_default_timezone_set('UTC');
                     16: $format = DATE_ISO8601;
                     17: 
                     18: //get an unset variable
                     19: $unset_var = 10;
                     20: unset ($unset_var);
                     21: 
                     22: // define some classes
                     23: class classWithToString
                     24: {
                     25:        public function __toString() {
                     26:                return "Class A object";
                     27:        }
                     28: }
                     29: 
                     30: class classWithoutToString
                     31: {
                     32: }
                     33: 
                     34: // heredoc string
                     35: $heredoc = <<<EOT
                     36: hello world
                     37: EOT;
                     38: 
                     39: // add arrays
                     40: $index_array = array (1, 2, 3);
                     41: $assoc_array = array ('one' => 1, 'two' => 2);
                     42: 
                     43: //array of values to iterate over
                     44: $inputs = array(
                     45: 
                     46:       // int data
                     47:       'int 0' => 0,
                     48:       'int 1' => 1,
                     49:       'int 12345' => 12345,
                     50:       'int -12345' => -12345,
                     51: 
                     52:       // float data
                     53:       'float 10.5' => 10.5,
                     54:       'float -10.5' => -10.5,
                     55:       'float .5' => .5,
                     56: 
                     57:       // array data
                     58:       'empty array' => array(),
                     59:       'int indexed array' => $index_array,
                     60:       'associative array' => $assoc_array,
                     61:       'nested arrays' => array('foo', $index_array, $assoc_array),
                     62: 
                     63:       // null data
                     64:       'uppercase NULL' => NULL,
                     65:       'lowercase null' => null,
                     66: 
                     67:       // boolean data
                     68:       'lowercase true' => true,
                     69:       'lowercase false' =>false,
                     70:       'uppercase TRUE' =>TRUE,
                     71:       'uppercase FALSE' =>FALSE,
                     72: 
                     73:       // empty data
                     74:       'empty string DQ' => "",
                     75:       'empty string SQ' => '',
                     76: 
                     77:       // string data
                     78:       'string DQ' => "string",
                     79:       'string SQ' => 'string',
                     80:       'mixed case string' => "sTrInG",
                     81:       'heredoc' => $heredoc,
                     82: 
                     83:       // object data
                     84:       'instance of classWithToString' => new classWithToString(),
                     85:       'instance of classWithoutToString' => new classWithoutToString(),
                     86: 
                     87:       // undefined data
                     88:       'undefined var' => @$undefined_var,
                     89: 
                     90:       // unset data
                     91:       'unset var' => @$unset_var,
                     92: );
                     93: 
                     94: // loop through each element of the array for timestamp
                     95: 
                     96: foreach($inputs as $key =>$value) {
                     97:       echo "\n--$key--\n";
                     98:       var_dump( gmdate($format, $value) );
                     99: };
                    100: 
                    101: ?>
                    102: ===DONE===
                    103: --EXPECTF--
                    104: *** Testing gmdate() : usage variation ***
                    105: 
                    106: --int 0--
                    107: string(24) "1970-01-01T00:00:00+0000"
                    108: 
                    109: --int 1--
                    110: string(24) "1970-01-01T00:00:01+0000"
                    111: 
                    112: --int 12345--
                    113: string(24) "1970-01-01T03:25:45+0000"
                    114: 
                    115: --int -12345--
                    116: string(24) "1969-12-31T20:34:15+0000"
                    117: 
                    118: --float 10.5--
                    119: string(24) "1970-01-01T00:00:10+0000"
                    120: 
                    121: --float -10.5--
                    122: string(24) "1969-12-31T23:59:50+0000"
                    123: 
                    124: --float .5--
                    125: string(24) "1970-01-01T00:00:00+0000"
                    126: 
                    127: --empty array--
                    128: 
                    129: Warning: gmdate() expects parameter 2 to be long, array given in %s on line %d
                    130: bool(false)
                    131: 
                    132: --int indexed array--
                    133: 
                    134: Warning: gmdate() expects parameter 2 to be long, array given in %s on line %d
                    135: bool(false)
                    136: 
                    137: --associative array--
                    138: 
                    139: Warning: gmdate() expects parameter 2 to be long, array given in %s on line %d
                    140: bool(false)
                    141: 
                    142: --nested arrays--
                    143: 
                    144: Warning: gmdate() expects parameter 2 to be long, array given in %s on line %d
                    145: bool(false)
                    146: 
                    147: --uppercase NULL--
                    148: string(24) "1970-01-01T00:00:00+0000"
                    149: 
                    150: --lowercase null--
                    151: string(24) "1970-01-01T00:00:00+0000"
                    152: 
                    153: --lowercase true--
                    154: string(24) "1970-01-01T00:00:01+0000"
                    155: 
                    156: --lowercase false--
                    157: string(24) "1970-01-01T00:00:00+0000"
                    158: 
                    159: --uppercase TRUE--
                    160: string(24) "1970-01-01T00:00:01+0000"
                    161: 
                    162: --uppercase FALSE--
                    163: string(24) "1970-01-01T00:00:00+0000"
                    164: 
                    165: --empty string DQ--
                    166: 
                    167: Warning: gmdate() expects parameter 2 to be long, string given in %s on line %d
                    168: bool(false)
                    169: 
                    170: --empty string SQ--
                    171: 
                    172: Warning: gmdate() expects parameter 2 to be long, string given in %s on line %d
                    173: bool(false)
                    174: 
                    175: --string DQ--
                    176: 
                    177: Warning: gmdate() expects parameter 2 to be long, string given in %s on line %d
                    178: bool(false)
                    179: 
                    180: --string SQ--
                    181: 
                    182: Warning: gmdate() expects parameter 2 to be long, string given in %s on line %d
                    183: bool(false)
                    184: 
                    185: --mixed case string--
                    186: 
                    187: Warning: gmdate() expects parameter 2 to be long, string given in %s on line %d
                    188: bool(false)
                    189: 
                    190: --heredoc--
                    191: 
                    192: Warning: gmdate() expects parameter 2 to be long, string given in %s on line %d
                    193: bool(false)
                    194: 
                    195: --instance of classWithToString--
                    196: 
                    197: Warning: gmdate() expects parameter 2 to be long, object given in %s on line %d
                    198: bool(false)
                    199: 
                    200: --instance of classWithoutToString--
                    201: 
                    202: Warning: gmdate() expects parameter 2 to be long, object given in %s on line %d
                    203: bool(false)
                    204: 
                    205: --undefined var--
                    206: string(24) "1970-01-01T00:00:00+0000"
                    207: 
                    208: --unset var--
                    209: string(24) "1970-01-01T00:00:00+0000"
                    210: ===DONE===

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>