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

1.1       misho       1: --TEST--
                      2: Test date_create() function : usage variation - Passing unexpected values to first argument $time.
                      3: --FILE--
                      4: <?php
                      5: /* Prototype  : DateTime date_create  ([ string $time  [, DateTimeZone $timezone  ]] )
                      6:  * Description: Returns new DateTime object
                      7:  * Source code: ext/date/php_date.c
                      8:  * Alias to functions: DateTime::__construct
                      9:  */
                     10: 
                     11: echo "*** Testing date_create() : usage variation -  unexpected values to first argument \$time***\n";
                     12: 
                     13: //Set the default time zone 
                     14: date_default_timezone_set("Europe/London");
                     15: 
                     16: //get an unset variable
                     17: $unset_var = 10;
                     18: unset ($unset_var);
                     19: 
                     20: // define some classes
                     21: class classWithToString
                     22: {
                     23:        public function __toString() {
                     24:                return "Class A object";
                     25:        }
                     26: }
                     27: 
                     28: class classWithoutToString
                     29: {
                     30: }
                     31: 
                     32: // heredoc string
                     33: $heredoc = <<<EOT
                     34: hello world
                     35: EOT;
                     36: 
                     37: // add arrays
                     38: $index_array = array (1, 2, 3);
                     39: $assoc_array = array ('one' => 1, 'two' => 2);
                     40: 
                     41: // resource
                     42: $file_handle = fopen(__FILE__, 'r');
                     43: 
                     44: //array of values to iterate over
                     45: $inputs = array(
                     46: 
                     47:       // int data
                     48:       'int 0' => 0,
                     49:       'int 1' => 1,
                     50:       'int 12345' => 12345,
                     51:       'int -12345' => -12345,
                     52: 
                     53:       // float data
                     54:       'float 10.5' => 10.5,
                     55:       'float -10.5' => -10.5,
                     56:       'float .5' => .5,
                     57: 
                     58:       // array data
                     59:       'empty array' => array(),
                     60:       'int indexed array' => $index_array,
                     61:       'associative array' => $assoc_array,
                     62:       'nested arrays' => array('foo', $index_array, $assoc_array),
                     63: 
                     64:       // null data
                     65:       'uppercase NULL' => NULL,
                     66:       'lowercase null' => null,
                     67: 
                     68:       // boolean data
                     69:       'lowercase true' => true,
                     70:       'lowercase false' =>false,
                     71:       'uppercase TRUE' =>TRUE,
                     72:       'uppercase FALSE' =>FALSE,
                     73: 
                     74:       // empty data
                     75:       'empty string DQ' => "",
                     76:       'empty string SQ' => '',
                     77: 
                     78:       // string data
                     79:       'string DQ' => "string",
                     80:       'string SQ' => 'string',
                     81:       'mixed case string' => "sTrInG",
                     82:       'heredoc' => $heredoc,
                     83: 
                     84:       // object data
                     85:       'instance of classWithToString' => new classWithToString(),
                     86:       'instance of classWithoutToString' => new classWithoutToString(),
                     87: 
                     88:       // undefined data
                     89:       'undefined var' => @$undefined_var,
                     90: 
                     91:       // unset data
                     92:       'unset var' => @$unset_var,
                     93:       
                     94:       // resource 
                     95:       'resource' => $file_handle
                     96: );
                     97: 
                     98: $timezone = new DateTimeZone("Europe/London");
                     99: 
                    100: foreach($inputs as $variation =>$time) {
                    101:       echo "\n-- $variation --\n";
                    102:       var_dump( date_create($time) );
                    103:       var_dump( date_create($time, $timezone) );
                    104: };
                    105: 
                    106: // closing the resource
                    107: fclose( $file_handle);
                    108: 
                    109: ?>
                    110: ===DONE===
                    111: --EXPECTF--
                    112: *** Testing date_create() : usage variation -  unexpected values to first argument $time***
                    113: 
                    114: -- int 0 --
                    115: bool(false)
                    116: bool(false)
                    117: 
                    118: -- int 1 --
                    119: bool(false)
                    120: bool(false)
                    121: 
                    122: -- int 12345 --
                    123: bool(false)
                    124: bool(false)
                    125: 
                    126: -- int -12345 --
                    127: bool(false)
                    128: bool(false)
                    129: 
                    130: -- float 10.5 --
                    131: object(DateTime)#%d (3) {
                    132:   ["date"]=>
                    133:   string(19) "%s"
                    134:   ["timezone_type"]=>
                    135:   int(3)
                    136:   ["timezone"]=>
                    137:   string(13) "Europe/London"
                    138: }
                    139: object(DateTime)#%d (3) {
                    140:   ["date"]=>
                    141:   string(19) "%s"
                    142:   ["timezone_type"]=>
                    143:   int(3)
                    144:   ["timezone"]=>
                    145:   string(13) "Europe/London"
                    146: }
                    147: 
                    148: -- float -10.5 --
                    149: bool(false)
                    150: bool(false)
                    151: 
                    152: -- float .5 --
                    153: object(DateTime)#%d (3) {
                    154:   ["date"]=>
                    155:   string(19) "%s"
                    156:   ["timezone_type"]=>
                    157:   int(3)
                    158:   ["timezone"]=>
                    159:   string(13) "Europe/London"
                    160: }
                    161: object(DateTime)#%d (3) {
                    162:   ["date"]=>
                    163:   string(19) "%s"
                    164:   ["timezone_type"]=>
                    165:   int(3)
                    166:   ["timezone"]=>
                    167:   string(13) "Europe/London"
                    168: }
                    169: 
                    170: -- empty array --
                    171: 
                    172: Warning: date_create() expects parameter 1 to be string, array given in %s on line %d
                    173: bool(false)
                    174: 
                    175: Warning: date_create() expects parameter 1 to be string, array given in %s on line %d
                    176: bool(false)
                    177: 
                    178: -- int indexed array --
                    179: 
                    180: Warning: date_create() expects parameter 1 to be string, array given in %s on line %d
                    181: bool(false)
                    182: 
                    183: Warning: date_create() expects parameter 1 to be string, array given in %s on line %d
                    184: bool(false)
                    185: 
                    186: -- associative array --
                    187: 
                    188: Warning: date_create() expects parameter 1 to be string, array given in %s on line %d
                    189: bool(false)
                    190: 
                    191: Warning: date_create() expects parameter 1 to be string, array given in %s on line %d
                    192: bool(false)
                    193: 
                    194: -- nested arrays --
                    195: 
                    196: Warning: date_create() expects parameter 1 to be string, array given in %s on line %d
                    197: bool(false)
                    198: 
                    199: Warning: date_create() expects parameter 1 to be string, array given in %s on line %d
                    200: bool(false)
                    201: 
                    202: -- uppercase NULL --
                    203: object(DateTime)#%d (3) {
                    204:   ["date"]=>
                    205:   string(19) "%s"
                    206:   ["timezone_type"]=>
                    207:   int(3)
                    208:   ["timezone"]=>
                    209:   string(13) "Europe/London"
                    210: }
                    211: object(DateTime)#%d (3) {
                    212:   ["date"]=>
                    213:   string(19) "%s"
                    214:   ["timezone_type"]=>
                    215:   int(3)
                    216:   ["timezone"]=>
                    217:   string(13) "Europe/London"
                    218: }
                    219: 
                    220: -- lowercase null --
                    221: object(DateTime)#%d (3) {
                    222:   ["date"]=>
                    223:   string(19) "%s"
                    224:   ["timezone_type"]=>
                    225:   int(3)
                    226:   ["timezone"]=>
                    227:   string(13) "Europe/London"
                    228: }
                    229: object(DateTime)#%d (3) {
                    230:   ["date"]=>
                    231:   string(19) "%s"
                    232:   ["timezone_type"]=>
                    233:   int(3)
                    234:   ["timezone"]=>
                    235:   string(13) "Europe/London"
                    236: }
                    237: 
                    238: -- lowercase true --
                    239: bool(false)
                    240: bool(false)
                    241: 
                    242: -- lowercase false --
                    243: object(DateTime)#%d (3) {
                    244:   ["date"]=>
                    245:   string(19) "%s"
                    246:   ["timezone_type"]=>
                    247:   int(3)
                    248:   ["timezone"]=>
                    249:   string(13) "Europe/London"
                    250: }
                    251: object(DateTime)#%d (3) {
                    252:   ["date"]=>
                    253:   string(19) "%s"
                    254:   ["timezone_type"]=>
                    255:   int(3)
                    256:   ["timezone"]=>
                    257:   string(13) "Europe/London"
                    258: }
                    259: 
                    260: -- uppercase TRUE --
                    261: bool(false)
                    262: bool(false)
                    263: 
                    264: -- uppercase FALSE --
                    265: object(DateTime)#%d (3) {
                    266:   ["date"]=>
                    267:   string(19) "%s"
                    268:   ["timezone_type"]=>
                    269:   int(3)
                    270:   ["timezone"]=>
                    271:   string(13) "Europe/London"
                    272: }
                    273: object(DateTime)#%d (3) {
                    274:   ["date"]=>
                    275:   string(19) "%s"
                    276:   ["timezone_type"]=>
                    277:   int(3)
                    278:   ["timezone"]=>
                    279:   string(13) "Europe/London"
                    280: }
                    281: 
                    282: -- empty string DQ --
                    283: object(DateTime)#%d (3) {
                    284:   ["date"]=>
                    285:   string(19) "%s"
                    286:   ["timezone_type"]=>
                    287:   int(3)
                    288:   ["timezone"]=>
                    289:   string(13) "Europe/London"
                    290: }
                    291: object(DateTime)#%d (3) {
                    292:   ["date"]=>
                    293:   string(19) "%s"
                    294:   ["timezone_type"]=>
                    295:   int(3)
                    296:   ["timezone"]=>
                    297:   string(13) "Europe/London"
                    298: }
                    299: 
                    300: -- empty string SQ --
                    301: object(DateTime)#%d (3) {
                    302:   ["date"]=>
                    303:   string(19) "%s"
                    304:   ["timezone_type"]=>
                    305:   int(3)
                    306:   ["timezone"]=>
                    307:   string(13) "Europe/London"
                    308: }
                    309: object(DateTime)#%d (3) {
                    310:   ["date"]=>
                    311:   string(19) "%s"
                    312:   ["timezone_type"]=>
                    313:   int(3)
                    314:   ["timezone"]=>
                    315:   string(13) "Europe/London"
                    316: }
                    317: 
                    318: -- string DQ --
                    319: bool(false)
                    320: bool(false)
                    321: 
                    322: -- string SQ --
                    323: bool(false)
                    324: bool(false)
                    325: 
                    326: -- mixed case string --
                    327: bool(false)
                    328: bool(false)
                    329: 
                    330: -- heredoc --
                    331: bool(false)
                    332: bool(false)
                    333: 
                    334: -- instance of classWithToString --
                    335: bool(false)
                    336: bool(false)
                    337: 
                    338: -- instance of classWithoutToString --
                    339: 
                    340: Warning: date_create() expects parameter 1 to be string, object given in %s on line %d
                    341: bool(false)
                    342: 
                    343: Warning: date_create() expects parameter 1 to be string, object given in %s on line %d
                    344: bool(false)
                    345: 
                    346: -- undefined var --
                    347: object(DateTime)#%d (3) {
                    348:   ["date"]=>
                    349:   string(19) "%s"
                    350:   ["timezone_type"]=>
                    351:   int(3)
                    352:   ["timezone"]=>
                    353:   string(13) "Europe/London"
                    354: }
                    355: object(DateTime)#%d (3) {
                    356:   ["date"]=>
                    357:   string(19) "%s"
                    358:   ["timezone_type"]=>
                    359:   int(3)
                    360:   ["timezone"]=>
                    361:   string(13) "Europe/London"
                    362: }
                    363: 
                    364: -- unset var --
                    365: object(DateTime)#%d (3) {
                    366:   ["date"]=>
                    367:   string(19) "%s"
                    368:   ["timezone_type"]=>
                    369:   int(3)
                    370:   ["timezone"]=>
                    371:   string(13) "Europe/London"
                    372: }
                    373: object(DateTime)#%d (3) {
                    374:   ["date"]=>
                    375:   string(19) "%s"
                    376:   ["timezone_type"]=>
                    377:   int(3)
                    378:   ["timezone"]=>
                    379:   string(13) "Europe/London"
                    380: }
                    381: 
                    382: -- resource --
                    383: 
                    384: Warning: date_create() expects parameter 1 to be string, resource given in %s on line %d
                    385: bool(false)
                    386: 
                    387: Warning: date_create() expects parameter 1 to be string, resource given in %s on line %d
                    388: bool(false)
                    389: ===DONE===

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