Annotation of embedaddon/php/ext/standard/tests/strings/strtr_variation8.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test strtr() function : usage variations - unexpected inputs for 'replace_pairs' 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 'replace_pairs' 
                     12:  *  and expected type for 'str' arguments 
                     13: */
                     14: 
                     15: echo "*** Testing strtr() function: with unexpected inputs for 'replace_pairs' ***\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: //defining 'str' argument
                     32: $str = "012atm";
                     33: 
                     34: // array of inputs for 'replace_pairs' argument
                     35: $replace_pairs_arr =  array (
                     36: 
                     37:   // integer values
                     38:   0,
                     39:   1,
                     40:   -2,
                     41: 
                     42:   // float values
                     43:   10.5,
                     44:   -20.5,
                     45:   10.5e10,
                     46: 
                     47:   // array values
                     48:   array(),
                     49:   array(0),
                     50:   array(1, 2),
                     51: 
                     52:   // boolean values
                     53:   true,
                     54:   false,
                     55:   TRUE,
                     56:   FALSE,
                     57: 
                     58:   // null vlaues
                     59:   NULL,
                     60:   null,
                     61: 
                     62:   // objects
                     63:   new sample(),
                     64: 
                     65:   // resource
                     66:   $file_handle,
                     67: 
                     68:   // undefined variable
                     69:   @$undefined_var,
                     70: 
                     71:   // unset variable
                     72:   @$unset_var
                     73: );
                     74: 
                     75: // loop through with each element of the $replace_pairs array to test strtr() function
                     76: $count = 1;
                     77: for($index = 0; $index < count($replace_pairs_arr); $index++) {
                     78:   echo "\n-- Iteration $count --\n";
                     79:   $replace_pairs = $replace_pairs_arr[$index];
                     80:   var_dump( strtr($str, $replace_pairs) );
                     81:   $count ++;
                     82: }
                     83: 
                     84: fclose($file_handle);  //closing the file handle
                     85: 
                     86: echo "*** Done ***";
                     87: ?>
                     88: --EXPECTF--
                     89: *** Testing strtr() function: with unexpected inputs for 'replace_pairs' ***
                     90: 
                     91: -- Iteration 1 --
                     92: 
                     93: Warning: strtr(): The second argument is not an array in %s on line %d
                     94: bool(false)
                     95: 
                     96: -- Iteration 2 --
                     97: 
                     98: Warning: strtr(): The second argument is not an array in %s on line %d
                     99: bool(false)
                    100: 
                    101: -- Iteration 3 --
                    102: 
                    103: Warning: strtr(): The second argument is not an array in %s on line %d
                    104: bool(false)
                    105: 
                    106: -- Iteration 4 --
                    107: 
                    108: Warning: strtr(): The second argument is not an array in %s on line %d
                    109: bool(false)
                    110: 
                    111: -- Iteration 5 --
                    112: 
                    113: Warning: strtr(): The second argument is not an array in %s on line %d
                    114: bool(false)
                    115: 
                    116: -- Iteration 6 --
                    117: 
                    118: Warning: strtr(): The second argument is not an array in %s on line %d
                    119: bool(false)
                    120: 
                    121: -- Iteration 7 --
                    122: string(6) "012atm"
                    123: 
                    124: -- Iteration 8 --
                    125: string(6) "012atm"
                    126: 
                    127: -- Iteration 9 --
                    128: string(6) "122atm"
                    129: 
                    130: -- Iteration 10 --
                    131: 
                    132: Warning: strtr(): The second argument is not an array in %s on line %d
                    133: bool(false)
                    134: 
                    135: -- Iteration 11 --
                    136: 
                    137: Warning: strtr(): The second argument is not an array in %s on line %d
                    138: bool(false)
                    139: 
                    140: -- Iteration 12 --
                    141: 
                    142: Warning: strtr(): The second argument is not an array in %s on line %d
                    143: bool(false)
                    144: 
                    145: -- Iteration 13 --
                    146: 
                    147: Warning: strtr(): The second argument is not an array in %s on line %d
                    148: bool(false)
                    149: 
                    150: -- Iteration 14 --
                    151: 
                    152: Warning: strtr(): The second argument is not an array in %s on line %d
                    153: bool(false)
                    154: 
                    155: -- Iteration 15 --
                    156: 
                    157: Warning: strtr(): The second argument is not an array in %s on line %d
                    158: bool(false)
                    159: 
                    160: -- Iteration 16 --
                    161: 
                    162: Warning: strtr(): The second argument is not an array in %s on line %d
                    163: bool(false)
                    164: 
                    165: -- Iteration 17 --
                    166: 
                    167: Warning: strtr(): The second argument is not an array in %s on line %d
                    168: bool(false)
                    169: 
                    170: -- Iteration 18 --
                    171: 
                    172: Warning: strtr(): The second argument is not an array in %s on line %d
                    173: bool(false)
                    174: 
                    175: -- Iteration 19 --
                    176: 
                    177: Warning: strtr(): The second argument is not an array in %s on line %d
                    178: bool(false)
                    179: *** Done ***

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