Skip to content

Commit

Permalink
Improve tests coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
Albert Garcia committed Jan 12, 2016
1 parent a2cd382 commit ed6ee4f
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 22 deletions.
10 changes: 0 additions & 10 deletions src/Period/Day.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
4 changes: 2 additions & 2 deletions src/Period/Month.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -50,6 +50,6 @@ public function isOutOfMonth($period)
*/
public function current()
{
return current($this->dates);
return parent::current();
}
}
2 changes: 1 addition & 1 deletion src/Period/Week.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ public static function getFirstDayOfWeek(\DateTime $a_day)
*/
public function current()
{
return current($this->dates);
return parent::current();
}
}
2 changes: 1 addition & 1 deletion src/Period/Year.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ public static function fromYear($year)
*/
public function current()
{
return current($this->dates);
return parent::current();
}
}
28 changes: 26 additions & 2 deletions tests/Period/DayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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());
}
}
29 changes: 25 additions & 4 deletions tests/Period/MonthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

}
11 changes: 11 additions & 0 deletions tests/Period/WeekTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace DateRangerTest\Period;

use DateRanger\Period\Day;
use DateRanger\Period\Week;

final class WeekTest extends \PHPUnit_Framework_TestCase
Expand All @@ -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);
}
}
}
18 changes: 16 additions & 2 deletions tests/Period/YearTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace DateRangerTest\Period;

use DateRanger\Period\Month;
use DateRanger\Period\Year;

final class YearTest extends \PHPUnit_Framework_TestCase
Expand All @@ -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'));
}

/**
Expand All @@ -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);
}
}
}

0 comments on commit ed6ee4f

Please sign in to comment.