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