AttributeMetadataTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Serializer\Tests\Mapping;
  11. use Symfony\Component\Serializer\Mapping\AttributeMetadata;
  12. /**
  13. * @author Kévin Dunglas <dunglas@gmail.com>
  14. */
  15. class AttributeMetadataTest extends \PHPUnit_Framework_TestCase
  16. {
  17. public function testInterface()
  18. {
  19. $attributeMetadata = new AttributeMetadata('name');
  20. $this->assertInstanceOf('Symfony\Component\Serializer\Mapping\AttributeMetadataInterface', $attributeMetadata);
  21. }
  22. public function testGetName()
  23. {
  24. $attributeMetadata = new AttributeMetadata('name');
  25. $this->assertEquals('name', $attributeMetadata->getName());
  26. }
  27. public function testGroups()
  28. {
  29. $attributeMetadata = new AttributeMetadata('group');
  30. $attributeMetadata->addGroup('a');
  31. $attributeMetadata->addGroup('a');
  32. $attributeMetadata->addGroup('b');
  33. $this->assertEquals(array('a', 'b'), $attributeMetadata->getGroups());
  34. }
  35. public function testMaxDepth()
  36. {
  37. $attributeMetadata = new AttributeMetadata('name');
  38. $attributeMetadata->setMaxDepth(69);
  39. $this->assertEquals(69, $attributeMetadata->getMaxDepth());
  40. }
  41. public function testMerge()
  42. {
  43. $attributeMetadata1 = new AttributeMetadata('a1');
  44. $attributeMetadata1->addGroup('a');
  45. $attributeMetadata1->addGroup('b');
  46. $attributeMetadata2 = new AttributeMetadata('a2');
  47. $attributeMetadata2->addGroup('a');
  48. $attributeMetadata2->addGroup('c');
  49. $attributeMetadata2->setMaxDepth(2);
  50. $attributeMetadata1->merge($attributeMetadata2);
  51. $this->assertEquals(array('a', 'b', 'c'), $attributeMetadata1->getGroups());
  52. $this->assertEquals(2, $attributeMetadata1->getMaxDepth());
  53. }
  54. public function testSerialize()
  55. {
  56. $attributeMetadata = new AttributeMetadata('attribute');
  57. $attributeMetadata->addGroup('a');
  58. $attributeMetadata->addGroup('b');
  59. $attributeMetadata->setMaxDepth(3);
  60. $serialized = serialize($attributeMetadata);
  61. $this->assertEquals($attributeMetadata, unserialize($serialized));
  62. }
  63. }