mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
migration for history, and create history location on each change
This commit is contained in:
@@ -11,6 +11,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Tests\Entity;
|
||||
|
||||
use ArrayIterator;
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\Comment;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation;
|
||||
@@ -60,6 +62,62 @@ final class AccompanyingPeriodTest extends \PHPUnit\Framework\TestCase
|
||||
$this->assertFalse($period->isClosingAfterOpening());
|
||||
}
|
||||
|
||||
public function testHistoryLocation()
|
||||
{
|
||||
$period = new AccompanyingPeriod();
|
||||
$person = new Person();
|
||||
$address = new Address();
|
||||
|
||||
$period->setPersonLocation($person);
|
||||
|
||||
$this->assertCount(0, $period->getLocationHistories());
|
||||
|
||||
$period->setAddressLocation($address);
|
||||
$period->setPersonLocation(null);
|
||||
|
||||
$this->assertCount(0, $period->getLocationHistories());
|
||||
|
||||
$period->setStep(AccompanyingPeriod::STEP_CONFIRMED);
|
||||
|
||||
$this->assertCount(1, $period->getLocationHistories());
|
||||
|
||||
$this->assertSame($address, $period->getLocationHistories()->first()->getAddressLocation());
|
||||
|
||||
$period->setPersonLocation($person);
|
||||
$period->setAddressLocation(null);
|
||||
|
||||
$this->assertCount(2, $period->getLocationHistories());
|
||||
$this->assertSame($person, $period->getLocationHistories()->last()->getPersonLocation());
|
||||
|
||||
$period->setAddressLocation($address);
|
||||
$period->setPersonLocation(null);
|
||||
|
||||
$this->assertCount(3, $period->getLocationHistories());
|
||||
|
||||
$locations = $period->getLocationHistories()->toArray();
|
||||
|
||||
usort($locations, static function (AccompanyingPeriod\AccompanyingPeriodLocationHistory $a, AccompanyingPeriod\AccompanyingPeriodLocationHistory $b) {
|
||||
return $a->getStartDate() <=> $b->getStartDate();
|
||||
});
|
||||
|
||||
$iterator = new ArrayIterator($locations);
|
||||
$iterator->rewind();
|
||||
|
||||
do {
|
||||
$current = $iterator->current();
|
||||
|
||||
$iterator->next();
|
||||
|
||||
if ($iterator->valid()) {
|
||||
$next = $iterator->current();
|
||||
$this->assertNotNull($current->getEndDate());
|
||||
$this->assertEquals($current->getEndDate(), $next->getStartDate());
|
||||
} else {
|
||||
$this->assertNull($current->getEndDate());
|
||||
}
|
||||
} while ($iterator->valid());
|
||||
}
|
||||
|
||||
public function testIsClosed()
|
||||
{
|
||||
$period = new AccompanyingPeriod(new DateTime());
|
||||
|
Reference in New Issue
Block a user