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

1.1       misho       1: --TEST--
                      2: Test str_pad() function : usage variations - unexpected inputs for '$pad_length' 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_length' 
                     11:  *  and expected type for '$input'
                     12: */
                     13: 
                     14: echo "*** Testing str_pad() function: with unexpected inputs for 'pad_length' 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_lengths =  array (
                     32: 
                     33:                  // integer values
                     34: /*1*/    0,
                     35:                  1,
                     36:                  -2,
                     37:                  255,
                     38:                
                     39:                  // float values
                     40: /*5*/    10.5,
                     41:                  -20.5,
                     42:                  10.12345e2,
                     43:                
                     44:                  // array values
                     45: /*8*/    array(),
                     46:                  array(0),
                     47:                  array(1, 2),
                     48:                
                     49:                  // boolean values
                     50: /*11*/   true,
                     51:                  false,
                     52:                  TRUE,
                     53:                  FALSE,
                     54:                
                     55:                  // null vlaues
                     56: /*15*/   NULL,
                     57:                  null,
                     58:                
                     59:                  // objects
                     60: /*17*/   new sample(),
                     61:                
                     62:                  // resource
                     63: /*18*/   $file_handle,
                     64:                
                     65:                  // undefined variable
                     66: /*19*/   @$undefined_var,
                     67:                
                     68:                  // unset variable
                     69: /*20*/   @$unset_var
                     70: );
                     71: 
                     72: //defining '$input' argument
                     73: $input = "Test string";
                     74: 
                     75: // loop through with each element of the $pad_lengths array to test str_pad() function
                     76: $count = 1;
                     77: foreach($pad_lengths as $pad_length) {
                     78:   echo "-- Iteration $count --\n";
                     79:   var_dump( str_pad($input, $pad_length) );
                     80:   $count ++;
                     81: }
                     82: 
                     83: fclose($file_handle);  //closing the file handle
                     84: 
                     85: ?>
                     86: ===DONE===
                     87: --EXPECTF--
                     88: *** Testing str_pad() function: with unexpected inputs for 'pad_length' argument ***
                     89: -- Iteration 1 --
                     90: string(11) "Test string"
                     91: -- Iteration 2 --
                     92: string(11) "Test string"
                     93: -- Iteration 3 --
                     94: string(11) "Test string"
                     95: -- Iteration 4 --
                     96: string(255) "Test string                                                                                                                                                                                                                                                    "
                     97: -- Iteration 5 --
                     98: string(11) "Test string"
                     99: -- Iteration 6 --
                    100: string(11) "Test string"
                    101: -- Iteration 7 --
                    102: string(1012) "Test string                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         "
                    103: -- Iteration 8 --
                    104: 
                    105: Warning: str_pad() expects parameter 2 to be long, array given in %s on line %d
                    106: NULL
                    107: -- Iteration 9 --
                    108: 
                    109: Warning: str_pad() expects parameter 2 to be long, array given in %s on line %d
                    110: NULL
                    111: -- Iteration 10 --
                    112: 
                    113: Warning: str_pad() expects parameter 2 to be long, array given in %s on line %d
                    114: NULL
                    115: -- Iteration 11 --
                    116: string(11) "Test string"
                    117: -- Iteration 12 --
                    118: string(11) "Test string"
                    119: -- Iteration 13 --
                    120: string(11) "Test string"
                    121: -- Iteration 14 --
                    122: string(11) "Test string"
                    123: -- Iteration 15 --
                    124: string(11) "Test string"
                    125: -- Iteration 16 --
                    126: string(11) "Test string"
                    127: -- Iteration 17 --
                    128: 
                    129: Warning: str_pad() expects parameter 2 to be long, object given in %s on line %d
                    130: NULL
                    131: -- Iteration 18 --
                    132: 
                    133: Warning: str_pad() expects parameter 2 to be long, resource given in %s on line %d
                    134: NULL
                    135: -- Iteration 19 --
                    136: string(11) "Test string"
                    137: -- Iteration 20 --
                    138: string(11) "Test string"
                    139: ===DONE===

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