3 namespace Doctrine\Tests\Common\Persistence\Mapping;
5 use Doctrine\Tests\DoctrineTestCase;
6 use Doctrine\Common\Persistence\Mapping\Driver\DefaultFileLocator;
7 use Doctrine\Common\Persistence\Mapping\ReflectionService;
8 use Doctrine\Common\Persistence\Mapping\ClassMetadata;
9 use Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory;
10 use Doctrine\Common\Cache\ArrayCache;
12 class ClassMetadataFactoryTest extends DoctrineTestCase
15 * @var TestClassMetadataFactory
19 public function setUp()
21 $driver = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver');
22 $metadata = $this->getMock('Doctrine\Common\Persistence\Mapping\ClassMetadata');
23 $this->cmf = new TestClassMetadataFactory($driver, $metadata);
26 public function testGetCacheDriver()
28 $this->assertNull($this->cmf->getCacheDriver());
29 $cache = new ArrayCache();
30 $this->cmf->setCacheDriver($cache);
31 $this->assertSame($cache, $this->cmf->getCacheDriver());
34 public function testGetMetadataFor()
36 $metadata = $this->cmf->getMetadataFor('stdClass');
38 $this->assertInstanceOf('Doctrine\Common\Persistence\Mapping\ClassMetadata', $metadata);
39 $this->assertTrue($this->cmf->hasMetadataFor('stdClass'));
42 public function testGetParentMetadata()
44 $metadata = $this->cmf->getMetadataFor(__NAMESPACE__ . '\ChildEntity');
46 $this->assertInstanceOf('Doctrine\Common\Persistence\Mapping\ClassMetadata', $metadata);
47 $this->assertTrue($this->cmf->hasMetadataFor(__NAMESPACE__ . '\ChildEntity'));
48 $this->assertTrue($this->cmf->hasMetadataFor(__NAMESPACE__ . '\RootEntity'));
51 public function testGetCachedMetadata()
53 $metadata = $this->getMock('Doctrine\Common\Persistence\Mapping\ClassMetadata');
54 $cache = new ArrayCache();
55 $cache->save(__NAMESPACE__. '\ChildEntity$CLASSMETADATA', $metadata);
57 $this->cmf->setCacheDriver($cache);
59 $loadedMetadata = $this->cmf->getMetadataFor(__NAMESPACE__ . '\ChildEntity');
60 $this->assertSame($loadedMetadata, $metadata);
63 public function testCacheGetMetadataFor()
65 $cache = new ArrayCache();
66 $this->cmf->setCacheDriver($cache);
68 $loadedMetadata = $this->cmf->getMetadataFor(__NAMESPACE__ . '\ChildEntity');
70 $this->assertSame($loadedMetadata, $cache->fetch(__NAMESPACE__. '\ChildEntity$CLASSMETADATA'));
73 public function testGetAliasedMetadata()
75 $loadedMetadata = $this->cmf->getMetadataFor('prefix:ChildEntity');
77 $this->assertTrue($this->cmf->hasMetadataFor(__NAMESPACE__ . '\ChildEntity'));
78 $this->assertTrue($this->cmf->hasMetadataFor('prefix:ChildEntity'));
82 class TestClassMetadataFactory extends AbstractClassMetadataFactory
87 public function __construct($driver, $metadata)
89 $this->driver = $driver;
90 $this->metadata = $metadata;
93 protected function doLoadMetadata($class, $parent, $rootEntityFound, array $nonSuperclassParents)
98 protected function getFqcnFromAlias($namespaceAlias, $simpleClassName)
100 return __NAMESPACE__ . '\\' . $simpleClassName;
103 protected function initialize()
108 protected function newClassMetadataInstance($className)
110 return $this->metadata;
113 protected function getDriver()
115 return $this->driver;
117 protected function wakeupReflection(ClassMetadata $class, ReflectionService $reflService)
121 protected function initializeReflection(ClassMetadata $class, ReflectionService $reflService)
125 protected function isEntity(ClassMetadata $class)
136 class ChildEntity extends RootEntity