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\Loader;
14 use Doctrine\Common\Annotations\AnnotationReader;
15 use PHPUnit\Framework\TestCase;
16 use Symfony\Component\Serializer\Mapping\ClassMetadata;
17 use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
18 use Symfony\Component\Serializer\Tests\Mapping\TestClassMetadataFactory;
21 * @author Kévin Dunglas <dunglas@gmail.com>
23 class AnnotationLoaderTest extends TestCase
26 * @var AnnotationLoader
30 protected function setUp()
32 $this->loader = new AnnotationLoader(new AnnotationReader());
35 public function testInterface()
37 $this->assertInstanceOf('Symfony\Component\Serializer\Mapping\Loader\LoaderInterface', $this->loader);
40 public function testLoadClassMetadataReturnsTrueIfSuccessful()
42 $classMetadata = new ClassMetadata('Symfony\Component\Serializer\Tests\Fixtures\GroupDummy');
44 $this->assertTrue($this->loader->loadClassMetadata($classMetadata));
47 public function testLoadGroups()
49 $classMetadata = new ClassMetadata('Symfony\Component\Serializer\Tests\Fixtures\GroupDummy');
50 $this->loader->loadClassMetadata($classMetadata);
52 $this->assertEquals(TestClassMetadataFactory::createClassMetadata(), $classMetadata);
55 public function testLoadMaxDepth()
57 $classMetadata = new ClassMetadata('Symfony\Component\Serializer\Tests\Fixtures\MaxDepthDummy');
58 $this->loader->loadClassMetadata($classMetadata);
60 $attributesMetadata = $classMetadata->getAttributesMetadata();
61 $this->assertEquals(2, $attributesMetadata['foo']->getMaxDepth());
62 $this->assertEquals(3, $attributesMetadata['bar']->getMaxDepth());
65 public function testLoadClassMetadataAndMerge()
67 $classMetadata = new ClassMetadata('Symfony\Component\Serializer\Tests\Fixtures\GroupDummy');
68 $parentClassMetadata = new ClassMetadata('Symfony\Component\Serializer\Tests\Fixtures\GroupDummyParent');
70 $this->loader->loadClassMetadata($parentClassMetadata);
71 $classMetadata->merge($parentClassMetadata);
73 $this->loader->loadClassMetadata($classMetadata);
75 $this->assertEquals(TestClassMetadataFactory::createClassMetadata(true), $classMetadata);