PersonMoveEventSubscriber: handle case when the move is before the last

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

View File

@ -927,15 +927,6 @@ parameters:
count: 1 count: 1
path: src/Bundle/ChillPersonBundle/Controller/HouseholdController.php path: src/Bundle/ChillPersonBundle/Controller/HouseholdController.php
-
message:
"""
#^Parameter \\$translator of method Chill\\\\PersonBundle\\\\Controller\\\\HouseholdMemberController\\:\\:__construct\\(\\) has typehint with deprecated interface Symfony\\\\Component\\\\Translation\\\\TranslatorInterface\\:
since Symfony 4\\.2, use Symfony\\\\Contracts\\\\Translation\\\\TranslatorInterface instead$#
"""
count: 1
path: src/Bundle/ChillPersonBundle/Controller/HouseholdMemberController.php
- -
message: message:
""" """

View File

@ -61,8 +61,18 @@ class PersonMoveEventSubscriber implements EventSubscriberInterface
continue; continue;
} }
if ($period->getPersonLocation() === $person $now = new \DateTimeImmutable('now');
&& $event->getMoveDate() >= $period->getLastLocationHistory()->getStartDate()
if (
$period->getPersonLocation() === $person
&&
(
$event->getMoveDate() >= $period->getLastLocationHistory()->getStartDate()
|| (
$event->getNextAddress()->getValidFrom() < $now
&& (null === $event->getNextAddress()->getValidTo() || $event->getNextAddress()->getValidTo() > $now)
)
)
&& null !== $period->getUser() && null !== $period->getUser()
&& $period->getUser() !== $this->security->getUser() && $period->getUser() !== $this->security->getUser()
) { ) {

View File

@ -26,7 +26,7 @@ use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Serializer\Exception; use Symfony\Component\Serializer\Exception;
use Symfony\Component\Translation\TranslatorInterface; use Symfony\Contracts\Translation\TranslatorInterface;
use function count; use function count;

View File

@ -80,6 +80,51 @@ final class PersonMoveEventSubscriberTest extends KernelTestCase
$eventSubscriber->resetPeriodLocation($event); $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() public function testEventChangeHouseholdNotification()
{ {
$person = new Person(); $person = new Person();