Fix bug in style changes for the Use cases on the live site.
[yaffs-website] / vendor / symfony / serializer / Tests / Mapping / ClassMetadataTest.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\ClassMetadata;
16
17 /**
18  * @author Kévin Dunglas <dunglas@gmail.com>
19  */
20 class ClassMetadataTest extends TestCase
21 {
22     public function testInterface()
23     {
24         $classMetadata = new ClassMetadata('name');
25         $this->assertInstanceOf('Symfony\Component\Serializer\Mapping\ClassMetadataInterface', $classMetadata);
26     }
27
28     public function testAttributeMetadata()
29     {
30         $classMetadata = new ClassMetadata('c');
31
32         $a1 = $this->getMockBuilder('Symfony\Component\Serializer\Mapping\AttributeMetadataInterface')->getMock();
33         $a1->method('getName')->willReturn('a1');
34
35         $a2 = $this->getMockBuilder('Symfony\Component\Serializer\Mapping\AttributeMetadataInterface')->getMock();
36         $a2->method('getName')->willReturn('a2');
37
38         $classMetadata->addAttributeMetadata($a1);
39         $classMetadata->addAttributeMetadata($a2);
40
41         $this->assertEquals(array('a1' => $a1, 'a2' => $a2), $classMetadata->getAttributesMetadata());
42     }
43
44     public function testMerge()
45     {
46         $classMetadata1 = new ClassMetadata('c1');
47         $classMetadata2 = new ClassMetadata('c2');
48
49         $ac1 = $this->getMockBuilder('Symfony\Component\Serializer\Mapping\AttributeMetadataInterface')->getMock();
50         $ac1->method('getName')->willReturn('a1');
51         $ac1->method('getGroups')->willReturn(array('a', 'b'));
52
53         $ac2 = $this->getMockBuilder('Symfony\Component\Serializer\Mapping\AttributeMetadataInterface')->getMock();
54         $ac2->method('getName')->willReturn('a1');
55         $ac2->method('getGroups')->willReturn(array('b', 'c'));
56
57         $classMetadata1->addAttributeMetadata($ac1);
58         $classMetadata2->addAttributeMetadata($ac2);
59
60         $classMetadata1->merge($classMetadata2);
61
62         $ac1->method('getGroups')->willReturn('a', 'b', 'c');
63
64         $this->assertEquals(array('a1' => $ac1), $classMetadata2->getAttributesMetadata());
65     }
66
67     public function testSerialize()
68     {
69         $classMetadata = new ClassMetadata('a');
70
71         $a1 = $this->getMockBuilder('Symfony\Component\Serializer\Mapping\AttributeMetadataInterface')->getMock();
72         $a1->method('getName')->willReturn('b1');
73
74         $a2 = $this->getMockBuilder('Symfony\Component\Serializer\Mapping\AttributeMetadataInterface')->getMock();
75         $a2->method('getName')->willReturn('b2');
76
77         $classMetadata->addAttributeMetadata($a1);
78         $classMetadata->addAttributeMetadata($a2);
79
80         $serialized = serialize($classMetadata);
81         $this->assertEquals($classMetadata, unserialize($serialized));
82     }
83 }