Annotation of embedaddon/php/ext/standard/tests/array/ksort_error.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test ksort() function : error conditions
! 3: --FILE--
! 4: <?php
! 5: /* Prototype : bool ksort(array &array_arg [, int sort_flags])
! 6: * Description: Sort an array by key, maintaining key to data correlation
! 7: * Source code: ext/standard/array.c
! 8: */
! 9:
! 10: /*
! 11: * Testing ksort() function with all possible error conditions
! 12: */
! 13:
! 14: echo "*** Testing ksort() : error conditions ***\n";
! 15:
! 16: // Zero arguments
! 17: echo "\n-- Testing ksort() function with Zero arguments --\n";
! 18: var_dump( ksort() );
! 19:
! 20: //Test ksort with more than the expected number of arguments
! 21: echo "\n-- Testing ksort() function with more than expected no. of arguments --\n";
! 22: $array_arg = array(1 => 1, 2 => 2);
! 23: $flag_value = array("SORT_REGULAR" => SORT_REGULAR, "SORT_STRING" => SORT_STRING, "SORT_NUMERIC" => SORT_NUMERIC);
! 24: $extra_arg = 10;
! 25:
! 26: // loop through $flag_value array and call krsort with all possible sort flag values
! 27: foreach($flag_value as $key => $flag){
! 28: echo "\n- Sort flag = $key -\n";
! 29: $temp_array = $array_arg;
! 30: var_dump( ksort($temp_array,$flag, $extra_arg) );
! 31: var_dump( $temp_array);
! 32: }
! 33:
! 34: echo "Done";
! 35: ?>
! 36: --EXPECTF--
! 37: *** Testing ksort() : error conditions ***
! 38:
! 39: -- Testing ksort() function with Zero arguments --
! 40:
! 41: Warning: ksort() expects at least 1 parameter, 0 given in %s on line %d
! 42: bool(false)
! 43:
! 44: -- Testing ksort() function with more than expected no. of arguments --
! 45:
! 46: - Sort flag = SORT_REGULAR -
! 47:
! 48: Warning: ksort() expects at most 2 parameters, 3 given in %s on line %d
! 49: bool(false)
! 50: array(2) {
! 51: [1]=>
! 52: int(1)
! 53: [2]=>
! 54: int(2)
! 55: }
! 56:
! 57: - Sort flag = SORT_STRING -
! 58:
! 59: Warning: ksort() expects at most 2 parameters, 3 given in %s on line %d
! 60: bool(false)
! 61: array(2) {
! 62: [1]=>
! 63: int(1)
! 64: [2]=>
! 65: int(2)
! 66: }
! 67:
! 68: - Sort flag = SORT_NUMERIC -
! 69:
! 70: Warning: ksort() expects at most 2 parameters, 3 given in %s on line %d
! 71: bool(false)
! 72: array(2) {
! 73: [1]=>
! 74: int(1)
! 75: [2]=>
! 76: int(2)
! 77: }
! 78: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>