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\Factory;
14 use Doctrine\Common\Annotations\AnnotationReader;
15 use PHPUnit\Framework\TestCase;
16 use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
17 use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
18 use Symfony\Component\Serializer\Mapping\Loader\LoaderChain;
19 use Symfony\Component\Serializer\Tests\Mapping\TestClassMetadataFactory;
22 * @author Kévin Dunglas <dunglas@gmail.com>
24 class ClassMetadataFactoryTest extends TestCase
26 public function testInterface()
28 $classMetadata = new ClassMetadataFactory(new LoaderChain(array()));
29 $this->assertInstanceOf('Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory', $classMetadata);
32 public function testGetMetadataFor()
34 $factory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
35 $classMetadata = $factory->getMetadataFor('Symfony\Component\Serializer\Tests\Fixtures\GroupDummy');
37 $this->assertEquals(TestClassMetadataFactory::createClassMetadata(true, true), $classMetadata);
40 public function testHasMetadataFor()
42 $factory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
43 $this->assertTrue($factory->hasMetadataFor('Symfony\Component\Serializer\Tests\Fixtures\GroupDummy'));
44 $this->assertTrue($factory->hasMetadataFor('Symfony\Component\Serializer\Tests\Fixtures\GroupDummyParent'));
45 $this->assertTrue($factory->hasMetadataFor('Symfony\Component\Serializer\Tests\Fixtures\GroupDummyInterface'));
46 $this->assertFalse($factory->hasMetadataFor('Dunglas\Entity'));
49 public function testCacheExists()
51 $cache = $this->getMockBuilder('Doctrine\Common\Cache\Cache')->getMock();
53 ->expects($this->once())
55 ->will($this->returnValue('foo'))
58 $factory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()), $cache);
59 $this->assertEquals('foo', $factory->getMetadataFor('Symfony\Component\Serializer\Tests\Fixtures\GroupDummy'));
62 public function testCacheNotExists()
64 $cache = $this->getMockBuilder('Doctrine\Common\Cache\Cache')->getMock();
67 ->will($this->returnValue(false))
74 $factory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()), $cache);
75 $metadata = $factory->getMetadataFor('Symfony\Component\Serializer\Tests\Fixtures\GroupDummy');
77 $this->assertEquals(TestClassMetadataFactory::createClassMetadata(true, true), $metadata);