diff --git a/tests/Functional/Driver/DBAL6146Test.php b/tests/Functional/Driver/DBAL6146Test.php new file mode 100644 index 00000000000..2d73a06595e --- /dev/null +++ b/tests/Functional/Driver/DBAL6146Test.php @@ -0,0 +1,85 @@ +,array}> */ + public static function equivalentCharsetAndCollationProvider(): iterable + { + yield [[], []]; + yield [['charset' => 'utf8'], ['charset' => 'utf8']]; + yield [['charset' => 'utf8'], ['charset' => 'utf8mb3']]; + yield [['charset' => 'utf8mb3'], ['charset' => 'utf8']]; + yield [['charset' => 'utf8mb3'], ['charset' => 'utf8mb3']]; + yield [['collation' => 'utf8_unicode_ci'], ['collation' => 'utf8_unicode_ci']]; + yield [['collation' => 'utf8_unicode_ci'], ['collation' => 'utf8mb3_unicode_ci']]; + yield [['collation' => 'utf8mb3_unicode_ci'], ['collation' => 'utf8mb3_unicode_ci']]; + yield [['collation' => 'utf8mb3_unicode_ci'], ['collation' => 'utf8_unicode_ci']]; + yield [ + ['charset' => 'utf8', 'collation' => 'utf8_unicode_ci'], + ['charset' => 'utf8', 'collation' => 'utf8_unicode_ci'], + ]; + + yield [ + ['charset' => 'utf8', 'collation' => 'utf8_unicode_ci'], + ['charset' => 'utf8mb3', 'collation' => 'utf8mb3_unicode_ci'], + ]; + + yield [ + ['charset' => 'utf8mb3', 'collation' => 'utf8mb3_unicode_ci'], + ['charset' => 'utf8', 'collation' => 'utf8_unicode_ci'], + ]; + + yield [ + ['charset' => 'utf8mb3', 'collation' => 'utf8mb3_unicode_ci'], + ['charset' => 'utf8mb3', 'collation' => 'utf8mb3_unicode_ci'], + ]; + } + + /** + * @param array $options1 + * @param array $options2 + */ + #[DataProvider('equivalentCharsetAndCollationProvider')] + public function testThereAreNoRedundantAlterTableStatements(array $options1, array $options2): void + { + $column1 = new Column('bar', new StringType(), ['length' => 32, 'platformOptions' => $options1]); + $table1 = new Table(name: 'foo6146', columns: [$column1]); + + $column2 = new Column('bar', new StringType(), ['length' => 32, 'platformOptions' => $options2]); + $table2 = new Table(name: 'foo6146', columns: [$column2]); + + $this->dropAndCreateTable($table1); + + $schemaManager = $this->connection->createSchemaManager(); + $oldSchema = $schemaManager->introspectSchema(); + $newSchema = new Schema([$table2]); + $comparator = $schemaManager->createComparator(); + $schemaDiff = $comparator->compareSchemas($oldSchema, $newSchema); + $alteredTables = $schemaDiff->getAlteredTables(); + + self::assertEmpty($alteredTables); + } +}