MinutesFieldTest.php 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace Cron\Tests;
  3. use Cron\MinutesField;
  4. use DateTime;
  5. use PHPUnit\Framework\TestCase;
  6. /**
  7. * @author Michael Dowling <mtdowling@gmail.com>
  8. */
  9. class MinutesFieldTest extends TestCase
  10. {
  11. /**
  12. * @covers \Cron\MinutesField::validate
  13. */
  14. public function testValidatesField()
  15. {
  16. $f = new MinutesField();
  17. $this->assertTrue($f->validate('1'));
  18. $this->assertTrue($f->validate('*'));
  19. $this->assertFalse($f->validate('*/3,1,1-12'));
  20. }
  21. /**
  22. * @covers \Cron\MinutesField::increment
  23. */
  24. public function testIncrementsDate()
  25. {
  26. $d = new DateTime('2011-03-15 11:15:00');
  27. $f = new MinutesField();
  28. $f->increment($d);
  29. $this->assertSame('2011-03-15 11:16:00', $d->format('Y-m-d H:i:s'));
  30. $f->increment($d, true);
  31. $this->assertSame('2011-03-15 11:15:00', $d->format('Y-m-d H:i:s'));
  32. }
  33. /**
  34. * Various bad syntaxes that are reported to work, but shouldn't.
  35. *
  36. * @author Chris Tankersley
  37. * @since 2017-08-18
  38. */
  39. public function testBadSyntaxesShouldNotValidate()
  40. {
  41. $f = new MinutesField();
  42. $this->assertFalse($f->validate('*-1'));
  43. $this->assertFalse($f->validate('1-2-3'));
  44. $this->assertFalse($f->validate('-1'));
  45. }
  46. }