From 01c714eef7d5c5515d664b1763af186ee7abd97b Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Tue, 4 Jun 2019 08:14:11 +0200 Subject: [PATCH 1/2] Deprecate configuring caches through doctrine-cache-bundle --- DependencyInjection/Configuration.php | 37 +++-- DependencyInjection/DoctrineExtension.php | 17 +++ Tests/Builder/BundleConfigurationBuilder.php | 2 +- Tests/ContainerTest.php | 8 +- .../AbstractDoctrineExtensionTest.php | 41 ++++-- .../DoctrineExtensionTest.php | 136 ++++++++++++++---- .../config/xml/orm_imports_import.xml | 2 +- .../config/xml/orm_second_level_cache.xml | 9 +- .../orm_service_multiple_entity_managers.xml | 4 +- ...m_service_simple_single_entity_manager.xml | 6 - ..._simple_single_entity_manager_memcache.xml | 26 ++++ ...e_single_entity_manager_without_dbname.xml | 6 - .../xml/orm_service_single_entity_manager.xml | 6 - .../config/yml/orm_imports_import.yml | 1 - .../config/yml/orm_second_level_cache.yml | 7 +- .../orm_service_multiple_entity_managers.yml | 2 - ...m_service_simple_single_entity_manager.yml | 6 - ..._simple_single_entity_manager_memcache.yml | 19 +++ ...e_single_entity_manager_without_dbname.yml | 6 - .../yml/orm_service_single_entity_manager.yml | 6 - Tests/ServiceRepositoryTest.php | 12 ++ Tests/TestCase.php | 9 ++ UPGRADE-1.12.md | 11 ++ UPGRADE-2.0.md | 7 + 24 files changed, 285 insertions(+), 101 deletions(-) create mode 100644 Tests/DependencyInjection/Fixtures/config/xml/orm_service_simple_single_entity_manager_memcache.xml create mode 100644 Tests/DependencyInjection/Fixtures/config/yml/orm_service_simple_single_entity_manager_memcache.yml create mode 100644 UPGRADE-1.12.md diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 3c0631748..112151fb2 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -9,8 +9,12 @@ use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; use Symfony\Component\DependencyInjection\Exception\LogicException; +use const E_USER_DEPRECATED; use function array_key_exists; +use function in_array; use function is_array; +use function sprintf; +use function trigger_error; /** * This class contains the configuration information for the bundle @@ -706,16 +710,33 @@ private function getOrmCacheDriverNode($name) }) ->end() ->children() - ->scalarNode('type')->defaultValue('array')->end() + ->scalarNode('type') + ->defaultNull() + ->beforeNormalization() + ->ifNotInArray([null, 'pool', 'service']) + ->then(static function ($v) use ($name) { + @trigger_error( + sprintf( + 'Using the "%s" type for cache "%s" is deprecated since DoctrineBundle 1.12 and will be dropped in 2.0. Please use the "service" or "pool" types exclusively.', + $v, + $name + ), + E_USER_DEPRECATED + ); + + return $v; + }) + ->end() + ->end() ->scalarNode('id')->end() ->scalarNode('pool')->end() - ->scalarNode('host')->end() - ->scalarNode('port')->end() - ->scalarNode('database')->end() - ->scalarNode('instance_class')->end() - ->scalarNode('class')->end() - ->scalarNode('namespace')->defaultNull()->end() - ->scalarNode('cache_provider')->defaultNull()->end() + ->scalarNode('host')->setDeprecated()->end() + ->scalarNode('port')->setDeprecated()->end() + ->scalarNode('database')->setDeprecated()->end() + ->scalarNode('instance_class')->setDeprecated()->end() + ->scalarNode('class')->setDeprecated()->end() + ->scalarNode('namespace')->defaultNull()->setDeprecated()->end() + ->scalarNode('cache_provider')->defaultNull()->setDeprecated()->end() ->end(); return $node; diff --git a/DependencyInjection/DoctrineExtension.php b/DependencyInjection/DoctrineExtension.php index cfcdeabe7..67fd74d6d 100644 --- a/DependencyInjection/DoctrineExtension.php +++ b/DependencyInjection/DoctrineExtension.php @@ -739,6 +739,13 @@ protected function loadCacheDriver($driverName, $entityManagerName, array $drive $serviceId = null; $aliasId = $this->getObjectManagerElementName(sprintf('%s_%s', $entityManagerName, $driverName)); + if ($driverMap['type'] === null) { + $driverMap = [ + 'type' => 'pool', + 'pool' => $this->getPoolNameForCacheDriver($driverName), + ]; + } + switch ($driverMap['type']) { case 'service': $serviceId = $driverMap['id']; @@ -888,4 +895,14 @@ private function createPoolCacheDefinition(ContainerBuilder $container, string $ return $serviceId; } + + private function getPoolNameForCacheDriver(string $driverName) : string + { + switch ($driverName) { + case 'metadata_cache': + return 'cache.system'; + default: + return 'cache.app'; + } + } } diff --git a/Tests/Builder/BundleConfigurationBuilder.php b/Tests/Builder/BundleConfigurationBuilder.php index c98b0cb66..234349289 100644 --- a/Tests/Builder/BundleConfigurationBuilder.php +++ b/Tests/Builder/BundleConfigurationBuilder.php @@ -51,7 +51,7 @@ public function addBaseEntityManager() public function addBaseSecondLevelCache() { $this->addSecondLevelCache([ - 'region_cache_driver' => ['type' => 'memcache'], + 'region_cache_driver' => ['type' => 'pool', 'pool' => 'my_pool'], 'regions' => [ 'hour_region' => ['lifetime' => 3600], ], diff --git a/Tests/ContainerTest.php b/Tests/ContainerTest.php index db669f687..161a5c580 100644 --- a/Tests/ContainerTest.php +++ b/Tests/ContainerTest.php @@ -3,7 +3,6 @@ namespace Doctrine\Bundle\DoctrineBundle\Tests; use Doctrine\Common\Annotations\Reader; -use Doctrine\Common\Cache\ArrayCache; use Doctrine\Common\EventManager; use Doctrine\Common\Persistence\ManagerRegistry; use Doctrine\Common\Persistence\Mapping\ClassMetadataFactory; @@ -20,6 +19,7 @@ use Symfony\Bridge\Doctrine\PropertyInfo\DoctrineExtractor; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntityValidator; use Symfony\Bridge\Doctrine\Validator\DoctrineLoader; +use Symfony\Component\Cache\DoctrineProvider; use Symfony\Component\PropertyInfo\PropertyInitializableExtractorInterface; class ContainerTest extends TestCase @@ -47,9 +47,9 @@ public function testContainer() $this->assertInstanceOf(Reader::class, $container->get('doctrine.orm.metadata.annotation_reader')); $this->assertInstanceOf(Configuration::class, $container->get('doctrine.orm.default_configuration')); $this->assertInstanceOf(MappingDriverChain::class, $container->get('doctrine.orm.default_metadata_driver')); - $this->assertInstanceOf(ArrayCache::class, $container->get('doctrine.orm.default_metadata_cache')); - $this->assertInstanceOf(ArrayCache::class, $container->get('doctrine.orm.default_query_cache')); - $this->assertInstanceOf(ArrayCache::class, $container->get('doctrine.orm.default_result_cache')); + $this->assertInstanceOf(DoctrineProvider::class, $container->get('doctrine.orm.default_metadata_cache')); + $this->assertInstanceOf(DoctrineProvider::class, $container->get('doctrine.orm.default_query_cache')); + $this->assertInstanceOf(DoctrineProvider::class, $container->get('doctrine.orm.default_result_cache')); $this->assertInstanceOf(EntityManager::class, $container->get('doctrine.orm.default_entity_manager')); $this->assertInstanceOf(Connection::class, $container->get('database_connection')); $this->assertInstanceOf(EntityManager::class, $container->get('doctrine.orm.entity_manager')); diff --git a/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php b/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php index bab4a8aa0..49601bad4 100644 --- a/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php +++ b/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php @@ -10,6 +10,8 @@ use Doctrine\ORM\EntityManager; use PHPUnit\Framework\TestCase; use Symfony\Bridge\Doctrine\DependencyInjection\CompilerPass\RegisterEventListenersAndSubscribersPass; +use Symfony\Component\Cache\Adapter\ArrayAdapter; +use Symfony\Component\Cache\DoctrineProvider; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\Compiler\ResolveChildDefinitionsPass; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -339,13 +341,19 @@ public function testLoadMultipleConnections() $this->assertEquals('doctrine.orm.em2_configuration', (string) $arguments[1]); $definition = $container->getDefinition((string) $container->getAlias('doctrine.orm.em1_metadata_cache')); - $this->assertEquals('%doctrine_cache.xcache.class%', $definition->getClass()); + $this->assertEquals(DoctrineProvider::class, $definition->getClass()); $definition = $container->getDefinition((string) $container->getAlias('doctrine.orm.em1_query_cache')); - $this->assertEquals('%doctrine_cache.array.class%', $definition->getClass()); + $this->assertEquals(DoctrineProvider::class, $definition->getClass()); + $arguments = $definition->getArguments(); + $this->assertInstanceOf(Reference::class, $arguments[0]); + $this->assertEquals('cache.app', (string) $arguments[0]); $definition = $container->getDefinition((string) $container->getAlias('doctrine.orm.em1_result_cache')); - $this->assertEquals('%doctrine_cache.array.class%', $definition->getClass()); + $this->assertEquals(DoctrineProvider::class, $definition->getClass()); + $arguments = $definition->getArguments(); + $this->assertInstanceOf(Reference::class, $arguments[0]); + $this->assertEquals('cache.app', (string) $arguments[0]); } public function testLoadLogging() @@ -373,15 +381,18 @@ public function testEntityManagerMetadataCacheDriverConfiguration() $container = $this->loadContainer('orm_service_multiple_entity_managers'); $definition = $container->getDefinition((string) $container->getAlias('doctrine.orm.em1_metadata_cache')); - $this->assertDICDefinitionClass($definition, '%doctrine_cache.xcache.class%'); + $this->assertDICDefinitionClass($definition, DoctrineProvider::class); $definition = $container->getDefinition((string) $container->getAlias('doctrine.orm.em2_metadata_cache')); - $this->assertDICDefinitionClass($definition, '%doctrine_cache.apc.class%'); + $this->assertDICDefinitionClass($definition, DoctrineProvider::class); } + /** + * @group legacy + */ public function testEntityManagerMemcacheMetadataCacheDriverConfiguration() { - $container = $this->loadContainer('orm_service_simple_single_entity_manager'); + $container = $this->loadContainer('orm_service_simple_single_entity_manager_memcache'); $definition = $container->getDefinition((string) $container->getAlias('doctrine.orm.default_metadata_cache')); $this->assertDICDefinitionClass($definition, '%doctrine_cache.memcache.class%'); @@ -399,6 +410,9 @@ public function testEntityManagerMemcacheMetadataCacheDriverConfiguration() ]); } + /** + * @group legacy + */ public function testEntityManagerRedisMetadataCacheDriverConfigurationWithDatabaseKey() { $container = $this->loadContainer('orm_service_simple_single_entity_manager_redis'); @@ -422,7 +436,7 @@ public function testDependencyInjectionImportsOverrideDefaults() $container = $this->loadContainer('orm_imports'); $cacheDefinition = $container->getDefinition((string) $container->getAlias('doctrine.orm.default_metadata_cache')); - $this->assertEquals('%doctrine_cache.apc.class%', $cacheDefinition->getClass()); + $this->assertEquals(DoctrineProvider::class, $cacheDefinition->getClass()); $configDefinition = $container->getDefinition('doctrine.orm.default_configuration'); $this->assertDICDefinitionMethodCallOnce($configDefinition, 'setAutoGenerateProxyClasses', ['%doctrine.orm.auto_generate_proxy_classes%']); @@ -605,7 +619,7 @@ public function testSecondLevelCache() $this->assertDICDefinitionClass($myEntityRegionDef, '%doctrine.orm.second_level_cache.default_region.class%'); $this->assertDICDefinitionClass($loggerChainDef, '%doctrine.orm.second_level_cache.logger_chain.class%'); $this->assertDICDefinitionClass($loggerStatisticsDef, '%doctrine.orm.second_level_cache.logger_statistics.class%'); - $this->assertDICDefinitionClass($cacheDriverDef, '%doctrine_cache.array.class%'); + $this->assertDICDefinitionClass($cacheDriverDef, DoctrineProvider::class); $this->assertDICDefinitionMethodCallOnce($configDef, 'setSecondLevelCacheConfiguration'); $this->assertDICDefinitionMethodCallCount($slcFactoryDef, 'setRegion', [], 3); $this->assertDICDefinitionMethodCallCount($loggerChainDef, 'setLogger', [], 3); @@ -1018,14 +1032,23 @@ private function getContainer(array $bundles) $map[$bundle] = 'Fixtures\\Bundles\\' . $bundle . '\\' . $bundle; } - return new ContainerBuilder(new ParameterBag([ + $container = new ContainerBuilder(new ParameterBag([ 'kernel.name' => 'app', 'kernel.debug' => false, 'kernel.bundles' => $map, 'kernel.cache_dir' => sys_get_temp_dir(), 'kernel.environment' => 'test', 'kernel.root_dir' => __DIR__ . '/../../', // src dir + 'kernel.project_dir' => __DIR__ . '/../../', // src dir + 'kernel.bundles_metadata' => [], + 'container.build_id' => uniqid(), ])); + + // Register dummy cache services so we don't have to load the FrameworkExtension + $container->setDefinition('cache.system', (new Definition(ArrayAdapter::class))->setPublic(true)); + $container->setDefinition('cache.app', (new Definition(ArrayAdapter::class))->setPublic(true)); + + return $container; } /** diff --git a/Tests/DependencyInjection/DoctrineExtensionTest.php b/Tests/DependencyInjection/DoctrineExtensionTest.php index edd415107..47f8216e7 100644 --- a/Tests/DependencyInjection/DoctrineExtensionTest.php +++ b/Tests/DependencyInjection/DoctrineExtensionTest.php @@ -11,6 +11,8 @@ use Doctrine\DBAL\Driver\Connection as DriverConnection; use Doctrine\ORM\EntityManagerInterface; use PHPUnit\Framework\TestCase; +use Symfony\Component\Cache\Adapter\ArrayAdapter; +use Symfony\Component\Cache\DoctrineProvider; use Symfony\Component\DependencyInjection\Compiler\ResolveChildDefinitionsPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; @@ -320,13 +322,22 @@ public function testDependencyInjectionConfigurationDefaults() $this->assertEquals('doctrine.orm.default_entity_listener_resolver', (string) $calls[12][1][0]); $definition = $container->getDefinition((string) $container->getAlias('doctrine.orm.default_metadata_cache')); - $this->assertEquals('%doctrine_cache.array.class%', $definition->getClass()); + $this->assertEquals(DoctrineProvider::class, $definition->getClass()); + $arguments = $definition->getArguments(); + $this->assertInstanceOf(Reference::class, $arguments[0]); + $this->assertEquals('cache.system', (string) $arguments[0]); $definition = $container->getDefinition((string) $container->getAlias('doctrine.orm.default_query_cache')); - $this->assertEquals('%doctrine_cache.array.class%', $definition->getClass()); + $this->assertEquals(DoctrineProvider::class, $definition->getClass()); + $arguments = $definition->getArguments(); + $this->assertInstanceOf(Reference::class, $arguments[0]); + $this->assertEquals('cache.app', (string) $arguments[0]); $definition = $container->getDefinition((string) $container->getAlias('doctrine.orm.default_result_cache')); - $this->assertEquals('%doctrine_cache.array.class%', $definition->getClass()); + $this->assertEquals(DoctrineProvider::class, $definition->getClass()); + $arguments = $definition->getArguments(); + $this->assertInstanceOf(Reference::class, $arguments[0]); + $this->assertEquals('cache.app', (string) $arguments[0]); } public function testUseSavePointsAddMethodCallToAddSavepointsToTheConnection() @@ -425,7 +436,7 @@ public function testSingleEntityManagerWithCustomSecondLevelCacheConfiguration() $configurationArray = BundleConfigurationBuilder::createBuilderWithBaseValues() ->addSecondLevelCache([ - 'region_cache_driver' => ['type' => 'memcache'], + 'region_cache_driver' => ['type' => 'service', 'id' => 'my_cache'], 'regions' => [ 'hour_region' => ['lifetime' => 3600], ], @@ -674,9 +685,10 @@ public function testMessengerIntegration() /** * @param array|string $cacheConfig * - * @dataProvider cacheConfigurationProvider + * @group legacy + * @dataProvider deprecatedCacheConfigurationProvider */ - public function testCacheConfiguration(string $expectedAliasName, string $expectedAliasTarget, string $cacheName, $cacheConfig) : void + public function testDeprecatedCacheConfiguration(string $expectedAliasName, string $expectedAliasTarget, string $cacheName, $cacheConfig) : void { $container = $this->getContainer(); $extension = new DoctrineExtension(); @@ -693,7 +705,7 @@ public function testCacheConfiguration(string $expectedAliasName, string $expect $this->assertEquals($expectedAliasTarget, (string) $alias); } - public static function cacheConfigurationProvider() : array + public static function deprecatedCacheConfigurationProvider() : array { return [ 'metadata_cache_provider' => [ @@ -715,42 +727,107 @@ public static function cacheConfigurationProvider() : array 'cacheConfig' => ['cache_provider' => 'result_cache'], ], - 'metadata_cache_service' => [ + 'metadata_cache_array' => [ 'expectedAliasName' => 'doctrine.orm.default_metadata_cache', - 'expectedAliasTarget' => 'service_target_metadata', + 'expectedAliasTarget' => 'doctrine_cache.providers.doctrine.orm.default_metadata_cache', 'cacheName' => 'metadata_cache_driver', - 'cacheConfig' => ['type' => 'service', 'id' => 'service_target_metadata'], + 'cacheConfig' => 'array', ], - 'query_cache_service' => [ + 'query_cache_array' => [ 'expectedAliasName' => 'doctrine.orm.default_query_cache', - 'expectedAliasTarget' => 'service_target_query', + 'expectedAliasTarget' => 'doctrine_cache.providers.doctrine.orm.default_query_cache', 'cacheName' => 'query_cache_driver', - 'cacheConfig' => ['type' => 'service', 'id' => 'service_target_query'], + 'cacheConfig' => 'array', ], - 'result_cache_service' => [ + 'result_cache_array' => [ 'expectedAliasName' => 'doctrine.orm.default_result_cache', - 'expectedAliasTarget' => 'service_target_result', + 'expectedAliasTarget' => 'doctrine_cache.providers.doctrine.orm.default_result_cache', 'cacheName' => 'result_cache_driver', - 'cacheConfig' => ['type' => 'service', 'id' => 'service_target_result'], + 'cacheConfig' => 'array', ], + ]; + } - 'metadata_cache_array' => [ + /** + * @param array|string $cacheConfig + * + * @dataProvider cacheConfigurationProvider + */ + public function testCacheConfiguration(string $expectedAliasName, string $expectedAliasTarget, string $cacheName, $cacheConfig) : void + { + $container = $this->getContainer(); + $extension = new DoctrineExtension(); + + $config = BundleConfigurationBuilder::createBuilder() + ->addBaseConnection() + ->addEntityManager([$cacheName => $cacheConfig]) + ->build(); + + $extension->load([$config], $container); + + $this->assertTrue($container->hasAlias($expectedAliasName)); + $alias = $container->getAlias($expectedAliasName); + $this->assertEquals($expectedAliasTarget, (string) $alias); + } + + public static function cacheConfigurationProvider() : array + { + return [ + 'metadata_cache_default' => [ 'expectedAliasName' => 'doctrine.orm.default_metadata_cache', - 'expectedAliasTarget' => 'doctrine_cache.providers.doctrine.orm.default_metadata_cache', + 'expectedAliasTarget' => 'doctrine.orm.cache.pool.cache.system', 'cacheName' => 'metadata_cache_driver', - 'cacheConfig' => 'array', + 'cacheConfig' => ['type' => null], ], - 'query_cache_array' => [ + 'query_cache_default' => [ 'expectedAliasName' => 'doctrine.orm.default_query_cache', - 'expectedAliasTarget' => 'doctrine_cache.providers.doctrine.orm.default_query_cache', + 'expectedAliasTarget' => 'doctrine.orm.cache.pool.cache.app', 'cacheName' => 'query_cache_driver', - 'cacheConfig' => 'array', + 'cacheConfig' => ['type' => null], ], - 'result_cache_array' => [ + 'result_cache_default' => [ 'expectedAliasName' => 'doctrine.orm.default_result_cache', - 'expectedAliasTarget' => 'doctrine_cache.providers.doctrine.orm.default_result_cache', + 'expectedAliasTarget' => 'doctrine.orm.cache.pool.cache.app', 'cacheName' => 'result_cache_driver', - 'cacheConfig' => 'array', + 'cacheConfig' => ['type' => null], + ], + + 'metadata_cache_pool' => [ + 'expectedAliasName' => 'doctrine.orm.default_metadata_cache', + 'expectedAliasTarget' => 'doctrine.orm.cache.pool.metadata_cache_pool', + 'cacheName' => 'metadata_cache_driver', + 'cacheConfig' => ['type' => 'pool', 'pool' => 'metadata_cache_pool'], + ], + 'query_cache_pool' => [ + 'expectedAliasName' => 'doctrine.orm.default_query_cache', + 'expectedAliasTarget' => 'doctrine.orm.cache.pool.query_cache_pool', + 'cacheName' => 'query_cache_driver', + 'cacheConfig' => ['type' => 'pool', 'pool' => 'query_cache_pool'], + ], + 'result_cache_pool' => [ + 'expectedAliasName' => 'doctrine.orm.default_result_cache', + 'expectedAliasTarget' => 'doctrine.orm.cache.pool.result_cache_pool', + 'cacheName' => 'result_cache_driver', + 'cacheConfig' => ['type' => 'pool', 'pool' => 'result_cache_pool'], + ], + + 'metadata_cache_service' => [ + 'expectedAliasName' => 'doctrine.orm.default_metadata_cache', + 'expectedAliasTarget' => 'service_target_metadata', + 'cacheName' => 'metadata_cache_driver', + 'cacheConfig' => ['type' => 'service', 'id' => 'service_target_metadata'], + ], + 'query_cache_service' => [ + 'expectedAliasName' => 'doctrine.orm.default_query_cache', + 'expectedAliasTarget' => 'service_target_query', + 'cacheName' => 'query_cache_driver', + 'cacheConfig' => ['type' => 'service', 'id' => 'service_target_query'], + ], + 'result_cache_service' => [ + 'expectedAliasName' => 'doctrine.orm.default_result_cache', + 'expectedAliasTarget' => 'service_target_result', + 'cacheName' => 'result_cache_driver', + 'cacheConfig' => ['type' => 'service', 'id' => 'service_target_result'], ], ]; } @@ -790,7 +867,7 @@ private function getContainer($bundles = 'YamlBundle', $vendor = null) $map[$bundle] = 'Fixtures\\Bundles\\' . ($vendor ? $vendor . '\\' : '') . $bundle . '\\' . $bundle; } - return new ContainerBuilder(new ParameterBag([ + $container = new ContainerBuilder(new ParameterBag([ 'kernel.name' => 'app', 'kernel.debug' => false, 'kernel.bundles' => $map, @@ -798,6 +875,13 @@ private function getContainer($bundles = 'YamlBundle', $vendor = null) 'kernel.environment' => 'test', 'kernel.root_dir' => __DIR__ . '/../../', // src dir ])); + + // Register dummy cache services so we don't have to load the FrameworkExtension + $container->setDefinition('cache.system', (new Definition(ArrayAdapter::class))->setPublic(true)); + $container->setDefinition('cache.app', (new Definition(ArrayAdapter::class))->setPublic(true)); + $container->setDefinition('my_pool', (new Definition(ArrayAdapter::class))->setPublic(true)); + + return $container; } private function assertDICConstructorArguments(Definition $definition, array $args) diff --git a/Tests/DependencyInjection/Fixtures/config/xml/orm_imports_import.xml b/Tests/DependencyInjection/Fixtures/config/xml/orm_imports_import.xml index de649bf0a..fab7060bc 100644 --- a/Tests/DependencyInjection/Fixtures/config/xml/orm_imports_import.xml +++ b/Tests/DependencyInjection/Fixtures/config/xml/orm_imports_import.xml @@ -15,7 +15,7 @@ auto-generate-proxy-classes="false" default-entity-manager="default" > - + diff --git a/Tests/DependencyInjection/Fixtures/config/xml/orm_second_level_cache.xml b/Tests/DependencyInjection/Fixtures/config/xml/orm_second_level_cache.xml index 33a80e2d3..01c4006b4 100644 --- a/Tests/DependencyInjection/Fixtures/config/xml/orm_second_level_cache.xml +++ b/Tests/DependencyInjection/Fixtures/config/xml/orm_second_level_cache.xml @@ -39,17 +39,12 @@ - - - - - - + + - diff --git a/Tests/DependencyInjection/Fixtures/config/xml/orm_service_multiple_entity_managers.xml b/Tests/DependencyInjection/Fixtures/config/xml/orm_service_multiple_entity_managers.xml index 9c3b840c4..c82f3735b 100644 --- a/Tests/DependencyInjection/Fixtures/config/xml/orm_service_multiple_entity_managers.xml +++ b/Tests/DependencyInjection/Fixtures/config/xml/orm_service_multiple_entity_managers.xml @@ -29,10 +29,10 @@ - + - + diff --git a/Tests/DependencyInjection/Fixtures/config/xml/orm_service_simple_single_entity_manager.xml b/Tests/DependencyInjection/Fixtures/config/xml/orm_service_simple_single_entity_manager.xml index 0870542e0..045c08fd5 100644 --- a/Tests/DependencyInjection/Fixtures/config/xml/orm_service_simple_single_entity_manager.xml +++ b/Tests/DependencyInjection/Fixtures/config/xml/orm_service_simple_single_entity_manager.xml @@ -13,12 +13,6 @@ - - Doctrine\Common\Cache\MemcacheCache - localhost - 11211 - Memcache - diff --git a/Tests/DependencyInjection/Fixtures/config/xml/orm_service_simple_single_entity_manager_memcache.xml b/Tests/DependencyInjection/Fixtures/config/xml/orm_service_simple_single_entity_manager_memcache.xml new file mode 100644 index 000000000..0870542e0 --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/config/xml/orm_service_simple_single_entity_manager_memcache.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + Doctrine\Common\Cache\MemcacheCache + localhost + 11211 + Memcache + + + + + + diff --git a/Tests/DependencyInjection/Fixtures/config/xml/orm_service_simple_single_entity_manager_without_dbname.xml b/Tests/DependencyInjection/Fixtures/config/xml/orm_service_simple_single_entity_manager_without_dbname.xml index 042726653..3ff68a849 100644 --- a/Tests/DependencyInjection/Fixtures/config/xml/orm_service_simple_single_entity_manager_without_dbname.xml +++ b/Tests/DependencyInjection/Fixtures/config/xml/orm_service_simple_single_entity_manager_without_dbname.xml @@ -13,12 +13,6 @@ - - Doctrine\Common\Cache\MemcacheCache - localhost - 11211 - Memcache - diff --git a/Tests/DependencyInjection/Fixtures/config/xml/orm_service_single_entity_manager.xml b/Tests/DependencyInjection/Fixtures/config/xml/orm_service_single_entity_manager.xml index bd6474332..7088826f4 100644 --- a/Tests/DependencyInjection/Fixtures/config/xml/orm_service_single_entity_manager.xml +++ b/Tests/DependencyInjection/Fixtures/config/xml/orm_service_single_entity_manager.xml @@ -26,12 +26,6 @@ auto-generate-proxy-classes="true" > - - Doctrine\Common\Cache\MemcacheCache - localhost - 11211 - Memcache - diff --git a/Tests/DependencyInjection/Fixtures/config/yml/orm_imports_import.yml b/Tests/DependencyInjection/Fixtures/config/yml/orm_imports_import.yml index c533c1ed6..cd2275615 100644 --- a/Tests/DependencyInjection/Fixtures/config/yml/orm_imports_import.yml +++ b/Tests/DependencyInjection/Fixtures/config/yml/orm_imports_import.yml @@ -10,6 +10,5 @@ doctrine: default_entity_manager: default entity_managers: default: - metadata_cache_driver: apc mappings: YamlBundle: ~ diff --git a/Tests/DependencyInjection/Fixtures/config/yml/orm_second_level_cache.yml b/Tests/DependencyInjection/Fixtures/config/yml/orm_second_level_cache.yml index 1dfd3a78e..9ce8550d8 100644 --- a/Tests/DependencyInjection/Fixtures/config/yml/orm_second_level_cache.yml +++ b/Tests/DependencyInjection/Fixtures/config/yml/orm_second_level_cache.yml @@ -39,7 +39,7 @@ doctrine: second_level_cache: log_enabled: true enabled: true - region_cache_driver: array + region_cache_driver: ~ loggers: my_service_logger1 : @@ -55,11 +55,10 @@ doctrine: my_query_region: lifetime: 300 - cache_driver: array + cache_driver: ~ type: filelock lock_path: "%kernel.cache_dir%/doctrine/orm/slc/filelock" my_entity_region: lifetime: 600 - cache_driver: - type: apc + cache_driver: ~ diff --git a/Tests/DependencyInjection/Fixtures/config/yml/orm_service_multiple_entity_managers.yml b/Tests/DependencyInjection/Fixtures/config/yml/orm_service_multiple_entity_managers.yml index 31b9cc1aa..8dcf0fca7 100644 --- a/Tests/DependencyInjection/Fixtures/config/yml/orm_service_multiple_entity_managers.yml +++ b/Tests/DependencyInjection/Fixtures/config/yml/orm_service_multiple_entity_managers.yml @@ -23,12 +23,10 @@ doctrine: auto_generate_proxy_classes: true entity_managers: em1: - metadata_cache_driver: xcache connection: conn1 mappings: YamlBundle: ~ em2: - metadata_cache_driver: apc connection: conn2 mappings: YamlBundle: ~ diff --git a/Tests/DependencyInjection/Fixtures/config/yml/orm_service_simple_single_entity_manager.yml b/Tests/DependencyInjection/Fixtures/config/yml/orm_service_simple_single_entity_manager.yml index b2082a5f2..9a5e26b0a 100644 --- a/Tests/DependencyInjection/Fixtures/config/yml/orm_service_simple_single_entity_manager.yml +++ b/Tests/DependencyInjection/Fixtures/config/yml/orm_service_simple_single_entity_manager.yml @@ -11,9 +11,3 @@ doctrine: default: mappings: YamlBundle: ~ - metadata_cache_driver: - type: memcache - class: Doctrine\Common\Cache\MemcacheCache - host: localhost - port: 11211 - instance_class: Memcache diff --git a/Tests/DependencyInjection/Fixtures/config/yml/orm_service_simple_single_entity_manager_memcache.yml b/Tests/DependencyInjection/Fixtures/config/yml/orm_service_simple_single_entity_manager_memcache.yml new file mode 100644 index 000000000..b2082a5f2 --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/config/yml/orm_service_simple_single_entity_manager_memcache.yml @@ -0,0 +1,19 @@ +doctrine: + dbal: + default_connection: default + connections: + default: + dbname: db + + orm: + default_entity_manager: default + entity_managers: + default: + mappings: + YamlBundle: ~ + metadata_cache_driver: + type: memcache + class: Doctrine\Common\Cache\MemcacheCache + host: localhost + port: 11211 + instance_class: Memcache diff --git a/Tests/DependencyInjection/Fixtures/config/yml/orm_service_simple_single_entity_manager_without_dbname.yml b/Tests/DependencyInjection/Fixtures/config/yml/orm_service_simple_single_entity_manager_without_dbname.yml index 2b7ec601e..3645db685 100644 --- a/Tests/DependencyInjection/Fixtures/config/yml/orm_service_simple_single_entity_manager_without_dbname.yml +++ b/Tests/DependencyInjection/Fixtures/config/yml/orm_service_simple_single_entity_manager_without_dbname.yml @@ -10,9 +10,3 @@ doctrine: default: mappings: YamlBundle: ~ - metadata_cache_driver: - type: memcache - class: Doctrine\Common\Cache\MemcacheCache - host: localhost - port: 11211 - instance_class: Memcache diff --git a/Tests/DependencyInjection/Fixtures/config/yml/orm_service_single_entity_manager.yml b/Tests/DependencyInjection/Fixtures/config/yml/orm_service_single_entity_manager.yml index 9f8198114..e3cb77a19 100644 --- a/Tests/DependencyInjection/Fixtures/config/yml/orm_service_single_entity_manager.yml +++ b/Tests/DependencyInjection/Fixtures/config/yml/orm_service_single_entity_manager.yml @@ -19,9 +19,3 @@ doctrine: default_repository_class: Acme\Doctrine\Repository mappings: YamlBundle: ~ - metadata_cache_driver: - type: memcache - class: Doctrine\Common\Cache\MemcacheCache - host: localhost - port: 11211 - instance_class: Memcache diff --git a/Tests/ServiceRepositoryTest.php b/Tests/ServiceRepositoryTest.php index 21754f707..f711e5cca 100644 --- a/Tests/ServiceRepositoryTest.php +++ b/Tests/ServiceRepositoryTest.php @@ -15,6 +15,7 @@ use Fixtures\Bundles\RepositoryServiceBundle\Repository\TestCustomClassRepoRepository; use Fixtures\Bundles\RepositoryServiceBundle\Repository\TestCustomServiceRepoRepository; use Fixtures\Bundles\RepositoryServiceBundle\RepositoryServiceBundle; +use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension; use Symfony\Component\DependencyInjection\Alias; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; @@ -44,8 +45,19 @@ public function testRepositoryServiceWiring() 'kernel.cache_dir' => sys_get_temp_dir(), 'kernel.environment' => 'test', 'kernel.root_dir' => __DIR__ . '/../../../../', // src dir + 'kernel.project_dir' => __DIR__ . '/../../../../', // src dir + 'kernel.bundles_metadata' => [], + 'kernel.charset' => 'UTF-8', + 'kernel.container_class' => ContainerBuilder::class, + 'kernel.secret' => 'test', + 'container.build_id' => uniqid(), ])); $container->set('annotation_reader', new AnnotationReader()); + + $extension = new FrameworkExtension(); + $container->registerExtension($extension); + $extension->load(['framework' => []], $container); + $extension = new DoctrineExtension(); $container->registerExtension($extension); $extension->load([[ diff --git a/Tests/TestCase.php b/Tests/TestCase.php index d57c94652..6822f2a33 100644 --- a/Tests/TestCase.php +++ b/Tests/TestCase.php @@ -7,6 +7,7 @@ use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\ORM\Version; use PHPUnit\Framework\TestCase as BaseTestCase; +use Symfony\Component\Cache\Adapter\ArrayAdapter; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\Compiler\ResolveChildDefinitionsPass; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -33,8 +34,12 @@ public function createYamlBundleTestContainer() 'kernel.cache_dir' => sys_get_temp_dir(), 'kernel.environment' => 'test', 'kernel.root_dir' => __DIR__ . '/../../../../', // src dir + 'kernel.project_dir' => __DIR__ . '/../../../../', // src dir + 'kernel.bundles_metadata' => [], + 'container.build_id' => uniqid(), ])); $container->set('annotation_reader', new AnnotationReader()); + $extension = new DoctrineExtension(); $container->registerExtension($extension); $extension->load([[ @@ -73,6 +78,10 @@ public function createYamlBundleTestContainer() $container->setDefinition('my.platform', new Definition('Doctrine\DBAL\Platforms\MySqlPlatform'))->setPublic(true); + // Register dummy cache services so we don't have to load the FrameworkExtension + $container->setDefinition('cache.system', (new Definition(ArrayAdapter::class))->setPublic(true)); + $container->setDefinition('cache.app', (new Definition(ArrayAdapter::class))->setPublic(true)); + $container->getCompilerPassConfig()->setOptimizationPasses([new ResolveChildDefinitionsPass()]); $container->getCompilerPassConfig()->setRemovingPasses([]); // make all Doctrine services public, so we can fetch them in the test diff --git a/UPGRADE-1.12.md b/UPGRADE-1.12.md new file mode 100644 index 000000000..2ed54db24 --- /dev/null +++ b/UPGRADE-1.12.md @@ -0,0 +1,11 @@ +UPGRADE FROM 1.11 to 1.12 +========================= + +Deprecation of DoctrineCacheBundle +---------------------------------- + +With DoctrineCacheBundle [being deprecated](https://github.com/doctrine/DoctrineCacheBundle/issues/156), +configuring caches through it has been deprecated. If you are using anything +other than the `pool` or `id` cache types, please update your configuration to +either use symfony/cache through the `pool` type or configure your cache +services manually and use the `service` type. diff --git a/UPGRADE-2.0.md b/UPGRADE-2.0.md index f5ad6ea49..6567b1424 100644 --- a/UPGRADE-2.0.md +++ b/UPGRADE-2.0.md @@ -20,6 +20,13 @@ Commands * `Doctrine\Bundle\DoctrineBundle\Command` no longer implements `ContainerAwareInterface`. +Deprecation of DoctrineCacheBundle +---------------------------------- + +Configuring caches through DoctrineCacheBundle is no longer possible. Please use +symfony/cache through the `pool` type or configure your cache services manually +and use the `service` type. + Mapping ------- From 0dc30c87083309ba0b93939f24bd179a10267906 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Tue, 30 Jul 2019 22:12:31 +0200 Subject: [PATCH 2/2] Require latest Symfony versions to work around issue with symfony/translator See https://github.com/symfony/symfony/pull/32664 for details. --- composer.json | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/composer.json b/composer.json index 66e8a0d54..f53a3b743 100644 --- a/composer.json +++ b/composer.json @@ -25,27 +25,27 @@ ], "require": { "php": "^7.1", - "symfony/framework-bundle": "^3.4|^4.1", - "symfony/config": "^3.4|^4.1", - "symfony/console": "^3.4|^4.1", - "symfony/dependency-injection": "^3.4|^4.1", + "symfony/framework-bundle": "^3.4.30|^4.3.3", + "symfony/config": "^3.4.30|^4.3.3", + "symfony/console": "^3.4.30|^4.3.3", + "symfony/dependency-injection": "^3.4.30|^4.3.3", "doctrine/dbal": "^2.5.12", "jdorn/sql-formatter": "^1.2.16", - "symfony/doctrine-bridge": "^3.4|^4.1", + "symfony/doctrine-bridge": "^3.4.30|^4.3.3", "doctrine/doctrine-cache-bundle": "~1.2" }, "require-dev": { "doctrine/orm": "^2.6", - "symfony/cache": "^3.4|^4.1", - "symfony/yaml": "^3.4|^4.1", - "symfony/validator": "^3.4|^4.1", - "symfony/property-info": "^3.4|^4.1", + "symfony/cache": "^3.4.30|^4.3.3", + "symfony/yaml": "^3.4.30|^4.3.3", + "symfony/validator": "^3.4.30|^4.3.3", + "symfony/property-info": "^3.4.30|^4.3.3", "symfony/phpunit-bridge": "^4.2", "symfony/twig-bridge": "^3.4|^4.1", "twig/twig": "^1.34|^2.4", "php-coveralls/php-coveralls": "^2.1", "phpunit/phpunit": "^7.5", - "symfony/web-profiler-bundle": "^3.4|^4.1", + "symfony/web-profiler-bundle": "^3.4.30|^4.3.3", "doctrine/coding-standard": "^6.0" }, "conflict": {