Skip to content

Commit

Permalink
Expand test coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Nov 14, 2015
1 parent 173f1a8 commit f967836
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 4 deletions.
33 changes: 33 additions & 0 deletions tests/Date/AddTest.php
Expand Up @@ -18,6 +18,22 @@

class AddTest extends TestCase
{
/**
* @dataProvider dateClassProvider
*/
public function testAddFullDay($class)
{
$interval = DateInterval::createFromDateString('1 day');
$date = $class::create(2001, 1, 1);
$new = $date->add($interval);

$this->assertEquals(0, $new->hour);
$this->assertEquals(0, $new->minute);
$this->assertEquals(0, $new->second);
$this->assertEquals(0, $date->hour);
$this->assertEquals(0, $date->minute);
$this->assertEquals(0, $date->second);
}

/**
* @dataProvider dateClassProvider
Expand All @@ -36,6 +52,23 @@ public function testAddIgnoreTime($class)
$this->assertEquals(0, $date->second);
}

/**
* @dataProvider dateClassProvider
*/
public function testSubFullDay($class)
{
$interval = DateInterval::createFromDateString('1 day');
$date = $class::create(2001, 1, 1);
$new = $date->sub($interval);

$this->assertEquals(0, $new->hour);
$this->assertEquals(0, $new->minute);
$this->assertEquals(0, $new->second);
$this->assertEquals(0, $date->hour);
$this->assertEquals(0, $date->minute);
$this->assertEquals(0, $date->second);
}

/**
* @dataProvider dateClassProvider
*/
Expand Down
22 changes: 18 additions & 4 deletions tests/Date/ConstructTest.php
Expand Up @@ -12,6 +12,7 @@
namespace Cake\Chronos\Test\Date;

use Cake\Chronos\Date;
use Cake\Chronos\MutableDate;
use DateTimeZone;
use TestCase;

Expand Down Expand Up @@ -172,16 +173,29 @@ public function testConstructWithTimeParts($time)
$this->assertEquals(0, $dt->second);
}

/**
* @dataProvider inputTimeProvider
* @return void
*/
public function testConstructMutableWithTimeParts($time)
{
$dt = new MutableDate($time);
$this->assertEquals(8, $dt->month);
$this->assertEquals(0, $dt->hour);
$this->assertEquals(0, $dt->minute);
$this->assertEquals(0, $dt->second);
}

/**
* @dataProvider dateClassProvider
*/
public function testConstructWithTestNow()
public function testConstructWithTestNow($class)
{
Date::setTestNow(Date::create(2001, 1, 1));
$date = new Date('+2 days');
$class::setTestNow($class::create(2001, 1, 1));
$date = new $class('+2 days');
$this->assertDateTime($date, 2001, 1, 3);

$date = new Date('2015-12-12');
$date = new $class('2015-12-12');
$this->assertDateTime($date, 2015, 12, 12);
}
}
17 changes: 17 additions & 0 deletions tests/DateTime/ComparisonTest.php
Expand Up @@ -13,11 +13,28 @@

namespace Cake\Chronos\Test\DateTime;

use Cake\Chronos\ChronosInterface;
use TestCase;

class ComparisonTest extends TestCase
{

/**
* @dataProvider classNameProvider
* @return void
*/
public function testGetSetWeekendDays($class)
{
$expected = [ChronosInterface::SATURDAY, ChronosInterface::SUNDAY];
$this->assertEquals($expected, $class::getWeekendDays());

$replace = [ChronosInterface::SUNDAY];
$class::setWeekendDays($replace);
$this->assertEquals($replace, $class::getWeekendDays());

$class::setWeekendDays($expected);
}

/**
* @dataProvider classNameProvider
* @return void
Expand Down

0 comments on commit f967836

Please sign in to comment.