Refactoring : adding doc + date in DateTime constructor

This commit is contained in:
Marc Ducobu 2015-03-05 19:09:32 +01:00
parent d12f5ee77f
commit 821454493b

View File

@ -26,12 +26,15 @@ use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriod;
/** /**
* Unit tests on person * Unit tests for the person Entity
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/ */
class PersonTest extends \PHPUnit_Framework_TestCase class PersonTest extends \PHPUnit_Framework_TestCase
{ {
/**
* Test the creation of an accompanying, its closure and the access to
* the current accompaniying period via the getCurrentAccompanyingPeriod
* function.
*/
public function testGetCurrentAccompanyingPeriod() public function testGetCurrentAccompanyingPeriod()
{ {
$d = new \DateTime('yesterday'); $d = new \DateTime('yesterday');
@ -48,25 +51,25 @@ class PersonTest extends \PHPUnit_Framework_TestCase
$shouldBeNull = $p->getCurrentAccompanyingPeriod(); $shouldBeNull = $p->getCurrentAccompanyingPeriod();
$this->assertNull($shouldBeNull); $this->assertNull($shouldBeNull);
} }
public function testAccompanyingPeriodOrderWithUnorderedAccompanyingPeriod() { /**
$d = new \DateTime(); * Test if the getAccompanyingPeriodsOrdered function return a list of
$d->setDate(2013, 2, 1); * periods ordered ascendency.
*/
public function testAccompanyingPeriodOrderWithUnorderedAccompanyingPeriod()
{
$d = new \DateTime("2013/2/1");
$p = new Person($d); $p = new Person($d);
$e = new \DateTime(); $e = new \DateTime("2013/3/1");
$e->setDate(2013, 3, 1);
$period = $p->getCurrentAccompanyingPeriod()->setDateClosing($e); $period = $p->getCurrentAccompanyingPeriod()->setDateClosing($e);
$p->close($period); $p->close($period);
$f = new \DateTime(); $f = new \DateTime("2013/1/1");
$f->setDate(2013, 1, 1);
$p->open(new AccompanyingPeriod($f)); $p->open(new AccompanyingPeriod($f));
$g = new \DateTime(); $g = new \DateTime("2013/4/1");
$g->setDate(2013, 4, 1);
$period = $p->getCurrentAccompanyingPeriod()->setDateClosing($g); $period = $p->getCurrentAccompanyingPeriod()->setDateClosing($g);
$p->close($period); $p->close($period);
@ -77,23 +80,30 @@ class PersonTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($date, '2013-01-01'); $this->assertEquals($date, '2013-01-01');
} }
/**
* TODO : choose the good doc
*
* Test if the getAccompanyingPeriodsOrdered function do not change the
* order of two periods starting at the same moment
*
* or
*
* Test if the getAccompanyingPeriodsOrdered function, for periods
* starting at the same time order regarding to the closing date.
*
*/
public function testAccompanyingPeriodOrderSameDateOpening() { public function testAccompanyingPeriodOrderSameDateOpening() {
$d = new \DateTime(); $d = new \DateTime("2013/2/1");
$d->setDate(2013, 2, 1);
$p = new Person($d); $p = new Person($d);
$e = new \DateTime(); $e = new \DateTime("2013/3/1");
$e->setDate(2013, 3, 1);
$period = $p->getCurrentAccompanyingPeriod()->setDateClosing($e); $period = $p->getCurrentAccompanyingPeriod()->setDateClosing($e);
$p->close($period); $p->close($period);
$f = new \DateTime(); $f = new \DateTime("2013/2/1");
$f->setDate(2013, 2, 1);
$p->open(new AccompanyingPeriod($f)); $p->open(new AccompanyingPeriod($f));
$g = new \DateTime(); $g = new \DateTime("2013/4/1");
$g->setDate(2013, 4, 1);
$period = $p->getCurrentAccompanyingPeriod()->setDateClosing($g); $period = $p->getCurrentAccompanyingPeriod()->setDateClosing($g);
$p->close($period); $p->close($period);
@ -104,22 +114,23 @@ class PersonTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($date, '2013-03-01'); $this->assertEquals($date, '2013-03-01');
} }
/**
* Test if the function checkAccompanyingPeriodIsNotCovering returns
* the good constant when two periods are collapsing : a period
* is covering another one : start_1 < start_2 & end_2 < end_1
*/
public function testDateCoveringWithCoveringAccompanyingPeriod() { public function testDateCoveringWithCoveringAccompanyingPeriod() {
$d = new \DateTime(); $d = new \DateTime("2013/2/1");
$d->setDate(2013, 2, 1);
$p = new Person($d); $p = new Person($d);
$e = new \DateTime(); $e = new \DateTime("2013/3/1");
$e->setDate(2013, 3, 1);
$period = $p->getCurrentAccompanyingPeriod()->setDateClosing($e); $period = $p->getCurrentAccompanyingPeriod()->setDateClosing($e);
$p->close($period); $p->close($period);
$f = new \DateTime(); $f = new \DateTime("2013/1/1");
$f->setDate(2013, 1, 1);
$p->open(new AccompanyingPeriod($f)); $p->open(new AccompanyingPeriod($f));
$g = new \DateTime(); $g = new \DateTime("2013/4/1");
$g->setDate(2013, 4, 1);
$period = $p->getCurrentAccompanyingPeriod()->setDateClosing($g); $period = $p->getCurrentAccompanyingPeriod()->setDateClosing($g);
$p->close($period); $p->close($period);
@ -128,18 +139,20 @@ class PersonTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($r['result'], Person::ERROR_OPENING_IS_INSIDE_CLOSING); $this->assertEquals($r['result'], Person::ERROR_OPENING_IS_INSIDE_CLOSING);
} }
/**
* Test if the function checkAccompanyingPeriodIsNotCovering returns
* the good constant when two periods are collapsing : a period is open
* before an existing period
*/
public function testNotOpenAFileReOpenedLater() { public function testNotOpenAFileReOpenedLater() {
$d = new \DateTime(); $d = new \DateTime("2013/2/1");
$d->setDate(2013, 2, 1);
$p = new Person($d); $p = new Person($d);
$e = new \DateTime(); $e = new \DateTime("2013/3/1");
$e->setDate(2013, 3, 1);
$period = $p->getCurrentAccompanyingPeriod()->setDateClosing($e); $period = $p->getCurrentAccompanyingPeriod()->setDateClosing($e);
$p->close($period); $p->close($period);
$f = new \DateTime(); $f = new \DateTime("2013/1/1");
$f->setDate(2013, 1, 1);
$p->open(new AccompanyingPeriod($f)); $p->open(new AccompanyingPeriod($f));
$r = $p->checkAccompanyingPeriodIsNotCovering(); $r = $p->checkAccompanyingPeriodIsNotCovering();