mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
add test for household membership sequential validator
This commit is contained in:
parent
78ca61c82e
commit
54997e5893
@ -0,0 +1,100 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Chill\PersonBundle\Tests\Validator\Household;
|
||||||
|
|
||||||
|
use Chill\PersonBundle\Entity\Household\HouseholdMember;
|
||||||
|
use Chill\PersonBundle\Entity\Household\Position;
|
||||||
|
use Chill\PersonBundle\Entity\Household\Household;
|
||||||
|
use Chill\PersonBundle\Entity\Person;
|
||||||
|
use Chill\PersonBundle\Templating\Entity\PersonRender;
|
||||||
|
use Chill\PersonBundle\Validator\Constraints\Household\HouseholdMembershipSequentialValidator;
|
||||||
|
use Chill\PersonBundle\Validator\Constraints\Household\HouseholdMembershipSequential;
|
||||||
|
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
|
||||||
|
|
||||||
|
class HouseholdMembershipSequentialValidatorTest extends ConstraintValidatorTestCase
|
||||||
|
{
|
||||||
|
public function testEmptyPerson()
|
||||||
|
{
|
||||||
|
$constraint = $this->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);
|
||||||
|
}
|
||||||
|
}
|
@ -50,7 +50,7 @@ class HouseholdMembershipSequentialValidator extends ConstraintValidator
|
|||||||
$nbHousehold = count($metadata);
|
$nbHousehold = count($metadata);
|
||||||
|
|
||||||
$this->context
|
$this->context
|
||||||
->buildViolation("household_membership.Person with membership covering")
|
->buildViolation($constraint->message)
|
||||||
->setParameters([
|
->setParameters([
|
||||||
'%person_name%' => $this->render->renderString(
|
'%person_name%' => $this->render->renderString(
|
||||||
$participation->getPerson(), []
|
$participation->getPerson(), []
|
||||||
|
Loading…
x
Reference in New Issue
Block a user