range_errors.phpt 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. --TEST--
  2. Test range() function (errors)
  3. --INI--
  4. precision=14
  5. --FILE--
  6. <?php
  7. echo "\n*** Testing error conditions ***\n";
  8. echo "\n-- Testing ( (low < high) && (step = 0) ) --";
  9. var_dump( range(1, 2, 0) );
  10. var_dump( range("a", "b", 0) );
  11. echo "\n\n-- Testing ( (low > high) && (step = 0) ) --";
  12. var_dump( range(2, 1, 0) );
  13. var_dump( range("b", "a", 0) );
  14. echo "\n\n-- Testing ( (low < high) && (high-low < step) ) --";
  15. var_dump( range(1.0, 7.0, 6.5) );
  16. echo "\n\n-- Testing ( (low > high) && (low-high < step) ) --";
  17. var_dump( range(7.0, 1.0, 6.5) );
  18. echo "\n-- Testing Invalid number of arguments --";
  19. var_dump( range() ); // No.of args = 0
  20. var_dump( range(1) ); // No.of args < expected
  21. var_dump( range(1,2,3,4) ); // No.of args > expected
  22. var_dump( range(-1, -2, 2) );
  23. var_dump( range("a", "j", "z") );
  24. echo "\n-- Testing Invalid steps --";
  25. $step_arr = array( "string", NULL, FALSE, "", "\0" );
  26. foreach( $step_arr as $step ) {
  27. var_dump( range( 1, 5, $step ) );
  28. }
  29. echo "Done\n";
  30. ?>
  31. --EXPECTF--
  32. *** Testing error conditions ***
  33. -- Testing ( (low < high) && (step = 0) ) --
  34. Warning: range(): step exceeds the specified range in %s on line %d
  35. bool(false)
  36. Warning: range(): step exceeds the specified range in %s on line %d
  37. bool(false)
  38. -- Testing ( (low > high) && (step = 0) ) --
  39. Warning: range(): step exceeds the specified range in %s on line %d
  40. bool(false)
  41. Warning: range(): step exceeds the specified range in %s on line %d
  42. bool(false)
  43. -- Testing ( (low < high) && (high-low < step) ) --
  44. Warning: range(): step exceeds the specified range in %s on line %d
  45. bool(false)
  46. -- Testing ( (low > high) && (low-high < step) ) --
  47. Warning: range(): step exceeds the specified range in %s on line %d
  48. bool(false)
  49. -- Testing Invalid number of arguments --
  50. Warning: range() expects at least 2 parameters, 0 given in %s on line %d
  51. bool(false)
  52. Warning: range() expects at least 2 parameters, 1 given in %s on line %d
  53. bool(false)
  54. Warning: range() expects at most 3 parameters, 4 given in %s on line %d
  55. bool(false)
  56. Warning: range(): step exceeds the specified range in %s on line %d
  57. bool(false)
  58. Warning: range(): step exceeds the specified range in %s on line %d
  59. bool(false)
  60. -- Testing Invalid steps --
  61. Warning: range(): step exceeds the specified range in %s on line %d
  62. bool(false)
  63. Warning: range(): step exceeds the specified range in %s on line %d
  64. bool(false)
  65. Warning: range(): step exceeds the specified range in %s on line %d
  66. bool(false)
  67. Warning: range(): step exceeds the specified range in %s on line %d
  68. bool(false)
  69. Warning: range(): step exceeds the specified range in %s on line %d
  70. bool(false)
  71. Done