Skip to content

Make internal Comparator methods protected #5652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions src/Schema/Comparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,7 @@ private function detectIndexRenamings(TableDiff $tableDifferences): void
}
}

/**
* @internal The method should be only used from within the {@see Comparator} class hierarchy.
*/
public function diffForeignKey(ForeignKeyConstraint $key1, ForeignKeyConstraint $key2): bool
protected function diffForeignKey(ForeignKeyConstraint $key1, ForeignKeyConstraint $key2): bool
{
if (
array_map('strtolower', $key1->getUnquotedLocalColumns())
Expand Down Expand Up @@ -415,11 +412,9 @@ public function diffForeignKey(ForeignKeyConstraint $key1, ForeignKeyConstraint
/**
* Compares the definitions of the given columns
*
* @internal The method should be only used from within the {@see Comparator} class hierarchy.
*
* @throws Exception
*/
public function columnsEqual(Column $column1, Column $column2): bool
protected function columnsEqual(Column $column1, Column $column2): bool
{
return $this->platform->columnsEqual($column1, $column2);
}
Expand Down Expand Up @@ -522,10 +517,8 @@ public function diffColumn(Column $column1, Column $column2): array
*
* Compares $index1 with $index2 and returns $index2 if there are any
* differences or false in case there are no differences.
*
* @internal The method should be only used from within the {@see Comparator} class hierarchy.
*/
public function diffIndex(Index $index1, Index $index2): bool
protected function diffIndex(Index $index1, Index $index2): bool
{
return ! ($index1->isFullfilledBy($index2) && $index2->isFullfilledBy($index1));
}
Expand Down
26 changes: 0 additions & 26 deletions tests/Schema/ComparatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -662,22 +662,6 @@ public function testCompareForeignKeyBasedOnPropertiesNotName(): void
self::assertNull($tableDiff);
}

public function testCompareForeignKeyRestrictNoActionAreTheSame(): void
{
$fk1 = new ForeignKeyConstraint(['foo'], 'bar', ['baz'], 'fk1', ['onDelete' => 'NO ACTION']);
$fk2 = new ForeignKeyConstraint(['foo'], 'bar', ['baz'], 'fk1', ['onDelete' => 'RESTRICT']);

self::assertFalse($this->comparator->diffForeignKey($fk1, $fk2));
}
Comment on lines -665 to -671
Copy link
Member Author

@morozov morozov Sep 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test has been reworked into ForeignKeyConstraintTest::testCompareRestrictAndNoActionAreTheSame().


public function testCompareForeignKeyNamesUnqualifiedAsNoSchemaInformationIsAvailable(): void
{
$fk1 = new ForeignKeyConstraint(['foo'], 'foo.bar', ['baz'], 'fk1');
$fk2 = new ForeignKeyConstraint(['foo'], 'baz.bar', ['baz'], 'fk1');

self::assertFalse($this->comparator->diffForeignKey($fk1, $fk2));
}
Comment on lines -673 to -679
Copy link
Member Author

@morozov morozov Sep 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is supposed to cover the fix (411d38f) for #1694 (I can't really find much about the actual issue).

This is obviously a hack. From the issue description:

[...] all foreign keys in non standard schema all always different, because table1 doesn't contain a schema name in it but table2 does.

The fact that the schema name of the foreign key is unavailable during schema comparison is a flaw in the API, and doesn't mean that any two foreign with the same name from different schemas are the same key.

The fix doesn't take into account the fact that a quoted name can contain a dot.

While we're keeping the code, I'll remove this test as not worth reworking.


public function testDetectRenameColumn(): void
{
$tableA = new Table('foo');
Expand Down Expand Up @@ -1032,16 +1016,6 @@ public function testCompareChangedBinaryColumn(): void
self::assertEquals($expected, $this->comparator->compareSchemas($oldSchema, $newSchema));
}

public function testCompareQuotedAndUnquotedForeignKeyColumns(): void
{
$fk1 = new ForeignKeyConstraint(['foo'], 'bar', ['baz'], 'fk1', ['onDelete' => 'NO ACTION']);
$fk2 = new ForeignKeyConstraint(['`foo`'], 'bar', ['`baz`'], 'fk1', ['onDelete' => 'NO ACTION']);

$diff = $this->comparator->diffForeignKey($fk1, $fk2);

self::assertFalse($diff);
}
Comment on lines -1035 to -1043
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assumptions under this test are invalid. Quoted and unquoted names may not be equal depending on the platform. This test cannot be reworked with a functional one.


public function assertSchemaTableChangeCount(
SchemaDiff $diff,
int $newTableCount = 0,
Expand Down
8 changes: 8 additions & 0 deletions tests/Schema/ForeignKeyConstraintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,12 @@ public static function getUnqualifiedForeignTableNameData(): iterable
['foreign_table', 'foreign_table'],
];
}

public function testCompareRestrictAndNoActionAreTheSame(): void
{
$fk1 = new ForeignKeyConstraint(['foo'], 'bar', ['baz'], 'fk1', ['onDelete' => 'NO ACTION']);
$fk2 = new ForeignKeyConstraint(['foo'], 'bar', ['baz'], 'fk1', ['onDelete' => 'RESTRICT']);

self::assertSame($fk1->onDelete(), $fk2->onDelete());
}
}