From edefcb3b2a32897c77865846bf3afc37bb001877 Mon Sep 17 00:00:00 2001 From: Sergei Tigrov Date: Mon, 10 Feb 2025 10:08:10 +0700 Subject: [PATCH] Add `IndexType` and `IndexMethod` classes (#374) --- CHANGELOG.md | 1 + src/IndexMethod.php | 20 ++++++++++++++++++++ src/IndexType.php | 24 ++++++++++++++++++++++++ tests/CommandTest.php | 8 ++++++++ tests/Provider/CommandProvider.php | 16 ++++++++++++++++ 5 files changed, 69 insertions(+) create mode 100644 src/IndexMethod.php create mode 100644 src/IndexType.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 203b644c0..d8e9faad3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ - Enh #371: Remove `ColumnInterface` (@Tigrov) - Enh #372: Rename `ColumnSchemaInterface` to `ColumnInterface` (@Tigrov) - Enh #373: Replace `DbArrayHelper::getColumn()` with `array_column()` (@Tigrov) +- New #374: Add `IndexType` and `IndexMethod` classes (@Tigrov) ## 1.2.0 March 21, 2024 diff --git a/src/IndexMethod.php b/src/IndexMethod.php new file mode 100644 index 000000000..ab46c0d34 --- /dev/null +++ b/src/IndexMethod.php @@ -0,0 +1,20 @@ +assertSame('mysql:host=127.0.0.1;port=3306', $db->getDriver()->getDsn()); $this->assertSame(['yiitest'], $command->showDatabases()); } + + #[DataProviderExternal(CommandProvider::class, 'createIndex')] + public function testCreateIndex(array $columns, array $indexColumns, string|null $indexType, string|null $indexMethod): void + { + parent::testCreateIndex($columns, $indexColumns, $indexType, $indexMethod); + } } diff --git a/tests/Provider/CommandProvider.php b/tests/Provider/CommandProvider.php index 9f0bcaeaa..6f89dba24 100644 --- a/tests/Provider/CommandProvider.php +++ b/tests/Provider/CommandProvider.php @@ -4,7 +4,23 @@ namespace Yiisoft\Db\Mysql\Tests\Provider; +use Yiisoft\Db\Mysql\Column\ColumnBuilder; +use Yiisoft\Db\Mysql\IndexMethod; +use Yiisoft\Db\Mysql\IndexType; + final class CommandProvider extends \Yiisoft\Db\Tests\Provider\CommandProvider { protected static string $driverName = 'mysql'; + + public static function createIndex(): array + { + return [ + ...parent::createIndex(), + [['col1' => ColumnBuilder::integer()], ['col1'], IndexType::UNIQUE, null], + [['col1' => ColumnBuilder::text()], ['col1'], IndexType::FULLTEXT, null], + [['col1' => 'point NOT NULL'], ['col1'], IndexType::SPATIAL, null], + [['col1' => ColumnBuilder::integer()], ['col1'], null, IndexMethod::BTREE], + [['col1' => ColumnBuilder::integer()], ['col1'], null, IndexMethod::HASH], + ]; + } }