No Description

MonthFieldTest.php 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace Cron\Tests;
  3. use Cron\MonthField;
  4. use DateTime;
  5. /**
  6. * @author Michael Dowling <mtdowling@gmail.com>
  7. */
  8. class MonthFieldTest extends \PHPUnit_Framework_TestCase
  9. {
  10. /**
  11. * @covers Cron\MonthField::validate
  12. */
  13. public function testValdatesField()
  14. {
  15. $f = new MonthField();
  16. $this->assertTrue($f->validate('12'));
  17. $this->assertTrue($f->validate('*'));
  18. $this->assertTrue($f->validate('*/10,2,1-12'));
  19. $this->assertFalse($f->validate('1.fix-regexp'));
  20. }
  21. /**
  22. * @covers Cron\MonthField::increment
  23. */
  24. public function testIncrementsDate()
  25. {
  26. $d = new DateTime('2011-03-15 11:15:00');
  27. $f = new MonthField();
  28. $f->increment($d);
  29. $this->assertEquals('2011-04-01 00:00:00', $d->format('Y-m-d H:i:s'));
  30. $d = new DateTime('2011-03-15 11:15:00');
  31. $f->increment($d, true);
  32. $this->assertEquals('2011-02-28 23:59:00', $d->format('Y-m-d H:i:s'));
  33. }
  34. /**
  35. * @covers Cron\MonthField::increment
  36. */
  37. public function testIncrementsYearAsNeeded()
  38. {
  39. $f = new MonthField();
  40. $d = new DateTime('2011-12-15 00:00:00');
  41. $f->increment($d);
  42. $this->assertEquals('2012-01-01 00:00:00', $d->format('Y-m-d H:i:s'));
  43. }
  44. /**
  45. * @covers Cron\MonthField::increment
  46. */
  47. public function testDecrementsYearAsNeeded()
  48. {
  49. $f = new MonthField();
  50. $d = new DateTime('2011-01-15 00:00:00');
  51. $f->increment($d, true);
  52. $this->assertEquals('2010-12-31 23:59:00', $d->format('Y-m-d H:i:s'));
  53. }
  54. }