public function AnnotationLoaderTest::testLoadClassMetadata

File

drupal/core/vendor/symfony/validator/Symfony/Component/Validator/Tests/Mapping/Loader/AnnotationLoaderTest.php, line 50

Class

AnnotationLoaderTest

Namespace

Symfony\Component\Validator\Tests\Mapping\Loader

Code

public function testLoadClassMetadata() {
  $loader = new AnnotationLoader(new AnnotationReader());
  $metadata = new ClassMetadata('Symfony\\Component\\Validator\\Tests\\Fixtures\\Entity');
  $loader
    ->loadClassMetadata($metadata);
  $expected = new ClassMetadata('Symfony\\Component\\Validator\\Tests\\Fixtures\\Entity');
  $expected
    ->setGroupSequence(array(
    'Foo',
    'Entity',
  ));
  $expected
    ->addConstraint(new ConstraintA());
  $expected
    ->addPropertyConstraint('firstName', new NotNull());
  $expected
    ->addPropertyConstraint('firstName', new Range(array(
    'min' => 3,
  )));
  $expected
    ->addPropertyConstraint('firstName', new All(array(
    new NotNull(),
    new Range(array(
      'min' => 3,
    )),
  )));
  $expected
    ->addPropertyConstraint('firstName', new All(array(
    'constraints' => array(
      new NotNull(),
      new Range(array(
        'min' => 3,
      )),
    ),
  )));
  $expected
    ->addPropertyConstraint('firstName', new Collection(array(
    'fields' => array(
      'foo' => array(
        new NotNull(),
        new Range(array(
          'min' => 3,
        )),
      ),
      'bar' => new Range(array(
        'min' => 5,
      )),
    ),
  )));
  $expected
    ->addPropertyConstraint('firstName', new Choice(array(
    'message' => 'Must be one of %choices%',
    'choices' => array(
      'A',
      'B',
    ),
  )));
  $expected
    ->addGetterConstraint('lastName', new NotNull());

  // load reflection class so that the comparison passes
  $expected
    ->getReflectionClass();
  $this
    ->assertEquals($expected, $metadata);
}