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

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

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