cac4367ca79955f66d8b4e770f4746ea57e90c95
[yaffs-website] / vendor / symfony / serializer / Tests / Mapping / Factory / CacheMetadataFactoryTest.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 PHPUnit\Framework\TestCase;
15 use Symfony\Component\Cache\Adapter\ArrayAdapter;
16 use Symfony\Component\Serializer\Mapping\ClassMetadata;
17 use Symfony\Component\Serializer\Mapping\Factory\CacheClassMetadataFactory;
18 use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface;
19 use Symfony\Component\Serializer\Tests\Fixtures\Dummy;
20
21 /**
22  * @author Kévin Dunglas <dunglas@gmail.com>
23  */
24 class CacheMetadataFactoryTest extends TestCase
25 {
26     public function testGetMetadataFor()
27     {
28         $metadata = new ClassMetadata(Dummy::class);
29
30         $decorated = $this->getMockBuilder(ClassMetadataFactoryInterface::class)->getMock();
31         $decorated
32             ->expects($this->once())
33             ->method('getMetadataFor')
34             ->will($this->returnValue($metadata))
35         ;
36
37         $factory = new CacheClassMetadataFactory($decorated, new ArrayAdapter());
38
39         $this->assertEquals($metadata, $factory->getMetadataFor(Dummy::class));
40         // The second call should retrieve the value from the cache
41         $this->assertEquals($metadata, $factory->getMetadataFor(Dummy::class));
42     }
43
44     public function testHasMetadataFor()
45     {
46         $decorated = $this->getMockBuilder(ClassMetadataFactoryInterface::class)->getMock();
47         $decorated
48             ->expects($this->once())
49             ->method('hasMetadataFor')
50             ->will($this->returnValue(true))
51         ;
52
53         $factory = new CacheClassMetadataFactory($decorated, new ArrayAdapter());
54
55         $this->assertTrue($factory->hasMetadataFor(Dummy::class));
56     }
57
58     /**
59      * @expectedException \Symfony\Component\Serializer\Exception\InvalidArgumentException
60      */
61     public function testInvalidClassThrowsException()
62     {
63         $decorated = $this->getMockBuilder(ClassMetadataFactoryInterface::class)->getMock();
64         $factory = new CacheClassMetadataFactory($decorated, new ArrayAdapter());
65
66         $factory->getMetadataFor('Not\Exist');
67     }
68 }