|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Doctrine\DBAL\Tests\Functional\Driver; |
| 6 | + |
| 7 | +use Doctrine\DBAL\Schema\Column; |
| 8 | +use Doctrine\DBAL\Schema\Schema; |
| 9 | +use Doctrine\DBAL\Schema\Table; |
| 10 | +use Doctrine\DBAL\Tests\FunctionalTestCase; |
| 11 | +use Doctrine\DBAL\Tests\TestUtil; |
| 12 | +use Doctrine\DBAL\Types\StringType; |
| 13 | +use PHPUnit\Framework\Attributes\DataProvider; |
| 14 | + |
| 15 | +class DBAL6146Test extends FunctionalTestCase |
| 16 | +{ |
| 17 | + protected function setUp(): void |
| 18 | + { |
| 19 | + parent::setUp(); |
| 20 | + |
| 21 | + if (TestUtil::isDriverOneOf('pdo_mysql', 'mysqli')) { |
| 22 | + return; |
| 23 | + } |
| 24 | + |
| 25 | + self::markTestSkipped('This test requires the pdo_mysql or the mysqli driver.'); |
| 26 | + } |
| 27 | + |
| 28 | + /** @return iterable<array{array<string,string>,array<string,string>}> */ |
| 29 | + public static function equivalentCharsetAndCollationProvider(): iterable |
| 30 | + { |
| 31 | + yield [[], []]; |
| 32 | + yield [['charset' => 'utf8'], ['charset' => 'utf8']]; |
| 33 | + yield [['charset' => 'utf8'], ['charset' => 'utf8mb3']]; |
| 34 | + yield [['charset' => 'utf8mb3'], ['charset' => 'utf8']]; |
| 35 | + yield [['charset' => 'utf8mb3'], ['charset' => 'utf8mb3']]; |
| 36 | + yield [['collation' => 'utf8_unicode_ci'], ['collation' => 'utf8_unicode_ci']]; |
| 37 | + yield [['collation' => 'utf8_unicode_ci'], ['collation' => 'utf8mb3_unicode_ci']]; |
| 38 | + yield [['collation' => 'utf8mb3_unicode_ci'], ['collation' => 'utf8mb3_unicode_ci']]; |
| 39 | + yield [['collation' => 'utf8mb3_unicode_ci'], ['collation' => 'utf8_unicode_ci']]; |
| 40 | + yield [ |
| 41 | + ['charset' => 'utf8', 'collation' => 'utf8_unicode_ci'], |
| 42 | + ['charset' => 'utf8', 'collation' => 'utf8_unicode_ci'], |
| 43 | + ]; |
| 44 | + |
| 45 | + yield [ |
| 46 | + ['charset' => 'utf8', 'collation' => 'utf8_unicode_ci'], |
| 47 | + ['charset' => 'utf8mb3', 'collation' => 'utf8mb3_unicode_ci'], |
| 48 | + ]; |
| 49 | + |
| 50 | + yield [ |
| 51 | + ['charset' => 'utf8mb3', 'collation' => 'utf8mb3_unicode_ci'], |
| 52 | + ['charset' => 'utf8', 'collation' => 'utf8_unicode_ci'], |
| 53 | + ]; |
| 54 | + |
| 55 | + yield [ |
| 56 | + ['charset' => 'utf8mb3', 'collation' => 'utf8mb3_unicode_ci'], |
| 57 | + ['charset' => 'utf8mb3', 'collation' => 'utf8mb3_unicode_ci'], |
| 58 | + ]; |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * @param array<string,string> $options1 |
| 63 | + * @param array<string,string> $options2 |
| 64 | + */ |
| 65 | + #[DataProvider('equivalentCharsetAndCollationProvider')] |
| 66 | + public function testThereAreNoRedundantAlterTableStatements(array $options1, array $options2): void |
| 67 | + { |
| 68 | + $column1 = new Column('bar', new StringType(), ['length' => 32, 'platformOptions' => $options1]); |
| 69 | + $table1 = new Table(name: 'foo6146', columns: [$column1]); |
| 70 | + |
| 71 | + $column2 = new Column('bar', new StringType(), ['length' => 32, 'platformOptions' => $options2]); |
| 72 | + $table2 = new Table(name: 'foo6146', columns: [$column2]); |
| 73 | + |
| 74 | + $this->dropAndCreateTable($table1); |
| 75 | + |
| 76 | + $schemaManager = $this->connection->createSchemaManager(); |
| 77 | + $oldSchema = $schemaManager->introspectSchema(); |
| 78 | + $newSchema = new Schema([$table2]); |
| 79 | + $comparator = $schemaManager->createComparator(); |
| 80 | + $schemaDiff = $comparator->compareSchemas($oldSchema, $newSchema); |
| 81 | + $alteredTables = $schemaDiff->getAlteredTables(); |
| 82 | + |
| 83 | + self::assertEmpty($alteredTables); |
| 84 | + } |
| 85 | +} |
0 commit comments