From a76ce4df2d66e846d6c99b17074e44792d52eda2 Mon Sep 17 00:00:00 2001 From: Cristi Contiu Date: Thu, 27 Feb 2025 23:09:53 +0200 Subject: [PATCH 1/2] Issue #1487 --- tests/Generator/DiffGeneratorTest.php | 47 +++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/tests/Generator/DiffGeneratorTest.php b/tests/Generator/DiffGeneratorTest.php index 48ad71db5..2e4b53b9b 100644 --- a/tests/Generator/DiffGeneratorTest.php +++ b/tests/Generator/DiffGeneratorTest.php @@ -18,6 +18,10 @@ use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; +use function array_map; +use function array_values; +use function preg_match; + class DiffGeneratorTest extends TestCase { private DBALConfiguration&MockObject $dbalConfiguration; @@ -180,6 +184,49 @@ public function testGenerateFromEmptySchema(): void self::assertSame('path2', $this->migrationDiffGenerator->generate('2345', null, false, 120, true, true)); } + public function testGenerateAppliesFilterOnMappedSchema(): void + { + // a standard Regex SchemaAssetsFilter already registered on the DBAL + $dbalSchemaAssetsFilter = static function ($assetName): bool { + return (bool) preg_match('~^some_schema~', $assetName); + }; + + $fromSchema = new Schema(); + + $toTable1 = new Table('some_schema.table1'); + $toTable2 = new Table('some_schema.table2'); + $toSchema = new Schema([$toTable1, $toTable2]); + + $this->schemaManager->expects(self::once()) + ->method('introspectSchema') + ->willReturn($fromSchema); + + $this->schemaProvider->expects(self::once()) + ->method('createSchema') + ->willReturn($toSchema); + + $this->dbalConfiguration->expects(self::once()) + ->method('getSchemaAssetsFilter') + ->willReturn($dbalSchemaAssetsFilter); + + $schemaDiff = self::createStub(SchemaDiff::class); + $comparator = $this->mockComparator($schemaDiff); + + $this->schemaManager->expects(self::once()) + ->method('createComparator') + ->willReturn($comparator); + + $this->migrationSqlGenerator->expects(self::exactly(2)) + ->method('generate') + ->willReturnOnConsecutiveCalls('up', 'down'); + + $this->migrationDiffGenerator->generate('Version1234', null); + + $filteredTableNames = array_map(static fn (Table $table) => $table->getName(), $toSchema->getTables()); + + self::assertSame(['some_schema.table1', 'some_schema.table2'], array_values($filteredTableNames)); + } + protected function setUp(): void { $this->dbalConfiguration = $this->createMock(DBALConfiguration::class); From e48897d9086918b65ab5ad73d827646b3afb8a0b Mon Sep 17 00:00:00 2001 From: Cristi Contiu Date: Fri, 28 Feb 2025 08:14:59 +0200 Subject: [PATCH 2/2] Fix for Issue #1487 --- src/Generator/DiffGenerator.php | 4 ++++ tests/Generator/DiffGeneratorTest.php | 22 ++++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/Generator/DiffGenerator.php b/src/Generator/DiffGenerator.php index 240885ab5..072c84d1f 100644 --- a/src/Generator/DiffGenerator.php +++ b/src/Generator/DiffGenerator.php @@ -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); diff --git a/tests/Generator/DiffGeneratorTest.php b/tests/Generator/DiffGeneratorTest.php index 2e4b53b9b..0f3d3dcf1 100644 --- a/tests/Generator/DiffGeneratorTest.php +++ b/tests/Generator/DiffGeneratorTest.php @@ -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 $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 { @@ -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); @@ -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>> */ + 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