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

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

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