From 3b083c31e7463a6432c12356cb906d434ba67737 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 30 Mar 2022 12:57:16 +0200 Subject: [PATCH] add tests for moving to not share position in another household --- .../Tests/Household/MembersEditorTest.php | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/Bundle/ChillPersonBundle/Tests/Household/MembersEditorTest.php b/src/Bundle/ChillPersonBundle/Tests/Household/MembersEditorTest.php index 84ca9f32e..a5d34b1dc 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Household/MembersEditorTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Household/MembersEditorTest.php @@ -40,6 +40,48 @@ final class MembersEditorTest extends TestCase $this->factory = $this->buildMembersEditorFactory(); } + /** + * We test here a move for a person:. + * + * * which was in a position "sharing household" + * * which move to the another household, in a position "not sharing household" + * + * The person should stays in the two households + */ + public function testMoveFromSharingHouseholdToNotSharingHousehouldInDifferentHousehold() + { + $person = new Person(); + $household = new Household(); + $positionSharing = (new Position())->setShareHousehold(true); + $positionNotSharing = (new Position())->setShareHousehold(false); + $factory = $this->buildMembersEditorFactory(); + $editor = $factory->createEditor($household); + + // we add the member to the household + $editor->addMovement(new DateTimeImmutable('1 month ago'), $person, $positionSharing); + + // double check that the person is in the household + $this->assertContains($person, $household->getCurrentPersons()); + + // we do the move to the position not sharing household + $editor = $factory->createEditor($household2 = new Household()); + $editor->addMovement(new DateTimeImmutable('yesterday'), $person, $positionNotSharing); + + $sharings = $household->getCurrentMembers()->filter(static function (HouseholdMember $m) { + return $m->getShareHousehold(); + }); + $notSharing = $household2->getCurrentMembers()->filter(static function (HouseholdMember $m) { + return !$m->getShareHousehold(); + }); + + $this->assertCount(1, $notSharing); + $this->assertCount(1, $sharings); + + $getPerson = static function (HouseholdMember $m) { return $m->getPerson(); }; + + $this->assertContains($person, $notSharing->map($getPerson)); + } + /** * We test here a move for a person:. *