DayOfMonthFieldTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace Cron\Tests;
  3. use Cron\DayOfMonthField;
  4. use DateTime;
  5. use PHPUnit_Framework_TestCase;
  6. /**
  7. * @author Michael Dowling <mtdowling@gmail.com>
  8. */
  9. class DayOfMonthFieldTest extends PHPUnit_Framework_TestCase
  10. {
  11. /**
  12. * @covers Cron\DayOfMonthField::validate
  13. */
  14. public function testValidatesField()
  15. {
  16. $f = new DayOfMonthField();
  17. $this->assertTrue($f->validate('1'));
  18. $this->assertTrue($f->validate('*'));
  19. $this->assertTrue($f->validate('5W,L'));
  20. $this->assertFalse($f->validate('1.'));
  21. }
  22. /**
  23. * @covers Cron\DayOfMonthField::isSatisfiedBy
  24. */
  25. public function testChecksIfSatisfied()
  26. {
  27. $f = new DayOfMonthField();
  28. $this->assertTrue($f->isSatisfiedBy(new DateTime(), '?'));
  29. }
  30. /**
  31. * @covers Cron\DayOfMonthField::increment
  32. */
  33. public function testIncrementsDate()
  34. {
  35. $d = new DateTime('2011-03-15 11:15:00');
  36. $f = new DayOfMonthField();
  37. $f->increment($d);
  38. $this->assertEquals('2011-03-16 00:00:00', $d->format('Y-m-d H:i:s'));
  39. $d = new DateTime('2011-03-15 11:15:00');
  40. $f->increment($d, true);
  41. $this->assertEquals('2011-03-14 23:59:00', $d->format('Y-m-d H:i:s'));
  42. }
  43. /**
  44. * Day of the month cannot accept a 0 value, it must be between 1 and 31
  45. * See Github issue #120
  46. *
  47. * @since 2017-01-22
  48. */
  49. public function testDoesNotAccept0Date()
  50. {
  51. $f = new DayOfMonthField();
  52. $this->assertFalse($f->validate(0));
  53. }
  54. }