public function AllowedValuesConstraintValidatorTest::testValidationCallbackException in Drupal 10
Same name and namespace in other branches
- 8 core/tests/Drupal/KernelTests/Core/TypedData/AllowedValuesConstraintValidatorTest.php \Drupal\KernelTests\Core\TypedData\AllowedValuesConstraintValidatorTest::testValidationCallbackException()
- 9 core/tests/Drupal/KernelTests/Core/TypedData/AllowedValuesConstraintValidatorTest.php \Drupal\KernelTests\Core\TypedData\AllowedValuesConstraintValidatorTest::testValidationCallbackException()
Tests the AllowedValuesConstraintValidator with an invalid callback.
File
- core/
tests/ Drupal/ KernelTests/ Core/ TypedData/ AllowedValuesConstraintValidatorTest.php, line 103
Class
- AllowedValuesConstraintValidatorTest
- Tests AllowedValues validation constraint with both valid and invalid values.
Namespace
Drupal\KernelTests\Core\TypedDataCode
public function testValidationCallbackException() {
// Create a definition that specifies some AllowedValues and a callback.
// This tests that callbacks have a higher priority than a supplied list of
// values and can be used to coerce the value to the correct type.
$definition = DataDefinition::create('string')
->addConstraint('AllowedValues', [
'choices' => [
1,
2,
3,
],
'callback' => [
static::class,
'doesNotExist',
],
]);
$typed_data = $this->typedData
->create($definition, 1);
$this
->expectException(ConstraintDefinitionException::class);
$this
->expectExceptionMessage('The AllowedValuesConstraint constraint expects a valid callback');
$typed_data
->validate();
}