From 913f249961851a5613f89addc07526ff7aeb1445 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Tue, 1 Oct 2024 14:41:35 +0200 Subject: [PATCH] rewrite test without reflection --- .../Schema/SqliteSchemaManagerTest.php | 89 +++++++++++++------ 1 file changed, 60 insertions(+), 29 deletions(-) diff --git a/tests/Functional/Schema/SqliteSchemaManagerTest.php b/tests/Functional/Schema/SqliteSchemaManagerTest.php index 4fbb000b934..a006adf2118 100644 --- a/tests/Functional/Schema/SqliteSchemaManagerTest.php +++ b/tests/Functional/Schema/SqliteSchemaManagerTest.php @@ -7,12 +7,12 @@ use Doctrine\DBAL\Platforms\SqlitePlatform; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\ForeignKeyConstraint; +use Doctrine\DBAL\Schema\SqliteSchemaManager; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Types\BlobType; use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Types; -use ReflectionMethod; use function array_keys; use function array_map; @@ -421,33 +421,64 @@ public function testListTableNoSchemaEmulation(): void CREATE INDEX i ON `list_table_no_schema_emulation.test` (parent_id); DDL); - $schemaManager = $this->schemaManager; - $refl = new ReflectionMethod($schemaManager, 'selectTableColumns'); - $refl->setAccessible(true); - $res = $refl->invoke($schemaManager, 'main', 'list_table_no_schema_emulation.test') - ->fetchAllAssociative(); - - self::assertSame([ - ['list_table_no_schema_emulation.test', 'id'], - ['list_table_no_schema_emulation.test', 'parent_id'], - ], array_map(static fn (array $row) => [$row['table_name'], $row['name']], $res)); - - $refl = new ReflectionMethod($schemaManager, 'selectIndexColumns'); - $refl->setAccessible(true); - $res = $refl->invoke($schemaManager, 'main', 'list_table_no_schema_emulation.test') - ->fetchAllAssociative(); - - self::assertSame([ - ['list_table_no_schema_emulation.test', 'i'], - ], array_map(static fn (array $row) => [$row['table_name'], $row['name']], $res)); - - $refl = new ReflectionMethod($schemaManager, 'selectForeignKeyColumns'); - $refl->setAccessible(true); - $res = $refl->invoke($schemaManager, 'main', 'list_table_no_schema_emulation.test') - ->fetchAllAssociative(); - - self::assertSame([ - ['list_table_no_schema_emulation.test', 'parent_id', 'id'], - ], array_map(static fn (array $row) => [$row['table_name'], $row['from'], $row['to']], $res)); + $customSqliteSchemaManager = new class($this->connection, $databasePlatform) extends SqliteSchemaManager { + /** + * @return list> + */ + public function selectTableColumnsWithSchema(): array + { + return $this->selectTableColumns('main', 'list_table_no_schema_emulation.test') + ->fetchAllAssociative(); + } + + /** + * @return list> + */ + public function selectIndexColumnsWithSchema(): array + { + return $this->selectIndexColumns('main', 'list_table_no_schema_emulation.test') + ->fetchAllAssociative(); + } + + /** + * @return list> + */ + public function selectForeignKeyColumnsWithSchema(): array + { + return $this->selectForeignKeyColumns('main', 'list_table_no_schema_emulation.test') + ->fetchAllAssociative(); + } + }; + + self::assertSame( + [ + ['list_table_no_schema_emulation.test', 'id'], + ['list_table_no_schema_emulation.test', 'parent_id'], + ], + array_map( + static fn (array $row) => [$row['table_name'], $row['name']], + $customSqliteSchemaManager->selectTableColumnsWithSchema() + ) + ); + + self::assertSame( + [ + ['list_table_no_schema_emulation.test', 'i'], + ], + array_map( + static fn (array $row) => [$row['table_name'], $row['name']], + $customSqliteSchemaManager->selectIndexColumnsWithSchema() + ) + ); + + self::assertSame( + [ + ['list_table_no_schema_emulation.test', 'parent_id', 'id'], + ], + array_map( + static fn (array $row) => [$row['table_name'], $row['from'], $row['to']], + $customSqliteSchemaManager->selectForeignKeyColumnsWithSchema() + ) + ); } }