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