4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Serializer\Tests\Mapping;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Serializer\Mapping\AttributeMetadata;
18 * @author Kévin Dunglas <dunglas@gmail.com>
20 class AttributeMetadataTest extends TestCase
22 public function testInterface()
24 $attributeMetadata = new AttributeMetadata('name');
25 $this->assertInstanceOf('Symfony\Component\Serializer\Mapping\AttributeMetadataInterface', $attributeMetadata);
28 public function testGetName()
30 $attributeMetadata = new AttributeMetadata('name');
31 $this->assertEquals('name', $attributeMetadata->getName());
34 public function testGroups()
36 $attributeMetadata = new AttributeMetadata('group');
37 $attributeMetadata->addGroup('a');
38 $attributeMetadata->addGroup('a');
39 $attributeMetadata->addGroup('b');
41 $this->assertEquals(array('a', 'b'), $attributeMetadata->getGroups());
44 public function testMerge()
46 $attributeMetadata1 = new AttributeMetadata('a1');
47 $attributeMetadata1->addGroup('a');
48 $attributeMetadata1->addGroup('b');
50 $attributeMetadata2 = new AttributeMetadata('a2');
51 $attributeMetadata2->addGroup('a');
52 $attributeMetadata2->addGroup('c');
54 $attributeMetadata1->merge($attributeMetadata2);
56 $this->assertEquals(array('a', 'b', 'c'), $attributeMetadata1->getGroups());
59 public function testSerialize()
61 $attributeMetadata = new AttributeMetadata('attribute');
62 $attributeMetadata->addGroup('a');
63 $attributeMetadata->addGroup('b');
65 $serialized = serialize($attributeMetadata);
66 $this->assertEquals($attributeMetadata, unserialize($serialized));