You are here

public function AbstractValidatorTest::testValidatePropertyValueWithClassName in Zircon Profile 8

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

File

vendor/symfony/validator/Tests/Validator/AbstractValidatorTest.php, line 920

Class

AbstractValidatorTest
@since 2.5

Namespace

Symfony\Component\Validator\Tests\Validator

Code

public function testValidatePropertyValueWithClassName() {
  $test = $this;
  $callback1 = function ($value, ExecutionContextInterface $context) use ($test) {
    $propertyMetadatas = $test->metadata
      ->getPropertyMetadata('firstName');
    $test
      ->assertSame($test::ENTITY_CLASS, $context
      ->getClassName());
    $test
      ->assertSame('firstName', $context
      ->getPropertyName());
    $test
      ->assertSame('', $context
      ->getPropertyPath());
    $test
      ->assertSame('Group', $context
      ->getGroup());
    $test
      ->assertSame($propertyMetadatas[0], $context
      ->getMetadata());
    $test
      ->assertSame('Bernhard', $context
      ->getRoot());
    $test
      ->assertSame('Bernhard', $context
      ->getValue());
    $test
      ->assertSame('Bernhard', $value);
    $context
      ->addViolation('Message %param%', array(
      '%param%' => 'value',
    ));
  };
  $callback2 = function ($value, ExecutionContextInterface $context) {
    $context
      ->addViolation('Other violation');
  };
  $this->metadata
    ->addPropertyConstraint('firstName', new Callback(array(
    'callback' => $callback1,
    'groups' => 'Group',
  )));
  $this->metadata
    ->addPropertyConstraint('lastName', new Callback(array(
    'callback' => $callback2,
    'groups' => 'Group',
  )));
  $violations = $this
    ->validatePropertyValue(self::ENTITY_CLASS, 'firstName', 'Bernhard', 'Group');

  /* @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('Bernhard', $violations[0]
    ->getRoot());
  $this
    ->assertSame('Bernhard', $violations[0]
    ->getInvalidValue());
  $this
    ->assertNull($violations[0]
    ->getPlural());
  $this
    ->assertNull($violations[0]
    ->getCode());
}