Файл: symfony-2.7/src/Symfony/Component/Serializer/Tests/Mapping/Factory/ClassMetadataFactoryTest.php
Строк: 120
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SymfonyComponentSerializerTestsMappingFactory;
use DoctrineCommonAnnotationsAnnotationReader;
use SymfonyComponentSerializerMappingFactoryClassMetadataFactory;
use SymfonyComponentSerializerMappingLoaderAnnotationLoader;
use SymfonyComponentSerializerTestsMappingTestClassMetadataFactory;
require_once __DIR__.'/../../../Annotation/Groups.php';
/**
* @author Kévin Dunglas <dunglas@gmail.com>
*/
class ClassMetadataFactoryTest extends PHPUnit_Framework_TestCase
{
public function testGetMetadataFor()
{
$factory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
$metadata = $factory->getMetadataFor('SymfonyComponentSerializerTestsFixturesGroupDummy');
$this->assertEquals(TestClassMetadataFactory::createClassMetadata(true, true), $metadata);
}
public function testHasMetadataFor()
{
$factory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
$this->assertTrue($factory->hasMetadataFor('SymfonyComponentSerializerTestsFixturesGroupDummy'));
$this->assertTrue($factory->hasMetadataFor('SymfonyComponentSerializerTestsFixturesGroupDummyParent'));
$this->assertTrue($factory->hasMetadataFor('SymfonyComponentSerializerTestsFixturesGroupDummyInterface'));
$this->assertFalse($factory->hasMetadataFor('DunglasEntity'));
}
public function testCacheExists()
{
$cache = $this->getMock('DoctrineCommonCacheCache');
$cache
->expects($this->once())
->method('fetch')
->will($this->returnValue('foo'))
;
$factory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()), $cache);
$this->assertEquals('foo', $factory->getMetadataFor('SymfonyComponentSerializerTestsFixturesGroupDummy'));
}
public function testCacheNotExists()
{
$cache = $this->getMock('DoctrineCommonCacheCache');
$cache
->method('fetch')
->will($this->returnValue(false))
;
$cache
->method('save')
;
$factory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()), $cache);
$metadata = $factory->getMetadataFor('SymfonyComponentSerializerTestsFixturesGroupDummy');
$this->assertEquals(TestClassMetadataFactory::createClassMetadata(true, true), $metadata);
}
}