mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-28 10:33:49 +00:00
Add ThirdPartyHasEmail validator
Introduce a new validator that ensures a third party has an email address, including the corresponding translation for error messaging and unit tests to verify its functionality.
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace ChillThirdParty\Tests\Validator;
|
||||
|
||||
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||
use Chill\ThirdPartyBundle\Templating\Entity\ThirdPartyRender;
|
||||
use Chill\ThirdPartyBundle\Validator\ThirdPartyHasEmail;
|
||||
use Chill\ThirdPartyBundle\Validator\ThirdPartyHasEmailValidator;
|
||||
use Prophecy\Argument;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
class ThirdPartyHasEmailValidatorTest extends \Symfony\Component\Validator\Test\ConstraintValidatorTestCase
|
||||
{
|
||||
use ProphecyTrait;
|
||||
|
||||
public function testThirdPartyWithEmail(): void
|
||||
{
|
||||
$thirdParty = new ThirdParty();
|
||||
$thirdParty->setEmail('third@example.com');
|
||||
|
||||
$this->validator->validate($thirdParty, new ThirdPartyHasEmail());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testThirdPartyHasNoEmail(): void
|
||||
{
|
||||
$thirdParty = new ThirdParty();
|
||||
|
||||
$constraint = new ThirdPartyHasEmail();
|
||||
$constraint->message = 'message';
|
||||
|
||||
$this->validator->validate($thirdParty, $constraint);
|
||||
|
||||
$this->buildViolation($constraint->message)
|
||||
->setParameter('{{ thirdParty }}', '3party-string')
|
||||
->setCode($constraint->code)
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
protected function createValidator(): ThirdPartyHasEmailValidator
|
||||
{
|
||||
$render = $this->prophesize(ThirdPartyRender::class);
|
||||
$render->renderString(Argument::type(ThirdParty::class), [])
|
||||
->willReturn('3party-string');
|
||||
|
||||
return new ThirdPartyHasEmailValidator($render->reveal());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user