a95b7b17745088aa87085360f8f773b6c487e4d2
[yaffs-website] / vendor / symfony / serializer / Tests / Mapping / Factory / ClassMetadataFactoryTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\Serializer\Tests\Mapping\Factory;
13
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;
20
21 /**
22  * @author Kévin Dunglas <dunglas@gmail.com>
23  */
24 class ClassMetadataFactoryTest extends TestCase
25 {
26     public function testInterface()
27     {
28         $classMetadata = new ClassMetadataFactory(new LoaderChain(array()));
29         $this->assertInstanceOf('Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory', $classMetadata);
30     }
31
32     public function testGetMetadataFor()
33     {
34         $factory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
35         $classMetadata = $factory->getMetadataFor('Symfony\Component\Serializer\Tests\Fixtures\GroupDummy');
36
37         $this->assertEquals(TestClassMetadataFactory::createClassMetadata(true, true), $classMetadata);
38     }
39
40     public function testHasMetadataFor()
41     {
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'));
47     }
48
49     public function testCacheExists()
50     {
51         $cache = $this->getMockBuilder('Doctrine\Common\Cache\Cache')->getMock();
52         $cache
53             ->expects($this->once())
54             ->method('fetch')
55             ->will($this->returnValue('foo'))
56         ;
57
58         $factory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()), $cache);
59         $this->assertEquals('foo', $factory->getMetadataFor('Symfony\Component\Serializer\Tests\Fixtures\GroupDummy'));
60     }
61
62     public function testCacheNotExists()
63     {
64         $cache = $this->getMockBuilder('Doctrine\Common\Cache\Cache')->getMock();
65         $cache
66             ->method('fetch')
67             ->will($this->returnValue(false))
68         ;
69
70         $cache
71             ->method('save')
72         ;
73
74         $factory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()), $cache);
75         $metadata = $factory->getMetadataFor('Symfony\Component\Serializer\Tests\Fixtures\GroupDummy');
76
77         $this->assertEquals(TestClassMetadataFactory::createClassMetadata(true, true), $metadata);
78     }
79 }