Annotation of embedaddon/php/ext/standard/tests/strings/strtr_variation5.phpt, revision 1.1

1.1     ! misho       1: --TEST--
        !             2: Test strtr() function : usage variations - unexpected inputs for 'str' argument
        !             3: --FILE--
        !             4: <?php
        !             5: /* Prototype  : string strtr(string $str, string $from[, string $to]);
        !             6:                 string strtr(string $str, array $replace_pairs);
        !             7:  * Description: Translates characters in str using given translation tables
        !             8:  * Source code: ext/standard/string.c
        !             9: */
        !            10: 
        !            11: /* Test strtr() function: with unexpected inputs for 'str' 
        !            12:  *  and expected type for 'from' & 'to' arguments 
        !            13: */
        !            14: 
        !            15: echo "*** Testing strtr() function: with unexpected inputs for 'str' ***\n";
        !            16: 
        !            17: //get an unset variable
        !            18: $unset_var = 'string_val';
        !            19: unset($unset_var);
        !            20: 
        !            21: //defining a class
        !            22: class sample  {
        !            23:   public function __toString() {
        !            24:     return "sample object";
        !            25:   } 
        !            26: }
        !            27: 
        !            28: //getting the resource
        !            29: $file_handle = fopen(__FILE__, "r");
        !            30: 
        !            31: // array with different values
        !            32: $strings =  array (
        !            33: 
        !            34:                  // integer values
        !            35: /*1*/    0,
        !            36:                  1,
        !            37:                  -2,
        !            38:                
        !            39:                  // float values
        !            40: /*4*/    10.5,
        !            41:                  -20.5,
        !            42:                  10.1234567e10,
        !            43:                
        !            44:                  // array values
        !            45: /*7*/    array(),
        !            46:                  array(0),
        !            47:                  array(1, 2),
        !            48:                
        !            49:                  // boolean values
        !            50: /*10*/   true,
        !            51:                  false,
        !            52:                  TRUE,
        !            53:                  FALSE,
        !            54:                
        !            55:                  // null vlaues
        !            56: /*14*/   NULL,
        !            57:                  null,
        !            58:                
        !            59:                  // objects
        !            60: /*16*/   new sample(),
        !            61:                
        !            62:                  // resource
        !            63: /*17*/   $file_handle,
        !            64:                
        !            65:                  // undefined variable
        !            66: /*18*/   @$undefined_var,
        !            67:                
        !            68:                  // unset variable
        !            69: /*19*/   @$unset_var
        !            70: );
        !            71: 
        !            72: //defining 'from' argument
        !            73: $from = "012atm";
        !            74: 
        !            75: //defining 'to' argument
        !            76: $to = "atm012";
        !            77: 
        !            78: // loop through with each element of the $strings array to test strtr() function
        !            79: $count = 1;
        !            80: for($index = 0; $index < count($strings); $index++) {
        !            81:   echo "-- Iteration $count --\n";
        !            82:   $str = $strings[$index];
        !            83:   var_dump( strtr($str, $from, $to) );
        !            84:   $count ++;
        !            85: }
        !            86: 
        !            87: fclose($file_handle);  //closing the file handle
        !            88: 
        !            89: ?>
        !            90: ===DONE===
        !            91: --EXPECTF--
        !            92: *** Testing strtr() function: with unexpected inputs for 'str' ***
        !            93: -- Iteration 1 --
        !            94: string(1) "a"
        !            95: -- Iteration 2 --
        !            96: string(1) "t"
        !            97: -- Iteration 3 --
        !            98: string(2) "-m"
        !            99: -- Iteration 4 --
        !           100: string(4) "ta.5"
        !           101: -- Iteration 5 --
        !           102: string(5) "-ma.5"
        !           103: -- Iteration 6 --
        !           104: string(12) "tatm34567aaa"
        !           105: -- Iteration 7 --
        !           106: 
        !           107: Warning: strtr() expects parameter 1 to be string, array given in %s on line %d
        !           108: NULL
        !           109: -- Iteration 8 --
        !           110: 
        !           111: Warning: strtr() expects parameter 1 to be string, array given in %s on line %d
        !           112: NULL
        !           113: -- Iteration 9 --
        !           114: 
        !           115: Warning: strtr() expects parameter 1 to be string, array given in %s on line %d
        !           116: NULL
        !           117: -- Iteration 10 --
        !           118: string(1) "t"
        !           119: -- Iteration 11 --
        !           120: string(0) ""
        !           121: -- Iteration 12 --
        !           122: string(1) "t"
        !           123: -- Iteration 13 --
        !           124: string(0) ""
        !           125: -- Iteration 14 --
        !           126: string(0) ""
        !           127: -- Iteration 15 --
        !           128: string(0) ""
        !           129: -- Iteration 16 --
        !           130: string(13) "s02ple objec1"
        !           131: -- Iteration 17 --
        !           132: 
        !           133: Warning: strtr() expects parameter 1 to be string, resource given in %s on line %d
        !           134: NULL
        !           135: -- Iteration 18 --
        !           136: string(0) ""
        !           137: -- Iteration 19 --
        !           138: string(0) ""
        !           139: ===DONE===

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