AbstractFieldTest.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace Cron\Tests;
  3. use Cron\DayOfWeekField;
  4. use PHPUnit_Framework_TestCase;
  5. /**
  6. * @author Michael Dowling <mtdowling@gmail.com>
  7. */
  8. class AbstractFieldTest extends PHPUnit_Framework_TestCase
  9. {
  10. /**
  11. * @covers Cron\AbstractField::isRange
  12. */
  13. public function testTestsIfRange()
  14. {
  15. $f = new DayOfWeekField();
  16. $this->assertTrue($f->isRange('1-2'));
  17. $this->assertFalse($f->isRange('2'));
  18. }
  19. /**
  20. * @covers Cron\AbstractField::isIncrementsOfRanges
  21. */
  22. public function testTestsIfIncrementsOfRanges()
  23. {
  24. $f = new DayOfWeekField();
  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->assertFalse($f->isInIncrementsOfRanges('0', '*/0'));
  59. $this->assertFalse($f->isInIncrementsOfRanges('1', '*/0'));
  60. $this->assertTrue($f->isInIncrementsOfRanges('4', '4/10'));
  61. $this->assertTrue($f->isInIncrementsOfRanges('14', '4/10'));
  62. $this->assertTrue($f->isInIncrementsOfRanges('34', '4/10'));
  63. }
  64. /**
  65. * @covers Cron\AbstractField::isSatisfied
  66. */
  67. public function testTestsIfSatisfied()
  68. {
  69. $f = new DayOfWeekField();
  70. $this->assertTrue($f->isSatisfied('12', '3-13'));
  71. $this->assertTrue($f->isSatisfied('15', '3-59/12'));
  72. $this->assertTrue($f->isSatisfied('12', '*'));
  73. $this->assertTrue($f->isSatisfied('12', '12'));
  74. $this->assertFalse($f->isSatisfied('12', '3-11'));
  75. $this->assertFalse($f->isSatisfied('12', '3-59/13'));
  76. $this->assertFalse($f->isSatisfied('12', '11'));
  77. }
  78. }