f08062369c70441f10ff3181fb2c73fdde17596e
[yaffs-website] / vendor / symfony / serializer / Tests / Mapping / AttributeMetadataTest.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\Serializer\Tests\Mapping;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Serializer\Mapping\AttributeMetadata;
16
17 /**
18  * @author Kévin Dunglas <dunglas@gmail.com>
19  */
20 class AttributeMetadataTest extends TestCase
21 {
22     public function testInterface()
23     {
24         $attributeMetadata = new AttributeMetadata('name');
25         $this->assertInstanceOf('Symfony\Component\Serializer\Mapping\AttributeMetadataInterface', $attributeMetadata);
26     }
27
28     public function testGetName()
29     {
30         $attributeMetadata = new AttributeMetadata('name');
31         $this->assertEquals('name', $attributeMetadata->getName());
32     }
33
34     public function testGroups()
35     {
36         $attributeMetadata = new AttributeMetadata('group');
37         $attributeMetadata->addGroup('a');
38         $attributeMetadata->addGroup('a');
39         $attributeMetadata->addGroup('b');
40
41         $this->assertEquals(array('a', 'b'), $attributeMetadata->getGroups());
42     }
43
44     public function testMerge()
45     {
46         $attributeMetadata1 = new AttributeMetadata('a1');
47         $attributeMetadata1->addGroup('a');
48         $attributeMetadata1->addGroup('b');
49
50         $attributeMetadata2 = new AttributeMetadata('a2');
51         $attributeMetadata2->addGroup('a');
52         $attributeMetadata2->addGroup('c');
53
54         $attributeMetadata1->merge($attributeMetadata2);
55
56         $this->assertEquals(array('a', 'b', 'c'), $attributeMetadata1->getGroups());
57     }
58
59     public function testSerialize()
60     {
61         $attributeMetadata = new AttributeMetadata('attribute');
62         $attributeMetadata->addGroup('a');
63         $attributeMetadata->addGroup('b');
64
65         $serialized = serialize($attributeMetadata);
66         $this->assertEquals($attributeMetadata, unserialize($serialized));
67     }
68 }