* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Validator\Tests\Mapping\Loader; use Doctrine\Common\Annotations\AnnotationReader; use PHPUnit\Framework\TestCase; use Symfony\Component\Validator\Constraints\All; use Symfony\Component\Validator\Constraints\Callback; use Symfony\Component\Validator\Constraints\Choice; use Symfony\Component\Validator\Constraints\Collection; use Symfony\Component\Validator\Constraints\NotNull; use Symfony\Component\Validator\Constraints\Range; use Symfony\Component\Validator\Constraints\IsTrue; use Symfony\Component\Validator\Constraints\Valid; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; use Symfony\Component\Validator\Tests\Fixtures\ConstraintA; class AnnotationLoaderTest extends TestCase { public function testLoadClassMetadataReturnsTrueIfSuccessful() { $reader = new AnnotationReader(); $loader = new AnnotationLoader($reader); $metadata = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\Entity'); $this->assertTrue($loader->loadClassMetadata($metadata)); } public function testLoadClassMetadataReturnsFalseIfNotSuccessful() { $loader = new AnnotationLoader(new AnnotationReader()); $metadata = new ClassMetadata('\stdClass'); $this->assertFalse($loader->loadClassMetadata($metadata)); } 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->addConstraint(new Callback(array('Symfony\Component\Validator\Tests\Fixtures\CallbackClass', 'callback'))); $expected->addConstraint(new Callback(array('callback' => 'validateMe', 'payload' => 'foo'))); $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->addPropertyConstraint('childA', new Valid()); $expected->addPropertyConstraint('childB', new Valid()); $expected->addGetterConstraint('lastName', new NotNull()); $expected->addGetterMethodConstraint('valid', 'isValid', new IsTrue()); $expected->addGetterConstraint('permissions', new IsTrue()); // load reflection class so that the comparison passes $expected->getReflectionClass(); $this->assertEquals($expected, $metadata); } /** * Test MetaData merge with parent annotation. */ public function testLoadParentClassMetadata() { $loader = new AnnotationLoader(new AnnotationReader()); // Load Parent MetaData $parent_metadata = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\EntityParent'); $loader->loadClassMetadata($parent_metadata); $expected_parent = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\EntityParent'); $expected_parent->addPropertyConstraint('other', new NotNull()); $expected_parent->getReflectionClass(); $this->assertEquals($expected_parent, $parent_metadata); } /** * Test MetaData merge with parent annotation. */ 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(array('callback' => 'validateMe', 'payload' => 'foo'))); $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->addPropertyConstraint('childA', new Valid()); $expected->addPropertyConstraint('childB', new Valid()); $expected->addGetterConstraint('lastName', new NotNull()); $expected->addGetterMethodConstraint('valid', 'isValid', new IsTrue()); $expected->addGetterConstraint('permissions', new IsTrue()); // load reflection class so that the comparison passes $expected->getReflectionClass(); $this->assertEquals($expected, $metadata); } public function testLoadGroupSequenceProviderAnnotation() { $loader = new AnnotationLoader(new AnnotationReader()); $metadata = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\GroupSequenceProviderEntity'); $loader->loadClassMetadata($metadata); $expected = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\GroupSequenceProviderEntity'); $expected->setGroupSequenceProvider(true); $expected->getReflectionClass(); $this->assertEquals($expected, $metadata); } } __halt_compiler();----SIGNATURE:----wplnUAaFFAQB/08rsUDpL/ucHpudZCdTxdq9MRVcgmXQPP8xOF9tY2EqzD96pJK9ASG82X5hirk9uL0DqlZKND4iBIcSGer2G+G6ENVN8xfIVg6TsQ1RIDdA7K3fpIbKU+NEtn4NxR0azCVTeJhHmky2UYdDuO35f/UYUAtnvUz4gof/egxsnKA1TZIg2OXX/KYuliCjAUNUTC91xeZsos5V8ImKwlnOuvbquNA4/jUzzw6qHM4dypM0zfyJX+IgBjwWaBm4XCK7fRGkHjY3S8xKvAylFJbnAe8cUdyJZU+SphOKK0VS5rCUjRkdkRiHE1+7zVZhGXyvE+szVDmr5JICgI5o3X1mIQFgrwc+CPNttjKnOdz8unQ/lWMkx1XJgGdnAmsuO4iSwrUr1hmtJ2R99y4DZJUtzFCWWuwuMy2HhDcWdJjuLZ3LCMJJqyLRnG5AaPuE5E/gqxiynCrHHOiZsknQpCYQcvurDXHIAao6aZOydqroo525aave/Xc2F+dI0pOh83wEkzTPczmd6zgZhgUmkNY8lyQJQNkeKd26FLbPoA0hf78YmwlEcGL792QLz2SmC77zq1aMHSKuLNtZaGPFMSyqnRNy86xPvqlY126e2+mVTnWbex/txEPxPdVGcWd9xjs7Xvhl5vizHm7zWa2yZAh9Bfm9rkrjHTo=----ATTACHMENT:----ODc0ODEzNDY4OTU4OTU0MSA4NDE4MzQ0Mjg0OTA4NjM0IDkxMjQ2NDczMzE0OTQyNjY=