public function CountryConstraintValidatorTest::testValidate in Address 8
@covers ::validate
@dataProvider providerTestValidate
File
- tests/
src/ Unit/ Plugin/ Validation/ Constraint/ CountryConstraintValidatorTest.php, line 49
Class
- CountryConstraintValidatorTest
- @coversDefaultClass \Drupal\address\Plugin\Validation\Constraint\CountryConstraintValidator @group address
Namespace
Drupal\Tests\address\Unit\Plugin\Validation\ConstraintCode
public function testValidate($country_code, $expected_violation) {
// If a violation is expected, then the context's buildViolation method
// will be called, otherwise it should not be called.
$context = $this
->prophesize(ExecutionContextInterface::class);
if ($expected_violation) {
$violation_builder = $this
->prophesize(ConstraintViolationBuilderInterface::class);
$violation_builder
->setParameter('%value', Argument::any())
->willReturn($violation_builder);
$violation_builder
->addViolation()
->willReturn($violation_builder);
$context
->buildViolation($expected_violation)
->willReturn($violation_builder
->reveal())
->shouldBeCalled();
}
else {
$context
->buildViolation(Argument::any())
->shouldNotBeCalled();
}
$this->validator
->initialize($context
->reveal());
$this->validator
->validate($country_code, $this->constraint);
}