From 04e73d1290deb3ce11c2bc9f6d13444d1f547868 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Sun, 13 Feb 2022 23:01:00 +0100 Subject: [PATCH] Deprecate "collate" default table option "collation" is what is expected now on the DBAL side. --- ConnectionFactory.php | 6 ++++++ DependencyInjection/Configuration.php | 10 +++++++++- Resources/doc/configuration.rst | 12 ++++++++++-- Tests/ConnectionFactoryTest.php | 8 +++++++- .../AbstractDoctrineExtensionTest.php | 4 ++-- .../xml/orm_single_em_default_table_options.xml | 2 +- .../yml/orm_single_em_default_table_options.yml | 2 +- UPGRADE-2.6.md | 7 +++++++ 8 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 UPGRADE-2.6.md diff --git a/ConnectionFactory.php b/ConnectionFactory.php index c0fd16761..9cb48c41f 100644 --- a/ConnectionFactory.php +++ b/ConnectionFactory.php @@ -11,6 +11,7 @@ use Doctrine\DBAL\Exception\DriverException; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\Type; +use Doctrine\Deprecations\Deprecation; use function array_merge; use function defined; @@ -86,6 +87,11 @@ public function createConnection(array $params, ?Configuration $config = null, ? after dropping support for doctrine/dbal 2, since this package requires doctrine/dbal 3.3.2 or higher. */ if (isset($params['defaultTableOptions']['collate']) && defined('Doctrine\DBAL\Connection::PARAM_ASCII_STR_ARRAY')) { + Deprecation::trigger( + 'doctrine/doctrine-bundle', + 'https://github.com/doctrine/dbal/issues/5214', + 'The "collate" default table option is deprecated in favor of "collation" and will be removed in doctrine/doctrine-bundle 3.0. ' + ); $params['defaultTableOptions']['collation'] = $params['defaultTableOptions']['collate']; unset($params['defaultTableOptions']['collate']); } diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index f13a5db6f..19b0864fd 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -22,6 +22,7 @@ use function class_exists; use function constant; use function count; +use function defined; use function implode; use function in_array; use function is_array; @@ -143,6 +144,10 @@ private function getDbalConnectionsNode(): ArrayNodeDefinition $this->configureDbalDriverNode($connectionNode); + $collationKey = defined('Doctrine\DBAL\Connection::PARAM_ASCII_STR_ARRAY') + ? 'collate' + : 'collation'; + $connectionNode ->fixXmlConfig('option') ->fixXmlConfig('mapping_type') @@ -186,7 +191,10 @@ private function getDbalConnectionsNode(): ArrayNodeDefinition ->prototype('scalar')->end() ->end() ->arrayNode('default_table_options') - ->info("This option is used by the schema-tool and affects generated SQL. Possible keys include 'charset','collate', and 'engine'.") + ->info(sprintf( + "This option is used by the schema-tool and affects generated SQL. Possible keys include 'charset','%s', and 'engine'.", + $collationKey + )) ->useAttributeAsKey('name') ->prototype('scalar')->end() ->end() diff --git a/Resources/doc/configuration.rst b/Resources/doc/configuration.rst index 629148aa6..63593de67 100644 --- a/Resources/doc/configuration.rst +++ b/Resources/doc/configuration.rst @@ -133,7 +133,8 @@ Configuration Reference # Affects schema-tool. If absent, DBAL chooses defaults # based on the platform. Examples here are for MySQL. # charset: utf8 - # collate: utf8_unicode_ci + # collate: utf8_unicode_ci # When using doctrine/dbal 2.x + # collation: utf8_unicode_ci # When using doctrine/dbal 3.x # engine: InnoDB replicas: @@ -486,7 +487,10 @@ Configuration Reference utf8 + utf8_unicode_ci + + utf8_unicode_ci InnoDB @@ -972,7 +976,8 @@ can configure. The following block shows all possible configuration keys: # Affects schema-tool. If absent, DBAL chooses defaults # based on the platform. charset: utf8 - collate: utf8_unicode_ci + collate: utf8_unicode_ci # when using doctrine/dbal 2.x + collation: utf8_unicode_ci # when using doctrine/dbal 3.x engine: InnoDB .. code-block:: xml @@ -1057,7 +1062,10 @@ can configure. The following block shows all possible configuration keys: bar string utf8 + utf8_unicode_ci + + utf8_unicode_ci InnoDB Acme\HelloBundle\MyCustomType diff --git a/Tests/ConnectionFactoryTest.php b/Tests/ConnectionFactoryTest.php index 116a63de1..87d6b17ec 100644 --- a/Tests/ConnectionFactoryTest.php +++ b/Tests/ConnectionFactoryTest.php @@ -14,6 +14,7 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\MySQLPlatform; use Doctrine\DBAL\Schema\AbstractSchemaManager; +use Doctrine\Deprecations\PHPUnit\VerifyDeprecations; use Exception; use Throwable; @@ -27,6 +28,8 @@ class_exists(\Doctrine\DBAL\Platforms\MySqlPlatform::class); class ConnectionFactoryTest extends TestCase { + use VerifyDeprecations; + public function testContainer(): void { $typesConfig = []; @@ -118,7 +121,10 @@ public function testCollateMapsToCollationForMySql(): void self::markTestSkipped('This test is only relevant for DBAL >= 3.3'); } - $factory = new ConnectionFactory([]); + $factory = new ConnectionFactory([]); + $this->expectDeprecationWithIdentifier( + 'https://github.com/doctrine/dbal/issues/5214' + ); $connection = $factory->createConnection([ 'driver' => 'pdo_mysql', 'defaultTableOptions' => ['collate' => 'my_collation'], diff --git a/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php b/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php index 7681f88a0..25c0f63f9 100644 --- a/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php +++ b/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php @@ -618,11 +618,11 @@ public function testSingleEntityManagerDefaultTableOptions(): void $defaults = $param['defaultTableOptions']; $this->assertArrayHasKey('charset', $defaults); - $this->assertArrayHasKey('collate', $defaults); + $this->assertArrayHasKey('collation', $defaults); $this->assertArrayHasKey('engine', $defaults); $this->assertEquals('utf8mb4', $defaults['charset']); - $this->assertEquals('utf8mb4_unicode_ci', $defaults['collate']); + $this->assertEquals('utf8mb4_unicode_ci', $defaults['collation']); $this->assertEquals('InnoDB', $defaults['engine']); } diff --git a/Tests/DependencyInjection/Fixtures/config/xml/orm_single_em_default_table_options.xml b/Tests/DependencyInjection/Fixtures/config/xml/orm_single_em_default_table_options.xml index a73d62a85..51e1b05e6 100644 --- a/Tests/DependencyInjection/Fixtures/config/xml/orm_single_em_default_table_options.xml +++ b/Tests/DependencyInjection/Fixtures/config/xml/orm_single_em_default_table_options.xml @@ -10,7 +10,7 @@ utf8mb4 - utf8mb4_unicode_ci + utf8mb4_unicode_ci InnoDB diff --git a/Tests/DependencyInjection/Fixtures/config/yml/orm_single_em_default_table_options.yml b/Tests/DependencyInjection/Fixtures/config/yml/orm_single_em_default_table_options.yml index 08f8050bf..4de8fce17 100644 --- a/Tests/DependencyInjection/Fixtures/config/yml/orm_single_em_default_table_options.yml +++ b/Tests/DependencyInjection/Fixtures/config/yml/orm_single_em_default_table_options.yml @@ -6,7 +6,7 @@ doctrine: dbname: db default_table_options: charset: utf8mb4 - collate: utf8mb4_unicode_ci + collation: utf8mb4_unicode_ci engine: InnoDB orm: diff --git a/UPGRADE-2.6.md b/UPGRADE-2.6.md new file mode 100644 index 000000000..c05fec669 --- /dev/null +++ b/UPGRADE-2.6.md @@ -0,0 +1,7 @@ +UPGRADE FROM 2.5 to 2.6 +======================= + +Configuration +------------- + * The `collate` default table option is deprecated in favor of `collation` +