|
12 | 12 | use Doctrine\DBAL\Schema\ForeignKeyConstraint; |
13 | 13 | use Doctrine\DBAL\Schema\Index; |
14 | 14 | use Doctrine\DBAL\Schema\PrimaryKeyConstraint; |
| 15 | +use Doctrine\DBAL\Schema\SQLiteSchemaManager; |
15 | 16 | use Doctrine\DBAL\Schema\Table; |
16 | 17 | use Doctrine\DBAL\Schema\TableDiff; |
17 | 18 | use Doctrine\DBAL\Types\BlobType; |
|
20 | 21 | use Doctrine\Deprecations\PHPUnit\VerifyDeprecations; |
21 | 22 |
|
22 | 23 | use function array_keys; |
| 24 | +use function array_map; |
23 | 25 | use function array_shift; |
24 | 26 | use function array_values; |
| 27 | +use function assert; |
25 | 28 |
|
26 | 29 | class SQLiteSchemaManagerTest extends SchemaManagerFunctionalTestCase |
27 | 30 | { |
@@ -495,6 +498,81 @@ public function testShorthandInForeignKeyReferenceWithMultipleColumns(): void |
495 | 498 | ); |
496 | 499 | } |
497 | 500 |
|
| 501 | + public function testListTableNoSchemaEmulation(): void |
| 502 | + { |
| 503 | + $databasePlatform = $this->connection->getDatabasePlatform(); |
| 504 | + assert($databasePlatform instanceof SQLitePlatform); |
| 505 | + |
| 506 | + $this->dropTableIfExists('`list_table_no_schema_emulation.test`'); |
| 507 | + |
| 508 | + $this->connection->executeStatement(<<<'DDL' |
| 509 | + CREATE TABLE `list_table_no_schema_emulation.test` ( |
| 510 | + id INTEGER, |
| 511 | + parent_id INTEGER, |
| 512 | + PRIMARY KEY (id), |
| 513 | + FOREIGN KEY (parent_id) REFERENCES `list_table_no_schema_emulation.test` (id) |
| 514 | + ); |
| 515 | + DDL); |
| 516 | + |
| 517 | + $this->connection->executeStatement(<<<'DDL' |
| 518 | + CREATE INDEX i ON `list_table_no_schema_emulation.test` (parent_id); |
| 519 | + DDL); |
| 520 | + |
| 521 | + $customSQLiteSchemaManager = new class ($this->connection, $databasePlatform) extends SQLiteSchemaManager { |
| 522 | + /** @return list<array<string, mixed>> */ |
| 523 | + public function selectTableColumnsWithSchema(): array |
| 524 | + { |
| 525 | + return $this->selectTableColumns('main', 'list_table_no_schema_emulation.test') |
| 526 | + ->fetchAllAssociative(); |
| 527 | + } |
| 528 | + |
| 529 | + /** @return list<array<string, mixed>> */ |
| 530 | + public function selectIndexColumnsWithSchema(): array |
| 531 | + { |
| 532 | + return $this->selectIndexColumns('main', 'list_table_no_schema_emulation.test') |
| 533 | + ->fetchAllAssociative(); |
| 534 | + } |
| 535 | + |
| 536 | + /** @return list<array<string, mixed>> */ |
| 537 | + public function selectForeignKeyColumnsWithSchema(): array |
| 538 | + { |
| 539 | + return $this->selectForeignKeyColumns('main', 'list_table_no_schema_emulation.test') |
| 540 | + ->fetchAllAssociative(); |
| 541 | + } |
| 542 | + }; |
| 543 | + |
| 544 | + self::assertSame( |
| 545 | + [ |
| 546 | + ['list_table_no_schema_emulation.test', 'id'], |
| 547 | + ['list_table_no_schema_emulation.test', 'parent_id'], |
| 548 | + ], |
| 549 | + array_map( |
| 550 | + static fn (array $row) => [$row['table_name'], $row['name']], |
| 551 | + $customSQLiteSchemaManager->selectTableColumnsWithSchema(), |
| 552 | + ), |
| 553 | + ); |
| 554 | + |
| 555 | + self::assertSame( |
| 556 | + [ |
| 557 | + ['list_table_no_schema_emulation.test', 'i'], |
| 558 | + ], |
| 559 | + array_map( |
| 560 | + static fn (array $row) => [$row['table_name'], $row['name']], |
| 561 | + $customSQLiteSchemaManager->selectIndexColumnsWithSchema(), |
| 562 | + ), |
| 563 | + ); |
| 564 | + |
| 565 | + self::assertSame( |
| 566 | + [ |
| 567 | + ['list_table_no_schema_emulation.test', 'parent_id', 'id'], |
| 568 | + ], |
| 569 | + array_map( |
| 570 | + static fn (array $row) => [$row['table_name'], $row['from'], $row['to']], |
| 571 | + $customSQLiteSchemaManager->selectForeignKeyColumnsWithSchema(), |
| 572 | + ), |
| 573 | + ); |
| 574 | + } |
| 575 | + |
498 | 576 | /** |
499 | 577 | * This test duplicates {@see parent::testCommentInTable()} with the only difference that the name of the table |
500 | 578 | * being created is quoted. It is only meant to cover the logic of parsing the SQLite CREATE TABLE statement |
|
0 commit comments