TestClassMetadataFactory.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. use Symfony\Component\Serializer\Mapping\ClassMetadata;
  13. /**
  14. * @author Kévin Dunglas <dunglas@gmail.com>
  15. */
  16. class TestClassMetadataFactory
  17. {
  18. public static function createClassMetadata($withParent = false, $withInterface = false)
  19. {
  20. $expected = new ClassMetadata('Symfony\Component\Serializer\Tests\Fixtures\GroupDummy');
  21. $foo = new AttributeMetadata('foo');
  22. $foo->addGroup('a');
  23. $expected->addAttributeMetadata($foo);
  24. $bar = new AttributeMetadata('bar');
  25. $bar->addGroup('b');
  26. $bar->addGroup('c');
  27. $bar->addGroup('name_converter');
  28. $expected->addAttributeMetadata($bar);
  29. $fooBar = new AttributeMetadata('fooBar');
  30. $fooBar->addGroup('a');
  31. $fooBar->addGroup('b');
  32. $fooBar->addGroup('name_converter');
  33. $expected->addAttributeMetadata($fooBar);
  34. $symfony = new AttributeMetadata('symfony');
  35. $expected->addAttributeMetadata($symfony);
  36. if ($withParent) {
  37. $kevin = new AttributeMetadata('kevin');
  38. $kevin->addGroup('a');
  39. $expected->addAttributeMetadata($kevin);
  40. $coopTilleuls = new AttributeMetadata('coopTilleuls');
  41. $coopTilleuls->addGroup('a');
  42. $coopTilleuls->addGroup('b');
  43. $expected->addAttributeMetadata($coopTilleuls);
  44. }
  45. if ($withInterface) {
  46. $symfony->addGroup('a');
  47. $symfony->addGroup('name_converter');
  48. }
  49. // load reflection class so that the comparison passes
  50. $expected->getReflectionClass();
  51. return $expected;
  52. }
  53. public static function createXmlCLassMetadata()
  54. {
  55. $expected = new ClassMetadata('Symfony\Component\Serializer\Tests\Fixtures\GroupDummy');
  56. $foo = new AttributeMetadata('foo');
  57. $foo->addGroup('group1');
  58. $foo->addGroup('group2');
  59. $expected->addAttributeMetadata($foo);
  60. $bar = new AttributeMetadata('bar');
  61. $bar->addGroup('group2');
  62. $expected->addAttributeMetadata($bar);
  63. return $expected;
  64. }
  65. }