Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 913f249

Browse files
committedOct 1, 2024·
rewrite test without reflection
1 parent 9969a51 commit 913f249

File tree

1 file changed

+60
-29
lines changed

1 file changed

+60
-29
lines changed
 

‎tests/Functional/Schema/SqliteSchemaManagerTest.php

+60-29
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
use Doctrine\DBAL\Platforms\SqlitePlatform;
88
use Doctrine\DBAL\Schema\Column;
99
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
10+
use Doctrine\DBAL\Schema\SqliteSchemaManager;
1011
use Doctrine\DBAL\Schema\Table;
1112
use Doctrine\DBAL\Schema\TableDiff;
1213
use Doctrine\DBAL\Types\BlobType;
1314
use Doctrine\DBAL\Types\Type;
1415
use Doctrine\DBAL\Types\Types;
15-
use ReflectionMethod;
1616

1717
use function array_keys;
1818
use function array_map;
@@ -421,33 +421,64 @@ public function testListTableNoSchemaEmulation(): void
421421
CREATE INDEX i ON `list_table_no_schema_emulation.test` (parent_id);
422422
DDL);
423423

424-
$schemaManager = $this->schemaManager;
425-
$refl = new ReflectionMethod($schemaManager, 'selectTableColumns');
426-
$refl->setAccessible(true);
427-
$res = $refl->invoke($schemaManager, 'main', 'list_table_no_schema_emulation.test')
428-
->fetchAllAssociative();
429-
430-
self::assertSame([
431-
['list_table_no_schema_emulation.test', 'id'],
432-
['list_table_no_schema_emulation.test', 'parent_id'],
433-
], array_map(static fn (array $row) => [$row['table_name'], $row['name']], $res));
434-
435-
$refl = new ReflectionMethod($schemaManager, 'selectIndexColumns');
436-
$refl->setAccessible(true);
437-
$res = $refl->invoke($schemaManager, 'main', 'list_table_no_schema_emulation.test')
438-
->fetchAllAssociative();
439-
440-
self::assertSame([
441-
['list_table_no_schema_emulation.test', 'i'],
442-
], array_map(static fn (array $row) => [$row['table_name'], $row['name']], $res));
443-
444-
$refl = new ReflectionMethod($schemaManager, 'selectForeignKeyColumns');
445-
$refl->setAccessible(true);
446-
$res = $refl->invoke($schemaManager, 'main', 'list_table_no_schema_emulation.test')
447-
->fetchAllAssociative();
448-
449-
self::assertSame([
450-
['list_table_no_schema_emulation.test', 'parent_id', 'id'],
451-
], array_map(static fn (array $row) => [$row['table_name'], $row['from'], $row['to']], $res));
424+
$customSqliteSchemaManager = new class($this->connection, $databasePlatform) extends SqliteSchemaManager {
425+
/**
426+
* @return list<array<string, mixed>>
427+
*/
428+
public function selectTableColumnsWithSchema(): array
429+
{
430+
return $this->selectTableColumns('main', 'list_table_no_schema_emulation.test')
431+
->fetchAllAssociative();
432+
}
433+
434+
/**
435+
* @return list<array<string, mixed>>
436+
*/
437+
public function selectIndexColumnsWithSchema(): array
438+
{
439+
return $this->selectIndexColumns('main', 'list_table_no_schema_emulation.test')
440+
->fetchAllAssociative();
441+
}
442+
443+
/**
444+
* @return list<array<string, mixed>>
445+
*/
446+
public function selectForeignKeyColumnsWithSchema(): array
447+
{
448+
return $this->selectForeignKeyColumns('main', 'list_table_no_schema_emulation.test')
449+
->fetchAllAssociative();
450+
}
451+
};
452+
453+
self::assertSame(
454+
[
455+
['list_table_no_schema_emulation.test', 'id'],
456+
['list_table_no_schema_emulation.test', 'parent_id'],
457+
],
458+
array_map(
459+
static fn (array $row) => [$row['table_name'], $row['name']],
460+
$customSqliteSchemaManager->selectTableColumnsWithSchema()
461+
)
462+
);
463+
464+
self::assertSame(
465+
[
466+
['list_table_no_schema_emulation.test', 'i'],
467+
],
468+
array_map(
469+
static fn (array $row) => [$row['table_name'], $row['name']],
470+
$customSqliteSchemaManager->selectIndexColumnsWithSchema()
471+
)
472+
);
473+
474+
self::assertSame(
475+
[
476+
['list_table_no_schema_emulation.test', 'parent_id', 'id'],
477+
],
478+
array_map(
479+
static fn (array $row) => [$row['table_name'], $row['from'], $row['to']],
480+
$customSqliteSchemaManager->selectForeignKeyColumnsWithSchema()
481+
)
482+
);
452483
}
453484
}

0 commit comments

Comments
 (0)
Please sign in to comment.