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

1.1       misho       1: --TEST--
                      2: Test array_unique() function : usage variations - unexpected values for 'input' argument
                      3: --FILE--
                      4: <?php
                      5: /* Prototype  : array array_unique(array $input)
                      6:  * Description: Removes duplicate values from array 
                      7:  * Source code: ext/standard/array.c
                      8: */
                      9: 
                     10: /*
                     11:  * Passing non array values to 'input' argument of array_unique() and see 
                     12:  * that the function outputs proper warning messages wherever expected.
                     13: */
                     14: 
                     15: echo "*** Testing array_unique() : Passing non array values to \$input argument ***\n";
                     16: 
                     17: //get an unset variable
                     18: $unset_var = 10;
                     19: unset($unset_var);
                     20: 
                     21: // get a class
                     22: class classA
                     23: {
                     24:   public function __toString() {
                     25:     return "Class A object";
                     26:   }
                     27: }
                     28: 
                     29: // heredoc string
                     30: $heredoc = <<<EOT
                     31: hello world
                     32: EOT;
                     33: 
                     34: // get a resource variable
                     35: $fp = fopen(__FILE__, "r");
                     36: 
                     37: // unexpected values to be passed to $input argument
                     38: $inputs = array (
                     39: 
                     40:        // int data
                     41: /*1*/  0,
                     42:        1,
                     43:        12345,
                     44:        -2345,
                     45: 
                     46:        // float data
                     47: /*5*/  10.5,
                     48:        -10.5,
                     49:        12.3456789000e10,
                     50:        12.3456789000E-10,
                     51:        .5,
                     52: 
                     53:        // null data
                     54: /*10*/ NULL,
                     55:        null,
                     56: 
                     57:        // boolean data
                     58: /*12*/ true,
                     59:        false,
                     60:        TRUE,
                     61:        FALSE,
                     62: 
                     63:        // empty data
                     64: /*16*/ "",
                     65:        '',
                     66: 
                     67:        // string data
                     68: /*18*/ "string",
                     69:        'string',
                     70:        $heredoc,
                     71: 
                     72:        // object data
                     73: /*21*/ new classA(),
                     74: 
                     75:        // undefined data
                     76: /*22*/ @$undefined_var,
                     77: 
                     78:        // unset data
                     79: /*23*/ @$unset_var,
                     80: 
                     81:        // resource variable
                     82: /*24*/ $fp
                     83: );
                     84: 
                     85: // loop through each element of $inputs and check the behavior of array_unique()
                     86: $iterator = 1;
                     87: foreach($inputs as $input) {
                     88:   echo "-- Iteration $iterator --\n";
                     89:   var_dump( array_unique($input) );
                     90:   $iterator++;
                     91: }
                     92: 
                     93: fclose($fp);
                     94: 
                     95: echo "Done";
                     96: ?>
                     97: --EXPECTF--
                     98: *** Testing array_unique() : Passing non array values to $input argument ***
                     99: -- Iteration 1 --
                    100: 
                    101: Warning: array_unique() expects parameter 1 to be array, integer given in %s on line %d
                    102: NULL
                    103: -- Iteration 2 --
                    104: 
                    105: Warning: array_unique() expects parameter 1 to be array, integer given in %s on line %d
                    106: NULL
                    107: -- Iteration 3 --
                    108: 
                    109: Warning: array_unique() expects parameter 1 to be array, integer given in %s on line %d
                    110: NULL
                    111: -- Iteration 4 --
                    112: 
                    113: Warning: array_unique() expects parameter 1 to be array, integer given in %s on line %d
                    114: NULL
                    115: -- Iteration 5 --
                    116: 
                    117: Warning: array_unique() expects parameter 1 to be array, double given in %s on line %d
                    118: NULL
                    119: -- Iteration 6 --
                    120: 
                    121: Warning: array_unique() expects parameter 1 to be array, double given in %s on line %d
                    122: NULL
                    123: -- Iteration 7 --
                    124: 
                    125: Warning: array_unique() expects parameter 1 to be array, double given in %s on line %d
                    126: NULL
                    127: -- Iteration 8 --
                    128: 
                    129: Warning: array_unique() expects parameter 1 to be array, double given in %s on line %d
                    130: NULL
                    131: -- Iteration 9 --
                    132: 
                    133: Warning: array_unique() expects parameter 1 to be array, double given in %s on line %d
                    134: NULL
                    135: -- Iteration 10 --
                    136: 
                    137: Warning: array_unique() expects parameter 1 to be array, null given in %s on line %d
                    138: NULL
                    139: -- Iteration 11 --
                    140: 
                    141: Warning: array_unique() expects parameter 1 to be array, null given in %s on line %d
                    142: NULL
                    143: -- Iteration 12 --
                    144: 
                    145: Warning: array_unique() expects parameter 1 to be array, boolean given in %s on line %d
                    146: NULL
                    147: -- Iteration 13 --
                    148: 
                    149: Warning: array_unique() expects parameter 1 to be array, boolean given in %s on line %d
                    150: NULL
                    151: -- Iteration 14 --
                    152: 
                    153: Warning: array_unique() expects parameter 1 to be array, boolean given in %s on line %d
                    154: NULL
                    155: -- Iteration 15 --
                    156: 
                    157: Warning: array_unique() expects parameter 1 to be array, boolean given in %s on line %d
                    158: NULL
                    159: -- Iteration 16 --
                    160: 
                    161: Warning: array_unique() expects parameter 1 to be array, string given in %s on line %d
                    162: NULL
                    163: -- Iteration 17 --
                    164: 
                    165: Warning: array_unique() expects parameter 1 to be array, string given in %s on line %d
                    166: NULL
                    167: -- Iteration 18 --
                    168: 
                    169: Warning: array_unique() expects parameter 1 to be array, string given in %s on line %d
                    170: NULL
                    171: -- Iteration 19 --
                    172: 
                    173: Warning: array_unique() expects parameter 1 to be array, string given in %s on line %d
                    174: NULL
                    175: -- Iteration 20 --
                    176: 
                    177: Warning: array_unique() expects parameter 1 to be array, string given in %s on line %d
                    178: NULL
                    179: -- Iteration 21 --
                    180: 
                    181: Warning: array_unique() expects parameter 1 to be array, object given in %s on line %d
                    182: NULL
                    183: -- Iteration 22 --
                    184: 
                    185: Warning: array_unique() expects parameter 1 to be array, null given in %s on line %d
                    186: NULL
                    187: -- Iteration 23 --
                    188: 
                    189: Warning: array_unique() expects parameter 1 to be array, null given in %s on line %d
                    190: NULL
                    191: -- Iteration 24 --
                    192: 
                    193: Warning: array_unique() expects parameter 1 to be array, resource given in %s on line %d
                    194: NULL
                    195: Done

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