AnnotationLoaderTest.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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\Loader;
  11. use Doctrine\Common\Annotations\AnnotationReader;
  12. use Symfony\Component\Serializer\Mapping\ClassMetadata;
  13. use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
  14. use Symfony\Component\Serializer\Tests\Mapping\TestClassMetadataFactory;
  15. /**
  16. * @author Kévin Dunglas <dunglas@gmail.com>
  17. */
  18. class AnnotationLoaderTest extends \PHPUnit_Framework_TestCase
  19. {
  20. /**
  21. * @var AnnotationLoader
  22. */
  23. private $loader;
  24. protected function setUp()
  25. {
  26. $this->loader = new AnnotationLoader(new AnnotationReader());
  27. }
  28. public function testInterface()
  29. {
  30. $this->assertInstanceOf('Symfony\Component\Serializer\Mapping\Loader\LoaderInterface', $this->loader);
  31. }
  32. public function testLoadClassMetadataReturnsTrueIfSuccessful()
  33. {
  34. $classMetadata = new ClassMetadata('Symfony\Component\Serializer\Tests\Fixtures\GroupDummy');
  35. $this->assertTrue($this->loader->loadClassMetadata($classMetadata));
  36. }
  37. public function testLoadGroups()
  38. {
  39. $classMetadata = new ClassMetadata('Symfony\Component\Serializer\Tests\Fixtures\GroupDummy');
  40. $this->loader->loadClassMetadata($classMetadata);
  41. $this->assertEquals(TestClassMetadataFactory::createClassMetadata(), $classMetadata);
  42. }
  43. public function testLoadMaxDepth()
  44. {
  45. $classMetadata = new ClassMetadata('Symfony\Component\Serializer\Tests\Fixtures\MaxDepthDummy');
  46. $this->loader->loadClassMetadata($classMetadata);
  47. $attributesMetadata = $classMetadata->getAttributesMetadata();
  48. $this->assertEquals(2, $attributesMetadata['foo']->getMaxDepth());
  49. $this->assertEquals(3, $attributesMetadata['bar']->getMaxDepth());
  50. }
  51. public function testLoadClassMetadataAndMerge()
  52. {
  53. $classMetadata = new ClassMetadata('Symfony\Component\Serializer\Tests\Fixtures\GroupDummy');
  54. $parentClassMetadata = new ClassMetadata('Symfony\Component\Serializer\Tests\Fixtures\GroupDummyParent');
  55. $this->loader->loadClassMetadata($parentClassMetadata);
  56. $classMetadata->merge($parentClassMetadata);
  57. $this->loader->loadClassMetadata($classMetadata);
  58. $this->assertEquals(TestClassMetadataFactory::createClassMetadata(true), $classMetadata);
  59. }
  60. }