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 a76ce4d commit e48897d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 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
22 changes: 20 additions & 2 deletions tests/Generator/DiffGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,12 @@ public function testGenerateFromEmptySchema(): void
self::assertSame('path2', $this->migrationDiffGenerator->generate('2345', null, false, 120, true, true));
}

public function testGenerateAppliesFilterOnMappedSchema(): 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 @@ -197,6 +202,10 @@ public function testGenerateAppliesFilterOnMappedSchema(): void
$toTable2 = new Table('some_schema.table2');
$toSchema = new Schema([$toTable1, $toTable2]);

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

$this->schemaManager->expects(self::once())
->method('introspectSchema')
->willReturn($fromSchema);
Expand Down Expand Up @@ -224,7 +233,16 @@ public function testGenerateAppliesFilterOnMappedSchema(): void

$filteredTableNames = array_map(static fn (Table $table) => $table->getName(), $toSchema->getTables());

self::assertSame(['some_schema.table1', 'some_schema.table2'], array_values($filteredTableNames));
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 e48897d

Please sign in to comment.