Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / common / tests / Doctrine / Tests / Common / Persistence / Mapping / ClassMetadataFactoryTest.php
1 <?php
2
3 namespace Doctrine\Tests\Common\Persistence\Mapping;
4
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;
11
12 class ClassMetadataFactoryTest extends DoctrineTestCase
13 {
14     /**
15      * @var TestClassMetadataFactory
16      */
17     private $cmf;
18
19     public function setUp()
20     {
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);
24     }
25
26     public function testGetCacheDriver()
27     {
28         $this->assertNull($this->cmf->getCacheDriver());
29         $cache = new ArrayCache();
30         $this->cmf->setCacheDriver($cache);
31         $this->assertSame($cache, $this->cmf->getCacheDriver());
32     }
33
34     public function testGetMetadataFor()
35     {
36         $metadata = $this->cmf->getMetadataFor('stdClass');
37
38         $this->assertInstanceOf('Doctrine\Common\Persistence\Mapping\ClassMetadata', $metadata);
39         $this->assertTrue($this->cmf->hasMetadataFor('stdClass'));
40     }
41
42     public function testGetParentMetadata()
43     {
44         $metadata = $this->cmf->getMetadataFor(__NAMESPACE__ . '\ChildEntity');
45
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'));
49     }
50
51     public function testGetCachedMetadata()
52     {
53         $metadata = $this->getMock('Doctrine\Common\Persistence\Mapping\ClassMetadata');
54         $cache = new ArrayCache();
55         $cache->save(__NAMESPACE__. '\ChildEntity$CLASSMETADATA', $metadata);
56
57         $this->cmf->setCacheDriver($cache);
58
59         $loadedMetadata = $this->cmf->getMetadataFor(__NAMESPACE__ . '\ChildEntity');
60         $this->assertSame($loadedMetadata, $metadata);
61     }
62
63     public function testCacheGetMetadataFor()
64     {
65         $cache = new ArrayCache();
66         $this->cmf->setCacheDriver($cache);
67
68         $loadedMetadata = $this->cmf->getMetadataFor(__NAMESPACE__ . '\ChildEntity');
69
70         $this->assertSame($loadedMetadata, $cache->fetch(__NAMESPACE__. '\ChildEntity$CLASSMETADATA'));
71     }
72
73     public function testGetAliasedMetadata()
74     {
75         $loadedMetadata = $this->cmf->getMetadataFor('prefix:ChildEntity');
76
77         $this->assertTrue($this->cmf->hasMetadataFor(__NAMESPACE__ . '\ChildEntity'));
78         $this->assertTrue($this->cmf->hasMetadataFor('prefix:ChildEntity'));
79     }
80 }
81
82 class TestClassMetadataFactory extends AbstractClassMetadataFactory
83 {
84     public $driver;
85     public $metadata;
86
87     public function __construct($driver, $metadata)
88     {
89         $this->driver = $driver;
90         $this->metadata = $metadata;
91     }
92
93     protected function doLoadMetadata($class, $parent, $rootEntityFound, array $nonSuperclassParents)
94     {
95
96     }
97
98     protected function getFqcnFromAlias($namespaceAlias, $simpleClassName)
99     {
100         return __NAMESPACE__ . '\\' . $simpleClassName;
101     }
102
103     protected function initialize()
104     {
105
106     }
107
108     protected function newClassMetadataInstance($className)
109     {
110         return $this->metadata;
111     }
112
113     protected function getDriver()
114     {
115         return $this->driver;
116     }
117     protected function wakeupReflection(ClassMetadata $class, ReflectionService $reflService)
118     {
119     }
120
121     protected function initializeReflection(ClassMetadata $class, ReflectionService $reflService)
122     {
123     }
124
125     protected function isEntity(ClassMetadata $class)
126     {
127         return true;
128     }
129 }
130
131 class RootEntity
132 {
133
134 }
135
136 class ChildEntity extends RootEntity
137 {
138
139 }