diff --git a/tests/RRuleTest.php b/tests/RRuleTest.php new file mode 100644 index 0000000..8316577 --- /dev/null +++ b/tests/RRuleTest.php @@ -0,0 +1,109 @@ +startAt($start); + + $start->setTime($start->format('H'), $start->format('i'), $start->format('s')); + + $this->assertTrue($rrule->isDue((clone $start)->modify('+1 minute'))); + } + + public function testIsDueWithEndTime() + { + $start = new DateTime(); + $start->setTime($start->format('H'), $start->format('i'), $start->format('s')); + + $end = clone $start; + $end->modify('+2 minute'); + + $rrule = (new RRule('FREQ=MINUTELY')) + ->startAt($start) + ->endAt($end); + + $this->assertTrue($rrule->isDue((clone $start)->modify('+1 minute'))); + $this->assertFalse($rrule->isDue((clone $end)->modify('+1 minute'))); + } + + public function testIsExpiredWithoutEndTime() + { + $rrule = (new RRule('FREQ=MINUTELY')) + ->startAt(new DateTime()); + + $this->assertFalse($rrule->isExpired(new DateTime('+1 day'))); + } + + public function testIsExpiredWithEndTime() + { + $rrule = (new RRule('FREQ=MINUTELY')) + ->startAt(new DateTime()) + ->endAt(new DateTime('+5 minute')); + + $this->assertFalse($rrule->isExpired(new DateTime('+2 minute'))); + $this->assertTrue($rrule->isExpired(new DateTime('+10 minute'))); + } + + public function testGetNextDueWithoutEndTime() + { + $start = new DateTime(); + $start->setTime($start->format('H'), $start->format('i'), $start->format('s')); + + $rrule = (new RRule('FREQ=MINUTELY')) + ->startAt($start); + + $this->assertEquals((clone $start)->modify('+1 minute'), $rrule->getNextDue($start)); + } + + public function testGetNextDueWithEndTime() + { + $end = new DateTime('+5 minutes'); + $rrule = (new RRule('FREQ=MINUTELY')) + ->startAt(new DateTime()) + ->endAt($end); + + $this->assertEquals($end, $rrule->getNextDue(new DateTime('+2 hours'))); + } + + public function testGetNextRecurrencesWithDefaultLimit() + { + $rrule = (new RRule('FREQ=MINUTELY')) + ->startAt(new DateTime('-1 hour')); + + $this->assertCount(1, iterator_to_array($rrule->getNextRecurrences(new DateTime()))); + } + + public function testGetNextRecurrencesWithCustomResultSetLimit() + { + $start = new DateTime('-2 day'); + $rrule = (new RRule('FREQ=MINUTELY')) + ->startAt($start) + ->limitTransformer(5); + + $this->assertCount(5, iterator_to_array($rrule->getNextRecurrences(new DateTime()))); + + $start->modify('+2 day'); + $rrule->startAt($start); + + $this->assertCount(5, iterator_to_array($rrule->getNextRecurrences(new DateTime()))); + } + + public function testMonthlyOn31DoesNotSkippFebruaryAndOtherMonths() + { + $start = new DateTime('January 31'); + $recurrences = (new RRule('FREQ=MONTHLY')) + ->startAt($start) + ->getNextRecurrences($start->modify('+5 days')); + + $this->assertEquals(new DateTime('February 28'), $recurrences->current()); + } +}