Skip to content
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

fixes incorrect database migration for quoted columns #3395

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ public function intersectsIndexColumns(Index $index)
{
foreach ($index->getUnquotedColumns() as $indexColumn) {
foreach ($this->_localColumnNames as $localColumn) {
if (strtolower($indexColumn) === strtolower($localColumn->trimQuotes($localColumn->getName()))) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

it seems this was not required testIntersectsIndexEscapedColumns should cover this

if (strtolower($indexColumn) === strtolower($localColumn->getName())) {
return true;
}
}
Expand Down
9 changes: 2 additions & 7 deletions tests/Doctrine/Tests/DBAL/Schema/ForeignKeyConstraintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,11 @@ public function testIntersectsIndexEscapedColumns(array $indexColumns, bool $exp
* @group DBAL-1062
* @dataProvider getIntersectsIndexColumnsData
*/
public function testIntersectsIndexColumns(array $indexColumns, $expectedResult)
public function testIntersectsIndexColumns(array $indexColumns, bool $expectedResult)
{
$foreignKey = new ForeignKeyConstraint(['foo', 'bar'], 'foreign_table', ['fk_foo', 'fk_bar']);

$index = $this->getMockBuilder(Index::class)
->disableOriginalConstructor()
->getMock();
$index->expects($this->once())
->method('getColumns')
->will($this->returnValue($indexColumns));
$index = new Index('INDEX_NAME', $indexColumns);
Copy link
Member

@Ocramius Ocramius May 17, 2019

Choose a reason for hiding this comment

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

I'm vary of test changes here: what was broken that required getting rid of the mock?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nothing, just thought maybe better to use an actual object instead of mock no?

Copy link
Member

Choose a reason for hiding this comment

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

If the previous code works without changes, let's avoid changing it at all. Let's put test refactoring in separate patches, to avoid hiding potential BC breaks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Ocramius as you can see tests fail and now I remember why. Because I use getUnquotedColumns instead of getColumns and I added some columns with quotes into data provider. And if I mock here can't test quoted names. I mean this:

$index->expects($this->once())
            ->method('getUnquotedColumns')
            ->will($this->returnValue($indexColumns));

should always return unquoted names and I can't add quoted names in data provider but maybe I don't have to?
I still think actual implementation would be better here and anyway I have to change mocked method anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Ocramius if you want I can still leave this mock but will have to change mocked method and will also have to duplicate this test and test data to actually test quoted names.


self::assertSame($expectedResult, $foreignKey->intersectsIndexColumns($index));
}
Expand Down