Yaffs site version 1.1
[yaffs-website] / vendor / symfony / validator / Tests / Mapping / LegacyElementMetadataTest.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\Mapping\ElementMetadata;
16 use Symfony\Component\Validator\Tests\Fixtures\ConstraintA;
17 use Symfony\Component\Validator\Tests\Fixtures\ConstraintB;
18
19 /**
20  * @group legacy
21  */
22 class LegacyElementMetadataTest extends TestCase
23 {
24     protected $metadata;
25
26     protected function setUp()
27     {
28         $this->metadata = new TestElementMetadata();
29     }
30
31     protected function tearDown()
32     {
33         $this->metadata = null;
34     }
35
36     public function testAddConstraints()
37     {
38         $this->metadata->addConstraint($constraint1 = new ConstraintA());
39         $this->metadata->addConstraint($constraint2 = new ConstraintA());
40
41         $this->assertEquals(array($constraint1, $constraint2), $this->metadata->getConstraints());
42     }
43
44     public function testMultipleConstraintsOfTheSameType()
45     {
46         $constraint1 = new ConstraintA(array('property1' => 'A'));
47         $constraint2 = new ConstraintA(array('property1' => 'B'));
48
49         $this->metadata->addConstraint($constraint1);
50         $this->metadata->addConstraint($constraint2);
51
52         $this->assertEquals(array($constraint1, $constraint2), $this->metadata->getConstraints());
53     }
54
55     public function testFindConstraintsByGroup()
56     {
57         $constraint1 = new ConstraintA(array('groups' => 'TestGroup'));
58         $constraint2 = new ConstraintB();
59
60         $this->metadata->addConstraint($constraint1);
61         $this->metadata->addConstraint($constraint2);
62
63         $this->assertEquals(array($constraint1), $this->metadata->findConstraints('TestGroup'));
64     }
65
66     public function testSerialize()
67     {
68         $this->metadata->addConstraint(new ConstraintA(array('property1' => 'A')));
69         $this->metadata->addConstraint(new ConstraintB(array('groups' => 'TestGroup')));
70
71         $metadata = unserialize(serialize($this->metadata));
72
73         $this->assertEquals($this->metadata, $metadata);
74     }
75 }
76
77 class TestElementMetadata extends ElementMetadata
78 {
79 }