|
4 | 4 |
|
5 | 5 | namespace Yiisoft\Db\Oracle\Tests; |
6 | 6 |
|
| 7 | +use PHPUnit\Framework\Attributes\DataProviderExternal; |
7 | 8 | use ReflectionException; |
8 | 9 | use Throwable; |
9 | 10 | use Yiisoft\Db\Constant\ColumnType; |
|
13 | 14 | use Yiisoft\Db\Exception\InvalidCallException; |
14 | 15 | use Yiisoft\Db\Exception\InvalidConfigException; |
15 | 16 | use Yiisoft\Db\Exception\NotSupportedException; |
| 17 | +use Yiisoft\Db\Oracle\Column\ColumnBuilder; |
16 | 18 | use Yiisoft\Db\Oracle\Connection; |
17 | 19 | use Yiisoft\Db\Oracle\Dsn; |
18 | 20 | use Yiisoft\Db\Oracle\Driver; |
| 21 | +use Yiisoft\Db\Oracle\IndexType; |
| 22 | +use Yiisoft\Db\Oracle\Tests\Provider\CommandProvider; |
19 | 23 | use Yiisoft\Db\Oracle\Tests\Support\TestTrait; |
20 | 24 | use Yiisoft\Db\Query\Query; |
21 | 25 | use Yiisoft\Db\Tests\Common\CommonCommandTest; |
|
26 | 30 | use function is_resource; |
27 | 31 | use function str_pad; |
28 | 32 | use function stream_get_contents; |
| 33 | +use function version_compare; |
29 | 34 |
|
30 | 35 | /** |
31 | 36 | * @group oracle |
@@ -636,4 +641,47 @@ public function testShowDatabases(): void |
636 | 641 | $this->assertSame('oci:dbname=localhost:1521', $db->getDriver()->getDsn()); |
637 | 642 | $this->assertSame(['YIITEST'], $command->showDatabases()); |
638 | 643 | } |
| 644 | + |
| 645 | + #[DataProviderExternal(CommandProvider::class, 'createIndex')] |
| 646 | + public function testCreateIndex(array $columns, array $indexColumns, string|null $indexType, string|null $indexMethod): void |
| 647 | + { |
| 648 | + parent::testCreateIndex($columns, $indexColumns, $indexType, $indexMethod); |
| 649 | + } |
| 650 | + |
| 651 | + public function testCreateSearchIndex() |
| 652 | + { |
| 653 | + $db = $this->getConnection(); |
| 654 | + |
| 655 | + if (version_compare($db->getServerInfo()->getVersion(), '21', '<')) { |
| 656 | + $this->markTestSkipped('Search index is supported since Oracle 21'); |
| 657 | + } |
| 658 | + |
| 659 | + $command = $db->createCommand(); |
| 660 | + $schema = $db->getSchema(); |
| 661 | + |
| 662 | + $tableName = 'test_create_index'; |
| 663 | + $indexName = 'test_index_name'; |
| 664 | + |
| 665 | + if ($schema->getTableSchema($tableName) !== null) { |
| 666 | + $command->dropTable($tableName)->execute(); |
| 667 | + } |
| 668 | + |
| 669 | + $command->createTable($tableName, ['col1' => ColumnBuilder::text()])->execute(); |
| 670 | + $command->createIndex($tableName, $indexName, ['col1'], IndexType::SEARCH)->execute(); |
| 671 | + |
| 672 | + $this->assertCount(2, $schema->getTableIndexes($tableName)); |
| 673 | + |
| 674 | + $index = $schema->getTableIndexes($tableName)[0]; |
| 675 | + |
| 676 | + $this->assertSame(['col1'], $index->getColumnNames()); |
| 677 | + $this->assertFalse($index->isUnique()); |
| 678 | + $this->assertFalse($index->isPrimary()); |
| 679 | + |
| 680 | + $sysIndex = $schema->getTableIndexes($tableName)[1]; |
| 681 | + $this->assertSame([], $sysIndex->getColumnNames()); |
| 682 | + $this->assertTrue($sysIndex->isUnique()); |
| 683 | + $this->assertFalse($sysIndex->isPrimary()); |
| 684 | + |
| 685 | + $db->close(); |
| 686 | + } |
639 | 687 | } |
0 commit comments