PersonMoveEventSubscriber: handle case when the move is before the last

locationHistory, but the move affects "now"
This commit is contained in:
2022-02-19 10:27:44 +01:00
parent 104af6d9b5
commit 8675bb65c1
4 changed files with 58 additions and 12 deletions

View File

@@ -80,6 +80,51 @@ final class PersonMoveEventSubscriberTest extends KernelTestCase
$eventSubscriber->resetPeriodLocation($event);
}
public function testEventChangeHouseholdNotificationForPeriodChangeLocationOfPersonAnteriorToCurrentLocationHistory()
{
$person = new Person();
$period = new AccompanyingPeriod();
$period
->setStep(AccompanyingPeriod::STEP_CONFIRMED)
->setPersonLocation($person)
->setUser(new User())
->addPerson($person);
$this->forceIdToPeriod($period);
$previousHousehold = (new Household())->addAddress(
($previousAddress = new Address())->setValidFrom(new DateTime('1 year ago'))
);
$previousMembership = new HouseholdMember();
$previousMembership
->setPerson($person)
->setHousehold($previousHousehold)
->setStartDate(new DateTimeImmutable('1 year ago'))
->setEndDate(new DateTimeImmutable('tomorrow'));
$nextHousehold = (new Household())->addAddress(
(new Address())->setValidFrom(new DateTime('1 month ago'))
);
$nextMembership = new HouseholdMember();
$nextMembership
->setPerson($person)
->setHousehold($nextHousehold)
->setStartDate(new DateTimeImmutable('1 month ago'));
$event = new PersonAddressMoveEvent($person);
$event
->setPreviousMembership($previousMembership)
->setNextMembership($nextMembership);
$em = $this->prophesize(EntityManagerInterface::class);
$em->persist(Argument::type(Notification::class))->shouldBeCalled(1);
$eventSubscriber = $this->buildSubscriber(null, $em->reveal(), null, null);
$eventSubscriber->resetPeriodLocation($event);
$this->assertSame($previousAddress, $period->getAddressLocation());
$this->assertNull($period->getPersonLocation());
}
public function testEventChangeHouseholdNotification()
{
$person = new Person();