Annotation of embedaddon/php/ext/standard/tests/array/uasort_error.phpt, revision 1.1.1.2

1.1       misho       1: --TEST--
                      2: Test uasort() function : error conditions 
                      3: --FILE--
                      4: <?php
                      5: /* Prototype  : bool uasort(array $array_arg, string $cmp_function)
                      6:  * Description: Sort an array with a user-defined comparison function and maintain index association 
                      7:  * Source code: ext/standard/array.c
                      8: */
                      9: 
                     10: echo "*** Testing uasort() : error conditions ***\n";
                     11: 
                     12: // comparison function 
                     13: /* Prototype : int cmp(mixed $value1, mixed $value2)
                     14:  * Parameters : $value1 and $value2 - values to be compared
                     15:  * Return value : 0 - if both values are same
                     16:  *                1 - if value1 is greater than value2
                     17:  *               -1 - if value1 is less than value2
                     18:  * Description : compares value1 and value2
                     19:  */
                     20: function cmp($value1, $value2)
                     21: {
                     22:   if($value1 == $value2) {
                     23:     return 0;
                     24:   }
                     25:   else if($value1 > $value2) {
                     26:     return 1;
                     27:   }
                     28:   else {
                     29:     return -1;
                     30:   }
                     31: }
                     32: 
                     33: // Initialize 'array_arg' 
                     34: $array_arg = array(0 => 1, 1 => 10, 2 => 'string', 3 => 3, 4 => 2, 5 => 100, 6 => 25);
                     35: 
                     36: // With zero arguments
                     37: echo "-- Testing uasort() function with Zero argument --\n";
                     38: var_dump( uasort() );
                     39: 
                     40: // With one more than the expected number of arguments
                     41: echo "-- Testing uasort() function with more than expected no. of arguments --\n";
                     42: $extra_arg = 10;
                     43: var_dump( uasort($array_arg, 'cmp', $extra_arg) );
                     44: 
                     45: // With one less than the expected number of arguments
                     46: echo "-- Testing uasort() function with less than expected no. of arguments --\n";
                     47: var_dump( uasort($array_arg) );
                     48: 
                     49: // With non existent comparison function
                     50: echo "-- Testing uasort() function with non-existent compare function --\n";
                     51: var_dump( uasort($array_arg, 'non_existent') );
                     52: 
1.1.1.2 ! misho      53: // With non existent comparison function and extra argument
1.1       misho      54: echo "-- Testing uasort() function with non-existent compare function and extra argument --\n";
                     55: var_dump( uasort($array_arg, 'non_existent', $extra_arg) );
                     56: 
                     57: echo "Done"
                     58: ?>
                     59: --EXPECTF--
                     60: *** Testing uasort() : error conditions ***
                     61: -- Testing uasort() function with Zero argument --
                     62: 
                     63: Warning: uasort() expects exactly 2 parameters, 0 given in %s on line %d
                     64: NULL
                     65: -- Testing uasort() function with more than expected no. of arguments --
                     66: 
                     67: Warning: uasort() expects exactly 2 parameters, 3 given in %s on line %d
                     68: NULL
                     69: -- Testing uasort() function with less than expected no. of arguments --
                     70: 
                     71: Warning: uasort() expects exactly 2 parameters, 1 given in %s on line %d
                     72: NULL
                     73: -- Testing uasort() function with non-existent compare function --
                     74: 
                     75: Warning: uasort() expects parameter 2 to be a valid callback, function 'non_existent' not found or invalid function name in %s on line %d
                     76: NULL
                     77: -- Testing uasort() function with non-existent compare function and extra argument --
                     78: 
                     79: Warning: uasort() expects exactly 2 parameters, 3 given in %s on line %d
                     80: NULL
                     81: Done

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