|
6 | 6 | use Doctrine\DBAL\Platforms\AbstractPlatform;
|
7 | 7 | use Doctrine\DBAL\Platforms\SqlitePlatform;
|
8 | 8 | use Doctrine\DBAL\Schema\Column;
|
| 9 | +use Doctrine\DBAL\Schema\Index; |
9 | 10 | use Doctrine\DBAL\Schema\Table;
|
10 | 11 | use Doctrine\DBAL\Schema\TableDiff;
|
11 | 12 | use Doctrine\DBAL\TransactionIsolationLevel;
|
12 | 13 | use Doctrine\DBAL\Types\Type;
|
13 | 14 | use Doctrine\DBAL\Types\Types;
|
14 | 15 |
|
| 16 | +use function assert; |
| 17 | +use function implode; |
| 18 | +use function is_string; |
| 19 | + |
15 | 20 | /** @extends AbstractPlatformTestCase<SqlitePlatform> */
|
16 | 21 | class SqlitePlatformTest extends AbstractPlatformTestCase
|
17 | 22 | {
|
@@ -250,6 +255,37 @@ public function getGenerateUniqueIndexSql(): string
|
250 | 255 | return 'CREATE UNIQUE INDEX index_name ON test (test, test2)';
|
251 | 256 | }
|
252 | 257 |
|
| 258 | + public function testGeneratesIndexCreationSqlWithSchema(): void |
| 259 | + { |
| 260 | + $indexDef = new Index('i', ['a', 'b']); |
| 261 | + |
| 262 | + self::assertSame( |
| 263 | + 'CREATE INDEX main.i ON mytable (a, b)', |
| 264 | + $this->platform->getCreateIndexSQL($indexDef, 'main.mytable'), |
| 265 | + ); |
| 266 | + } |
| 267 | + |
| 268 | + public function testGeneratesPrimaryIndexCreationSqlWithSchema(): void |
| 269 | + { |
| 270 | + $primaryIndexDef = new Index('i2', ['a', 'b'], false, true); |
| 271 | + |
| 272 | + self::assertSame( |
| 273 | + 'TEST: main.mytable, i2 - a, b', |
| 274 | + (new class () extends SqlitePlatform { |
| 275 | + /** |
| 276 | + * {@inheritDoc} |
| 277 | + */ |
| 278 | + public function getCreatePrimaryKeySQL(Index $index, $table) |
| 279 | + { |
| 280 | + assert(is_string($table)); |
| 281 | + |
| 282 | + return 'TEST: ' . $table . ', ' . $index->getName() |
| 283 | + . ' - ' . implode(', ', $index->getColumns()); |
| 284 | + } |
| 285 | + })->getCreateIndexSQL($primaryIndexDef, 'main.mytable'), |
| 286 | + ); |
| 287 | + } |
| 288 | + |
253 | 289 | public function testGeneratesForeignKeyCreationSql(): void
|
254 | 290 | {
|
255 | 291 | $this->expectException(Exception::class);
|
|
0 commit comments