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\Constraints\Valid;
16 use Symfony\Component\Validator\Mapping\MemberMetadata;
17 use Symfony\Component\Validator\Tests\Fixtures\ClassConstraint;
18 use Symfony\Component\Validator\Tests\Fixtures\ConstraintA;
19 use Symfony\Component\Validator\Tests\Fixtures\ConstraintB;
21 class MemberMetadataTest extends TestCase
25 protected function setUp()
27 $this->metadata = new TestMemberMetadata(
28 'Symfony\Component\Validator\Tests\Fixtures\Entity',
34 protected function tearDown()
36 $this->metadata = null;
39 public function testAddConstraintRequiresClassConstraints()
41 $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
43 $this->metadata->addConstraint(new ClassConstraint());
46 public function testSerialize()
48 $this->metadata->addConstraint(new ConstraintA(array('property1' => 'A')));
49 $this->metadata->addConstraint(new ConstraintB(array('groups' => 'TestGroup')));
51 $metadata = unserialize(serialize($this->metadata));
53 $this->assertEquals($this->metadata, $metadata);
56 public function testSerializeCollectionCascaded()
58 $this->metadata->addConstraint(new Valid(array('traverse' => true)));
60 $metadata = unserialize(serialize($this->metadata));
62 $this->assertEquals($this->metadata, $metadata);
65 public function testSerializeCollectionNotCascaded()
67 $this->metadata->addConstraint(new Valid(array('traverse' => false)));
69 $metadata = unserialize(serialize($this->metadata));
71 $this->assertEquals($this->metadata, $metadata);
75 class TestMemberMetadata extends MemberMetadata
77 public function getPropertyValue($object)
81 protected function newReflectionMember($object)