From 060837267e110df3902e542cfe196210949ce60b Mon Sep 17 00:00:00 2001 From: Leo Feyer Date: Wed, 2 Jan 2019 14:41:37 +0100 Subject: [PATCH] Cast the index length to int in the MySqlSchemaManager class --- lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php | 2 +- .../Functional/Schema/MySqlSchemaManagerTest.php | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php index 85b5b5c4734..9f50517e1d4 100644 --- a/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php @@ -68,7 +68,7 @@ protected function _getPortableTableIndexesList($tableIndexes, $tableName = null } elseif (strpos($v['index_type'], 'SPATIAL') !== false) { $v['flags'] = ['SPATIAL']; } - $v['length'] = $v['sub_part'] ?? null; + $v['length'] = isset($v['sub_part']) ? (int) $v['sub_part'] : null; $tableIndexes[$k] = $v; } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php index ef457f0c590..9cb4b7e51b1 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php @@ -107,6 +107,19 @@ public function testSpatialIndex() self::assertTrue($indexes['s_index']->hasFlag('spatial')); } + public function testIndexWithLength() : void + { + $table = new Table('index_length'); + $table->addColumn('text', 'string', ['length' => 255]); + $table->addIndex(['text'], 'text_index', [], ['lengths' => [128]]); + + $this->schemaManager->dropAndCreateTable($table); + + $indexes = $this->schemaManager->listTableIndexes('index_length'); + self::assertArrayHasKey('text_index', $indexes); + self::assertSame([128], $indexes['text_index']->getOption('lengths')); + } + /** * @group DBAL-400 */