diff --git a/UPGRADE-2.17.md b/UPGRADE-2.17.md index b012a0e9..7d505f4c 100644 --- a/UPGRADE-2.17.md +++ b/UPGRADE-2.17.md @@ -9,6 +9,11 @@ Configuration This option is a no-op when using `doctrine/orm` 3 and has been conditionally deprecated. You should stop using it as soon as you upgrade to Doctrine ORM 3. +### The `doctrine.dbal.connections.some_connection.disable_type_comments` configuration option is deprecated + +This option is a no-op when using `doctrine/dbal` 4 and has been conditionally +deprecated. You should stop using it as soon as you upgrade to Doctrine DBAL 4. + ConnectionFactory::createConnection() signature change ------------------------------------------------------ diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index dfd89972..cc9be4eb 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -4,6 +4,8 @@ namespace Doctrine\Bundle\DoctrineBundle\DependencyInjection; +use Doctrine\DBAL\Connection; +use Doctrine\Deprecations\Deprecation; use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\Mapping\ClassMetadata; @@ -29,6 +31,7 @@ use function is_array; use function is_string; use function key; +use function method_exists; use function reset; use function sprintf; use function strtoupper; @@ -185,7 +188,20 @@ private function getDbalConnectionsNode(): ArrayNodeDefinition ->defaultValue(true) ->info('Enables collecting schema errors when profiling is enabled') ->end() - ->booleanNode('disable_type_comments')->end() + ->booleanNode('disable_type_comments') + ->beforeNormalization() + ->ifTrue(static fn ($v): bool => isset($v) && ! method_exists(Connection::class, 'getEventManager')) + ->then(static function ($v) { + Deprecation::trigger( + 'doctrine/doctrine-bundle', + 'https://github.com/doctrine/DoctrineBundle/pull/2048', + 'The "disable_type_comments" configuration key is deprecated when using DBAL 4 and will be removed in DoctrineBundle 3.0.', + ); + + return $v; + }) + ->end() + ->end() ->scalarNode('server_version')->end() ->integerNode('idle_connection_ttl')->defaultValue(600)->end() ->scalarNode('driver_class')->end() diff --git a/tests/DependencyInjection/AbstractDoctrineExtensionTestCase.php b/tests/DependencyInjection/AbstractDoctrineExtensionTestCase.php index 326f7c6e..fbfa4492 100644 --- a/tests/DependencyInjection/AbstractDoctrineExtensionTestCase.php +++ b/tests/DependencyInjection/AbstractDoctrineExtensionTestCase.php @@ -9,8 +9,10 @@ use Doctrine\Bundle\DoctrineBundle\DependencyInjection\DoctrineExtension; use Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection\Fixtures\InvokableEntityListener; use Doctrine\DBAL\Configuration; +use Doctrine\DBAL\Connection; use Doctrine\DBAL\Connections\PrimaryReadReplicaConnection; use Doctrine\DBAL\Platforms\PostgreSQLPlatform; +use Doctrine\Deprecations\PHPUnit\VerifyDeprecations; use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\ClassMetadata; @@ -41,6 +43,7 @@ use function end; use function interface_exists; use function is_dir; +use function method_exists; use function sprintf; use function sys_get_temp_dir; use function uniqid; @@ -49,6 +52,8 @@ abstract class AbstractDoctrineExtensionTestCase extends TestCase { + use VerifyDeprecations; + abstract protected function loadFromFile(ContainerBuilder $container, string $file): void; public function testDbalLoadFromXmlMultipleConnections(): void @@ -795,6 +800,27 @@ public function testAddFilter(): void $this->assertCount(2, $entityManager->getFilters()->getEnabledFilters()); } + #[IgnoreDeprecations] + public function testSettingDisableTypeCommentsWithDbal4IsDeprecated(): void + { + if (method_exists(Connection::class, 'getEventManager')) { + self::markTestSkipped('This test requires DBAL 4.'); + } + + $this->expectDeprecationWithIdentifier('https://github.com/doctrine/DoctrineBundle/pull/2048'); + $this->loadContainer('dbal_disable_type_comments'); + } + + public function testSettingDisableTypeCommentsWithDbal3IsFine(): void + { + if (! method_exists(Connection::class, 'getEventManager')) { + self::markTestSkipped('This test requires DBAL 3.'); + } + + $this->expectNoDeprecationWithIdentifier('https://github.com/doctrine/DoctrineBundle/pull/2048'); + $this->loadContainer('dbal_disable_type_comments'); + } + public function testResolveTargetEntity(): void { if (! interface_exists(EntityManagerInterface::class)) {