1 | <?php |
||
27 | class ConfigurationFactoryTest extends PHPUnit_Framework_TestCase |
||
28 | { |
||
29 | /** |
||
30 | * @var ServiceManager |
||
31 | */ |
||
32 | protected $serviceManager; |
||
33 | /** |
||
34 | * @var ConfigurationFactory |
||
35 | */ |
||
36 | protected $factory; |
||
37 | |||
38 | /** |
||
39 | * {@inheritDoc} |
||
40 | */ |
||
41 | public function setUp() |
||
42 | { |
||
43 | $this->serviceManager = new ServiceManager(); |
||
44 | $this->factory = new ConfigurationFactory('test_default'); |
||
45 | $this->serviceManager->setService('doctrine.cache.array', new ArrayCache()); |
||
46 | $this->serviceManager->setService( |
||
47 | 'doctrine.driver.orm_default', |
||
48 | $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver') |
||
49 | ); |
||
50 | } |
||
51 | |||
52 | public function testWillInstantiateConfigWithoutNamingStrategySetting() |
||
53 | { |
||
54 | $config = array( |
||
55 | 'doctrine' => array( |
||
56 | 'configuration' => array( |
||
57 | 'test_default' => array(), |
||
58 | ), |
||
59 | ), |
||
60 | ); |
||
61 | $this->serviceManager->setService('Config', $config); |
||
62 | $ormConfig = $this->factory->createService($this->serviceManager); |
||
63 | $this->assertInstanceOf('Doctrine\ORM\Mapping\NamingStrategy', $ormConfig->getNamingStrategy()); |
||
64 | } |
||
65 | |||
66 | public function testWillInstantiateConfigWithNamingStrategyObject() |
||
67 | { |
||
68 | $namingStrategy = $this->getMock('Doctrine\ORM\Mapping\NamingStrategy'); |
||
69 | |||
70 | $config = array( |
||
71 | 'doctrine' => array( |
||
72 | 'configuration' => array( |
||
73 | 'test_default' => array( |
||
74 | 'naming_strategy' => $namingStrategy, |
||
75 | ), |
||
76 | ), |
||
77 | ), |
||
78 | ); |
||
79 | $this->serviceManager->setService('Config', $config); |
||
80 | $factory = new ConfigurationFactory('test_default'); |
||
81 | $ormConfig = $factory->createService($this->serviceManager); |
||
82 | $this->assertSame($namingStrategy, $ormConfig->getNamingStrategy()); |
||
83 | } |
||
84 | |||
85 | public function testWillInstantiateConfigWithNamingStrategyReference() |
||
86 | { |
||
87 | $namingStrategy = $this->getMock('Doctrine\ORM\Mapping\NamingStrategy'); |
||
88 | $config = array( |
||
89 | 'doctrine' => array( |
||
90 | 'configuration' => array( |
||
91 | 'test_default' => array( |
||
92 | 'naming_strategy' => 'test_naming_strategy', |
||
93 | ), |
||
94 | ), |
||
95 | ), |
||
96 | ); |
||
97 | $this->serviceManager->setService('Config', $config); |
||
98 | $this->serviceManager->setService('test_naming_strategy', $namingStrategy); |
||
99 | $ormConfig = $this->factory->createService($this->serviceManager); |
||
100 | $this->assertSame($namingStrategy, $ormConfig->getNamingStrategy()); |
||
101 | } |
||
102 | |||
103 | public function testWillNotInstantiateConfigWithInvalidNamingStrategyReference() |
||
104 | { |
||
105 | $config = array( |
||
106 | 'doctrine' => array( |
||
107 | 'configuration' => array( |
||
108 | 'test_default' => array( |
||
109 | 'naming_strategy' => 'test_naming_strategy', |
||
110 | ), |
||
111 | ), |
||
112 | ), |
||
113 | ); |
||
114 | $this->serviceManager->setService('Config', $config); |
||
115 | $this->setExpectedException('Zend\ServiceManager\Exception\InvalidArgumentException'); |
||
116 | $this->factory->createService($this->serviceManager); |
||
117 | } |
||
118 | |||
119 | public function testWillInstantiateConfigWithQuoteStrategyObject() |
||
137 | |||
138 | public function testWillInstantiateConfigWithQuoteStrategyReference() |
||
155 | |||
156 | public function testWillNotInstantiateConfigWithInvalidQuoteStrategyReference() |
||
171 | |||
172 | public function testWillInstantiateConfigWithHydrationCacheSetting() |
||
188 | |||
189 | public function testCanSetDefaultRepositoryClass() |
||
210 | |||
211 | public function testAcceptsMetadataFactory() |
||
212 | { |
||
213 | $config = array( |
||
214 | 'doctrine' => array( |
||
215 | 'configuration' => array( |
||
216 | 'test_default' => array( |
||
217 | 'classMetadataFactoryName' => 'Factory' |
||
218 | ), |
||
219 | ), |
||
220 | ), |
||
221 | ); |
||
222 | $this->serviceManager->setService('Config', $config); |
||
223 | $factory = new ConfigurationFactory('test_default'); |
||
224 | $ormConfig = $factory->createService($this->serviceManager); |
||
225 | $this->assertEquals('Factory', $ormConfig->getClassMetadataFactoryName()); |
||
226 | } |
||
227 | |||
228 | public function testDefaultMetadatFactory() |
||
229 | { |
||
230 | $config = array( |
||
231 | 'doctrine' => array( |
||
232 | 'configuration' => array( |
||
233 | 'test_default' => array( |
||
234 | ), |
||
235 | ), |
||
236 | ), |
||
237 | ); |
||
238 | $this->serviceManager->setService('Config', $config); |
||
239 | $factory = new ConfigurationFactory('test_default'); |
||
240 | $ormConfig = $factory->createService($this->serviceManager); |
||
241 | $this->assertEquals('Doctrine\ORM\Mapping\ClassMetadataFactory', $ormConfig->getClassMetadataFactoryName()); |
||
242 | } |
||
243 | |||
244 | public function testWillInstantiateConfigWithoutEntityListenerResolverSetting() |
||
245 | { |
||
246 | $config = array( |
||
247 | 'doctrine' => array( |
||
248 | 'configuration' => array( |
||
249 | 'test_default' => array(), |
||
250 | ), |
||
251 | ), |
||
252 | ); |
||
253 | |||
254 | $this->serviceManager->setService('Config', $config); |
||
255 | |||
256 | $ormConfig = $this->factory->createService($this->serviceManager); |
||
257 | |||
258 | $this->assertInstanceOf('Doctrine\ORM\Mapping\EntityListenerResolver', $ormConfig->getEntityListenerResolver()); |
||
259 | } |
||
260 | |||
261 | public function testWillInstantiateConfigWithEntityListenerResolverObject() |
||
262 | { |
||
263 | $entityListenerResolver = $this->getMock('Doctrine\ORM\Mapping\EntityListenerResolver'); |
||
264 | |||
265 | $config = array( |
||
266 | 'doctrine' => array( |
||
267 | 'configuration' => array( |
||
268 | 'test_default' => array( |
||
269 | 'entity_listener_resolver' => $entityListenerResolver, |
||
270 | ), |
||
271 | ), |
||
272 | ), |
||
273 | ); |
||
274 | |||
275 | $this->serviceManager->setService('Config', $config); |
||
276 | |||
277 | $ormConfig = $this->factory->createService($this->serviceManager); |
||
278 | |||
279 | $this->assertSame($entityListenerResolver, $ormConfig->getEntityListenerResolver()); |
||
280 | } |
||
281 | |||
282 | public function testWillInstantiateConfigWithEntityListenerResolverReference() |
||
283 | { |
||
284 | $entityListenerResolver = $this->getMock('Doctrine\ORM\Mapping\EntityListenerResolver'); |
||
285 | |||
286 | $config = array( |
||
287 | 'doctrine' => array( |
||
288 | 'configuration' => array( |
||
289 | 'test_default' => array( |
||
290 | 'entity_listener_resolver' => 'test_entity_listener_resolver', |
||
291 | ), |
||
292 | ), |
||
293 | ), |
||
294 | ); |
||
295 | |||
296 | $this->serviceManager->setService('Config', $config); |
||
297 | $this->serviceManager->setService('test_entity_listener_resolver', $entityListenerResolver); |
||
298 | |||
299 | $ormConfig = $this->factory->createService($this->serviceManager); |
||
300 | |||
301 | $this->assertSame($entityListenerResolver, $ormConfig->getEntityListenerResolver()); |
||
302 | } |
||
303 | |||
304 | public function testDoNotCreateSecondLevelCacheByDefault() |
||
305 | { |
||
306 | $config = array( |
||
307 | 'doctrine' => array( |
||
308 | 'configuration' => array( |
||
309 | 'test_default' => array(), |
||
310 | ), |
||
311 | ), |
||
312 | ); |
||
313 | |||
314 | $this->serviceManager->setService('Config', $config); |
||
315 | |||
316 | $ormConfig = $this->factory->createService($this->serviceManager); |
||
317 | |||
318 | $this->assertNull($ormConfig->getSecondLevelCacheConfiguration()); |
||
319 | } |
||
320 | |||
321 | public function testCanInstantiateWithSecondLevelCacheConfig() |
||
379 | } |
||
380 |