593f90faa66b60a4db2b8ba5c2d07088c3999575
[yaffs-website] / vendor / symfony / validator / Tests / Mapping / MemberMetadataTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\Validator\Tests\Mapping;
13
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;
20
21 class MemberMetadataTest extends TestCase
22 {
23     protected $metadata;
24
25     protected function setUp()
26     {
27         $this->metadata = new TestMemberMetadata(
28             'Symfony\Component\Validator\Tests\Fixtures\Entity',
29             'getLastName',
30             'lastName'
31         );
32     }
33
34     protected function tearDown()
35     {
36         $this->metadata = null;
37     }
38
39     public function testAddConstraintRequiresClassConstraints()
40     {
41         $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
42
43         $this->metadata->addConstraint(new ClassConstraint());
44     }
45
46     public function testSerialize()
47     {
48         $this->metadata->addConstraint(new ConstraintA(array('property1' => 'A')));
49         $this->metadata->addConstraint(new ConstraintB(array('groups' => 'TestGroup')));
50
51         $metadata = unserialize(serialize($this->metadata));
52
53         $this->assertEquals($this->metadata, $metadata);
54     }
55
56     public function testSerializeCollectionCascaded()
57     {
58         $this->metadata->addConstraint(new Valid(array('traverse' => true)));
59
60         $metadata = unserialize(serialize($this->metadata));
61
62         $this->assertEquals($this->metadata, $metadata);
63     }
64
65     public function testSerializeCollectionNotCascaded()
66     {
67         $this->metadata->addConstraint(new Valid(array('traverse' => false)));
68
69         $metadata = unserialize(serialize($this->metadata));
70
71         $this->assertEquals($this->metadata, $metadata);
72     }
73 }
74
75 class TestMemberMetadata extends MemberMetadata
76 {
77     public function getPropertyValue($object)
78     {
79     }
80
81     protected function newReflectionMember($object)
82     {
83     }
84 }