remove deprecation on PersonHasCenterValidator and fix tests

This commit is contained in:
Julien Fastré 2021-11-24 14:20:17 +00:00
parent 41f0578966
commit a2681a02f9
3 changed files with 18 additions and 16 deletions

View File

@ -1330,14 +1330,6 @@ parameters:
count: 1 count: 1
path: src/Bundle/ChillPersonBundle/Search/SimilarPersonMatcher.php path: src/Bundle/ChillPersonBundle/Search/SimilarPersonMatcher.php
-
message:
"""
#^Parameter \\$centerResolverDispatcher of method Chill\\\\PersonBundle\\\\Validator\\\\Constraints\\\\Person\\\\PersonHasCenterValidator\\:\\:__construct\\(\\) has typehint with deprecated interface Chill\\\\MainBundle\\\\Security\\\\Resolver\\\\CenterResolverDispatcherInterface\\:
Use CenterResolverManager and its interface CenterResolverManagerInterface$#
"""
count: 1
path: src/Bundle/ChillPersonBundle/Validator/Constraints/Person/PersonHasCenterValidator.php
- -
message: message:

View File

@ -12,10 +12,11 @@ declare(strict_types=1);
namespace Validator\Person; namespace Validator\Person;
use Chill\MainBundle\Entity\Center; use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Security\Resolver\CenterResolverDispatcherInterface; use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface;
use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Validator\Constraints\Person\PersonHasCenter; use Chill\PersonBundle\Validator\Constraints\Person\PersonHasCenter;
use Chill\PersonBundle\Validator\Constraints\Person\PersonHasCenterValidator; use Chill\PersonBundle\Validator\Constraints\Person\PersonHasCenterValidator;
use Prophecy\Argument;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase; use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
@ -52,9 +53,18 @@ class PersonHasCenterValidatorTest extends ConstraintValidatorTestCase
], ],
]); ]);
$centerResolverDispatcher = $this->createMock(CenterResolverDispatcherInterface::class); $prophecy = $this->prophesize(CenterResolverManagerInterface::class);
$prophecy->resolveCenters(Argument::type(Person::class), Argument::any())->will(function ($args) {
$center = $args[0]->getCenter();
return new PersonHasCenterValidator($parameterBag, $centerResolverDispatcher); if ($center instanceof Center) {
return [$center];
}
return [];
});
return new PersonHasCenterValidator($parameterBag, $prophecy->reveal());
} }
protected function getConstraint() protected function getConstraint()

View File

@ -11,7 +11,7 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Validator\Constraints\Person; namespace Chill\PersonBundle\Validator\Constraints\Person;
use Chill\MainBundle\Security\Resolver\CenterResolverDispatcherInterface; use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface;
use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\Person;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\Constraint;
@ -22,12 +22,12 @@ class PersonHasCenterValidator extends ConstraintValidator
{ {
private bool $centerRequired; private bool $centerRequired;
private CenterResolverDispatcherInterface $centerResolverDispatcher; private CenterResolverManagerInterface $centerResolverManager;
public function __construct(ParameterBagInterface $parameterBag, CenterResolverDispatcherInterface $centerResolverDispatcher) public function __construct(ParameterBagInterface $parameterBag, CenterResolverManagerInterface $centerResolverManager)
{ {
$this->centerRequired = $parameterBag->get('chill_person')['validation']['center_required']; $this->centerRequired = $parameterBag->get('chill_person')['validation']['center_required'];
$this->centerResolverDispatcher = $centerResolverDispatcher; $this->centerResolverManager = $centerResolverManager;
} }
public function validate($person, Constraint $constraint) public function validate($person, Constraint $constraint)
@ -40,7 +40,7 @@ class PersonHasCenterValidator extends ConstraintValidator
return; return;
} }
if (null === $this->centerResolverDispatcher->resolveCenter($person)) { if ([] === $this->centerResolverManager->resolveCenters($person)) {
$this $this
->context ->context
->buildViolation($constraint->message) ->buildViolation($constraint->message)