date_modify_error.phpt 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. --TEST--
  2. Test date_modify() function : error conditions
  3. --FILE--
  4. <?php
  5. /* Prototype : DateTime date_modify ( DateTime $object , string $modify )
  6. * Description: Alter the timestamp of a DateTime object by incrementing or decrementing in a format accepted by strtotime().
  7. * Source code: ext/date/php_date.c
  8. * Alias to functions: public DateTime DateTime::modify()
  9. */
  10. //Set the default time zone
  11. date_default_timezone_set("Europe/London");
  12. echo "*** Testing date_modify() : error conditions ***\n";
  13. echo "\n-- Testing date_modify() function with zero arguments --\n";
  14. var_dump( date_modify() );
  15. // Create a date object
  16. $datetime = date_create("2009-01-30 19:34:10");
  17. echo "\n-- Testing date_modify() function with less than expected no. of arguments --\n";
  18. var_dump( date_modify($datetime) );
  19. echo "\n-- Testing date_modify() function with more than expected no. of arguments --\n";
  20. $modify = "+1 day";
  21. $extra_arg = 99;
  22. var_dump( date_modify($datetime, $modify, $extra_arg) );
  23. echo "\n-- Testing date_modify() function with an invalid values for \$object argument --\n";
  24. $invalid_obj = new stdClass();
  25. var_dump( date_modify($invalid_obj, $modify) );
  26. $invalid_obj = 10;
  27. var_dump( date_modify($invalid_obj, $modify) );
  28. $invalid_obj = null;
  29. var_dump( date_modify($invalid_obj, $modify) );
  30. ?>
  31. ===DONE===
  32. --EXPECTF--
  33. *** Testing date_modify() : error conditions ***
  34. -- Testing date_modify() function with zero arguments --
  35. Warning: date_modify() expects exactly 2 parameters, 0 given in %s on line %d
  36. bool(false)
  37. -- Testing date_modify() function with less than expected no. of arguments --
  38. Warning: date_modify() expects exactly 2 parameters, 1 given in %s on line %d
  39. bool(false)
  40. -- Testing date_modify() function with more than expected no. of arguments --
  41. Warning: date_modify() expects exactly 2 parameters, 3 given in %s on line %d
  42. bool(false)
  43. -- Testing date_modify() function with an invalid values for $object argument --
  44. Warning: date_modify() expects parameter 1 to be DateTime, object given in %s on line %d
  45. bool(false)
  46. Warning: date_modify() expects parameter 1 to be DateTime, integer given in %s on line %d
  47. bool(false)
  48. Warning: date_modify() expects parameter 1 to be DateTime, null given in %s on line %d
  49. bool(false)
  50. ===DONE===