mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Do not dispatch PersonMoveEvent if moving to a position not sharing
household
This commit is contained in:
parent
df24d085ca
commit
e433b6a42b
@ -61,8 +61,6 @@ class MembersEditor
|
|||||||
throw new LogicException('You must define a household first');
|
throw new LogicException('You must define a household first');
|
||||||
}
|
}
|
||||||
|
|
||||||
$event = new PersonAddressMoveEvent($person);
|
|
||||||
|
|
||||||
$membership = (new HouseholdMember())
|
$membership = (new HouseholdMember())
|
||||||
->setStartDate($date)
|
->setStartDate($date)
|
||||||
->setPerson($person)
|
->setPerson($person)
|
||||||
@ -70,9 +68,13 @@ class MembersEditor
|
|||||||
->setHolder($holder)
|
->setHolder($holder)
|
||||||
->setComment($comment);
|
->setComment($comment);
|
||||||
$this->household->addMember($membership);
|
$this->household->addMember($membership);
|
||||||
$event->setNextMembership($membership);
|
|
||||||
|
|
||||||
if ($position->getShareHousehold()) {
|
if ($position->getShareHousehold()) {
|
||||||
|
// launch event only if moving to a "share household" position
|
||||||
|
$event = new PersonAddressMoveEvent($person);
|
||||||
|
$event->setNextMembership($membership);
|
||||||
|
$this->events[] = $event;
|
||||||
|
|
||||||
foreach ($person->getHouseholdParticipationsShareHousehold() as $participation) {
|
foreach ($person->getHouseholdParticipationsShareHousehold() as $participation) {
|
||||||
if ($participation === $membership) {
|
if ($participation === $membership) {
|
||||||
continue;
|
continue;
|
||||||
@ -108,7 +110,6 @@ class MembersEditor
|
|||||||
|
|
||||||
$this->membershipsAffected[] = $membership;
|
$this->membershipsAffected[] = $membership;
|
||||||
$this->persistables[] = $membership;
|
$this->persistables[] = $membership;
|
||||||
$this->events[] = $event;
|
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@ -167,7 +167,7 @@ final class MembersEditorTest extends TestCase
|
|||||||
$this->assertEquals($date, $membership1->getEndDate());
|
$this->assertEquals($date, $membership1->getEndDate());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPostMove()
|
public function testPostMoveToAPositionNotSharingHousehold()
|
||||||
{
|
{
|
||||||
$person = new Person();
|
$person = new Person();
|
||||||
$position = (new Position())
|
$position = (new Position())
|
||||||
@ -175,6 +175,28 @@ final class MembersEditorTest extends TestCase
|
|||||||
$household1 = new Household();
|
$household1 = new Household();
|
||||||
$household2 = new Household();
|
$household2 = new Household();
|
||||||
$eventDispatcher = $this->prophesize(EventDispatcherInterface::class);
|
$eventDispatcher = $this->prophesize(EventDispatcherInterface::class);
|
||||||
|
$eventDispatcher
|
||||||
|
->dispatch(Argument::type(PersonAddressMoveEvent::class))
|
||||||
|
->shouldNotBeCalled();
|
||||||
|
$factory = $this->buildMembersEditorFactory(
|
||||||
|
$eventDispatcher->reveal(),
|
||||||
|
null
|
||||||
|
);
|
||||||
|
$editor = $factory->createEditor($household1);
|
||||||
|
|
||||||
|
$editor->addMovement(new DateTimeImmutable('now'), $person, $position);
|
||||||
|
|
||||||
|
$editor->postMove();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPostMoveToAPositionSharingHousehold()
|
||||||
|
{
|
||||||
|
$person = new Person();
|
||||||
|
$position = (new Position())
|
||||||
|
->setShareHousehold(true);
|
||||||
|
$household1 = new Household();
|
||||||
|
$household2 = new Household();
|
||||||
|
$eventDispatcher = $this->prophesize(EventDispatcherInterface::class);
|
||||||
$eventDispatcher
|
$eventDispatcher
|
||||||
->dispatch(Argument::type(PersonAddressMoveEvent::class))
|
->dispatch(Argument::type(PersonAddressMoveEvent::class))
|
||||||
->shouldBeCalled();
|
->shouldBeCalled();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user