Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like AbstractDoctrineExtensionTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use AbstractDoctrineExtensionTest, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
27 | abstract class AbstractDoctrineExtensionTest extends \PHPUnit_Framework_TestCase |
||
28 | { |
||
29 | abstract protected function loadFromFile(ContainerBuilder $container, $file); |
||
30 | |||
31 | public function testDbalLoadFromXmlMultipleConnections() |
||
32 | { |
||
33 | $container = $this->loadContainer('dbal_service_multiple_connections'); |
||
34 | |||
35 | // doctrine.dbal.mysql_connection |
||
36 | $config = $container->getDefinition('doctrine.dbal.mysql_connection')->getArgument(0); |
||
37 | |||
38 | $this->assertEquals('mysql_s3cr3t', $config['password']); |
||
39 | $this->assertEquals('mysql_user', $config['user']); |
||
40 | $this->assertEquals('mysql_db', $config['dbname']); |
||
41 | $this->assertEquals('/path/to/mysqld.sock', $config['unix_socket']); |
||
42 | |||
43 | // doctrine.dbal.sqlite_connection |
||
44 | $config = $container->getDefinition('doctrine.dbal.sqlite_connection')->getArgument(0); |
||
45 | $this->assertSame('pdo_sqlite', $config['driver']); |
||
46 | $this->assertSame('sqlite_db', $config['dbname']); |
||
47 | $this->assertSame('sqlite_user', $config['user']); |
||
48 | $this->assertSame('sqlite_s3cr3t', $config['password']); |
||
49 | $this->assertSame('/tmp/db.sqlite', $config['path']); |
||
50 | $this->assertTrue($config['memory']); |
||
51 | |||
52 | // doctrine.dbal.oci8_connection |
||
53 | $config = $container->getDefinition('doctrine.dbal.oci_connection')->getArgument(0); |
||
54 | $this->assertSame('oci8', $config['driver']); |
||
55 | $this->assertSame('oracle_db', $config['dbname']); |
||
56 | $this->assertSame('oracle_user', $config['user']); |
||
57 | $this->assertSame('oracle_s3cr3t', $config['password']); |
||
58 | $this->assertSame('oracle_service', $config['servicename']); |
||
59 | $this->assertTrue($config['service']); |
||
60 | $this->assertTrue($config['pooled']); |
||
61 | $this->assertSame('utf8', $config['charset']); |
||
62 | |||
63 | // doctrine.dbal.ibmdb2_connection |
||
64 | $config = $container->getDefinition('doctrine.dbal.ibmdb2_connection')->getArgument(0); |
||
65 | $this->assertSame('ibm_db2', $config['driver']); |
||
66 | $this->assertSame('ibmdb2_db', $config['dbname']); |
||
67 | $this->assertSame('ibmdb2_user', $config['user']); |
||
68 | $this->assertSame('ibmdb2_s3cr3t', $config['password']); |
||
69 | $this->assertSame('TCPIP', $config['protocol']); |
||
70 | |||
71 | // doctrine.dbal.pgsql_connection |
||
72 | $config = $container->getDefinition('doctrine.dbal.pgsql_connection')->getArgument(0); |
||
73 | $this->assertSame('pdo_pgsql', $config['driver']); |
||
74 | $this->assertSame('pgsql_db', $config['dbname']); |
||
75 | $this->assertSame('pgsql_user', $config['user']); |
||
76 | $this->assertSame('pgsql_s3cr3t', $config['password']); |
||
77 | $this->assertSame('require', $config['sslmode']); |
||
78 | $this->assertSame('postgresql-ca.pem', $config['sslrootcert']); |
||
79 | $this->assertSame('utf8', $config['charset']); |
||
80 | |||
81 | // doctrine.dbal.sqlanywhere_connection |
||
82 | $config = $container->getDefinition('doctrine.dbal.sqlanywhere_connection')->getArgument(0); |
||
83 | $this->assertSame('sqlanywhere', $config['driver']); |
||
84 | $this->assertSame('localhost', $config['host']); |
||
85 | $this->assertSame(2683, $config['port']); |
||
86 | $this->assertSame('sqlanywhere_server', $config['server']); |
||
87 | $this->assertSame('sqlanywhere_db', $config['dbname']); |
||
88 | $this->assertSame('sqlanywhere_user', $config['user']); |
||
89 | $this->assertSame('sqlanywhere_s3cr3t', $config['password']); |
||
90 | $this->assertTrue($config['persistent']); |
||
91 | $this->assertSame('utf8', $config['charset']); |
||
92 | } |
||
93 | |||
94 | public function testDbalLoadFromXmlSingleConnections() |
||
107 | |||
108 | public function testDbalLoadSingleMasterSlaveConnection() |
||
109 | { |
||
110 | $container = $this->loadContainer('dbal_service_single_master_slave_connection'); |
||
111 | |||
112 | // doctrine.dbal.mysql_connection |
||
113 | $param = $container->getDefinition('doctrine.dbal.default_connection')->getArgument(0); |
||
114 | |||
115 | $this->assertEquals('Doctrine\\DBAL\\Connections\\MasterSlaveConnection', $param['wrapperClass']); |
||
116 | $this->assertTrue($param['keepSlave']); |
||
117 | $this->assertEquals( |
||
118 | array('user' => 'mysql_user', 'password' => 'mysql_s3cr3t', |
||
119 | 'port' => null, 'dbname' => 'mysql_db', 'host' => 'localhost', |
||
120 | 'unix_socket' => '/path/to/mysqld.sock', |
||
121 | 'defaultTableOptions' => array(), |
||
122 | ), |
||
123 | $param['master'] |
||
124 | ); |
||
125 | $this->assertEquals( |
||
126 | array( |
||
127 | 'user' => 'slave_user', 'password' => 'slave_s3cr3t', 'port' => null, 'dbname' => 'slave_db', |
||
128 | 'host' => 'localhost', 'unix_socket' => '/path/to/mysqld_slave.sock', |
||
129 | ), |
||
130 | $param['slaves']['slave1'] |
||
131 | ); |
||
132 | } |
||
133 | |||
134 | public function testDbalLoadPoolShardingConnection() |
||
135 | { |
||
136 | $container = $this->loadContainer('dbal_service_pool_sharding_connection'); |
||
137 | |||
138 | // doctrine.dbal.mysql_connection |
||
139 | $param = $container->getDefinition('doctrine.dbal.default_connection')->getArgument(0); |
||
140 | |||
141 | $this->assertEquals('Doctrine\\DBAL\\Sharding\\PoolingShardConnection', $param['wrapperClass']); |
||
142 | $this->assertEquals(new Reference('foo.shard_choser'), $param['shardChoser']); |
||
143 | $this->assertEquals( |
||
144 | array('user' => 'mysql_user', 'password' => 'mysql_s3cr3t', |
||
145 | 'port' => null, 'dbname' => 'mysql_db', 'host' => 'localhost', |
||
146 | 'unix_socket' => '/path/to/mysqld.sock', |
||
147 | 'defaultTableOptions' => array(), |
||
148 | ), |
||
149 | $param['global'] |
||
150 | ); |
||
151 | $this->assertEquals( |
||
152 | array( |
||
153 | 'user' => 'shard_user', 'password' => 'shard_s3cr3t', 'port' => null, 'dbname' => 'shard_db', |
||
154 | 'host' => 'localhost', 'unix_socket' => '/path/to/mysqld_shard.sock', 'id' => 1, |
||
155 | ), |
||
156 | $param['shards'][0] |
||
157 | ); |
||
158 | } |
||
159 | |||
160 | public function testDbalLoadSavepointsForNestedTransactions() |
||
161 | { |
||
162 | $container = $this->loadContainer('dbal_savepoints'); |
||
163 | |||
164 | $calls = $container->getDefinition('doctrine.dbal.savepoints_connection')->getMethodCalls(); |
||
165 | $this->assertCount(1, $calls); |
||
166 | $this->assertEquals('setNestTransactionsWithSavepoints', $calls[0][0]); |
||
167 | $this->assertTrue($calls[0][1][0]); |
||
168 | |||
169 | $calls = $container->getDefinition('doctrine.dbal.nosavepoints_connection')->getMethodCalls(); |
||
170 | $this->assertCount(0, $calls); |
||
171 | |||
172 | $calls = $container->getDefinition('doctrine.dbal.notset_connection')->getMethodCalls(); |
||
173 | $this->assertCount(0, $calls); |
||
174 | } |
||
175 | |||
176 | public function testLoadSimpleSingleConnection() |
||
177 | { |
||
178 | $container = $this->loadContainer('orm_service_simple_single_entity_manager'); |
||
179 | |||
180 | $definition = $container->getDefinition('doctrine.dbal.default_connection'); |
||
181 | |||
182 | $this->assertDICConstructorArguments($definition, array( |
||
183 | array( |
||
184 | 'dbname' => 'db', |
||
185 | 'host' => 'localhost', |
||
186 | 'port' => null, |
||
187 | 'user' => 'root', |
||
188 | 'password' => null, |
||
189 | 'driver' => 'pdo_mysql', |
||
190 | 'driverOptions' => array(), |
||
191 | 'defaultTableOptions' => array(), |
||
192 | ), |
||
193 | new Reference('doctrine.dbal.default_connection.configuration'), |
||
194 | new Reference('doctrine.dbal.default_connection.event_manager'), |
||
195 | array(), |
||
196 | )); |
||
197 | |||
198 | $definition = $container->getDefinition('doctrine.orm.default_entity_manager'); |
||
199 | $this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getClass()); |
||
200 | View Code Duplication | if (method_exists($definition, 'getFactory')) { |
|
201 | $this->assertEquals(array('%doctrine.orm.entity_manager.class%', 'create'), $definition->getFactory()); |
||
202 | } else { |
||
203 | $this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getFactoryClass()); |
||
204 | $this->assertEquals('create', $definition->getFactoryMethod()); |
||
205 | } |
||
206 | |||
207 | $this->assertDICConstructorArguments($definition, array( |
||
208 | new Reference('doctrine.dbal.default_connection'), new Reference('doctrine.orm.default_configuration'), |
||
209 | )); |
||
210 | } |
||
211 | |||
212 | /** |
||
213 | * The PDO driver doesn't require a database name to be to set when connecting to a database server |
||
214 | */ |
||
215 | public function testLoadSimpleSingleConnectionWithoutDbName() |
||
216 | { |
||
217 | |||
218 | $container = $this->loadContainer('orm_service_simple_single_entity_manager_without_dbname'); |
||
219 | |||
220 | /** @var Definition $definition */ |
||
221 | $definition = $container->getDefinition('doctrine.dbal.default_connection'); |
||
222 | |||
223 | $this->assertDICConstructorArguments($definition, array( |
||
224 | array( |
||
225 | 'host' => 'localhost', |
||
226 | 'port' => null, |
||
227 | 'user' => 'root', |
||
228 | 'password' => null, |
||
229 | 'driver' => 'pdo_mysql', |
||
230 | 'driverOptions' => array(), |
||
231 | 'defaultTableOptions' => array(), |
||
232 | ), |
||
233 | new Reference('doctrine.dbal.default_connection.configuration'), |
||
234 | new Reference('doctrine.dbal.default_connection.event_manager'), |
||
235 | array(), |
||
236 | )); |
||
237 | |||
238 | $definition = $container->getDefinition('doctrine.orm.default_entity_manager'); |
||
239 | $this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getClass()); |
||
240 | if (method_exists($definition, 'getFactory')) { |
||
241 | $factory = $definition->getFactory(); |
||
242 | } else { |
||
243 | $factory[0] = $definition->getFactoryClass(); |
||
244 | $factory[1] = $definition->getFactoryMethod(); |
||
245 | } |
||
246 | |||
247 | $this->assertEquals('%doctrine.orm.entity_manager.class%', $factory[0]); |
||
248 | $this->assertEquals('create', $factory[1]); |
||
249 | |||
250 | $this->assertDICConstructorArguments($definition, array( |
||
251 | new Reference('doctrine.dbal.default_connection'), new Reference('doctrine.orm.default_configuration') |
||
252 | )); |
||
253 | } |
||
254 | |||
255 | public function testLoadSingleConnection() |
||
256 | { |
||
257 | $container = $this->loadContainer('orm_service_single_entity_manager'); |
||
258 | |||
259 | $definition = $container->getDefinition('doctrine.dbal.default_connection'); |
||
260 | |||
261 | $this->assertDICConstructorArguments($definition, array( |
||
262 | array( |
||
263 | 'host' => 'localhost', |
||
264 | 'driver' => 'pdo_sqlite', |
||
265 | 'driverOptions' => array(), |
||
266 | 'user' => 'sqlite_user', |
||
267 | 'port' => null, |
||
268 | 'password' => 'sqlite_s3cr3t', |
||
269 | 'dbname' => 'sqlite_db', |
||
270 | 'memory' => true, |
||
271 | 'defaultTableOptions' => array(), |
||
272 | ), |
||
273 | new Reference('doctrine.dbal.default_connection.configuration'), |
||
274 | new Reference('doctrine.dbal.default_connection.event_manager'), |
||
275 | array(), |
||
276 | )); |
||
277 | |||
278 | $definition = $container->getDefinition('doctrine.orm.default_entity_manager'); |
||
279 | $this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getClass()); |
||
280 | View Code Duplication | if (method_exists($definition, 'setFactory')) { |
|
281 | $this->assertEquals(array('%doctrine.orm.entity_manager.class%', 'create'), $definition->getFactory()); |
||
282 | } else { |
||
283 | $this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getFactoryClass()); |
||
284 | $this->assertEquals('create', $definition->getFactoryMethod()); |
||
285 | } |
||
286 | |||
287 | $this->assertDICConstructorArguments($definition, array( |
||
288 | new Reference('doctrine.dbal.default_connection'), new Reference('doctrine.orm.default_configuration'), |
||
289 | )); |
||
290 | |||
291 | $configDef = $container->getDefinition('doctrine.orm.default_configuration'); |
||
292 | $this->assertDICDefinitionMethodCallOnce($configDef, 'setDefaultRepositoryClassName', array('Acme\Doctrine\Repository')); |
||
293 | } |
||
294 | |||
295 | public function testLoadMultipleConnections() |
||
296 | { |
||
297 | $container = $this->loadContainer('orm_service_multiple_entity_managers'); |
||
298 | |||
299 | $definition = $container->getDefinition('doctrine.dbal.conn1_connection'); |
||
300 | |||
301 | $args = $definition->getArguments(); |
||
302 | $this->assertEquals('pdo_sqlite', $args[0]['driver']); |
||
303 | $this->assertEquals('localhost', $args[0]['host']); |
||
304 | $this->assertEquals('sqlite_user', $args[0]['user']); |
||
305 | $this->assertEquals('doctrine.dbal.conn1_connection.configuration', (string) $args[1]); |
||
306 | $this->assertEquals('doctrine.dbal.conn1_connection.event_manager', (string) $args[2]); |
||
307 | |||
308 | $this->assertEquals('doctrine.orm.em2_entity_manager', (string) $container->getAlias('doctrine.orm.entity_manager')); |
||
309 | |||
310 | $definition = $container->getDefinition('doctrine.orm.em1_entity_manager'); |
||
311 | $this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getClass()); |
||
312 | View Code Duplication | if (method_exists($definition, 'getFactory')) { |
|
313 | $this->assertEquals(array('%doctrine.orm.entity_manager.class%', 'create'), $definition->getFactory()); |
||
314 | } else { |
||
315 | $this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getFactoryClass()); |
||
316 | $this->assertEquals('create', $definition->getFactoryMethod()); |
||
317 | } |
||
318 | |||
319 | $arguments = $definition->getArguments(); |
||
320 | $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $arguments[0]); |
||
321 | $this->assertEquals('doctrine.dbal.conn1_connection', (string) $arguments[0]); |
||
322 | $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $arguments[1]); |
||
323 | $this->assertEquals('doctrine.orm.em1_configuration', (string) $arguments[1]); |
||
324 | |||
325 | $definition = $container->getDefinition('doctrine.dbal.conn2_connection'); |
||
326 | |||
327 | $args = $definition->getArguments(); |
||
328 | $this->assertEquals('pdo_sqlite', $args[0]['driver']); |
||
329 | $this->assertEquals('localhost', $args[0]['host']); |
||
330 | $this->assertEquals('sqlite_user', $args[0]['user']); |
||
331 | $this->assertEquals('doctrine.dbal.conn2_connection.configuration', (string) $args[1]); |
||
332 | $this->assertEquals('doctrine.dbal.conn2_connection.event_manager', (string) $args[2]); |
||
333 | |||
334 | $definition = $container->getDefinition('doctrine.orm.em2_entity_manager'); |
||
335 | $this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getClass()); |
||
336 | View Code Duplication | if (method_exists($definition, 'getFactory')) { |
|
337 | $this->assertEquals(array('%doctrine.orm.entity_manager.class%', 'create'), $definition->getFactory()); |
||
338 | } else { |
||
339 | $this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getFactoryClass()); |
||
340 | $this->assertEquals('create', $definition->getFactoryMethod()); |
||
341 | } |
||
342 | |||
343 | $arguments = $definition->getArguments(); |
||
344 | $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $arguments[0]); |
||
345 | $this->assertEquals('doctrine.dbal.conn2_connection', (string) $arguments[0]); |
||
346 | $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $arguments[1]); |
||
347 | $this->assertEquals('doctrine.orm.em2_configuration', (string) $arguments[1]); |
||
348 | |||
349 | $definition = $container->getDefinition($container->getAlias('doctrine.orm.em1_metadata_cache')); |
||
350 | $this->assertEquals('%doctrine_cache.xcache.class%', $definition->getClass()); |
||
351 | |||
352 | $definition = $container->getDefinition($container->getAlias('doctrine.orm.em1_query_cache')); |
||
353 | $this->assertEquals('%doctrine_cache.array.class%', $definition->getClass()); |
||
354 | |||
355 | $definition = $container->getDefinition($container->getAlias('doctrine.orm.em1_result_cache')); |
||
356 | $this->assertEquals('%doctrine_cache.array.class%', $definition->getClass()); |
||
357 | } |
||
358 | |||
359 | public function testLoadLogging() |
||
372 | |||
373 | public function testEntityManagerMetadataCacheDriverConfiguration() |
||
383 | |||
384 | public function testEntityManagerMemcacheMetadataCacheDriverConfiguration() |
||
400 | |||
401 | public function testDependencyInjectionImportsOverrideDefaults() |
||
411 | |||
412 | public function testSingleEntityManagerMultipleMappingBundleDefinitions() |
||
449 | |||
450 | public function testMultipleEntityManagersMappingBundleDefinitions() |
||
491 | |||
492 | public function testSingleEntityManagerDefaultTableOptions() |
||
493 | { |
||
494 | $container = $this->loadContainer('orm_single_em_default_table_options', array('YamlBundle', 'AnnotationsBundle', 'XmlBundle')); |
||
495 | |||
496 | $param = $container->getDefinition('doctrine.dbal.default_connection')->getArgument(0); |
||
497 | |||
498 | $this->assertArrayHasKey('defaultTableOptions',$param); |
||
499 | |||
500 | $defaults = $param['defaultTableOptions']; |
||
501 | |||
502 | $this->assertArrayHasKey('charset', $defaults); |
||
503 | $this->assertArrayHasKey('collate', $defaults); |
||
504 | $this->assertArrayHasKey('engine', $defaults); |
||
505 | |||
506 | $this->assertEquals('utf8mb4',$defaults['charset']); |
||
507 | $this->assertEquals('utf8mb4_unicode_ci',$defaults['collate']); |
||
508 | $this->assertEquals('InnoDB',$defaults['engine']); |
||
509 | |||
510 | } |
||
511 | |||
512 | public function testSetTypes() |
||
522 | |||
523 | public function testSetCustomFunctions() |
||
532 | |||
533 | View Code Duplication | public function testSetNamingStrategy() |
|
546 | |||
547 | View Code Duplication | public function testSetQuoteStrategy() |
|
548 | { |
||
549 | if (version_compare(Version::VERSION, "2.3.0-DEV") < 0) { |
||
550 | $this->markTestSkipped('Quote Strategies are not available'); |
||
551 | } |
||
552 | $container = $this->loadContainer('orm_quotestrategy'); |
||
553 | |||
554 | $def1 = $container->getDefinition('doctrine.orm.em1_configuration'); |
||
555 | $def2 = $container->getDefinition('doctrine.orm.em2_configuration'); |
||
556 | |||
557 | $this->assertDICDefinitionMethodCallOnce($def1, 'setQuoteStrategy', array(0 => new Reference('doctrine.orm.quote_strategy.default'))); |
||
558 | $this->assertDICDefinitionMethodCallOnce($def2, 'setQuoteStrategy', array(0 => new Reference('doctrine.orm.quote_strategy.ansi'))); |
||
559 | } |
||
560 | |||
561 | public function testSecondLevelCache() |
||
562 | { |
||
563 | if (version_compare(Version::VERSION, '2.5.0-DEV') < 0) { |
||
564 | $this->markTestSkipped('Second-level cache requires doctrine-orm 2.5.0 or newer'); |
||
565 | } |
||
566 | |||
567 | $container = $this->loadContainer('orm_second_level_cache'); |
||
568 | |||
569 | $this->assertTrue($container->has('doctrine.orm.default_configuration')); |
||
570 | $this->assertTrue($container->has('doctrine.orm.default_second_level_cache.cache_configuration')); |
||
571 | $this->assertTrue($container->has('doctrine.orm.default_second_level_cache.region_cache_driver')); |
||
572 | $this->assertTrue($container->has('doctrine.orm.default_second_level_cache.regions_configuration')); |
||
573 | $this->assertTrue($container->has('doctrine.orm.default_second_level_cache.default_cache_factory')); |
||
574 | |||
575 | $this->assertTrue($container->has('doctrine.orm.default_second_level_cache.logger_chain')); |
||
576 | $this->assertTrue($container->has('doctrine.orm.default_second_level_cache.logger_statistics')); |
||
577 | $this->assertTrue($container->has('doctrine.orm.default_second_level_cache.logger.my_service_logger1')); |
||
578 | $this->assertTrue($container->has('doctrine.orm.default_second_level_cache.logger.my_service_logger2')); |
||
579 | |||
580 | $this->assertTrue($container->has('doctrine.orm.default_second_level_cache.region.my_entity_region')); |
||
581 | $this->assertTrue($container->has('doctrine.orm.default_second_level_cache.region.my_service_region')); |
||
582 | $this->assertTrue($container->has('doctrine.orm.default_second_level_cache.region.my_query_region_filelock')); |
||
583 | |||
584 | $slcFactoryDef = $container->getDefinition('doctrine.orm.default_second_level_cache.default_cache_factory'); |
||
585 | $myEntityRegionDef = $container->getDefinition('doctrine.orm.default_second_level_cache.region.my_entity_region'); |
||
586 | $loggerChainDef = $container->getDefinition('doctrine.orm.default_second_level_cache.logger_chain'); |
||
587 | $loggerStatisticsDef = $container->getDefinition('doctrine.orm.default_second_level_cache.logger_statistics'); |
||
588 | $myQueryRegionDef = $container->getDefinition('doctrine.orm.default_second_level_cache.region.my_query_region_filelock'); |
||
589 | $cacheDriverDef = $container->getDefinition($container->getAlias('doctrine.orm.default_second_level_cache.region_cache_driver')); |
||
590 | $configDef = $container->getDefinition('doctrine.orm.default_configuration'); |
||
591 | $myEntityRegionArgs = $myEntityRegionDef->getArguments(); |
||
592 | $myQueryRegionArgs = $myQueryRegionDef->getArguments(); |
||
593 | $slcFactoryArgs = $slcFactoryDef->getArguments(); |
||
594 | |||
595 | $this->assertDICDefinitionClass($slcFactoryDef, '%doctrine.orm.second_level_cache.default_cache_factory.class%'); |
||
596 | $this->assertDICDefinitionClass($myQueryRegionDef, '%doctrine.orm.second_level_cache.filelock_region.class%'); |
||
597 | $this->assertDICDefinitionClass($myEntityRegionDef, '%doctrine.orm.second_level_cache.default_region.class%'); |
||
598 | $this->assertDICDefinitionClass($loggerChainDef, '%doctrine.orm.second_level_cache.logger_chain.class%'); |
||
599 | $this->assertDICDefinitionClass($loggerStatisticsDef, '%doctrine.orm.second_level_cache.logger_statistics.class%'); |
||
600 | $this->assertDICDefinitionClass($cacheDriverDef, '%doctrine_cache.array.class%'); |
||
601 | $this->assertDICDefinitionMethodCallOnce($configDef, 'setSecondLevelCacheConfiguration'); |
||
602 | $this->assertDICDefinitionMethodCallCount($slcFactoryDef, 'setRegion', array(), 3); |
||
603 | $this->assertDICDefinitionMethodCallCount($loggerChainDef, 'setLogger', array(), 3); |
||
604 | |||
605 | $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $slcFactoryArgs[0]); |
||
606 | $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $slcFactoryArgs[1]); |
||
607 | |||
608 | $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $myEntityRegionArgs[1]); |
||
609 | $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $myQueryRegionArgs[0]); |
||
610 | |||
611 | $this->assertEquals('my_entity_region', $myEntityRegionArgs[0]); |
||
612 | $this->assertEquals('doctrine.orm.default_second_level_cache.region.my_entity_region_driver', $myEntityRegionArgs[1]); |
||
613 | $this->assertEquals(600, $myEntityRegionArgs[2]); |
||
614 | |||
615 | $this->assertEquals('doctrine.orm.default_second_level_cache.region.my_query_region', $myQueryRegionArgs[0]); |
||
616 | $this->assertContains('/doctrine/orm/slc/filelock', $myQueryRegionArgs[1]); |
||
617 | $this->assertEquals(60, $myQueryRegionArgs[2]); |
||
618 | |||
619 | $this->assertEquals('doctrine.orm.default_second_level_cache.regions_configuration', $slcFactoryArgs[0]); |
||
620 | $this->assertEquals('doctrine.orm.default_second_level_cache.region_cache_driver', $slcFactoryArgs[1]); |
||
621 | } |
||
622 | |||
623 | public function testSingleEMSetCustomFunctions() |
||
630 | |||
631 | public function testAddCustomHydrationMode() |
||
638 | |||
639 | public function testAddFilter() |
||
658 | |||
659 | public function testResolveTargetEntity() |
||
660 | { |
||
661 | $container = $this->loadContainer('orm_resolve_target_entity'); |
||
662 | |||
663 | $definition = $container->getDefinition('doctrine.orm.listeners.resolve_target_entity'); |
||
664 | $this->assertDICDefinitionMethodCallOnce($definition, 'addResolveTargetEntity', array('Symfony\Component\Security\Core\User\UserInterface', 'MyUserClass', array())); |
||
665 | |||
666 | if (version_compare(Version::VERSION, '2.5.0-DEV') < 0) { |
||
667 | $this->assertEquals(array('doctrine.event_listener' => array(array('event' => 'loadClassMetadata'))), $definition->getTags()); |
||
668 | } else { |
||
669 | $this->assertEquals(array('doctrine.event_subscriber' => array(array())), $definition->getTags()); |
||
670 | } |
||
671 | } |
||
672 | |||
673 | public function testAttachEntityListeners() |
||
729 | |||
730 | public function testDbalAutoCommit() |
||
737 | |||
738 | public function testDbalOracleConnectstring() |
||
739 | { |
||
740 | $container = $this->loadContainer('dbal_oracle_connectstring'); |
||
741 | |||
742 | $config = $container->getDefinition('doctrine.dbal.default_connection')->getArgument(0); |
||
743 | $this->assertSame('scott@sales-server:1521/sales.us.example.com', $config['connectstring']); |
||
744 | } |
||
745 | |||
746 | public function testDbalOracleInstancename() |
||
747 | { |
||
748 | $container = $this->loadContainer('dbal_oracle_instancename'); |
||
749 | |||
750 | $config = $container->getDefinition('doctrine.dbal.default_connection')->getArgument(0); |
||
751 | $this->assertSame('mySuperInstance', $config['instancename']); |
||
752 | } |
||
753 | |||
754 | public function testDbalSchemaFilter() |
||
761 | |||
762 | public function testEntityListenerResolver() |
||
763 | { |
||
764 | $container = $this->loadContainer('orm_entity_listener_resolver', array('YamlBundle'), new EntityListenerPass()); |
||
765 | |||
766 | $definition = $container->getDefinition('doctrine.orm.em1_configuration'); |
||
767 | View Code Duplication | if (version_compare(Version::VERSION, "2.4.0-DEV") >= 0) { |
|
768 | $this->assertDICDefinitionMethodCallOnce($definition, 'setEntityListenerResolver', array(new Reference('doctrine.orm.em1_entity_listener_resolver'))); |
||
769 | } |
||
770 | |||
771 | $definition = $container->getDefinition('doctrine.orm.em2_configuration'); |
||
772 | View Code Duplication | if (version_compare(Version::VERSION, "2.4.0-DEV") >= 0) { |
|
773 | $this->assertDICDefinitionMethodCallOnce($definition, 'setEntityListenerResolver', array(new Reference('doctrine.orm.em2_entity_listener_resolver'))); |
||
774 | } |
||
775 | |||
782 | |||
783 | public function testAttachEntityListenerTag() |
||
810 | |||
811 | public function testAttachLazyEntityListener() |
||
832 | |||
833 | /** |
||
834 | * @expectedException \InvalidArgumentException |
||
835 | * @expectedExceptionMessage EntityListenerServiceResolver |
||
836 | */ |
||
837 | View Code Duplication | public function testLazyEntityListenerResolverWithoutCorrectInterface() |
|
852 | |||
853 | /** |
||
854 | * @expectedException \InvalidArgumentException |
||
855 | * @expectedExceptionMessageRegExp /The service ".*" must be public as this entity listener is lazy-loaded/ |
||
856 | */ |
||
857 | View Code Duplication | public function testPrivateLazyEntityListener() |
|
872 | |||
873 | /** |
||
874 | * @expectedException \InvalidArgumentException |
||
875 | * @expectedExceptionMessageRegExp /The service ".*" must not be abstract as this entity listener is lazy-loaded/ |
||
876 | */ |
||
877 | View Code Duplication | public function testAbstractLazyEntityListener() |
|
892 | |||
893 | public function testRepositoryFactory() |
||
900 | |||
901 | private function loadContainer($fixture, array $bundles = array('YamlBundle'), CompilerPassInterface $compilerPass = null) |
||
916 | |||
917 | private function getContainer(array $bundles) |
||
934 | |||
935 | /** |
||
936 | * Assertion on the Class of a DIC Service Definition. |
||
937 | * |
||
938 | * @param Definition $definition |
||
939 | * @param string $expectedClass |
||
940 | */ |
||
941 | private function assertDICDefinitionClass(Definition $definition, $expectedClass) |
||
945 | |||
946 | private function assertDICConstructorArguments(Definition $definition, $args) |
||
950 | |||
951 | View Code Duplication | private function assertDICDefinitionMethodCallAt($pos, Definition $definition, $methodName, array $params = null) |
|
962 | |||
963 | /** |
||
964 | * Assertion for the DI Container, check if the given definition contains a method call with the given parameters. |
||
965 | * |
||
966 | * @param Definition $definition |
||
967 | * @param string $methodName |
||
968 | * @param array $params |
||
969 | */ |
||
970 | View Code Duplication | private function assertDICDefinitionMethodCallOnce(Definition $definition, $methodName, array $params = null) |
|
990 | |||
991 | private function assertDICDefinitionMethodCallCount(Definition $definition, $methodName, array $params = array(), $nbCalls = 1) |
||
1010 | |||
1011 | private function compileContainer(ContainerBuilder $container) |
||
1017 | } |
||
1018 |
For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a
@return
doc comment to communicate to implementors of these methods what they are expected to return.