From 0a999f1422993d83ab69a917e5968502877e1894 Mon Sep 17 00:00:00 2001 From: Ishan Vyas Date: Mon, 16 Feb 2026 14:51:22 +0530 Subject: [PATCH] Add test to show collation issue When collation is set on field the createTable() generates wrong sql which leads to wrong collation on the field when table is created. --- .../TestCase/Db/Adapter/MysqlAdapterTest.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/TestCase/Db/Adapter/MysqlAdapterTest.php b/tests/TestCase/Db/Adapter/MysqlAdapterTest.php index f0d3a3bc..138148fc 100644 --- a/tests/TestCase/Db/Adapter/MysqlAdapterTest.php +++ b/tests/TestCase/Db/Adapter/MysqlAdapterTest.php @@ -18,6 +18,7 @@ use Migrations\Db\Table\Column; use Migrations\Db\Table\ForeignKey; use Migrations\Db\Table\Index; +use Migrations\Db\Table\Table as TableMetadata; use PDO; use PDOException; use PHPUnit\Framework\Attributes\DataProvider; @@ -166,6 +167,29 @@ public function testCreateTable() $this->assertFalse($columns[0]->isSigned()); } + public function testCreateTableMethod() + { + $table = new TableMetadata('custom_collation', ['id' => false, 'primary_key' => ['id'], 'collation' => 'utf8mb4_unicode_ci']); + + $columnId = new Column(); + $columnId + ->setName('id') + ->setType('uuid') + ->setCollation('ascii_general_ci') + ->setEncoding('ascii'); + $columnName = new Column(); + $columnName + ->setName('name') + ->setType('text'); + $columns = [$columnId, $columnName]; + + $this->adapter->createTable($table, $columns); + + $rows = $this->adapter->fetchAll('SHOW FULL COLUMNS FROM custom_collation'); + $this->assertEquals('ascii_general_ci', $rows[0]['Collation']); // specified collation is set + $this->assertEquals('utf8mb4_unicode_ci', $rows[1]['Collation']); // if not specified uses table's collation + } + public function testCreateTableWithComment() { $tableComment = 'Table comment';