Skip to content

Commit ee4cf6f

Browse files
committed
rewrite test without reflection
1 parent 9969a51 commit ee4cf6f

File tree

1 file changed

+54
-29
lines changed

1 file changed

+54
-29
lines changed

tests/Functional/Schema/SqliteSchemaManagerTest.php

+54-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,58 @@ 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+
/** @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+
);
452477
}
453478
}

0 commit comments

Comments
 (0)