function ClassResolverConstraintValidatorTest::testValidationForService
Tests validation for service.
Attributes
#[DataProvider('provideServiceValidationCases')]
File
-
core/
tests/ Drupal/ KernelTests/ Core/ TypedData/ ClassResolverConstraintValidatorTest.php, line 102
Class
- ClassResolverConstraintValidatorTest
- Tests ClassResolver validation constraint with both valid and invalid values.
Namespace
Drupal\KernelTests\Core\TypedDataCode
public function testValidationForService(string $method, int $expected_violations, string $message, ?string $expected_violation_message = NULL) : void {
$definition = DataDefinition::create('integer')->addConstraint('ClassResolver', [
'classOrService' => 'test.service',
'method' => $method,
]);
$typed_data = $this->typedDataManager
->create($definition, 1);
$violations = $typed_data->validate();
$this->assertEquals($expected_violations, $violations->count(), $message);
if ($expected_violation_message) {
$this->assertEquals($expected_violation_message, $violations->get(0)
->getMessage());
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.