Skip to content

Commit

Permalink
Fix for Issue doctrine#1487
Browse files Browse the repository at this point in the history
  • Loading branch information
cristi-contiu committed Feb 28, 2025
1 parent aaff3f4 commit acfad01
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/Generator/DiffGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ private function createToSchema(): Schema
*/
private function resolveTableName(string $name): string
{
if ($this->platform->supportsSchemas()) {
return $name;
}

$pos = strpos($name, '.');

return $pos === false ? $name : substr($name, $pos + 1);
Expand Down
23 changes: 20 additions & 3 deletions tests/Generator/DiffGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

use function array_map;
use function array_values;
use function preg_match;

Expand Down Expand Up @@ -183,7 +184,12 @@ public function testGenerateFromEmptySchema(): void
self::assertSame('path2', $this->migrationDiffGenerator->generate('2345', null, false, 120, true, true));
}

public function testGenerateAppliesDbalSchemaAssetsFilterOnQualifiedTableName(): void
/**
* @param array<int, string> $expectedTables
*
* @dataProvider getGenerateAppliesFilterOnMappedSchemaData
*/
public function testGenerateAppliesFilterOnMappedSchema(bool $platformSupportsSchemas, array $expectedTables): void
{
// a standard Regex SchemaAssetsFilter already registered on the DBAL
$dbalSchemaAssetsFilter = static function ($assetName): bool {
Expand All @@ -198,7 +204,7 @@ public function testGenerateAppliesDbalSchemaAssetsFilterOnQualifiedTableName():

$this->platform->expects(self::atLeast(2))
->method('supportsSchemas')
->willReturn(true);
->willReturn($platformSupportsSchemas);

$this->schemaManager->expects(self::once())
->method('introspectSchema')
Expand All @@ -225,7 +231,18 @@ public function testGenerateAppliesDbalSchemaAssetsFilterOnQualifiedTableName():

$this->migrationDiffGenerator->generate('Version1234', null);

self::assertEquals([$toTable1, $toTable2], array_values($toSchema->getTables()));
$filteredTableNames = array_map(static fn (Table $table) => $table->getName(), $toSchema->getTables());

self::assertSame($expectedTables, array_values($filteredTableNames));
}

/** @return array<string, array<int, bool|array<int, string>>> */
public static function getGenerateAppliesFilterOnMappedSchemaData(): array
{
return [
'platform without schemas supports' => [false, []],
'platform with schema schemas support' => [true, ['some_schema.table1', 'some_schema.table2']],
];
}

protected function setUp(): void
Expand Down

0 comments on commit acfad01

Please sign in to comment.