function SerializedConstraintValidatorTest::testValidate
Validate serializer constraint.
Attributes
#[DataProvider('provideTestValidate')]
File
-
core/
tests/ Drupal/ Tests/ Core/ Validation/ Plugin/ Validation/ Constraint/ SerializedConstraintValidatorTest.php, line 27
Class
- SerializedConstraintValidatorTest
- Tests serialize validator.
Namespace
Drupal\Tests\Core\Validation\Plugin\Validation\ConstraintCode
public function testValidate($value, bool $valid) : void {
$typed_data = new StringData(DataDefinition::create('string'));
$context = $this->createMock(ExecutionContextInterface::class);
$context->expects($this->any())
->method('getObject')
->willReturn($typed_data);
if ($valid) {
$context->expects($this->never())
->method('addViolation');
}
else {
$context->expects($this->once())
->method('addViolation');
}
$constraint = new SerializedConstraint();
$validate = new SerializedConstraintValidator();
$validate->initialize($context);
$validate->validate($value, $constraint);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.