Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@

use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Serializer\Mapping\ClassMetadata;
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface;
use Symfony\Component\Serializer\Mapping\Factory\CacheClassMetadataFactory;
use Symfony\Component\Serializer\Tests\Fixtures\Dummy;

/**
* @author Kévin Dunglas <dunglas@gmail.com>
Expand All @@ -22,9 +24,9 @@ class CacheMetadataFactoryTest extends \PHPUnit_Framework_TestCase
{
public function testGetMetadataFor()
{
$metadata = new ClassMetadata('Symfony\Component\Serializer\Tests\Fixtures\Dummy');
$metadata = new ClassMetadata(Dummy::class);

$decorated = $this->getMock('Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface');
$decorated = $this->getMock(ClassMetadataFactoryInterface::class);
$decorated
->expects($this->once())
->method('getMetadataFor')
Expand All @@ -33,14 +35,14 @@ public function testGetMetadataFor()

$factory = new CacheClassMetadataFactory($decorated, new ArrayAdapter());

$this->assertEquals($metadata, $factory->getMetadataFor('Symfony\Component\Serializer\Tests\Fixtures\Dummy'));
$this->assertEquals($metadata, $factory->getMetadataFor(Dummy::class));
// The second call should retrieve the value from the cache
$this->assertEquals($metadata, $factory->getMetadataFor('Symfony\Component\Serializer\Tests\Fixtures\Dummy'));
$this->assertEquals($metadata, $factory->getMetadataFor(Dummy::class));
}

public function testHasMetadataFor()
{
$decorated = $this->getMock('Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface');
$decorated = $this->getMock(ClassMetadataFactoryInterface::class);
$decorated
->expects($this->once())
->method('hasMetadataFor')
Expand All @@ -49,15 +51,15 @@ public function testHasMetadataFor()

$factory = new CacheClassMetadataFactory($decorated, new ArrayAdapter());

$this->assertTrue($factory->hasMetadataFor('Symfony\Component\Serializer\Tests\Fixtures\Dummy'));
$this->assertTrue($factory->hasMetadataFor(Dummy::class));
}

/**
* @expectedException \Symfony\Component\Serializer\Exception\InvalidArgumentException
*/
public function testInvalidClassThrowsException()
{
$decorated = $this->getMock('Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface');
$decorated = $this->getMock(ClassMetadataFactoryInterface::class);
$factory = new CacheClassMetadataFactory($decorated, new ArrayAdapter());

$factory->getMetadataFor('Not\Exist');
Expand Down