From 54997e5893eec060d95ab1ed01473e01fd7975ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 15 Jun 2021 21:31:02 +0200 Subject: [PATCH] add test for household membership sequential validator --- ...eholdMembershipSequentialValidatorTest.php | 100 ++++++++++++++++++ ...HouseholdMembershipSequentialValidator.php | 2 +- 2 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 src/Bundle/ChillPersonBundle/Tests/Validator/Household/HouseholdMembershipSequentialValidatorTest.php diff --git a/src/Bundle/ChillPersonBundle/Tests/Validator/Household/HouseholdMembershipSequentialValidatorTest.php b/src/Bundle/ChillPersonBundle/Tests/Validator/Household/HouseholdMembershipSequentialValidatorTest.php new file mode 100644 index 000000000..fad902e73 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Tests/Validator/Household/HouseholdMembershipSequentialValidatorTest.php @@ -0,0 +1,100 @@ +getConstraint(); + + $person = new Person(); + + $this->validator->validate($person, $constraint); + + $this->assertNoViolation(); + } + + public function testMembershipCovering() + { + $constraint = $this->getConstraint(); + + $person = new Person(); + $household = new Household(); + $position = (new Position()) + ->setShareHousehold(true) + ; + $membership = (new HouseholdMember()) + ->setPosition($position) + ->setStartDate(new \DateTimeImmutable('2010-01-01')) + ->setPerson($person) + ; + $membership = (new HouseholdMember()) + ->setPosition($position) + ->setStartDate(new \DateTimeImmutable('2011-01-01')) + ->setPerson($person) + ; + + $this->validator->validate($person, $constraint); + + $this->buildViolation('msg') + ->setParameters([ + '%person_name%' => 'name', + '%from%' => '01-01-2011', + '%nbHousehold%' => 2 + ]) + ->assertRaised() + ; + } + + public function testMembershipCoveringNoShareHousehold() + { + $constraint = $this->getConstraint(); + + $person = new Person(); + $household = new Household(); + $position = (new Position()) + ->setShareHousehold(false) + ; + $membership = (new HouseholdMember()) + ->setPosition($position) + ->setStartDate(new \DateTimeImmutable('2010-01-01')) + ->setPerson($person) + ; + $membership = (new HouseholdMember()) + ->setPosition($position) + ->setStartDate(new \DateTimeImmutable('2011-01-01')) + ->setPerson($person) + ; + + $this->validator->validate($person, $constraint); + + $this->assertNoViolation(); + } + + protected function getConstraint() + { + return new HouseholdMembershipSequential([ + 'message' => 'msg' + ]); + } + + protected function createValidator() + { + $render = $this->createMock(PersonRender::class); + $render->method('renderString') + ->willReturn('name') + ; + + return new HouseholdMembershipSequentialValidator($render); + } +} diff --git a/src/Bundle/ChillPersonBundle/Validator/Constraints/Household/HouseholdMembershipSequentialValidator.php b/src/Bundle/ChillPersonBundle/Validator/Constraints/Household/HouseholdMembershipSequentialValidator.php index a14127e6f..87b74f784 100644 --- a/src/Bundle/ChillPersonBundle/Validator/Constraints/Household/HouseholdMembershipSequentialValidator.php +++ b/src/Bundle/ChillPersonBundle/Validator/Constraints/Household/HouseholdMembershipSequentialValidator.php @@ -50,7 +50,7 @@ class HouseholdMembershipSequentialValidator extends ConstraintValidator $nbHousehold = count($metadata); $this->context - ->buildViolation("household_membership.Person with membership covering") + ->buildViolation($constraint->message) ->setParameters([ '%person_name%' => $this->render->renderString( $participation->getPerson(), []