Annotation of embedaddon/php/ext/standard/tests/array/array_pad_variation2.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test array_pad() function : usage variations - unexpected values for 'pad_size' argument(Bug#43482)
                      3: --FILE--
                      4: <?php
                      5: /* Prototype  : array array_pad(array $input, int $pad_size, mixed $pad_value)
                      6:  * Description: Returns a copy of input array padded with pad_value to size pad_size 
                      7:  * Source code: ext/standard/array.c
                      8: */
                      9: 
                     10: /*
                     11: * Testing array_pad() function by passing values to $pad_size argument other than integers
                     12: * and see that function outputs proper warning messages wherever expected.
                     13: * The $input and $pad_value arguments passed are fixed values.
                     14: */
                     15: 
                     16: echo "*** Testing array_pad() : passing non integer values to \$pad_size argument ***\n";
                     17: 
                     18: // Initialise $input and $pad_value arguments
                     19: $input = array(1, 2);
                     20: $pad_value = 1;
                     21: 
                     22: //get an unset variable
                     23: $unset_var = 10;
                     24: unset ($unset_var);
                     25: 
                     26: // get a class
                     27: class classA
                     28: {
                     29:   public function __toString() {
                     30:     return "Class A object";
                     31:   }
                     32: }
                     33: 
                     34: //array of values to iterate over
                     35: $pad_sizes = array(
                     36: 
                     37:       // float data
                     38: /*1*/  10.5,
                     39:        -10.5,
                     40:        12.3456789000e10,
                     41:        -12.3456789000e10,
                     42:        12.3456789000E-10,
                     43:        .5,
                     44: 
                     45:        // array data
                     46: /*6*/  array(),
                     47:        array(0),
                     48:        array(1),
                     49:        array(1, 2),
                     50:        array('color' => 'red', 'item' => 'pen'),
                     51: 
                     52:        // null data
                     53: /*11*/ NULL,
                     54:        null,
                     55: 
                     56:        // boolean data
                     57: /*13*/ true,
                     58:        false,
                     59:        TRUE,
                     60:        FALSE,
                     61: 
                     62:        // empty data
                     63: /*17*/ "",
                     64:        '',
                     65: 
                     66:        // string data
                     67: /*19*/ "string",
                     68:        'string',
                     69: 
                     70:        // object data
                     71: /*21*/ new classA(),
                     72:  
                     73:        // undefined data
                     74: /*22*/ @$undefined_var,
                     75: 
                     76:        // unset data
                     77: /*23*/ @$unset_var,
                     78: );
                     79: 
                     80: // loop through each element of $pad_sizes to check the behavior of array_pad()
                     81: $iterator = 1;
                     82: foreach($pad_sizes as $pad_size) {
                     83:   echo "-- Iteration $iterator --\n";
                     84:   var_dump( array_pad($input, $pad_size, $pad_value) );
                     85:   $iterator++;
                     86: };
                     87: 
                     88: echo "Done";
                     89: ?>
                     90: --EXPECTF--
                     91: *** Testing array_pad() : passing non integer values to $pad_size argument ***
                     92: -- Iteration 1 --
                     93: array(10) {
                     94:   [0]=>
                     95:   int(1)
                     96:   [1]=>
                     97:   int(2)
                     98:   [2]=>
                     99:   int(1)
                    100:   [3]=>
                    101:   int(1)
                    102:   [4]=>
                    103:   int(1)
                    104:   [5]=>
                    105:   int(1)
                    106:   [6]=>
                    107:   int(1)
                    108:   [7]=>
                    109:   int(1)
                    110:   [8]=>
                    111:   int(1)
                    112:   [9]=>
                    113:   int(1)
                    114: }
                    115: -- Iteration 2 --
                    116: array(10) {
                    117:   [0]=>
                    118:   int(1)
                    119:   [1]=>
                    120:   int(1)
                    121:   [2]=>
                    122:   int(1)
                    123:   [3]=>
                    124:   int(1)
                    125:   [4]=>
                    126:   int(1)
                    127:   [5]=>
                    128:   int(1)
                    129:   [6]=>
                    130:   int(1)
                    131:   [7]=>
                    132:   int(1)
                    133:   [8]=>
                    134:   int(1)
                    135:   [9]=>
                    136:   int(2)
                    137: }
                    138: -- Iteration 3 --
                    139: 
                    140: Warning: array_pad(): You may only pad up to 1048576 elements at a time in %s on line %d
                    141: bool(false)
                    142: -- Iteration 4 --
                    143: 
                    144: Warning: array_pad(): You may only pad up to 1048576 elements at a time in %s on line %d
                    145: bool(false)
                    146: -- Iteration 5 --
                    147: array(2) {
                    148:   [0]=>
                    149:   int(1)
                    150:   [1]=>
                    151:   int(2)
                    152: }
                    153: -- Iteration 6 --
                    154: array(2) {
                    155:   [0]=>
                    156:   int(1)
                    157:   [1]=>
                    158:   int(2)
                    159: }
                    160: -- Iteration 7 --
                    161: 
                    162: Warning: array_pad() expects parameter 2 to be long, array given in %s on line %d
                    163: NULL
                    164: -- Iteration 8 --
                    165: 
                    166: Warning: array_pad() expects parameter 2 to be long, array given in %s on line %d
                    167: NULL
                    168: -- Iteration 9 --
                    169: 
                    170: Warning: array_pad() expects parameter 2 to be long, array given in %s on line %d
                    171: NULL
                    172: -- Iteration 10 --
                    173: 
                    174: Warning: array_pad() expects parameter 2 to be long, array given in %s on line %d
                    175: NULL
                    176: -- Iteration 11 --
                    177: 
                    178: Warning: array_pad() expects parameter 2 to be long, array given in %s on line %d
                    179: NULL
                    180: -- Iteration 12 --
                    181: array(2) {
                    182:   [0]=>
                    183:   int(1)
                    184:   [1]=>
                    185:   int(2)
                    186: }
                    187: -- Iteration 13 --
                    188: array(2) {
                    189:   [0]=>
                    190:   int(1)
                    191:   [1]=>
                    192:   int(2)
                    193: }
                    194: -- Iteration 14 --
                    195: array(2) {
                    196:   [0]=>
                    197:   int(1)
                    198:   [1]=>
                    199:   int(2)
                    200: }
                    201: -- Iteration 15 --
                    202: array(2) {
                    203:   [0]=>
                    204:   int(1)
                    205:   [1]=>
                    206:   int(2)
                    207: }
                    208: -- Iteration 16 --
                    209: array(2) {
                    210:   [0]=>
                    211:   int(1)
                    212:   [1]=>
                    213:   int(2)
                    214: }
                    215: -- Iteration 17 --
                    216: array(2) {
                    217:   [0]=>
                    218:   int(1)
                    219:   [1]=>
                    220:   int(2)
                    221: }
                    222: -- Iteration 18 --
                    223: 
                    224: Warning: array_pad() expects parameter 2 to be long, string given in %s on line %d
                    225: NULL
                    226: -- Iteration 19 --
                    227: 
                    228: Warning: array_pad() expects parameter 2 to be long, string given in %s on line %d
                    229: NULL
                    230: -- Iteration 20 --
                    231: 
                    232: Warning: array_pad() expects parameter 2 to be long, string given in %s on line %d
                    233: NULL
                    234: -- Iteration 21 --
                    235: 
                    236: Warning: array_pad() expects parameter 2 to be long, string given in %s on line %d
                    237: NULL
                    238: -- Iteration 22 --
                    239: 
                    240: Warning: array_pad() expects parameter 2 to be long, object given in %s on line %d
                    241: NULL
                    242: -- Iteration 23 --
                    243: array(2) {
                    244:   [0]=>
                    245:   int(1)
                    246:   [1]=>
                    247:   int(2)
                    248: }
                    249: -- Iteration 24 --
                    250: array(2) {
                    251:   [0]=>
                    252:   int(1)
                    253:   [1]=>
                    254:   int(2)
                    255: }
                    256: Done

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