Annotation of embedaddon/php/ext/standard/tests/array/arsort_variation2.phpt, revision 1.1.1.3

1.1       misho       1: --TEST--
                      2: Test arsort() function : usage variations - unexpected values for 'sort_flags' argument
                      3: --FILE--
                      4: <?php
                      5: /* Prototype  : proto bool arsort(array &array_arg [, int sort_flags])
                      6:  * Description: Sort an array and maintain index association
                      7:                 Elements will be arranged from highest to lowest when this function has completed.
                      8:  * Source code: ext/standard/array.c
                      9: */
                     10: 
                     11: /*
                     12:  * Testing arsort() by providing different unexpected values for flag argument
                     13: */
                     14: 
                     15: echo "*** Testing arsort() : usage variations ***\n";
                     16: 
                     17: //get an unset variable
                     18: $unset_var = 10;
                     19: unset ($unset_var);
                     20: 
                     21: // resource variable
                     22: $fp = fopen(__FILE__, "r");
                     23: 
                     24: // temperory array for checking unexpected behavior
                     25: $unsorted_values = array(1 => 10, 2 => 2, 3 => 45);
                     26: 
                     27: //array of values to iterate over
                     28: $unexpected_values = array(
                     29: 
                     30:        // int data
                     31: /*1*/  -2345,
                     32: 
                     33:        // float data
                     34: /*2*/  10.5,
                     35:        -10.5,
                     36:        10.5e2,
                     37:        10.6E-2,
                     38:        .5,
                     39: 
                     40:        // null data
                     41: /*7*/  NULL,
                     42:        null,
                     43: 
                     44:        // boolean data
                     45: /*9*/  true,
                     46:        false,
                     47:        TRUE,
                     48:        FALSE,
                     49: 
                     50:        // empty data
                     51: /*13*/ "",
                     52:        '',
                     53: 
                     54:        // string data
                     55: /*15*/ "string",
                     56:        'string',
                     57: 
                     58:        // object data
                     59: /*16*/ new stdclass(),
                     60: 
                     61:        // undefined data
                     62: /*17*/ @undefined_var,
                     63: 
                     64:        // unset data
                     65: /*18*/ @unset_var,
                     66: 
                     67:        // resource variable
                     68: /*19*/ $fp
                     69: 
                     70: );
                     71: 
                     72: // loop though each element of the array and check the working of arsort()
1.1.1.3 ! misho      73: // when $flag argument is supplied with different values from $unexpected_values
1.1       misho      74: echo "\n-- Testing arsort() by supplying different unexpected values for 'sort_flags' argument --\n";
                     75: 
                     76: $counter = 1;
                     77: for($index = 0; $index < count($unexpected_values); $index ++) {
                     78:   echo "-- Iteration $counter --\n";
                     79:   $value = $unexpected_values [$index];
                     80:   $temp_array = $unsorted_values;
                     81:   var_dump( arsort($temp_array, $value) ); 
                     82:   var_dump($temp_array);
                     83:   $counter++;
                     84: }
                     85: 
                     86: echo "Done";
                     87: ?>
                     88: --EXPECTF--
                     89: *** Testing arsort() : usage variations ***
                     90: 
                     91: -- Testing arsort() by supplying different unexpected values for 'sort_flags' argument --
                     92: -- Iteration 1 --
                     93: bool(true)
                     94: array(3) {
                     95:   [3]=>
                     96:   int(45)
                     97:   [1]=>
                     98:   int(10)
                     99:   [2]=>
                    100:   int(2)
                    101: }
                    102: -- Iteration 2 --
                    103: bool(true)
                    104: array(3) {
                    105:   [3]=>
                    106:   int(45)
                    107:   [2]=>
                    108:   int(2)
1.1.1.2   misho     109:   [1]=>
                    110:   int(10)
1.1       misho     111: }
                    112: -- Iteration 3 --
                    113: bool(true)
                    114: array(3) {
                    115:   [3]=>
                    116:   int(45)
                    117:   [1]=>
                    118:   int(10)
                    119:   [2]=>
                    120:   int(2)
                    121: }
                    122: -- Iteration 4 --
                    123: bool(true)
                    124: array(3) {
                    125:   [3]=>
                    126:   int(45)
                    127:   [1]=>
                    128:   int(10)
                    129:   [2]=>
                    130:   int(2)
                    131: }
                    132: -- Iteration 5 --
                    133: bool(true)
                    134: array(3) {
                    135:   [3]=>
                    136:   int(45)
                    137:   [1]=>
                    138:   int(10)
                    139:   [2]=>
                    140:   int(2)
                    141: }
                    142: -- Iteration 6 --
                    143: bool(true)
                    144: array(3) {
                    145:   [3]=>
                    146:   int(45)
                    147:   [1]=>
                    148:   int(10)
                    149:   [2]=>
                    150:   int(2)
                    151: }
                    152: -- Iteration 7 --
                    153: bool(true)
                    154: array(3) {
                    155:   [3]=>
                    156:   int(45)
                    157:   [1]=>
                    158:   int(10)
                    159:   [2]=>
                    160:   int(2)
                    161: }
                    162: -- Iteration 8 --
                    163: bool(true)
                    164: array(3) {
                    165:   [3]=>
                    166:   int(45)
                    167:   [1]=>
                    168:   int(10)
                    169:   [2]=>
                    170:   int(2)
                    171: }
                    172: -- Iteration 9 --
                    173: bool(true)
                    174: array(3) {
                    175:   [3]=>
                    176:   int(45)
                    177:   [1]=>
                    178:   int(10)
                    179:   [2]=>
                    180:   int(2)
                    181: }
                    182: -- Iteration 10 --
                    183: bool(true)
                    184: array(3) {
                    185:   [3]=>
                    186:   int(45)
                    187:   [1]=>
                    188:   int(10)
                    189:   [2]=>
                    190:   int(2)
                    191: }
                    192: -- Iteration 11 --
                    193: bool(true)
                    194: array(3) {
                    195:   [3]=>
                    196:   int(45)
                    197:   [1]=>
                    198:   int(10)
                    199:   [2]=>
                    200:   int(2)
                    201: }
                    202: -- Iteration 12 --
                    203: bool(true)
                    204: array(3) {
                    205:   [3]=>
                    206:   int(45)
                    207:   [1]=>
                    208:   int(10)
                    209:   [2]=>
                    210:   int(2)
                    211: }
                    212: -- Iteration 13 --
                    213: 
                    214: Warning: arsort() expects parameter 2 to be long, string given in %sarsort_variation2.php on line %d
                    215: bool(false)
                    216: array(3) {
                    217:   [1]=>
                    218:   int(10)
                    219:   [2]=>
                    220:   int(2)
                    221:   [3]=>
                    222:   int(45)
                    223: }
                    224: -- Iteration 14 --
                    225: 
                    226: Warning: arsort() expects parameter 2 to be long, string given in %sarsort_variation2.php on line %d
                    227: bool(false)
                    228: array(3) {
                    229:   [1]=>
                    230:   int(10)
                    231:   [2]=>
                    232:   int(2)
                    233:   [3]=>
                    234:   int(45)
                    235: }
                    236: -- Iteration 15 --
                    237: 
                    238: Warning: arsort() expects parameter 2 to be long, string given in %sarsort_variation2.php on line %d
                    239: bool(false)
                    240: array(3) {
                    241:   [1]=>
                    242:   int(10)
                    243:   [2]=>
                    244:   int(2)
                    245:   [3]=>
                    246:   int(45)
                    247: }
                    248: -- Iteration 16 --
                    249: 
                    250: Warning: arsort() expects parameter 2 to be long, string given in %sarsort_variation2.php on line %d
                    251: bool(false)
                    252: array(3) {
                    253:   [1]=>
                    254:   int(10)
                    255:   [2]=>
                    256:   int(2)
                    257:   [3]=>
                    258:   int(45)
                    259: }
                    260: -- Iteration 17 --
                    261: 
                    262: Warning: arsort() expects parameter 2 to be long, object given in %sarsort_variation2.php on line %d
                    263: bool(false)
                    264: array(3) {
                    265:   [1]=>
                    266:   int(10)
                    267:   [2]=>
                    268:   int(2)
                    269:   [3]=>
                    270:   int(45)
                    271: }
                    272: -- Iteration 18 --
                    273: 
                    274: Warning: arsort() expects parameter 2 to be long, string given in %sarsort_variation2.php on line %d
                    275: bool(false)
                    276: array(3) {
                    277:   [1]=>
                    278:   int(10)
                    279:   [2]=>
                    280:   int(2)
                    281:   [3]=>
                    282:   int(45)
                    283: }
                    284: -- Iteration 19 --
                    285: 
                    286: Warning: arsort() expects parameter 2 to be long, string given in %sarsort_variation2.php on line %d
                    287: bool(false)
                    288: array(3) {
                    289:   [1]=>
                    290:   int(10)
                    291:   [2]=>
                    292:   int(2)
                    293:   [3]=>
                    294:   int(45)
                    295: }
                    296: -- Iteration 20 --
                    297: 
                    298: Warning: arsort() expects parameter 2 to be long, resource given in %sarsort_variation2.php on line %d
                    299: bool(false)
                    300: array(3) {
                    301:   [1]=>
                    302:   int(10)
                    303:   [2]=>
                    304:   int(2)
                    305:   [3]=>
                    306:   int(45)
                    307: }
1.1.1.2   misho     308: Done

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