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 DoctrineExtensionTest 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 DoctrineExtensionTest, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 23 | class DoctrineExtensionTest extends TestCase |
||
| 24 | { |
||
| 25 | public function testAutowiringAlias() |
||
| 26 | { |
||
| 27 | $container = $this->getContainer(); |
||
| 28 | $extension = new DoctrineExtension(); |
||
| 29 | $config = BundleConfigurationBuilder::createBuilderWithBaseValues()->build(); |
||
| 30 | |||
| 31 | $extension->load([$config], $container); |
||
| 32 | |||
| 33 | $expectedAliases = [ |
||
| 34 | DriverConnection::class => 'database_connection', |
||
| 35 | Connection::class => 'database_connection', |
||
| 36 | ManagerRegistry::class => 'doctrine', |
||
| 37 | ObjectManager::class => 'doctrine.orm.entity_manager', |
||
| 38 | EntityManagerInterface::class => 'doctrine.orm.entity_manager', |
||
| 39 | ]; |
||
| 40 | |||
| 41 | foreach ($expectedAliases as $id => $target) { |
||
| 42 | $this->assertTrue($container->hasAlias($id), sprintf('The container should have a `%s` alias for autowiring support.', $id)); |
||
| 43 | |||
| 44 | $alias = $container->getAlias($id); |
||
| 45 | $this->assertEquals($target, (string) $alias, sprintf('The autowiring for `%s` should use `%s`.', $id, $target)); |
||
| 46 | $this->assertFalse($alias->isPublic(), sprintf('The autowiring alias for `%s` should be private.', $id, $target)); |
||
| 47 | } |
||
| 48 | } |
||
| 49 | |||
| 50 | public function testPublicServicesAndAliases() |
||
| 51 | { |
||
| 52 | $container = $this->getContainer(); |
||
| 53 | $extension = new DoctrineExtension(); |
||
| 54 | $config = BundleConfigurationBuilder::createBuilderWithBaseValues()->build(); |
||
| 55 | |||
| 56 | $extension->load([$config], $container); |
||
| 57 | |||
| 58 | $this->assertTrue($container->getDefinition('doctrine')->isPublic()); |
||
| 59 | $this->assertTrue($container->getAlias('doctrine.orm.entity_manager')->isPublic()); |
||
| 60 | $this->assertTrue($container->getAlias('database_connection')->isPublic()); |
||
| 61 | } |
||
| 62 | |||
| 63 | public function testDbalGenerateDefaultConnectionConfiguration() |
||
| 64 | { |
||
| 65 | $container = $this->getContainer(); |
||
| 66 | $extension = new DoctrineExtension(); |
||
| 67 | |||
| 68 | $container->registerExtension($extension); |
||
| 69 | |||
| 70 | $extension->load([['dbal' => []]], $container); |
||
| 71 | |||
| 72 | // doctrine.dbal.default_connection |
||
| 73 | $this->assertEquals('%doctrine.default_connection%', $container->getDefinition('doctrine')->getArgument(3)); |
||
| 74 | $this->assertEquals('default', $container->getParameter('doctrine.default_connection')); |
||
| 75 | $this->assertEquals('root', $container->getDefinition('doctrine.dbal.default_connection')->getArgument(0)['user']); |
||
| 76 | $this->assertNull($container->getDefinition('doctrine.dbal.default_connection')->getArgument(0)['password']); |
||
| 77 | $this->assertEquals('localhost', $container->getDefinition('doctrine.dbal.default_connection')->getArgument(0)['host']); |
||
| 78 | $this->assertNull($container->getDefinition('doctrine.dbal.default_connection')->getArgument(0)['port']); |
||
| 79 | $this->assertEquals('pdo_mysql', $container->getDefinition('doctrine.dbal.default_connection')->getArgument(0)['driver']); |
||
| 80 | $this->assertEquals([], $container->getDefinition('doctrine.dbal.default_connection')->getArgument(0)['driverOptions']); |
||
| 81 | } |
||
| 82 | |||
| 83 | public function testDbalOverrideDefaultConnection() |
||
| 84 | { |
||
| 85 | $container = $this->getContainer(); |
||
| 86 | $extension = new DoctrineExtension(); |
||
| 87 | |||
| 88 | $container->registerExtension($extension); |
||
| 89 | |||
| 90 | $extension->load([[], ['dbal' => ['default_connection' => 'foo']], []], $container); |
||
| 91 | |||
| 92 | // doctrine.dbal.default_connection |
||
| 93 | $this->assertEquals('%doctrine.default_connection%', $container->getDefinition('doctrine')->getArgument(3), '->load() overrides existing configuration options'); |
||
| 94 | $this->assertEquals('foo', $container->getParameter('doctrine.default_connection'), '->load() overrides existing configuration options'); |
||
| 95 | } |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @expectedException \LogicException |
||
| 99 | * @expectedExceptionMessage Configuring the ORM layer requires to configure the DBAL layer as well. |
||
| 100 | */ |
||
| 101 | public function testOrmRequiresDbal() |
||
| 102 | { |
||
| 103 | $extension = new DoctrineExtension(); |
||
| 104 | |||
| 105 | $extension->load([['orm' => ['auto_mapping' => true]]], $this->getContainer()); |
||
| 106 | } |
||
| 107 | |||
| 108 | public function getAutomappingConfigurations() |
||
| 109 | { |
||
| 110 | return [ |
||
| 111 | [ |
||
| 112 | [ |
||
| 113 | 'em1' => [ |
||
| 114 | 'mappings' => ['YamlBundle' => null], |
||
| 115 | ], |
||
| 116 | 'em2' => [ |
||
| 117 | 'mappings' => ['XmlBundle' => null], |
||
| 118 | ], |
||
| 119 | ], |
||
| 120 | ], |
||
| 121 | [ |
||
| 122 | [ |
||
| 123 | 'em1' => ['auto_mapping' => true], |
||
| 124 | 'em2' => [ |
||
| 125 | 'mappings' => ['XmlBundle' => null], |
||
| 126 | ], |
||
| 127 | ], |
||
| 128 | ], |
||
| 129 | [ |
||
| 130 | [ |
||
| 131 | 'em1' => [ |
||
| 132 | 'auto_mapping' => true, |
||
| 133 | 'mappings' => ['YamlBundle' => null], |
||
| 134 | ], |
||
| 135 | 'em2' => [ |
||
| 136 | 'mappings' => ['XmlBundle' => null], |
||
| 137 | ], |
||
| 138 | ], |
||
| 139 | ], |
||
| 140 | ]; |
||
| 141 | } |
||
| 142 | |||
| 143 | /** |
||
| 144 | * @dataProvider getAutomappingConfigurations |
||
| 145 | */ |
||
| 146 | public function testAutomapping(array $entityManagers) |
||
| 147 | { |
||
| 148 | $extension = new DoctrineExtension(); |
||
| 149 | |||
| 150 | if (! method_exists($extension, 'fixManagersAutoMappings')) { |
||
| 151 | $this->markTestSkipped('Auto mapping with multiple managers available with Symfony ~2.6'); |
||
| 152 | } |
||
| 153 | |||
| 154 | $container = $this->getContainer([ |
||
|
|
|||
| 155 | 'YamlBundle', |
||
| 156 | 'XmlBundle', |
||
| 157 | ]); |
||
| 158 | |||
| 159 | $extension->load( |
||
| 160 | [ |
||
| 161 | [ |
||
| 162 | 'dbal' => [ |
||
| 163 | 'default_connection' => 'cn1', |
||
| 164 | 'connections' => [ |
||
| 165 | 'cn1' => [], |
||
| 166 | 'cn2' => [], |
||
| 167 | ], |
||
| 168 | ], |
||
| 169 | 'orm' => ['entity_managers' => $entityManagers], |
||
| 170 | ], |
||
| 171 | ], |
||
| 172 | $container |
||
| 173 | ); |
||
| 174 | |||
| 175 | $configEm1 = $container->getDefinition('doctrine.orm.em1_configuration'); |
||
| 176 | $configEm2 = $container->getDefinition('doctrine.orm.em2_configuration'); |
||
| 177 | |||
| 178 | $this->assertContains( |
||
| 179 | [ |
||
| 180 | 'setEntityNamespaces', |
||
| 181 | [ |
||
| 182 | ['YamlBundle' => 'Fixtures\Bundles\YamlBundle\Entity'], |
||
| 183 | ], |
||
| 184 | ], |
||
| 185 | $configEm1->getMethodCalls() |
||
| 186 | ); |
||
| 187 | |||
| 188 | $this->assertContains( |
||
| 189 | [ |
||
| 190 | 'setEntityNamespaces', |
||
| 191 | [ |
||
| 192 | ['XmlBundle' => 'Fixtures\Bundles\XmlBundle\Entity'], |
||
| 193 | ], |
||
| 194 | ], |
||
| 195 | $configEm2->getMethodCalls() |
||
| 196 | ); |
||
| 197 | } |
||
| 198 | |||
| 199 | public function testDbalLoad() |
||
| 200 | { |
||
| 201 | $container = $this->getContainer(); |
||
| 202 | $extension = new DoctrineExtension(); |
||
| 203 | |||
| 204 | $extension->load([ |
||
| 205 | ['dbal' => ['connections' => ['default' => ['password' => 'foo']]]], |
||
| 206 | [], |
||
| 207 | ['dbal' => ['default_connection' => 'foo']], |
||
| 208 | [], |
||
| 209 | ], $container); |
||
| 210 | |||
| 211 | $config = $container->getDefinition('doctrine.dbal.default_connection')->getArgument(0); |
||
| 212 | |||
| 213 | $this->assertEquals('foo', $config['password']); |
||
| 214 | $this->assertEquals('root', $config['user']); |
||
| 215 | } |
||
| 216 | |||
| 217 | public function testDbalWrapperClass() |
||
| 218 | { |
||
| 219 | $container = $this->getContainer(); |
||
| 220 | $extension = new DoctrineExtension(); |
||
| 221 | |||
| 222 | $extension->load( |
||
| 223 | [ |
||
| 224 | [ |
||
| 225 | 'dbal' => [ |
||
| 226 | 'connections' => [ |
||
| 227 | 'default' => ['password' => 'foo', 'wrapper_class' => TestWrapperClass::class], |
||
| 228 | 'second' => ['password' => 'boo'], |
||
| 229 | ], |
||
| 230 | ], |
||
| 231 | ], |
||
| 232 | [], |
||
| 233 | ['dbal' => ['default_connection' => 'foo']], |
||
| 234 | [], |
||
| 235 | ], |
||
| 236 | $container |
||
| 237 | ); |
||
| 238 | |||
| 239 | $this->assertEquals(TestWrapperClass::class, $container->getDefinition('doctrine.dbal.default_connection')->getClass()); |
||
| 240 | $this->assertNull($container->getDefinition('doctrine.dbal.second_connection')->getClass()); |
||
| 241 | } |
||
| 242 | |||
| 243 | public function testDependencyInjectionConfigurationDefaults() |
||
| 244 | { |
||
| 245 | $container = $this->getContainer(); |
||
| 246 | $extension = new DoctrineExtension(); |
||
| 247 | $config = BundleConfigurationBuilder::createBuilderWithBaseValues()->build(); |
||
| 248 | |||
| 249 | $extension->load([$config], $container); |
||
| 250 | |||
| 251 | $this->assertFalse($container->getParameter('doctrine.orm.auto_generate_proxy_classes')); |
||
| 252 | $this->assertEquals('Doctrine\ORM\Configuration', $container->getParameter('doctrine.orm.configuration.class')); |
||
| 253 | $this->assertEquals('Doctrine\ORM\EntityManager', $container->getParameter('doctrine.orm.entity_manager.class')); |
||
| 254 | $this->assertEquals('Proxies', $container->getParameter('doctrine.orm.proxy_namespace')); |
||
| 255 | $this->assertEquals('Doctrine\Common\Cache\ArrayCache', $container->getParameter('doctrine.orm.cache.array.class')); |
||
| 256 | $this->assertEquals('Doctrine\Common\Cache\ApcCache', $container->getParameter('doctrine.orm.cache.apc.class')); |
||
| 257 | $this->assertEquals('Doctrine\Common\Cache\MemcacheCache', $container->getParameter('doctrine.orm.cache.memcache.class')); |
||
| 258 | $this->assertEquals('localhost', $container->getParameter('doctrine.orm.cache.memcache_host')); |
||
| 259 | $this->assertEquals('11211', $container->getParameter('doctrine.orm.cache.memcache_port')); |
||
| 260 | $this->assertEquals('Memcache', $container->getParameter('doctrine.orm.cache.memcache_instance.class')); |
||
| 261 | $this->assertEquals('Doctrine\Common\Cache\XcacheCache', $container->getParameter('doctrine.orm.cache.xcache.class')); |
||
| 262 | $this->assertEquals('Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain', $container->getParameter('doctrine.orm.metadata.driver_chain.class')); |
||
| 263 | $this->assertEquals('Doctrine\ORM\Mapping\Driver\AnnotationDriver', $container->getParameter('doctrine.orm.metadata.annotation.class')); |
||
| 264 | $this->assertEquals('Doctrine\ORM\Mapping\Driver\SimplifiedXmlDriver', $container->getParameter('doctrine.orm.metadata.xml.class')); |
||
| 265 | $this->assertEquals('Doctrine\ORM\Mapping\Driver\SimplifiedYamlDriver', $container->getParameter('doctrine.orm.metadata.yml.class')); |
||
| 266 | |||
| 267 | // second-level cache |
||
| 268 | $this->assertEquals('Doctrine\ORM\Cache\DefaultCacheFactory', $container->getParameter('doctrine.orm.second_level_cache.default_cache_factory.class')); |
||
| 269 | $this->assertEquals('Doctrine\ORM\Cache\Region\DefaultRegion', $container->getParameter('doctrine.orm.second_level_cache.default_region.class')); |
||
| 270 | $this->assertEquals('Doctrine\ORM\Cache\Region\FileLockRegion', $container->getParameter('doctrine.orm.second_level_cache.filelock_region.class')); |
||
| 271 | $this->assertEquals('Doctrine\ORM\Cache\Logging\CacheLoggerChain', $container->getParameter('doctrine.orm.second_level_cache.logger_chain.class')); |
||
| 272 | $this->assertEquals('Doctrine\ORM\Cache\Logging\StatisticsCacheLogger', $container->getParameter('doctrine.orm.second_level_cache.logger_statistics.class')); |
||
| 273 | $this->assertEquals('Doctrine\ORM\Cache\CacheConfiguration', $container->getParameter('doctrine.orm.second_level_cache.cache_configuration.class')); |
||
| 274 | $this->assertEquals('Doctrine\ORM\Cache\RegionsConfiguration', $container->getParameter('doctrine.orm.second_level_cache.regions_configuration.class')); |
||
| 275 | |||
| 276 | $config = BundleConfigurationBuilder::createBuilder() |
||
| 277 | ->addBaseConnection() |
||
| 278 | ->addEntityManager([ |
||
| 279 | 'proxy_namespace' => 'MyProxies', |
||
| 280 | 'auto_generate_proxy_classes' => true, |
||
| 281 | 'default_entity_manager' => 'default', |
||
| 282 | 'entity_managers' => [ |
||
| 283 | 'default' => [ |
||
| 284 | 'mappings' => ['YamlBundle' => []], |
||
| 285 | ], |
||
| 286 | ], |
||
| 287 | ]) |
||
| 288 | ->build(); |
||
| 289 | |||
| 290 | $container = $this->getContainer(); |
||
| 291 | $extension->load([$config], $container); |
||
| 292 | $this->compileContainer($container); |
||
| 293 | |||
| 294 | $definition = $container->getDefinition('doctrine.dbal.default_connection'); |
||
| 295 | |||
| 296 | $args = $definition->getArguments(); |
||
| 297 | $this->assertEquals('pdo_mysql', $args[0]['driver']); |
||
| 298 | $this->assertEquals('localhost', $args[0]['host']); |
||
| 299 | $this->assertEquals('root', $args[0]['user']); |
||
| 300 | $this->assertEquals('doctrine.dbal.default_connection.configuration', (string) $args[1]); |
||
| 301 | $this->assertEquals('doctrine.dbal.default_connection.event_manager', (string) $args[2]); |
||
| 302 | $this->assertCount(0, $definition->getMethodCalls()); |
||
| 303 | |||
| 304 | $definition = $container->getDefinition('doctrine.orm.default_entity_manager'); |
||
| 305 | $this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getClass()); |
||
| 306 | View Code Duplication | if (method_exists($definition, 'getFactory')) { |
|
| 307 | $this->assertEquals(['%doctrine.orm.entity_manager.class%', 'create'], $definition->getFactory()); |
||
| 308 | } else { |
||
| 309 | $this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getFactoryClass()); |
||
| 310 | $this->assertEquals('create', $definition->getFactoryMethod()); |
||
| 311 | } |
||
| 312 | |||
| 313 | $this->assertEquals(['default' => 'doctrine.orm.default_entity_manager'], $container->getParameter('doctrine.entity_managers'), 'Set of the existing EntityManagers names is incorrect.'); |
||
| 314 | $this->assertEquals('%doctrine.entity_managers%', $container->getDefinition('doctrine')->getArgument(2), 'Set of the existing EntityManagers names is incorrect.'); |
||
| 315 | |||
| 316 | $arguments = $definition->getArguments(); |
||
| 317 | $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $arguments[0]); |
||
| 318 | $this->assertEquals('doctrine.dbal.default_connection', (string) $arguments[0]); |
||
| 319 | $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $arguments[1]); |
||
| 320 | $this->assertEquals('doctrine.orm.default_configuration', (string) $arguments[1]); |
||
| 321 | |||
| 322 | $definition = $container->getDefinition('doctrine.orm.default_configuration'); |
||
| 323 | $calls = array_values($definition->getMethodCalls()); |
||
| 324 | $this->assertEquals(['YamlBundle' => 'Fixtures\Bundles\YamlBundle\Entity'], $calls[0][1][0]); |
||
| 325 | $this->assertEquals('doctrine.orm.default_metadata_cache', (string) $calls[1][1][0]); |
||
| 326 | $this->assertEquals('doctrine.orm.default_query_cache', (string) $calls[2][1][0]); |
||
| 327 | $this->assertEquals('doctrine.orm.default_result_cache', (string) $calls[3][1][0]); |
||
| 328 | |||
| 329 | if (version_compare(Version::VERSION, '2.3.0-DEV') >= 0) { |
||
| 330 | $this->assertEquals('doctrine.orm.naming_strategy.default', (string) $calls[10][1][0]); |
||
| 331 | $this->assertEquals('doctrine.orm.quote_strategy.default', (string) $calls[11][1][0]); |
||
| 332 | } |
||
| 333 | if (version_compare(Version::VERSION, '2.4.0-DEV') >= 0) { |
||
| 334 | $this->assertEquals('doctrine.orm.default_entity_listener_resolver', (string) $calls[12][1][0]); |
||
| 335 | } |
||
| 336 | |||
| 337 | $definition = $container->getDefinition((string) $container->getAlias('doctrine.orm.default_metadata_cache')); |
||
| 338 | $this->assertEquals('%doctrine_cache.array.class%', $definition->getClass()); |
||
| 339 | |||
| 340 | $definition = $container->getDefinition((string) $container->getAlias('doctrine.orm.default_query_cache')); |
||
| 341 | $this->assertEquals('%doctrine_cache.array.class%', $definition->getClass()); |
||
| 342 | |||
| 343 | $definition = $container->getDefinition((string) $container->getAlias('doctrine.orm.default_result_cache')); |
||
| 344 | $this->assertEquals('%doctrine_cache.array.class%', $definition->getClass()); |
||
| 345 | } |
||
| 346 | |||
| 347 | public function testUseSavePointsAddMethodCallToAddSavepointsToTheConnection() |
||
| 348 | { |
||
| 349 | $container = $this->getContainer(); |
||
| 350 | $extension = new DoctrineExtension(); |
||
| 351 | |||
| 352 | $extension->load([[ |
||
| 353 | 'dbal' => [ |
||
| 354 | 'connections' => [ |
||
| 355 | 'default' => ['password' => 'foo', 'use_savepoints' => true], |
||
| 356 | ], |
||
| 357 | ], |
||
| 358 | ], |
||
| 359 | ], $container); |
||
| 360 | |||
| 361 | $calls = $container->getDefinition('doctrine.dbal.default_connection')->getMethodCalls(); |
||
| 362 | $this->assertCount(1, $calls); |
||
| 363 | $this->assertEquals('setNestTransactionsWithSavepoints', $calls[0][0]); |
||
| 364 | $this->assertTrue($calls[0][1][0]); |
||
| 365 | } |
||
| 366 | |||
| 367 | public function testAutoGenerateProxyClasses() |
||
| 390 | |||
| 391 | public function testSingleEntityManagerWithDefaultConfiguration() |
||
| 392 | { |
||
| 393 | $container = $this->getContainer(); |
||
| 394 | $extension = new DoctrineExtension(); |
||
| 395 | |||
| 396 | $configurationArray = BundleConfigurationBuilder::createBuilderWithBaseValues()->build(); |
||
| 397 | |||
| 398 | $extension->load([$configurationArray], $container); |
||
| 399 | $this->compileContainer($container); |
||
| 400 | |||
| 401 | $definition = $container->getDefinition('doctrine.orm.default_entity_manager'); |
||
| 402 | $this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getClass()); |
||
| 403 | View Code Duplication | if (method_exists($definition, 'getFactory')) { |
|
| 404 | $this->assertEquals(['%doctrine.orm.entity_manager.class%', 'create'], $definition->getFactory()); |
||
| 405 | } else { |
||
| 406 | $this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getFactoryClass()); |
||
| 407 | $this->assertEquals('create', $definition->getFactoryMethod()); |
||
| 408 | } |
||
| 409 | |||
| 410 | $this->assertDICConstructorArguments($definition, [ |
||
| 411 | new Reference('doctrine.dbal.default_connection'), |
||
| 412 | new Reference('doctrine.orm.default_configuration'), |
||
| 413 | ]); |
||
| 414 | } |
||
| 415 | |||
| 416 | public function testSingleEntityManagerWithDefaultSecondLevelCacheConfiguration() |
||
| 417 | { |
||
| 418 | if (version_compare(Version::VERSION, '2.5.0-DEV') < 0) { |
||
| 419 | $this->markTestSkipped(sprintf('Second Level cache not supported by this version of the ORM : %s', Version::VERSION)); |
||
| 420 | } |
||
| 421 | $container = $this->getContainer(); |
||
| 422 | $extension = new DoctrineExtension(); |
||
| 423 | |||
| 424 | $configurationArray = BundleConfigurationBuilder::createBuilderWithBaseValues() |
||
| 425 | ->addBaseSecondLevelCache() |
||
| 426 | ->build(); |
||
| 427 | |||
| 428 | $extension->load([$configurationArray], $container); |
||
| 429 | $this->compileContainer($container); |
||
| 430 | |||
| 431 | $definition = $container->getDefinition('doctrine.orm.default_entity_manager'); |
||
| 432 | $this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getClass()); |
||
| 433 | View Code Duplication | if (method_exists($definition, 'getFactory')) { |
|
| 434 | $this->assertEquals(['%doctrine.orm.entity_manager.class%', 'create'], $definition->getFactory()); |
||
| 435 | } else { |
||
| 436 | $this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getFactoryClass()); |
||
| 437 | $this->assertEquals('create', $definition->getFactoryMethod()); |
||
| 438 | } |
||
| 439 | |||
| 440 | $this->assertDICConstructorArguments($definition, [ |
||
| 441 | new Reference('doctrine.dbal.default_connection'), |
||
| 442 | new Reference('doctrine.orm.default_configuration'), |
||
| 443 | ]); |
||
| 444 | |||
| 445 | $slcDefinition = $container->getDefinition('doctrine.orm.default_second_level_cache.default_cache_factory'); |
||
| 446 | $this->assertEquals('%doctrine.orm.second_level_cache.default_cache_factory.class%', $slcDefinition->getClass()); |
||
| 447 | } |
||
| 448 | |||
| 449 | public function testSingleEntityManagerWithCustomSecondLevelCacheConfiguration() |
||
| 450 | { |
||
| 451 | if (version_compare(Version::VERSION, '2.5.0-DEV') < 0) { |
||
| 452 | $this->markTestSkipped(sprintf('Second Level cache not supported by this version of the ORM : %s', Version::VERSION)); |
||
| 453 | } |
||
| 454 | $container = $this->getContainer(); |
||
| 455 | $extension = new DoctrineExtension(); |
||
| 456 | |||
| 457 | $configurationArray = BundleConfigurationBuilder::createBuilderWithBaseValues() |
||
| 458 | ->addSecondLevelCache([ |
||
| 459 | 'region_cache_driver' => ['type' => 'memcache'], |
||
| 460 | 'regions' => [ |
||
| 461 | 'hour_region' => ['lifetime' => 3600], |
||
| 462 | ], |
||
| 463 | 'factory' => 'YamlBundle\Cache\MyCacheFactory', |
||
| 464 | ]) |
||
| 465 | ->build(); |
||
| 466 | |||
| 467 | $extension->load([$configurationArray], $container); |
||
| 468 | $this->compileContainer($container); |
||
| 469 | |||
| 470 | $definition = $container->getDefinition('doctrine.orm.default_entity_manager'); |
||
| 471 | $this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getClass()); |
||
| 472 | View Code Duplication | if (method_exists($definition, 'getFactory')) { |
|
| 473 | $this->assertEquals(['%doctrine.orm.entity_manager.class%', 'create'], $definition->getFactory()); |
||
| 474 | } else { |
||
| 475 | $this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getFactoryClass()); |
||
| 476 | $this->assertEquals('create', $definition->getFactoryMethod()); |
||
| 477 | } |
||
| 478 | |||
| 479 | $this->assertDICConstructorArguments($definition, [ |
||
| 480 | new Reference('doctrine.dbal.default_connection'), |
||
| 481 | new Reference('doctrine.orm.default_configuration'), |
||
| 482 | ]); |
||
| 483 | |||
| 484 | $slcDefinition = $container->getDefinition('doctrine.orm.default_second_level_cache.default_cache_factory'); |
||
| 485 | $this->assertEquals('YamlBundle\Cache\MyCacheFactory', $slcDefinition->getClass()); |
||
| 486 | } |
||
| 487 | |||
| 488 | View Code Duplication | public function testBundleEntityAliases() |
|
| 489 | { |
||
| 490 | $container = $this->getContainer(); |
||
| 491 | $extension = new DoctrineExtension(); |
||
| 492 | |||
| 493 | $config = BundleConfigurationBuilder::createBuilder() |
||
| 494 | ->addBaseConnection() |
||
| 495 | ->build(); |
||
| 496 | $config['orm'] = ['default_entity_manager' => 'default', 'entity_managers' => ['default' => ['mappings' => ['YamlBundle' => []]]]]; |
||
| 497 | $extension->load([$config], $container); |
||
| 498 | |||
| 499 | $definition = $container->getDefinition('doctrine.orm.default_configuration'); |
||
| 500 | $this->assertDICDefinitionMethodCallOnce( |
||
| 501 | $definition, |
||
| 502 | 'setEntityNamespaces', |
||
| 503 | [['YamlBundle' => 'Fixtures\Bundles\YamlBundle\Entity']] |
||
| 504 | ); |
||
| 505 | } |
||
| 506 | |||
| 507 | View Code Duplication | public function testOverwriteEntityAliases() |
|
| 508 | { |
||
| 509 | $container = $this->getContainer(); |
||
| 510 | $extension = new DoctrineExtension(); |
||
| 511 | |||
| 512 | $config = BundleConfigurationBuilder::createBuilder() |
||
| 513 | ->addBaseConnection() |
||
| 514 | ->build(); |
||
| 515 | $config['orm'] = ['default_entity_manager' => 'default', 'entity_managers' => ['default' => ['mappings' => ['YamlBundle' => ['alias' => 'yml']]]]]; |
||
| 516 | $extension->load([$config], $container); |
||
| 517 | |||
| 518 | $definition = $container->getDefinition('doctrine.orm.default_configuration'); |
||
| 519 | $this->assertDICDefinitionMethodCallOnce( |
||
| 520 | $definition, |
||
| 521 | 'setEntityNamespaces', |
||
| 522 | [['yml' => 'Fixtures\Bundles\YamlBundle\Entity']] |
||
| 523 | ); |
||
| 524 | } |
||
| 525 | |||
| 526 | public function testYamlBundleMappingDetection() |
||
| 543 | |||
| 544 | View Code Duplication | public function testXmlBundleMappingDetection() |
|
| 570 | |||
| 571 | View Code Duplication | public function testAnnotationsBundleMappingDetection() |
|
| 597 | |||
| 598 | public function testOrmMergeConfigs() |
||
| 654 | |||
| 655 | public function testAnnotationsBundleMappingDetectionWithVendorNamespace() |
||
| 679 | |||
| 680 | public function testMessengerIntegration() |
||
| 681 | { |
||
| 682 | if (! interface_exists(MessageBusInterface::class)) { |
||
| 683 | $this->markTestSkipped('Symfony Messenger component is not installed'); |
||
| 684 | } |
||
| 685 | |||
| 686 | $container = $this->getContainer(); |
||
| 687 | $extension = new DoctrineExtension(); |
||
| 688 | |||
| 689 | $config = BundleConfigurationBuilder::createBuilder() |
||
| 690 | ->addBaseConnection() |
||
| 691 | ->addEntityManager([ |
||
| 692 | 'default_entity_manager' => 'default', |
||
| 693 | 'entity_managers' => [ |
||
| 694 | 'default' => [], |
||
| 695 | ], |
||
| 704 | |||
| 705 | public function testCacheConfiguration() |
||
| 733 | |||
| 734 | public function testShardManager() |
||
| 757 | |||
| 758 | private function getContainer($bundles = 'YamlBundle', $vendor = null) |
||
| 778 | |||
| 779 | private function assertDICConstructorArguments(Definition $definition, array $args) |
||
| 783 | |||
| 784 | View Code Duplication | private function assertDICDefinitionMethodCallAt($pos, Definition $definition, $methodName, array $params = null) |
|
| 799 | |||
| 800 | /** |
||
| 801 | * Assertion for the DI Container, check if the given definition contains a method call with the given parameters. |
||
| 802 | * |
||
| 803 | * @param string $methodName |
||
| 804 | * @param array|null $params |
||
| 805 | */ |
||
| 806 | View Code Duplication | private function assertDICDefinitionMethodCallOnce(Definition $definition, $methodName, array $params = null) |
|
| 830 | |||
| 831 | private function compileContainer(ContainerBuilder $container) |
||
| 837 | } |
||
| 838 | |||
| 842 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: