migration for history, and create history location on each change

This commit is contained in:
2022-02-14 23:03:40 +01:00
parent 441704dc29
commit b9dbb1916a
6 changed files with 324 additions and 173 deletions

View File

@@ -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());