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 testMaxDepth()
46 $attributeMetadata = new AttributeMetadata('name');
47 $attributeMetadata->setMaxDepth(69);
49 $this->assertEquals(69, $attributeMetadata->getMaxDepth());
52 public function testMerge()
54 $attributeMetadata1 = new AttributeMetadata('a1');
55 $attributeMetadata1->addGroup('a');
56 $attributeMetadata1->addGroup('b');
58 $attributeMetadata2 = new AttributeMetadata('a2');
59 $attributeMetadata2->addGroup('a');
60 $attributeMetadata2->addGroup('c');
61 $attributeMetadata2->setMaxDepth(2);
63 $attributeMetadata1->merge($attributeMetadata2);
65 $this->assertEquals(array('a', 'b', 'c'), $attributeMetadata1->getGroups());
66 $this->assertEquals(2, $attributeMetadata1->getMaxDepth());
69 public function testSerialize()
71 $attributeMetadata = new AttributeMetadata('attribute');
72 $attributeMetadata->addGroup('a');
73 $attributeMetadata->addGroup('b');
74 $attributeMetadata->setMaxDepth(3);
76 $serialized = serialize($attributeMetadata);
77 $this->assertEquals($attributeMetadata, unserialize($serialized));