do not launch PersonMoveEvent when moving to the same household

This commit is contained in:
2022-03-30 16:42:57 +02:00
parent dae9d48574
commit 36b1f05524
3 changed files with 84 additions and 4 deletions

View File

@@ -231,13 +231,71 @@ final class MembersEditorTest extends TestCase
$editor->postMove();
}
public function testPostMoveToAPositionSharingHousehold()
public function testPostMoveToAPositionSharingHouseholdAndSameHousehold()
{
$person = new Person();
$position = (new Position())
->setShareHousehold(true);
$position2 = (new Position())
->setShareHousehold(true);
$household1 = new Household();
// set into the first household
$editor = $this->buildMembersEditorFactory()
->createEditor($household1);
$editor->addMovement(new DateTimeImmutable('1 year ago'), $person, $position);
// prepare for next move
$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, $position2);
$editor->postMove();
}
public function testPostMoveToAPositionSharingHouseholdFromDifferentHousehold()
{
$person = new Person();
$position = (new Position())
->setShareHousehold(true);
$household1 = new Household();
$household2 = new Household();
// set into the first household
$editor = $this->buildMembersEditorFactory()
->createEditor($household1);
$editor->addMovement(new DateTimeImmutable('1 year ago'), $person, $position);
// perform now the movement
$eventDispatcher = $this->prophesize(EventDispatcherInterface::class);
$eventDispatcher
->dispatch(Argument::type(PersonAddressMoveEvent::class))
->shouldBeCalled();
$factory = $this->buildMembersEditorFactory(
$eventDispatcher->reveal(),
null
);
$editor = $factory->createEditor($household2);
$editor->addMovement(new DateTimeImmutable('now'), $person, $position);
$editor->postMove();
}
public function testPostMoveToAPositionSharingHouseholdFromNoHousehold()
{
$person = new Person();
$position = (new Position())
->setShareHousehold(true);
$household1 = new Household();
$eventDispatcher = $this->prophesize(EventDispatcherInterface::class);
$eventDispatcher
->dispatch(Argument::type(PersonAddressMoveEvent::class))