You are here

public function AnnotationLoaderTest::testLoadClassMetadataAndMerge in Zircon Profile 8

Same name in this branch
  1. 8 vendor/symfony/validator/Tests/Mapping/Loader/AnnotationLoaderTest.php \Symfony\Component\Validator\Tests\Mapping\Loader\AnnotationLoaderTest::testLoadClassMetadataAndMerge()
  2. 8 vendor/symfony/serializer/Tests/Mapping/Loader/AnnotationLoaderTest.php \Symfony\Component\Serializer\Tests\Mapping\Loader\AnnotationLoaderTest::testLoadClassMetadataAndMerge()
Same name and namespace in other branches
  1. 8.0 vendor/symfony/validator/Tests/Mapping/Loader/AnnotationLoaderTest.php \Symfony\Component\Validator\Tests\Mapping\Loader\AnnotationLoaderTest::testLoadClassMetadataAndMerge()

Test MetaData merge with parent annotation.

File

vendor/symfony/validator/Tests/Mapping/Loader/AnnotationLoaderTest.php, line 100

Class

AnnotationLoaderTest

Namespace

Symfony\Component\Validator\Tests\Mapping\Loader

Code

public function testLoadClassMetadataAndMerge() {
  $loader = new AnnotationLoader(new AnnotationReader());

  // Load Parent MetaData
  $parent_metadata = new ClassMetadata('Symfony\\Component\\Validator\\Tests\\Fixtures\\EntityParent');
  $loader
    ->loadClassMetadata($parent_metadata);
  $metadata = new ClassMetadata('Symfony\\Component\\Validator\\Tests\\Fixtures\\Entity');

  // Merge parent metaData.
  $metadata
    ->mergeConstraints($parent_metadata);
  $loader
    ->loadClassMetadata($metadata);
  $expected_parent = new ClassMetadata('Symfony\\Component\\Validator\\Tests\\Fixtures\\EntityParent');
  $expected_parent
    ->addPropertyConstraint('other', new NotNull());
  $expected_parent
    ->getReflectionClass();
  $expected = new ClassMetadata('Symfony\\Component\\Validator\\Tests\\Fixtures\\Entity');
  $expected
    ->mergeConstraints($expected_parent);
  $expected
    ->setGroupSequence(array(
    'Foo',
    'Entity',
  ));
  $expected
    ->addConstraint(new ConstraintA());
  $expected
    ->addConstraint(new Callback(array(
    'Symfony\\Component\\Validator\\Tests\\Fixtures\\CallbackClass',
    'callback',
  )));
  $expected
    ->addConstraint(new Callback('validateMe'));
  $expected
    ->addConstraint(new Callback('validateMeStatic'));
  $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());
  $expected
    ->addGetterConstraint('valid', new IsTrue());
  $expected
    ->addGetterConstraint('permissions', new IsTrue());

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