Annotation of embedaddon/php/ext/date/tests/DateTime_construct_variation1.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test new DateTime() function : usage variation - Passing unexpected values to first argument $time.
! 3: --FILE--
! 4: <?php
! 5: /* Prototype : DateTime::__construct ([ string $time="now" [, DateTimeZone $timezone=NULL ]] )
! 6: * Description: Returns new DateTime object
! 7: * Source code: ext/date/php_date.c
! 8: * Alias to functions: date_create
! 9: */
! 10:
! 11: echo "*** Testing new DateTime(): 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:
! 103: try {
! 104: var_dump( new DateTime($time) );
! 105: } catch(Exception $e) {
! 106: $msg = $e->getMessage();
! 107: echo "FAILED: " . $msg . "\n";
! 108: }
! 109:
! 110: try {
! 111: var_dump( new DateTime($time, $timezone) );
! 112: } catch(Exception$e) {
! 113: $msg = $e->getMessage();
! 114: echo "FAILED: " . $msg . "\n";
! 115: }
! 116: };
! 117:
! 118: // closing the resource
! 119: fclose( $file_handle);
! 120:
! 121: ?>
! 122: ===DONE===
! 123: --EXPECTF--
! 124: *** Testing new DateTime(): usage variation - unexpected values to first argument $time***
! 125:
! 126: -- int 0 --
! 127: FAILED: DateTime::__construct(): Failed to parse time string (0) at position 0 (0): Unexpected character
! 128: FAILED: DateTime::__construct(): Failed to parse time string (0) at position 0 (0): Unexpected character
! 129:
! 130: -- int 1 --
! 131: FAILED: DateTime::__construct(): Failed to parse time string (1) at position 0 (1): Unexpected character
! 132: FAILED: DateTime::__construct(): Failed to parse time string (1) at position 0 (1): Unexpected character
! 133:
! 134: -- int 12345 --
! 135: FAILED: DateTime::__construct(): Failed to parse time string (12345) at position 4 (5): Unexpected character
! 136: FAILED: DateTime::__construct(): Failed to parse time string (12345) at position 4 (5): Unexpected character
! 137:
! 138: -- int -12345 --
! 139: FAILED: DateTime::__construct(): Failed to parse time string (-12345) at position 5 (5): Unexpected character
! 140: FAILED: DateTime::__construct(): Failed to parse time string (-12345) at position 5 (5): Unexpected character
! 141:
! 142: -- float 10.5 --
! 143: object(DateTime)#%d (3) {
! 144: ["date"]=>
! 145: string(19) "%s"
! 146: ["timezone_type"]=>
! 147: int(3)
! 148: ["timezone"]=>
! 149: string(13) "Europe/London"
! 150: }
! 151: object(DateTime)#%d (3) {
! 152: ["date"]=>
! 153: string(19) "%s"
! 154: ["timezone_type"]=>
! 155: int(3)
! 156: ["timezone"]=>
! 157: string(13) "Europe/London"
! 158: }
! 159:
! 160: -- float -10.5 --
! 161: FAILED: DateTime::__construct(): Failed to parse time string (-10.5) at position 4 (5): Unexpected character
! 162: FAILED: DateTime::__construct(): Failed to parse time string (-10.5) at position 4 (5): Unexpected character
! 163:
! 164: -- float .5 --
! 165: object(DateTime)#%d (3) {
! 166: ["date"]=>
! 167: string(19) "%s"
! 168: ["timezone_type"]=>
! 169: int(3)
! 170: ["timezone"]=>
! 171: string(13) "Europe/London"
! 172: }
! 173: object(DateTime)#%d (3) {
! 174: ["date"]=>
! 175: string(19) "%s"
! 176: ["timezone_type"]=>
! 177: int(3)
! 178: ["timezone"]=>
! 179: string(13) "Europe/London"
! 180: }
! 181:
! 182: -- empty array --
! 183: FAILED: DateTime::__construct() expects parameter 1 to be string, array given
! 184: FAILED: DateTime::__construct() expects parameter 1 to be string, array given
! 185:
! 186: -- int indexed array --
! 187: FAILED: DateTime::__construct() expects parameter 1 to be string, array given
! 188: FAILED: DateTime::__construct() expects parameter 1 to be string, array given
! 189:
! 190: -- associative array --
! 191: FAILED: DateTime::__construct() expects parameter 1 to be string, array given
! 192: FAILED: DateTime::__construct() expects parameter 1 to be string, array given
! 193:
! 194: -- nested arrays --
! 195: FAILED: DateTime::__construct() expects parameter 1 to be string, array given
! 196: FAILED: DateTime::__construct() expects parameter 1 to be string, array given
! 197:
! 198: -- uppercase NULL --
! 199: object(DateTime)#%d (3) {
! 200: ["date"]=>
! 201: string(19) "%s"
! 202: ["timezone_type"]=>
! 203: int(3)
! 204: ["timezone"]=>
! 205: string(13) "Europe/London"
! 206: }
! 207: object(DateTime)#%d (3) {
! 208: ["date"]=>
! 209: string(19) "%s"
! 210: ["timezone_type"]=>
! 211: int(3)
! 212: ["timezone"]=>
! 213: string(13) "Europe/London"
! 214: }
! 215:
! 216: -- lowercase null --
! 217: object(DateTime)#%d (3) {
! 218: ["date"]=>
! 219: string(19) "%s"
! 220: ["timezone_type"]=>
! 221: int(3)
! 222: ["timezone"]=>
! 223: string(13) "Europe/London"
! 224: }
! 225: object(DateTime)#%d (3) {
! 226: ["date"]=>
! 227: string(19) "%s"
! 228: ["timezone_type"]=>
! 229: int(3)
! 230: ["timezone"]=>
! 231: string(13) "Europe/London"
! 232: }
! 233:
! 234: -- lowercase true --
! 235: FAILED: DateTime::__construct(): Failed to parse time string (1) at position 0 (1): Unexpected character
! 236: FAILED: DateTime::__construct(): Failed to parse time string (1) at position 0 (1): Unexpected character
! 237:
! 238: -- lowercase false --
! 239: object(DateTime)#%d (3) {
! 240: ["date"]=>
! 241: string(19) "%s"
! 242: ["timezone_type"]=>
! 243: int(3)
! 244: ["timezone"]=>
! 245: string(13) "Europe/London"
! 246: }
! 247: object(DateTime)#%d (3) {
! 248: ["date"]=>
! 249: string(19) "%s"
! 250: ["timezone_type"]=>
! 251: int(3)
! 252: ["timezone"]=>
! 253: string(13) "Europe/London"
! 254: }
! 255:
! 256: -- uppercase TRUE --
! 257: FAILED: DateTime::__construct(): Failed to parse time string (1) at position 0 (1): Unexpected character
! 258: FAILED: DateTime::__construct(): Failed to parse time string (1) at position 0 (1): Unexpected character
! 259:
! 260: -- uppercase FALSE --
! 261: object(DateTime)#%d (3) {
! 262: ["date"]=>
! 263: string(19) "%s"
! 264: ["timezone_type"]=>
! 265: int(3)
! 266: ["timezone"]=>
! 267: string(13) "Europe/London"
! 268: }
! 269: object(DateTime)#%d (3) {
! 270: ["date"]=>
! 271: string(19) "%s"
! 272: ["timezone_type"]=>
! 273: int(3)
! 274: ["timezone"]=>
! 275: string(13) "Europe/London"
! 276: }
! 277:
! 278: -- empty string DQ --
! 279: object(DateTime)#%d (3) {
! 280: ["date"]=>
! 281: string(19) "%s"
! 282: ["timezone_type"]=>
! 283: int(3)
! 284: ["timezone"]=>
! 285: string(13) "Europe/London"
! 286: }
! 287: object(DateTime)#%d (3) {
! 288: ["date"]=>
! 289: string(19) "%s"
! 290: ["timezone_type"]=>
! 291: int(3)
! 292: ["timezone"]=>
! 293: string(13) "Europe/London"
! 294: }
! 295:
! 296: -- empty string SQ --
! 297: object(DateTime)#%d (3) {
! 298: ["date"]=>
! 299: string(19) "%s"
! 300: ["timezone_type"]=>
! 301: int(3)
! 302: ["timezone"]=>
! 303: string(13) "Europe/London"
! 304: }
! 305: object(DateTime)#%d (3) {
! 306: ["date"]=>
! 307: string(19) "%s"
! 308: ["timezone_type"]=>
! 309: int(3)
! 310: ["timezone"]=>
! 311: string(13) "Europe/London"
! 312: }
! 313:
! 314: -- string DQ --
! 315: FAILED: DateTime::__construct(): Failed to parse time string (string) at position 0 (s): The timezone could not be found in the database
! 316: FAILED: DateTime::__construct(): Failed to parse time string (string) at position 0 (s): The timezone could not be found in the database
! 317:
! 318: -- string SQ --
! 319: FAILED: DateTime::__construct(): Failed to parse time string (string) at position 0 (s): The timezone could not be found in the database
! 320: FAILED: DateTime::__construct(): Failed to parse time string (string) at position 0 (s): The timezone could not be found in the database
! 321:
! 322: -- mixed case string --
! 323: FAILED: DateTime::__construct(): Failed to parse time string (sTrInG) at position 0 (s): The timezone could not be found in the database
! 324: FAILED: DateTime::__construct(): Failed to parse time string (sTrInG) at position 0 (s): The timezone could not be found in the database
! 325:
! 326: -- heredoc --
! 327: FAILED: DateTime::__construct(): Failed to parse time string (hello world) at position 0 (h): The timezone could not be found in the database
! 328: FAILED: DateTime::__construct(): Failed to parse time string (hello world) at position 0 (h): The timezone could not be found in the database
! 329:
! 330: -- instance of classWithToString --
! 331: FAILED: DateTime::__construct(): Failed to parse time string (Class A object) at position 0 (C): The timezone could not be found in the database
! 332: FAILED: DateTime::__construct(): Failed to parse time string (Class A object) at position 0 (C): The timezone could not be found in the database
! 333:
! 334: -- instance of classWithoutToString --
! 335: FAILED: DateTime::__construct() expects parameter 1 to be string, object given
! 336: FAILED: DateTime::__construct() expects parameter 1 to be string, object given
! 337:
! 338: -- undefined var --
! 339: object(DateTime)#%d (3) {
! 340: ["date"]=>
! 341: string(19) "%s"
! 342: ["timezone_type"]=>
! 343: int(3)
! 344: ["timezone"]=>
! 345: string(13) "Europe/London"
! 346: }
! 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:
! 356: -- unset var --
! 357: object(DateTime)#%d (3) {
! 358: ["date"]=>
! 359: string(19) "%s"
! 360: ["timezone_type"]=>
! 361: int(3)
! 362: ["timezone"]=>
! 363: string(13) "Europe/London"
! 364: }
! 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:
! 374: -- resource --
! 375: FAILED: DateTime::__construct() expects parameter 1 to be string, resource given
! 376: FAILED: DateTime::__construct() expects parameter 1 to be string, resource given
! 377: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>