function RecursiveContextualValidatorTest::testBasicValidateWithMultipleConstraints

Same name and namespace in other branches
  1. 10 core/tests/Drupal/Tests/Core/TypedData/RecursiveContextualValidatorTest.php \Drupal\Tests\Core\TypedData\RecursiveContextualValidatorTest::testBasicValidateWithMultipleConstraints()
  2. 9 core/tests/Drupal/Tests/Core/TypedData/RecursiveContextualValidatorTest.php \Drupal\Tests\Core\TypedData\RecursiveContextualValidatorTest::testBasicValidateWithMultipleConstraints()
  3. 8.9.x core/tests/Drupal/Tests/Core/TypedData/RecursiveContextualValidatorTest.php \Drupal\Tests\Core\TypedData\RecursiveContextualValidatorTest::testBasicValidateWithMultipleConstraints()

Tests basic validate with multiple constraints.

@legacy-covers ::validate

File

core/tests/Drupal/Tests/Core/TypedData/RecursiveContextualValidatorTest.php, line 151

Class

RecursiveContextualValidatorTest
Tests Drupal\Core\TypedData\Validation\RecursiveContextualValidator.

Namespace

Drupal\Tests\Core\TypedData

Code

public function testBasicValidateWithMultipleConstraints() : void {
  $options = [
    'callback' => function ($value, ExecutionContextInterface $context) : void {
      $context->addViolation('test violation');
    },
  ];
  $typed_data = $this->typedDataManager
    ->create(DataDefinition::create('string')->addConstraint('Callback', $options)
    ->addConstraint('NotNull'));
  $violations = $this->recursiveValidator
    ->validate($typed_data);
  $this->assertCount(2, $violations);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.