-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<?php | ||
|
||
namespace ipl\Tests\Scheduler; | ||
|
||
use DateTime; | ||
use ipl\Scheduler\RRule; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class RRuleTest extends TestCase | ||
{ | ||
public function testIsDueWithoutEndTime() | ||
{ | ||
$start = new DateTime(); | ||
$rrule = (new RRule('FREQ=MINUTELY')) | ||
->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()); | ||
} | ||
} |