diff --git a/src/Bundle/ChillPersonBundle/Tests/Validator/AccompanyingPeriod/ParticipationOverlapValidatorTest.php b/src/Bundle/ChillPersonBundle/Tests/Validator/AccompanyingPeriod/ParticipationOverlapValidatorTest.php new file mode 100644 index 000000000..381a42578 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Tests/Validator/AccompanyingPeriod/ParticipationOverlapValidatorTest.php @@ -0,0 +1,108 @@ +getConstraint(); + + $period = new AccompanyingPeriod(); + $person1 = new Person(); + $person2 = new Person(); + + $period->createParticipationFor($person1); + $period->createParticipationFor($person2); + + $this->validator->validate($period->getParticipations(), $constraint); + + $this->assertNoViolation(); + } + + public function testHasTwoParticipationsOverlaps(): void + { + $constraint = $this->getConstraint(); + + $period = new AccompanyingPeriod(); + $person1 = new Person(); + $reflectionPerson = new \ReflectionClass($person1); + $personId = $reflectionPerson->getProperty('id'); + $personId->setAccessible(true); + $personId->setValue($person1, 1); + $person2 = new Person(); + + $period->createParticipationFor($person1); + $period->createParticipationFor($person1); + $period->createParticipationFor($person2); + + $this->validator->validate($period->getParticipations(), $constraint); + + $this->buildViolation('participation-overlaps') + ->setParameters([ + '{{ start }}' => (new \DateTimeImmutable('today'))->format('d-m-Y'), + '{{ end }}' => null, + '{{ ids }}' => [null, null], + '{{ name }}' => 'person' + ]) + ->assertRaised(); + } + + public function testHasTwoParticipationsButDoNotOverlaps(): void + { + $constraint = $this->getConstraint(); + + $period = new AccompanyingPeriod(); + $person1 = new Person(); + $reflectionPerson = new \ReflectionClass($person1); + $personId = $reflectionPerson->getProperty('id'); + $personId->setAccessible(true); + $personId->setValue($person1, 1); + $person2 = new Person(); + + $participation1 = $period->createParticipationFor($person1); + $period->createParticipationFor($person1); + $participation1->setEndDate(new \DateTime('now')); + $period->createParticipationFor($person2); + + $this->validator->validate($period->getParticipations(), $constraint); + + $this->assertNoViolation(); + } + protected function createValidator(): ParticipationOverlapValidator + { + $personRender = $this->prophesize(PersonRenderInterface::class); + $personRender->renderString(Argument::type(Person::class), []) + ->willReturn('person'); + $thirdPartyRender = $this->prophesize(ThirdPartyRender::class); + $thirdPartyRender->renderString(Argument::type(ThirdParty::class), []) + ->willReturn('third-party'); + + return new ParticipationOverlapValidator( + $personRender->reveal(), + $thirdPartyRender->reveal() + ); + } + + public function getConstraint(): ParticipationOverlap + { + return new ParticipationOverlap(['message' => 'participation-overlaps']); + } + + + + +} diff --git a/src/Bundle/ChillPersonBundle/Validator/Constraints/AccompanyingPeriod/ParticipationOverlapValidator.php b/src/Bundle/ChillPersonBundle/Validator/Constraints/AccompanyingPeriod/ParticipationOverlapValidator.php index 9c9991a1a..527bb43cb 100644 --- a/src/Bundle/ChillPersonBundle/Validator/Constraints/AccompanyingPeriod/ParticipationOverlapValidator.php +++ b/src/Bundle/ChillPersonBundle/Validator/Constraints/AccompanyingPeriod/ParticipationOverlapValidator.php @@ -61,9 +61,9 @@ class ParticipationOverlapValidator extends ConstraintValidator throw new UnexpectedTypeException($participation, AccompanyingPeriodParticipation::class); } - $personId = $participation->getPerson()->getId(); + $hashPerson = spl_object_hash($participation->getPerson()); - $participationList[$personId][] = $participation; + $participationList[$hashPerson][] = $participation; } foreach ($participationList as $group) { diff --git a/src/Bundle/ChillThirdPartyBundle/Form/ChoiceLoader/ThirdPartyChoiceLoader.php b/src/Bundle/ChillThirdPartyBundle/Form/ChoiceLoader/ThirdPartyChoiceLoader.php index 5c990c9ad..3b5931aa6 100644 --- a/src/Bundle/ChillThirdPartyBundle/Form/ChoiceLoader/ThirdPartyChoiceLoader.php +++ b/src/Bundle/ChillThirdPartyBundle/Form/ChoiceLoader/ThirdPartyChoiceLoader.php @@ -23,6 +23,8 @@ use function in_array; /** * Lazy load third parties. + * + * @deprecated As the PickThirdPartyType is deprecated, this should not be in use */ class ThirdPartyChoiceLoader implements ChoiceLoaderInterface { @@ -57,7 +59,7 @@ class ThirdPartyChoiceLoader implements ChoiceLoaderInterface $choices = []; foreach ($values as $value) { - if (empty($value)) { + if (null === $value || '' === $value) { continue; } diff --git a/src/Bundle/ChillThirdPartyBundle/Form/Type/PickThirdPartyType.php b/src/Bundle/ChillThirdPartyBundle/Form/Type/PickThirdPartyType.php index 259fb63f4..ed4b3c1e7 100644 --- a/src/Bundle/ChillThirdPartyBundle/Form/Type/PickThirdPartyType.php +++ b/src/Bundle/ChillThirdPartyBundle/Form/Type/PickThirdPartyType.php @@ -29,6 +29,10 @@ use function array_merge; use function count; use function is_array; +/** + * @deprecated use the @link{PickThirdPartyDynamicType::class} + * @note do remove ThirdPartyChoiceLoader if this class is removed + */ class PickThirdPartyType extends AbstractType { /** diff --git a/src/Bundle/ChillThirdPartyBundle/Repository/ThirdPartyRepository.php b/src/Bundle/ChillThirdPartyBundle/Repository/ThirdPartyRepository.php index 134957c0f..76e15ef17 100644 --- a/src/Bundle/ChillThirdPartyBundle/Repository/ThirdPartyRepository.php +++ b/src/Bundle/ChillThirdPartyBundle/Repository/ThirdPartyRepository.php @@ -180,7 +180,7 @@ final class ThirdPartyRepository implements ObjectRepository if (array_key_exists('name', $terms) || array_key_exists('_default', $terms)) { $term = $terms['name'] ?? $terms['_default']; - if (empty($term)) { + if (null === $term || '' === $term) { return; } $qb->andWhere($qb->expr()->like('UNACCENT(LOWER(tp.name))', 'UNACCENT(LOWER(:name))'));