public function testDateTimeMutableReferenceBug() { $date = date_create('2007-01-01'); $rrule = new RRule(array('freq' => 'daily', 'count' => 10, 'dtstart' => $date)); $this->assertEquals(date_create('2007-01-01'), $rrule[0]); $date->modify('+1day'); $rrule->clearCache(); $this->assertEquals(date_create('2007-01-01'), $rrule[0], 'No modification possible of dtstart'); $rrule = new RRule(array('freq' => 'daily', 'count' => 10, 'dtstart' => '2007-01-01')); // offsetGet $this->assertEquals(date_create('2007-01-01'), $rrule[0]); $rrule[0]->modify('+1 day'); $this->assertEquals(date_create('2007-01-01'), $rrule[0], 'No modification possible with offsetGet (uncached)'); $rrule[0]->modify('+1 day'); $this->assertEquals(date_create('2007-01-01'), $rrule[0], 'No modification possible with offsetGet (cached)'); // iterate $rrule->clearCache(); foreach ($rrule as $occurrence) { break; } $this->assertEquals(date_create('2007-01-01'), $occurrence); $occurrence->modify('+1 day'); $this->assertEquals(date_create('2007-01-01'), $rrule[0], 'No modification possible with foreach (uncached)'); foreach ($rrule as $occurrence) { break; } $this->assertEquals(date_create('2007-01-01'), $occurrence); $occurrence->modify('+1 day'); $this->assertEquals(date_create('2007-01-01'), $rrule[0], 'No modification possible with foreach (cached)'); // getOccurences $occurrences = $rrule->getOccurrences(); $this->assertEquals(date_create('2007-01-01'), $occurrences[0]); $occurrences[0]->modify('+1 day'); $this->assertEquals(date_create('2007-01-02'), $occurrences[0]); $this->assertEquals(date_create('2007-01-01'), $rrule[0], 'No modification possible with getOccurences (uncached version)'); $occurrences = $rrule->getOccurrences(); $this->assertEquals(date_create('2007-01-01'), $occurrences[0]); $occurrences[0]->modify('+1 day'); $this->assertEquals(date_create('2007-01-02'), $occurrences[0]); $this->assertEquals(date_create('2007-01-01'), $rrule[0], 'No modification possible with getOccurences (cached version)'); // getOccurrencesBetween $occurrences = $rrule->getOccurrencesBetween(null, null); $this->assertEquals(date_create('2007-01-01'), $occurrences[0]); $occurrences[0]->modify('+1 day'); $this->assertEquals(date_create('2007-01-02'), $occurrences[0]); $this->assertEquals(date_create('2007-01-01'), $rrule[0], 'No modification possible with getOccurences (uncached version)'); $occurrences = $rrule->getOccurrencesBetween(null, null); $this->assertEquals(date_create('2007-01-01'), $occurrences[0]); $occurrences[0]->modify('+1 day'); $this->assertEquals(date_create('2007-01-02'), $occurrences[0]); $this->assertEquals(date_create('2007-01-01'), $rrule[0], 'No modification possible with getOccurences (cached version)'); }
/** * @dataProvider variousRules */ public function testVariousRules($rule, $occurrences) { $rule = new RRule($rule); $this->assertEquals($occurrences, $rule->getOccurrences()); foreach ($occurrences as $date) { $this->assertTrue($rule->occursAt($date), 'RRule occurs at: ' . $date->format('r')); } }