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