public function AbstractValidatorTest::testReferencePropertyConstraint in Plug 7
File
- lib/
Symfony/ validator/ Symfony/ Component/ Validator/ Tests/ Validator/ AbstractValidatorTest.php, line 417
Class
- AbstractValidatorTest
- @since 2.5 @author Bernhard Schussek <bschussek@gmail.com>
Namespace
Symfony\Component\Validator\Tests\ValidatorCode
public function testReferencePropertyConstraint() {
$test = $this;
$entity = new Entity();
$entity->reference = new Reference();
$entity->reference->value = 'Foobar';
$callback = function ($value, ExecutionContextInterface $context) use ($test, $entity) {
$propertyMetadatas = $test->referenceMetadata
->getPropertyMetadata('value');
$test
->assertSame($test::REFERENCE_CLASS, $context
->getClassName());
$test
->assertSame('value', $context
->getPropertyName());
$test
->assertSame('reference.value', $context
->getPropertyPath());
$test
->assertSame('Group', $context
->getGroup());
$test
->assertSame($propertyMetadatas[0], $context
->getMetadata());
$test
->assertSame($entity, $context
->getRoot());
$test
->assertSame('Foobar', $context
->getValue());
$test
->assertSame('Foobar', $value);
$context
->addViolation('Message %param%', array(
'%param%' => 'value',
));
};
$this->metadata
->addPropertyConstraint('reference', new Valid());
$this->referenceMetadata
->addPropertyConstraint('value', new Callback(array(
'callback' => $callback,
'groups' => 'Group',
)));
$violations = $this
->validate($entity, null, '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]
->getMessageParameters());
$this
->assertSame('reference.value', $violations[0]
->getPropertyPath());
$this
->assertSame($entity, $violations[0]
->getRoot());
$this
->assertSame('Foobar', $violations[0]
->getInvalidValue());
$this
->assertNull($violations[0]
->getMessagePluralization());
$this
->assertNull($violations[0]
->getCode());
}