mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
PersonAddressMove: fix tests, address history on household, and household::getMembersOnRange
This commit is contained in:
@@ -14,7 +14,7 @@ namespace AccompanyingPeriod\Events;
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
use Chill\MainBundle\Entity\Notification;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\PersonBundle\AccompanyingPeriod\Events\PersonMoveEventSubscriber;
|
||||
use Chill\PersonBundle\AccompanyingPeriod\Events\PersonAddressMoveEventSubscriber;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\Household\Household;
|
||||
use Chill\PersonBundle\Entity\Household\HouseholdMember;
|
||||
@@ -80,51 +80,6 @@ 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->assertNotNull($period->getAddressLocation());
|
||||
$this->assertNull($period->getPersonLocation());
|
||||
}
|
||||
|
||||
public function testEventChangeHouseholdNotification()
|
||||
{
|
||||
$person = new Person();
|
||||
@@ -170,40 +125,43 @@ final class PersonMoveEventSubscriberTest extends KernelTestCase
|
||||
$this->assertNull($period->getPersonLocation());
|
||||
}
|
||||
|
||||
public function testEventPersonChangeAddressInThePast()
|
||||
public function testEventChangeHouseholdNotificationForPeriodChangeLocationOfPersonAnteriorToCurrentLocationHistory()
|
||||
{
|
||||
$person = new Person();
|
||||
$period = new AccompanyingPeriod();
|
||||
$period
|
||||
->setStep(AccompanyingPeriod::STEP_CONFIRMED)
|
||||
->setPersonLocation($person)
|
||||
->addPerson($person)
|
||||
->setUser(new User());
|
||||
->setUser(new User())
|
||||
->addPerson($person);
|
||||
$this->forceIdToPeriod($period);
|
||||
|
||||
$membership = new HouseholdMember();
|
||||
$membership
|
||||
$previousHousehold = (new Household())->addAddress(
|
||||
($previousAddress = new Address())->setValidFrom(new DateTime('1 year ago'))
|
||||
);
|
||||
$previousMembership = new HouseholdMember();
|
||||
$previousMembership
|
||||
->setPerson($person)
|
||||
->setHousehold($household = new Household())
|
||||
->setHousehold($previousHousehold)
|
||||
->setStartDate(new DateTimeImmutable('1 year ago'))
|
||||
;
|
||||
->setEndDate(new DateTimeImmutable('tomorrow'));
|
||||
|
||||
$previousAddress = new Address();
|
||||
$previousAddress->setValidFrom(new DateTime('6 months ago'));
|
||||
$household->addAddress($previousAddress);
|
||||
|
||||
$newAddress = new Address();
|
||||
$newAddress->setValidFrom(new DateTime('tomorrow'));
|
||||
$household->addAddress($newAddress);
|
||||
$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
|
||||
->setPreviousAddress($household->getPreviousAddressOf($newAddress))
|
||||
->setNextAddress($newAddress)
|
||||
;
|
||||
->setPreviousMembership($previousMembership)
|
||||
->setNextMembership($nextMembership);
|
||||
|
||||
$em = $this->prophesize(EntityManagerInterface::class);
|
||||
$em->persist(Argument::type(Notification::class))->shouldBeCalledTimes(1);
|
||||
$em->persist(Argument::type(Notification::class))->shouldBeCalled(1);
|
||||
$eventSubscriber = $this->buildSubscriber(null, $em->reveal(), null, null);
|
||||
|
||||
$eventSubscriber->resetPeriodLocation($event);
|
||||
@@ -247,12 +205,52 @@ final class PersonMoveEventSubscriberTest extends KernelTestCase
|
||||
$this->assertNull($period->getPersonLocation());
|
||||
}
|
||||
|
||||
public function testEventPersonChangeAddressInThePast()
|
||||
{
|
||||
$person = new Person();
|
||||
$period = new AccompanyingPeriod();
|
||||
$period
|
||||
->setStep(AccompanyingPeriod::STEP_CONFIRMED)
|
||||
->setPersonLocation($person)
|
||||
->addPerson($person)
|
||||
->setUser(new User());
|
||||
$this->forceIdToPeriod($period);
|
||||
|
||||
$membership = new HouseholdMember();
|
||||
$membership
|
||||
->setPerson($person)
|
||||
->setHousehold($household = new Household())
|
||||
->setStartDate(new DateTimeImmutable('1 year ago'));
|
||||
|
||||
$previousAddress = new Address();
|
||||
$previousAddress->setValidFrom(new DateTime('6 months ago'));
|
||||
$household->addAddress($previousAddress);
|
||||
|
||||
$newAddress = new Address();
|
||||
$newAddress->setValidFrom(new DateTime('tomorrow'));
|
||||
$household->addAddress($newAddress);
|
||||
|
||||
$event = new PersonAddressMoveEvent($person);
|
||||
$event
|
||||
->setPreviousAddress($household->getPreviousAddressOf($newAddress))
|
||||
->setNextAddress($newAddress);
|
||||
|
||||
$em = $this->prophesize(EntityManagerInterface::class);
|
||||
$em->persist(Argument::type(Notification::class))->shouldBeCalledTimes(1);
|
||||
$eventSubscriber = $this->buildSubscriber(null, $em->reveal(), null, null);
|
||||
|
||||
$eventSubscriber->resetPeriodLocation($event);
|
||||
|
||||
$this->assertNotNull($period->getAddressLocation());
|
||||
$this->assertNull($period->getPersonLocation());
|
||||
}
|
||||
|
||||
private function buildSubscriber(
|
||||
?EngineInterface $engine = null,
|
||||
?EntityManagerInterface $entityManager = null,
|
||||
?Security $security = null,
|
||||
?TranslatorInterface $translator = null
|
||||
): PersonMoveEventSubscriber {
|
||||
): PersonAddressMoveEventSubscriber {
|
||||
if (null === $translator) {
|
||||
$double = $this->prophesize(TranslatorInterface::class);
|
||||
$translator = $double->reveal();
|
||||
@@ -274,7 +272,7 @@ final class PersonMoveEventSubscriberTest extends KernelTestCase
|
||||
$entityManager = $double->reveal();
|
||||
}
|
||||
|
||||
return new PersonMoveEventSubscriber(
|
||||
return new PersonAddressMoveEventSubscriber(
|
||||
$engine,
|
||||
$entityManager,
|
||||
$security,
|
||||
|
Reference in New Issue
Block a user