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