Updated to Drupal 8.5. Core Media not yet in use.
[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\ClassMetadataFactoryInterface', $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     /**
50      * @group legacy
51      */
52     public function testCacheExists()
53     {
54         $cache = $this->getMockBuilder('Doctrine\Common\Cache\Cache')->getMock();
55         $cache
56             ->expects($this->once())
57             ->method('fetch')
58             ->will($this->returnValue('foo'))
59         ;
60
61         $factory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()), $cache);
62         $this->assertEquals('foo', $factory->getMetadataFor('Symfony\Component\Serializer\Tests\Fixtures\GroupDummy'));
63     }
64
65     /**
66      * @group legacy
67      */
68     public function testCacheNotExists()
69     {
70         $cache = $this->getMockBuilder('Doctrine\Common\Cache\Cache')->getMock();
71         $cache->method('fetch')->will($this->returnValue(false));
72         $cache->method('save');
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 }