4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Validator\Tests\Mapping;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Validator\Mapping\ElementMetadata;
16 use Symfony\Component\Validator\Tests\Fixtures\ConstraintA;
17 use Symfony\Component\Validator\Tests\Fixtures\ConstraintB;
22 class LegacyElementMetadataTest extends TestCase
26 protected function setUp()
28 $this->metadata = new TestElementMetadata();
31 protected function tearDown()
33 $this->metadata = null;
36 public function testAddConstraints()
38 $this->metadata->addConstraint($constraint1 = new ConstraintA());
39 $this->metadata->addConstraint($constraint2 = new ConstraintA());
41 $this->assertEquals(array($constraint1, $constraint2), $this->metadata->getConstraints());
44 public function testMultipleConstraintsOfTheSameType()
46 $constraint1 = new ConstraintA(array('property1' => 'A'));
47 $constraint2 = new ConstraintA(array('property1' => 'B'));
49 $this->metadata->addConstraint($constraint1);
50 $this->metadata->addConstraint($constraint2);
52 $this->assertEquals(array($constraint1, $constraint2), $this->metadata->getConstraints());
55 public function testFindConstraintsByGroup()
57 $constraint1 = new ConstraintA(array('groups' => 'TestGroup'));
58 $constraint2 = new ConstraintB();
60 $this->metadata->addConstraint($constraint1);
61 $this->metadata->addConstraint($constraint2);
63 $this->assertEquals(array($constraint1), $this->metadata->findConstraints('TestGroup'));
66 public function testSerialize()
68 $this->metadata->addConstraint(new ConstraintA(array('property1' => 'A')));
69 $this->metadata->addConstraint(new ConstraintB(array('groups' => 'TestGroup')));
71 $metadata = unserialize(serialize($this->metadata));
73 $this->assertEquals($this->metadata, $metadata);
77 class TestElementMetadata extends ElementMetadata