diff --git a/src/Period/Day.php b/src/Period/Day.php index b99e920..e29fa2d 100644 --- a/src/Period/Day.php +++ b/src/Period/Day.php @@ -64,14 +64,4 @@ public function isHoliday() return false; } - - /** - * It's unnecessary defining this method. It's here only to allow IDE type hinting. - * - * @return Day - */ - public function current() - { - return current($this->dates); - } } diff --git a/src/Period/Month.php b/src/Period/Month.php index 7b26efc..aa6e740 100644 --- a/src/Period/Month.php +++ b/src/Period/Month.php @@ -37,7 +37,7 @@ public function isOutOfMonth($period) { if ($period instanceof \DateTime) { - return !$this->overlaps(new Day($period)); + return !$this->overlaps(new Day($period->format('Y-m-d'))); } return !$this->overlaps($period); @@ -50,6 +50,6 @@ public function isOutOfMonth($period) */ public function current() { - return current($this->dates); + return parent::current(); } } diff --git a/src/Period/Week.php b/src/Period/Week.php index e682e38..547b7bd 100644 --- a/src/Period/Week.php +++ b/src/Period/Week.php @@ -57,6 +57,6 @@ public static function getFirstDayOfWeek(\DateTime $a_day) */ public function current() { - return current($this->dates); + return parent::current(); } } diff --git a/src/Period/Year.php b/src/Period/Year.php index ef528be..871d95c 100644 --- a/src/Period/Year.php +++ b/src/Period/Year.php @@ -35,6 +35,6 @@ public static function fromYear($year) */ public function current() { - return current($this->dates); + return parent::current(); } } diff --git a/tests/Period/DayTest.php b/tests/Period/DayTest.php index aa813b2..39581c0 100644 --- a/tests/Period/DayTest.php +++ b/tests/Period/DayTest.php @@ -16,8 +16,15 @@ public function validDay() /** @test */ public function detectHoliday() { - $day = new Day('2015-01-01'); - $this->assertTrue($day->isHoliday()); + $day1 = new Day('2015-01-01'); + $day2 = new Day('2015-04-06'); + $day3 = new Day('2015-04-11'); + $day4 = new Day('2015-04-15'); + + $this->assertTrue($day1->isHoliday()); + $this->assertTrue($day2->isHoliday()); + $this->assertTrue($day3->isHoliday()); + $this->assertFalse($day4->isHoliday()); } /** @test */ @@ -26,4 +33,21 @@ public function detectWeekend() $day = new Day('2015-09-27'); $this->assertTrue($day->isWeekend()); } + + /** @test */ + public function shouldDetectDifferentDays() + { + $day1 = new Day('2015-09-27'); + $day2 = new Day('2015-09-26'); + + $this->assertFalse($day1->equals($day2)); + } + + /** @test */ + public function shouldDetectCurrentDay() + { + $day = new Day('now'); + + $this->assertTrue($day->isCurrent()); + } } diff --git a/tests/Period/MonthTest.php b/tests/Period/MonthTest.php index 5a2aedb..676708f 100644 --- a/tests/Period/MonthTest.php +++ b/tests/Period/MonthTest.php @@ -4,22 +4,43 @@ use DateRanger\Period\Day; use DateRanger\Period\Month; +use DateRanger\Period\Week; final class MonthTest extends \PHPUnit_Framework_TestCase { /** @test */ public function validMonth() { - $month = new Month(); - $this->assertEquals(date('Y-m'), $month->start()->format('Y-m')); + $month1 = new Month(); + $this->assertEquals(date('Y-m'), $month1->start()->format('Y-m')); + + $month2 = Month::fromMonth(date('Y'), date('m')); + $this->assertEquals(date('Y-m'), $month2->start()->format('Y-m')); } /** @test */ public function outsiderDays() { $month = new Month('2015-09-01'); - $day = new Day('2015-08-20'); - $this->assertTrue($month->isOutOfMonth($day)); + $day_inside = new Day('2015-08-20'); + $day_outside = new Day('2015-09-20'); + $day_outside_string = new \DateTime('2015-09-20'); + + $this->assertTrue($month->isOutOfMonth($day_inside)); + $this->assertFalse($month->isOutOfMonth($day_outside)); + $this->assertFalse($month->isOutOfMonth($day_outside_string)); + } + + + /** @test */ + public function shouldContainWeeks() + { + $week = new Month(); + foreach ($week as $position => $day) + { + $this->assertInstanceOf(Week::class, $day); + } } + } diff --git a/tests/Period/WeekTest.php b/tests/Period/WeekTest.php index f176d10..9c07bf3 100644 --- a/tests/Period/WeekTest.php +++ b/tests/Period/WeekTest.php @@ -2,6 +2,7 @@ namespace DateRangerTest\Period; +use DateRanger\Period\Day; use DateRanger\Period\Week; final class WeekTest extends \PHPUnit_Framework_TestCase @@ -20,4 +21,14 @@ public function createFromWeekNumber() $week2 = Week::fromWeekNumber(2015, 7); $this->assertEquals($week1, $week2); } + + /** @test */ + public function shouldContainDays() + { + $week = new Week(); + foreach ($week as $position => $day) + { + $this->assertInstanceOf(Day::class, $day); + } + } } diff --git a/tests/Period/YearTest.php b/tests/Period/YearTest.php index 97b45f1..84f37c9 100644 --- a/tests/Period/YearTest.php +++ b/tests/Period/YearTest.php @@ -2,6 +2,7 @@ namespace DateRangerTest\Period; +use DateRanger\Period\Month; use DateRanger\Period\Year; final class YearTest extends \PHPUnit_Framework_TestCase @@ -11,8 +12,11 @@ final class YearTest extends \PHPUnit_Framework_TestCase */ public function validYear() { - $year = new Year(); - $this->assertEquals(date('Y'), $year->start()->format('Y')); + $year1 = new Year(); + $this->assertEquals(date('Y'), $year1->start()->format('Y')); + + $year2 = Year::fromYear(date('Y')); + $this->assertEquals(date('Y'), $year2->start()->format('Y')); } /** @@ -23,4 +27,14 @@ public function validContents() $year = new Year(); $this->assertEquals(12, count($year)); } + + /** @test */ + public function shouldContainMonths() + { + $week = new Year(); + foreach ($week as $position => $day) + { + $this->assertInstanceOf(Month::class, $day); + } + } }