diff --git a/phpstan-deprecations.neon b/phpstan-deprecations.neon index 7489d4d80..7632883aa 100644 --- a/phpstan-deprecations.neon +++ b/phpstan-deprecations.neon @@ -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: """ diff --git a/src/Bundle/ChillPersonBundle/AccompanyingPeriod/Events/PersonMoveEventSubscriber.php b/src/Bundle/ChillPersonBundle/AccompanyingPeriod/Events/PersonMoveEventSubscriber.php index 053130240..a0ab44c4f 100644 --- a/src/Bundle/ChillPersonBundle/AccompanyingPeriod/Events/PersonMoveEventSubscriber.php +++ b/src/Bundle/ChillPersonBundle/AccompanyingPeriod/Events/PersonMoveEventSubscriber.php @@ -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() ) { diff --git a/src/Bundle/ChillPersonBundle/Controller/HouseholdMemberController.php b/src/Bundle/ChillPersonBundle/Controller/HouseholdMemberController.php index 849d411d7..2ec72a786 100644 --- a/src/Bundle/ChillPersonBundle/Controller/HouseholdMemberController.php +++ b/src/Bundle/ChillPersonBundle/Controller/HouseholdMemberController.php @@ -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; diff --git a/src/Bundle/ChillPersonBundle/Tests/AccompanyingPeriod/Events/PersonMoveEventSubscriberTest.php b/src/Bundle/ChillPersonBundle/Tests/AccompanyingPeriod/Events/PersonMoveEventSubscriberTest.php index 0ba8cf878..5948e6471 100644 --- a/src/Bundle/ChillPersonBundle/Tests/AccompanyingPeriod/Events/PersonMoveEventSubscriberTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/AccompanyingPeriod/Events/PersonMoveEventSubscriberTest.php @@ -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();