No Description

AbstractFieldTest.php 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace Cron\Tests;
  3. use Cron\DayOfWeekField;
  4. /**
  5. * @author Michael Dowling <mtdowling@gmail.com>
  6. */
  7. class AbstractFieldTest extends \PHPUnit_Framework_TestCase
  8. {
  9. /**
  10. * @covers Cron\AbstractField::isRange
  11. */
  12. public function testTestsIfRange()
  13. {
  14. $f = new DayOfWeekField();
  15. $this->assertTrue($f->isRange('1-2'));
  16. $this->assertFalse($f->isRange('2'));
  17. }
  18. /**
  19. * @covers Cron\AbstractField::isIncrementsOfRanges
  20. */
  21. public function testTestsIfIncrementsOfRanges()
  22. {
  23. $f = new DayOfWeekField();
  24. $this->assertFalse($f->isIncrementsOfRanges('1-2'));
  25. $this->assertFalse($f->isIncrementsOfRanges('1-2'));
  26. $this->assertTrue($f->isIncrementsOfRanges('1/2'));
  27. $this->assertTrue($f->isIncrementsOfRanges('*/2'));
  28. $this->assertTrue($f->isIncrementsOfRanges('3-12/2'));
  29. }
  30. /**
  31. * @covers Cron\AbstractField::isInRange
  32. */
  33. public function testTestsIfInRange()
  34. {
  35. $f = new DayOfWeekField();
  36. $this->assertTrue($f->isInRange(1, '1-2'));
  37. $this->assertTrue($f->isInRange(2, '1-2'));
  38. $this->assertTrue($f->isInRange(5, '4-12'));
  39. $this->assertFalse($f->isInRange(3, '4-12'));
  40. $this->assertFalse($f->isInRange(13, '4-12'));
  41. }
  42. /**
  43. * @covers Cron\AbstractField::isInIncrementsOfRanges
  44. */
  45. public function testTestsIfInIncrementsOfRanges()
  46. {
  47. $f = new DayOfWeekField();
  48. $this->assertTrue($f->isInIncrementsOfRanges(3, '3-59/2'));
  49. $this->assertTrue($f->isInIncrementsOfRanges(13, '3-59/2'));
  50. $this->assertTrue($f->isInIncrementsOfRanges(15, '3-59/2'));
  51. $this->assertTrue($f->isInIncrementsOfRanges(14, '*/2'));
  52. $this->assertFalse($f->isInIncrementsOfRanges(2, '3-59/13'));
  53. $this->assertFalse($f->isInIncrementsOfRanges(14, '*/13'));
  54. $this->assertFalse($f->isInIncrementsOfRanges(14, '3-59/2'));
  55. $this->assertFalse($f->isInIncrementsOfRanges(3, '2-59'));
  56. $this->assertFalse($f->isInIncrementsOfRanges(3, '2'));
  57. $this->assertFalse($f->isInIncrementsOfRanges(3, '*'));
  58. $this->assertTrue($f->isInIncrementsOfRanges(4, '4/10'));
  59. $this->assertTrue($f->isInIncrementsOfRanges(14, '4/10'));
  60. $this->assertTrue($f->isInIncrementsOfRanges(34, '4/10'));
  61. }
  62. /**
  63. * @covers Cron\AbstractField::isSatisfied
  64. */
  65. public function testTestsIfSatisfied()
  66. {
  67. $f = new DayOfWeekField();
  68. $this->assertTrue($f->isSatisfied('12', '3-13'));
  69. $this->assertTrue($f->isSatisfied('15', '3-59/12'));
  70. $this->assertTrue($f->isSatisfied('12', '*'));
  71. $this->assertTrue($f->isSatisfied('12', '12'));
  72. $this->assertFalse($f->isSatisfied('12', '3-11'));
  73. $this->assertFalse($f->isSatisfied('12', '3-59/13'));
  74. $this->assertFalse($f->isSatisfied('12', '11'));
  75. }
  76. }