You are here

public function AbstractLegacyApiTest::testAddCustomizedViolation in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/validator/Tests/Validator/AbstractLegacyApiTest.php \Symfony\Component\Validator\Tests\Validator\AbstractLegacyApiTest::testAddCustomizedViolation()

File

vendor/symfony/validator/Tests/Validator/AbstractLegacyApiTest.php, line 235

Class

AbstractLegacyApiTest
Verifies that a validator satisfies the API of Symfony < 2.5.

Namespace

Symfony\Component\Validator\Tests\Validator

Code

public function testAddCustomizedViolation() {
  $entity = new Entity();
  $callback = function ($value, ExecutionContextInterface $context) {
    $context
      ->addViolation('Message %param%', array(
      '%param%' => 'value',
    ), 'Invalid value', 2, 'Code');
  };
  $this->metadata
    ->addConstraint(new Callback($callback));
  $violations = $this->validator
    ->validate($entity);

  /* @var ConstraintViolationInterface[] $violations */
  $this
    ->assertCount(1, $violations);
  $this
    ->assertSame('Message value', $violations[0]
    ->getMessage());
  $this
    ->assertSame('Message %param%', $violations[0]
    ->getMessageTemplate());
  $this
    ->assertSame(array(
    '%param%' => 'value',
  ), $violations[0]
    ->getParameters());
  $this
    ->assertSame('', $violations[0]
    ->getPropertyPath());
  $this
    ->assertSame($entity, $violations[0]
    ->getRoot());
  $this
    ->assertSame('Invalid value', $violations[0]
    ->getInvalidValue());
  $this
    ->assertSame(2, $violations[0]
    ->getPlural());
  $this
    ->assertSame('Code', $violations[0]
    ->getCode());
}