DayOfMonthFieldTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 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('L'));
  20. $this->assertTrue($f->validate('5W'));
  21. $this->assertTrue($f->validate('01'));
  22. $this->assertFalse($f->validate('5W,L'));
  23. $this->assertFalse($f->validate('1.'));
  24. }
  25. /**
  26. * @covers \Cron\DayOfMonthField::isSatisfiedBy
  27. */
  28. public function testChecksIfSatisfied()
  29. {
  30. $f = new DayOfMonthField();
  31. $this->assertTrue($f->isSatisfiedBy(new DateTime(), '?'));
  32. }
  33. /**
  34. * @covers \Cron\DayOfMonthField::increment
  35. */
  36. public function testIncrementsDate()
  37. {
  38. $d = new DateTime('2011-03-15 11:15:00');
  39. $f = new DayOfMonthField();
  40. $f->increment($d);
  41. $this->assertSame('2011-03-16 00:00:00', $d->format('Y-m-d H:i:s'));
  42. $d = new DateTime('2011-03-15 11:15:00');
  43. $f->increment($d, true);
  44. $this->assertSame('2011-03-14 23:59:00', $d->format('Y-m-d H:i:s'));
  45. }
  46. /**
  47. * Day of the month cannot accept a 0 value, it must be between 1 and 31
  48. * See Github issue #120
  49. *
  50. * @since 2017-01-22
  51. */
  52. public function testDoesNotAccept0Date()
  53. {
  54. $f = new DayOfMonthField();
  55. $this->assertFalse($f->validate(0));
  56. }
  57. }