You are here

public function CollectionValidatorTest::testExtraFieldsDisallowed in Plug 7

File

lib/Symfony/validator/Symfony/Component/Validator/Tests/Constraints/CollectionValidatorTest.php, line 127

Class

CollectionValidatorTest

Namespace

Symfony\Component\Validator\Tests\Constraints

Code

public function testExtraFieldsDisallowed() {
  $constraint = new Range(array(
    'min' => 4,
  ));
  $data = $this
    ->prepareTestData(array(
    'foo' => 5,
    'baz' => 6,
  ));
  $this
    ->expectValidateValueAt(0, '[foo]', $data['foo'], array(
    $constraint,
  ));
  $this->validator
    ->validate($data, new Collection(array(
    'fields' => array(
      'foo' => $constraint,
    ),
    'extraFieldsMessage' => 'myMessage',
  )));
  $this
    ->buildViolation('myMessage')
    ->setParameter('{{ field }}', '"baz"')
    ->atPath('property.path[baz]')
    ->setInvalidValue(6)
    ->setCode(Collection::NO_SUCH_FIELD_ERROR)
    ->assertRaised();
}