mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-25 09:03:48 +00:00
@@ -23,79 +23,76 @@
|
||||
namespace Chill\PersonBundle\Tests\Entity;
|
||||
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
|
||||
class AccompanyingPeriodTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testClosingIsAfterOpeningConsistency()
|
||||
{
|
||||
$datetime1 = new \DateTime('now');
|
||||
$datetime2 = new \DateTime('tomorrow');
|
||||
|
||||
|
||||
$period = new AccompanyingPeriod($datetime1);
|
||||
$period->setClosingDate($datetime2);
|
||||
|
||||
|
||||
$r = $period->isClosingAfterOpening();
|
||||
|
||||
|
||||
$this->assertTrue($r);
|
||||
}
|
||||
|
||||
public function testClosingIsBeforeOpeningConsistency() {
|
||||
|
||||
public function testClosingIsBeforeOpeningConsistency()
|
||||
{
|
||||
$datetime1 = new \DateTime('tomorrow');
|
||||
$datetime2 = new \DateTime('now');
|
||||
|
||||
|
||||
$period = new AccompanyingPeriod($datetime1);
|
||||
$period->setClosingDate($datetime2);
|
||||
|
||||
|
||||
$this->assertFalse($period->isClosingAfterOpening());
|
||||
}
|
||||
|
||||
public function testClosingEqualOpening() {
|
||||
|
||||
public function testClosingEqualOpening()
|
||||
{
|
||||
$datetime = new \DateTime('now');
|
||||
|
||||
|
||||
$period = new AccompanyingPeriod($datetime);
|
||||
$period->setClosingDate($datetime);
|
||||
|
||||
|
||||
$this->assertTrue($period->isClosingAfterOpening());
|
||||
}
|
||||
|
||||
public function testIsOpen() {
|
||||
|
||||
public function testIsOpen()
|
||||
{
|
||||
$period = new AccompanyingPeriod(new \DateTime());
|
||||
|
||||
|
||||
$this->assertTrue($period->isOpen());
|
||||
}
|
||||
|
||||
public function testIsClosed() {
|
||||
|
||||
public function testIsClosed()
|
||||
{
|
||||
$period = new AccompanyingPeriod(new \DateTime());
|
||||
$period->setClosingDate(new \DateTime('tomorrow'));
|
||||
|
||||
|
||||
$this->assertFalse($period->isOpen());
|
||||
}
|
||||
|
||||
/**
|
||||
* This test seems only to test ordering datetime... Maybe delete ?
|
||||
*/
|
||||
public function testOrder() {
|
||||
$d = new \DateTime(); $d->setDate(2013, 2, 1);
|
||||
$g = new \DateTime(); $g->setDate(2013, 4, 1);
|
||||
$f = new \DateTime(); $f->setDate(2013, 1, 1);
|
||||
$e = new \DateTime(); $e->setDate(2013,3,1);
|
||||
|
||||
public function testCanBeReOpened()
|
||||
{
|
||||
$person = new Person(\DateTime::createFromFormat('Y-m-d', '2010-01-01'));
|
||||
$person->close($person->getAccompanyingPeriods()[0]
|
||||
->setClosingDate(\DateTime::createFromFormat('Y-m-d', '2010-12-31')));
|
||||
|
||||
$a = array($d, $g, $f, $e);
|
||||
$firstAccompanygingPeriod = $person->getAccompanyingPeriodsOrdered()[0];
|
||||
|
||||
usort($a, function($a, $b) {
|
||||
if ($a === $b) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ($a < $b) {
|
||||
return -1;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
$this->assertTrue($firstAccompanygingPeriod->canBeReOpened());
|
||||
|
||||
$date = $a[0]->format('Y-m-d');
|
||||
$lastAccompanyingPeriod = (new AccompanyingPeriod(\DateTime::createFromFormat('Y-m-d', '2011-01-01')))
|
||||
->setClosingDate(\DateTime::createFromFormat('Y-m-d', '2011-12-31'))
|
||||
;
|
||||
$person->addAccompanyingPeriod($lastAccompanyingPeriod);
|
||||
|
||||
$this->assertEquals($date, '2013-01-01');
|
||||
$this->assertFalse($firstAccompanygingPeriod->canBeReOpened());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user