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

1.1       misho       1: --TEST--
                      2: Test DateTime::__construct() function : usage variation - Passing unexpected values to first argument $timezone.
                      3: --FILE--
                      4: <?php
                      5: /* Prototype  : DateTimeZone::__construct  ( string $timezone  )
                      6:  * Description: Returns new DateTimeZone object
                      7:  * Source code: ext/date/php_date.c
                      8:  * Alias to functions: 
                      9:  */
                     10: 
                     11: echo "*** Testing DateTime::__construct() : usage variation -  unexpected values to first argument \$timezone***\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: foreach($inputs as $variation =>$timezone) {
                     99:       echo "\n-- $variation --\n";
                    100:       try {
                    101:        var_dump( new DateTimezone($timezone) );
                    102:       } catch(Exception $e) {
                    103:          $msg = $e->getMessage();
                    104:          echo "FAILED: " . $msg . "\n";
                    105:       }        
                    106:       
                    107: };
                    108: 
                    109: // closing the resource
                    110: fclose( $file_handle );
                    111: 
                    112: ?>
                    113: ===DONE===
                    114: --EXPECTF--
                    115: *** Testing DateTime::__construct() : usage variation -  unexpected values to first argument $timezone***
                    116: 
                    117: -- int 0 --
                    118: FAILED: DateTimeZone::__construct(): Unknown or bad timezone (0)
                    119: 
                    120: -- int 1 --
                    121: FAILED: DateTimeZone::__construct(): Unknown or bad timezone (1)
                    122: 
                    123: -- int 12345 --
                    124: FAILED: DateTimeZone::__construct(): Unknown or bad timezone (12345)
                    125: 
                    126: -- int -12345 --
                    127: FAILED: DateTimeZone::__construct(): Unknown or bad timezone (-12345)
                    128: 
                    129: -- float 10.5 --
                    130: FAILED: DateTimeZone::__construct(): Unknown or bad timezone (10.5)
                    131: 
                    132: -- float -10.5 --
                    133: FAILED: DateTimeZone::__construct(): Unknown or bad timezone (-10.5)
                    134: 
                    135: -- float .5 --
                    136: FAILED: DateTimeZone::__construct(): Unknown or bad timezone (0.5)
                    137: 
                    138: -- empty array --
                    139: FAILED: DateTimeZone::__construct() expects parameter 1 to be string, array given
                    140: 
                    141: -- int indexed array --
                    142: FAILED: DateTimeZone::__construct() expects parameter 1 to be string, array given
                    143: 
                    144: -- associative array --
                    145: FAILED: DateTimeZone::__construct() expects parameter 1 to be string, array given
                    146: 
                    147: -- nested arrays --
                    148: FAILED: DateTimeZone::__construct() expects parameter 1 to be string, array given
                    149: 
                    150: -- uppercase NULL --
                    151: FAILED: DateTimeZone::__construct(): Unknown or bad timezone ()
                    152: 
                    153: -- lowercase null --
                    154: FAILED: DateTimeZone::__construct(): Unknown or bad timezone ()
                    155: 
                    156: -- lowercase true --
                    157: FAILED: DateTimeZone::__construct(): Unknown or bad timezone (1)
                    158: 
                    159: -- lowercase false --
                    160: FAILED: DateTimeZone::__construct(): Unknown or bad timezone ()
                    161: 
                    162: -- uppercase TRUE --
                    163: FAILED: DateTimeZone::__construct(): Unknown or bad timezone (1)
                    164: 
                    165: -- uppercase FALSE --
                    166: FAILED: DateTimeZone::__construct(): Unknown or bad timezone ()
                    167: 
                    168: -- empty string DQ --
                    169: FAILED: DateTimeZone::__construct(): Unknown or bad timezone ()
                    170: 
                    171: -- empty string SQ --
                    172: FAILED: DateTimeZone::__construct(): Unknown or bad timezone ()
                    173: 
                    174: -- string DQ --
                    175: FAILED: DateTimeZone::__construct(): Unknown or bad timezone (string)
                    176: 
                    177: -- string SQ --
                    178: FAILED: DateTimeZone::__construct(): Unknown or bad timezone (string)
                    179: 
                    180: -- mixed case string --
                    181: FAILED: DateTimeZone::__construct(): Unknown or bad timezone (sTrInG)
                    182: 
                    183: -- heredoc --
                    184: FAILED: DateTimeZone::__construct(): Unknown or bad timezone (hello world)
                    185: 
                    186: -- instance of classWithToString --
                    187: FAILED: DateTimeZone::__construct(): Unknown or bad timezone (Class A object)
                    188: 
                    189: -- instance of classWithoutToString --
                    190: FAILED: DateTimeZone::__construct() expects parameter 1 to be string, object given
                    191: 
                    192: -- undefined var --
                    193: FAILED: DateTimeZone::__construct(): Unknown or bad timezone ()
                    194: 
                    195: -- unset var --
                    196: FAILED: DateTimeZone::__construct(): Unknown or bad timezone ()
                    197: 
                    198: -- resource --
                    199: FAILED: DateTimeZone::__construct() expects parameter 1 to be string, resource given
                    200: ===DONE===

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