Skip to content

Commit

Permalink
Better tests for LocalDateRange / YearMonthRange iterators
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorel committed Mar 8, 2019
1 parent 97cd11c commit 6f74cfa
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
21 changes: 16 additions & 5 deletions tests/LocalDateRangeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,28 @@ public function providerContains() : array

public function testIterator()
{
$start = LocalDate::of(2013, 12, 30);
$end = LocalDate::of(2014, 1, 2);
$start = LocalDate::of(2013, 12, 29);
$end = LocalDate::of(2014, 1, 3);

$range = LocalDateRange::of($start, $end);

$expected = [
'2013-12-29',
'2013-12-30',
'2013-12-31',
'2014-01-01',
'2014-01-02',
'2014-01-03'
];

for ($i = 0; $i < 2; $i++) { // Test twice to test iterator rewind
$expected = $start;
$actual = [];

foreach ($range as $date) {
$this->assertTrue($date->isEqualTo($expected));
$expected = $expected->plusDays(1);
$actual[] = (string) $date;
}

$this->assertSame($expected, $actual);
}
}

Expand Down
17 changes: 14 additions & 3 deletions tests/YearMonthRangeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,23 @@ public function testIterator()

$range = YearMonthRange::of($start, $end);

$expected = [
'2013-10',
'2013-11',
'2013-12',
'2014-01',
'2014-02',
'2014-03'
];

for ($i = 0; $i < 2; $i++) { // Test twice to test iterator rewind
$expected = $start;
$actual = [];

foreach ($range as $yearMonth) {
$this->assertTrue($yearMonth->isEqualTo($expected));
$expected = $expected->plusMonths(1);
$actual[] = (string) $yearMonth;
}

$this->assertSame($expected, $actual);
}
}

Expand Down

0 comments on commit 6f74cfa

Please sign in to comment.