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 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;
22 * @author Kévin Dunglas <dunglas@gmail.com>
24 class CacheMetadataFactoryTest extends TestCase
26 public function testGetMetadataFor()
28 $metadata = new ClassMetadata(Dummy::class);
30 $decorated = $this->getMockBuilder(ClassMetadataFactoryInterface::class)->getMock();
32 ->expects($this->once())
33 ->method('getMetadataFor')
34 ->will($this->returnValue($metadata))
37 $factory = new CacheClassMetadataFactory($decorated, new ArrayAdapter());
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));
44 public function testHasMetadataFor()
46 $decorated = $this->getMockBuilder(ClassMetadataFactoryInterface::class)->getMock();
48 ->expects($this->once())
49 ->method('hasMetadataFor')
50 ->will($this->returnValue(true))
53 $factory = new CacheClassMetadataFactory($decorated, new ArrayAdapter());
55 $this->assertTrue($factory->hasMetadataFor(Dummy::class));
59 * @expectedException \Symfony\Component\Serializer\Exception\InvalidArgumentException
61 public function testInvalidClassThrowsException()
63 $decorated = $this->getMockBuilder(ClassMetadataFactoryInterface::class)->getMock();
64 $factory = new CacheClassMetadataFactory($decorated, new ArrayAdapter());
66 $factory->getMetadataFor('Not\Exist');