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

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

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