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 913f249
Showing 1 changed file with 60 additions and 29 deletions.
89 changes: 60 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,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 {

Check failure on line 424 in tests/Functional/Schema/SqliteSchemaManagerTest.php

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (8.3)

Expected 1 space after class keyword; 0 found
/**

Check failure on line 425 in tests/Functional/Schema/SqliteSchemaManagerTest.php

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (8.3)

Found multi-line doc comment with single line content, use one-line doc comment instead.
* @return list<array<string, mixed>>
*/
public function selectTableColumnsWithSchema(): array
{
return $this->selectTableColumns('main', 'list_table_no_schema_emulation.test')
->fetchAllAssociative();
}

/**

Check failure on line 434 in tests/Functional/Schema/SqliteSchemaManagerTest.php

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (8.3)

Found multi-line doc comment with single line content, use one-line doc comment instead.
* @return list<array<string, mixed>>
*/
public function selectIndexColumnsWithSchema(): array
{
return $this->selectIndexColumns('main', 'list_table_no_schema_emulation.test')
->fetchAllAssociative();
}

/**

Check failure on line 443 in tests/Functional/Schema/SqliteSchemaManagerTest.php

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (8.3)

Found multi-line doc comment with single line content, use one-line doc comment instead.
* @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()

Check failure on line 460 in tests/Functional/Schema/SqliteSchemaManagerTest.php

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (8.3)

Multi-line function calls must have a trailing comma after the last parameter.
)

Check failure on line 461 in tests/Functional/Schema/SqliteSchemaManagerTest.php

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (8.3)

Multi-line function calls must have a trailing comma after the last parameter.
);

self::assertSame(
[
['list_table_no_schema_emulation.test', 'i'],
],
array_map(
static fn (array $row) => [$row['table_name'], $row['name']],
$customSqliteSchemaManager->selectIndexColumnsWithSchema()

Check failure on line 470 in tests/Functional/Schema/SqliteSchemaManagerTest.php

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (8.3)

Multi-line function calls must have a trailing comma after the last parameter.
)

Check failure on line 471 in tests/Functional/Schema/SqliteSchemaManagerTest.php

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (8.3)

Multi-line function calls must have a trailing comma after the last parameter.
);

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()

Check failure on line 480 in tests/Functional/Schema/SqliteSchemaManagerTest.php

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (8.3)

Multi-line function calls must have a trailing comma after the last parameter.
)

Check failure on line 481 in tests/Functional/Schema/SqliteSchemaManagerTest.php

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (8.3)

Multi-line function calls must have a trailing comma after the last parameter.
);
}
}

0 comments on commit 913f249

Please sign in to comment.