Skip to content

Commit

Permalink
rewrite test without reflection
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Oct 1, 2024
1 parent 9969a51 commit ee4cf6f
Showing 1 changed file with 54 additions and 29 deletions.
83 changes: 54 additions & 29 deletions tests/Functional/Schema/SqliteSchemaManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -421,33 +421,58 @@ 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<array<string, mixed>> */
public function selectTableColumnsWithSchema(): array
{
return $this->selectTableColumns('main', 'list_table_no_schema_emulation.test')
->fetchAllAssociative();
}

/** @return list<array<string, mixed>> */
public function selectIndexColumnsWithSchema(): array
{
return $this->selectIndexColumns('main', 'list_table_no_schema_emulation.test')
->fetchAllAssociative();
}

/** @return list<array<string, mixed>> */
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(),
),
);
}
}

0 comments on commit ee4cf6f

Please sign in to comment.