mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
57 lines
1.8 KiB
PHP
57 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Validator\Person;
|
|
|
|
use Chill\MainBundle\Entity\Center;
|
|
use Chill\MainBundle\Security\Resolver\CenterResolverDispatcher;
|
|
use Chill\MainBundle\Security\Resolver\CenterResolverDispatcherInterface;
|
|
use Chill\PersonBundle\Entity\Person;
|
|
use Chill\PersonBundle\Validator\Constraints\Person\PersonHasCenter;
|
|
use Chill\PersonBundle\Validator\Constraints\Person\PersonHasCenterValidator;
|
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
|
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
|
|
|
|
class PersonHasCenterValidatorTest extends ConstraintValidatorTestCase
|
|
{
|
|
public function testValidateRequired()
|
|
{
|
|
$constraint = $this->getConstraint();
|
|
$personHasCenter = (new Person())->setCenter(new Center());
|
|
$personNoCenter = new Person();
|
|
|
|
$this->validator->validate($personHasCenter, $constraint);
|
|
$this->assertNoViolation();
|
|
|
|
$this->validator->validate($personNoCenter, $constraint);
|
|
$this->buildViolation('msg')
|
|
->atPath('property.path.center')
|
|
->assertRaised();
|
|
}
|
|
|
|
protected function getConstraint()
|
|
{
|
|
return new PersonHasCenter([
|
|
'message' => 'msg'
|
|
]);
|
|
}
|
|
|
|
protected function createValidator()
|
|
{
|
|
$parameterBag = $this->createMock(ParameterBagInterface::class);
|
|
$parameterBag
|
|
->method('get')
|
|
->with($this->equalTo('chill_person'))
|
|
->willReturn([
|
|
'validation' => [
|
|
'center_required' => true
|
|
]
|
|
]);
|
|
|
|
$centerResolverDispatcher = $this->createMock(CenterResolverDispatcherInterface::class);
|
|
|
|
return new PersonHasCenterValidator($parameterBag, $centerResolverDispatcher);
|
|
}
|
|
}
|