shuffle_error.phpt 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. --TEST--
  2. Test shuffle() function : error conditions
  3. --FILE--
  4. <?php
  5. /* Prototype : bool shuffle(array $array_arg)
  6. * Description: Randomly shuffle the contents of an array
  7. * Source code: ext/standard/array.c
  8. */
  9. /* Test shuffle() to see that warning messages are emitted
  10. * when invalid number of arguments are passed to the function
  11. */
  12. echo "*** Testing shuffle() : error conditions ***\n";
  13. // zero arguments
  14. echo "\n-- Testing shuffle() function with Zero arguments --\n";
  15. var_dump( shuffle() );
  16. // more than the expected number of arguments
  17. echo "\n-- Testing shuffle() function with more than expected no. of arguments --\n";
  18. $array_arg = array(1, "two" => 2);
  19. $extra_arg = 10;
  20. var_dump( shuffle($array_arg, $extra_arg) );
  21. // printing the input array to check that it is not affected
  22. // by above shuffle() function calls
  23. echo "\n-- original input array --\n";
  24. var_dump( $array_arg );
  25. echo "Done";
  26. ?>
  27. --EXPECTF--
  28. *** Testing shuffle() : error conditions ***
  29. -- Testing shuffle() function with Zero arguments --
  30. Warning: shuffle() expects exactly 1 parameter, 0 given in %s on line %d
  31. bool(false)
  32. -- Testing shuffle() function with more than expected no. of arguments --
  33. Warning: shuffle() expects exactly 1 parameter, 2 given in %s on line %d
  34. bool(false)
  35. -- original input array --
  36. array(2) {
  37. [0]=>
  38. int(1)
  39. ["two"]=>
  40. int(2)
  41. }
  42. Done