public function MinQtyLessThanOrEqualMaxQtyConstraintValidatorTest::testValidate in Commerce Product Bundle 8
@covers ::validate
@dataProvider providerTestValidate
File
- tests/
src/ Unit/ Plugin/ Validation/ Constraint/ MinQtyLessThanOrEqualMaxQtyConstraintValidatorTest.php, line 48
Class
- MinQtyLessThanOrEqualMaxQtyConstraintValidatorTest
- Test the MinQtyLessThanOrEqualMaxQty constraint validator.
Namespace
Drupal\Tests\commerce_product_bundle\Unit\Plugin\Validation\ConstraintCode
public function testValidate($entity, $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('%min', 20)
->willReturn($violation_builder);
$violation_builder
->setParameter('%max', 10)
->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($entity, $this->constraint);
}