mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
PersonMoveEventSubscriber: handle case when the move is before the last
locationHistory, but the move affects "now"
This commit is contained in:
parent
104af6d9b5
commit
8675bb65c1
@ -927,15 +927,6 @@ parameters:
|
||||
count: 1
|
||||
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:
|
||||
"""
|
||||
|
@ -61,8 +61,18 @@ class PersonMoveEventSubscriber implements EventSubscriberInterface
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($period->getPersonLocation() === $person
|
||||
&& $event->getMoveDate() >= $period->getLastLocationHistory()->getStartDate()
|
||||
$now = new \DateTimeImmutable('now');
|
||||
|
||||
if (
|
||||
$period->getPersonLocation() === $person
|
||||
&&
|
||||
(
|
||||
$event->getMoveDate() >= $period->getLastLocationHistory()->getStartDate()
|
||||
|| (
|
||||
$event->getNextAddress()->getValidFrom() < $now
|
||||
&& (null === $event->getNextAddress()->getValidTo() || $event->getNextAddress()->getValidTo() > $now)
|
||||
)
|
||||
)
|
||||
&& null !== $period->getUser()
|
||||
&& $period->getUser() !== $this->security->getUser()
|
||||
) {
|
||||
|
@ -26,7 +26,7 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Symfony\Component\Serializer\Exception;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
use function count;
|
||||
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user