|
7 | 7 | use Doctrine\DBAL\Platforms\SqlitePlatform; |
8 | 8 | use Doctrine\DBAL\Schema\Column; |
9 | 9 | use Doctrine\DBAL\Schema\ForeignKeyConstraint; |
| 10 | +use Doctrine\DBAL\Schema\SqliteSchemaManager; |
10 | 11 | use Doctrine\DBAL\Schema\Table; |
11 | 12 | use Doctrine\DBAL\Schema\TableDiff; |
12 | 13 | use Doctrine\DBAL\Types\BlobType; |
13 | 14 | use Doctrine\DBAL\Types\Type; |
14 | 15 | use Doctrine\DBAL\Types\Types; |
15 | 16 |
|
16 | 17 | use function array_keys; |
| 18 | +use function array_map; |
17 | 19 | use function array_shift; |
18 | 20 | use function assert; |
19 | 21 | use function dirname; |
@@ -398,6 +400,82 @@ public function testShorthandInForeignKeyReferenceWithMultipleColumns(): void |
398 | 400 | ); |
399 | 401 | } |
400 | 402 |
|
| 403 | + public function testListTableNoSchemaEmulation(): void |
| 404 | + { |
| 405 | + $databasePlatform = $this->connection->getDatabasePlatform(); |
| 406 | + assert($databasePlatform instanceof SqlitePlatform); |
| 407 | + $databasePlatform->disableSchemaEmulation(); |
| 408 | + |
| 409 | + $this->dropTableIfExists('`list_table_no_schema_emulation.test`'); |
| 410 | + |
| 411 | + $this->connection->executeStatement(<<<'DDL' |
| 412 | + CREATE TABLE `list_table_no_schema_emulation.test` ( |
| 413 | + id INTEGER, |
| 414 | + parent_id INTEGER, |
| 415 | + PRIMARY KEY (id), |
| 416 | + FOREIGN KEY (parent_id) REFERENCES `list_table_no_schema_emulation.test` (id) |
| 417 | + ); |
| 418 | + DDL); |
| 419 | + |
| 420 | + $this->connection->executeStatement(<<<'DDL' |
| 421 | + CREATE INDEX i ON `list_table_no_schema_emulation.test` (parent_id); |
| 422 | + DDL); |
| 423 | + |
| 424 | + $customSqliteSchemaManager = new class ($this->connection, $databasePlatform) extends SqliteSchemaManager { |
| 425 | + /** @return list<array<string, mixed>> */ |
| 426 | + public function selectTableColumnsWithSchema(): array |
| 427 | + { |
| 428 | + return $this->selectTableColumns('main', 'list_table_no_schema_emulation.test') |
| 429 | + ->fetchAllAssociative(); |
| 430 | + } |
| 431 | + |
| 432 | + /** @return list<array<string, mixed>> */ |
| 433 | + public function selectIndexColumnsWithSchema(): array |
| 434 | + { |
| 435 | + return $this->selectIndexColumns('main', 'list_table_no_schema_emulation.test') |
| 436 | + ->fetchAllAssociative(); |
| 437 | + } |
| 438 | + |
| 439 | + /** @return list<array<string, mixed>> */ |
| 440 | + public function selectForeignKeyColumnsWithSchema(): array |
| 441 | + { |
| 442 | + return $this->selectForeignKeyColumns('main', 'list_table_no_schema_emulation.test') |
| 443 | + ->fetchAllAssociative(); |
| 444 | + } |
| 445 | + }; |
| 446 | + |
| 447 | + self::assertSame( |
| 448 | + [ |
| 449 | + ['list_table_no_schema_emulation.test', 'id'], |
| 450 | + ['list_table_no_schema_emulation.test', 'parent_id'], |
| 451 | + ], |
| 452 | + array_map( |
| 453 | + static fn (array $row) => [$row['table_name'], $row['name']], |
| 454 | + $customSqliteSchemaManager->selectTableColumnsWithSchema(), |
| 455 | + ), |
| 456 | + ); |
| 457 | + |
| 458 | + self::assertSame( |
| 459 | + [ |
| 460 | + ['list_table_no_schema_emulation.test', 'i'], |
| 461 | + ], |
| 462 | + array_map( |
| 463 | + static fn (array $row) => [$row['table_name'], $row['name']], |
| 464 | + $customSqliteSchemaManager->selectIndexColumnsWithSchema(), |
| 465 | + ), |
| 466 | + ); |
| 467 | + |
| 468 | + self::assertSame( |
| 469 | + [ |
| 470 | + ['list_table_no_schema_emulation.test', 'parent_id', 'id'], |
| 471 | + ], |
| 472 | + array_map( |
| 473 | + static fn (array $row) => [$row['table_name'], $row['from'], $row['to']], |
| 474 | + $customSqliteSchemaManager->selectForeignKeyColumnsWithSchema(), |
| 475 | + ), |
| 476 | + ); |
| 477 | + } |
| 478 | + |
401 | 479 | /** |
402 | 480 | * This test duplicates {@see parent::testCommentInTable()} with the only difference that the name of the table |
403 | 481 | * being created is quoted. It is only meant to cover the logic of parsing the SQLite CREATE TABLE statement |
|
0 commit comments