Minor dependency updates
[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     /**
40      * @group legacy
41      */
42     public function testLegacyAddValidSetsMemberToCascaded()
43     {
44         $result = $this->metadata->addConstraint(new Valid());
45
46         $this->assertEquals(array(), $this->metadata->getConstraints());
47         $this->assertEquals($result, $this->metadata);
48         $this->assertTrue($this->metadata->isCascaded());
49     }
50
51     /**
52      * @group legacy
53      */
54     public function testLegacyAddOtherConstraintDoesNotSetMemberToCascaded()
55     {
56         $result = $this->metadata->addConstraint($constraint = new ConstraintA());
57
58         $this->assertEquals(array($constraint), $this->metadata->getConstraints());
59         $this->assertEquals($result, $this->metadata);
60         $this->assertFalse($this->metadata->isCascaded());
61     }
62
63     public function testAddConstraintRequiresClassConstraints()
64     {
65         $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
66
67         $this->metadata->addConstraint(new ClassConstraint());
68     }
69
70     public function testSerialize()
71     {
72         $this->metadata->addConstraint(new ConstraintA(array('property1' => 'A')));
73         $this->metadata->addConstraint(new ConstraintB(array('groups' => 'TestGroup')));
74
75         $metadata = unserialize(serialize($this->metadata));
76
77         $this->assertEquals($this->metadata, $metadata);
78     }
79
80     public function testSerializeCollectionCascaded()
81     {
82         $this->metadata->addConstraint(new Valid(array('traverse' => true)));
83
84         $metadata = unserialize(serialize($this->metadata));
85
86         $this->assertEquals($this->metadata, $metadata);
87     }
88
89     /**
90      * @group legacy
91      */
92     public function testLegacySerializeCollectionCascadedDeeply()
93     {
94         $this->metadata->addConstraint(new Valid(array('traverse' => true)));
95
96         $metadata = unserialize(serialize($this->metadata));
97
98         $this->assertEquals($this->metadata, $metadata);
99     }
100
101     public function testSerializeCollectionNotCascaded()
102     {
103         $this->metadata->addConstraint(new Valid(array('traverse' => false)));
104
105         $metadata = unserialize(serialize($this->metadata));
106
107         $this->assertEquals($this->metadata, $metadata);
108     }
109 }
110
111 class TestMemberMetadata extends MemberMetadata
112 {
113     public function getPropertyValue($object)
114     {
115     }
116
117     protected function newReflectionMember($object)
118     {
119     }
120 }