Skip to content

Commit

Permalink
fixed unqualified table name of fk constraints when using schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
S38151 committed Dec 29, 2019
1 parent c0b3892 commit e144166
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public function getUnqualifiedForeignTableName() : string
$position = strrpos($name, '.');

if ($position !== false) {
$name = substr($name, $position);
$name = substr($name, $position + 1);
}

return strtolower($name);
Expand Down
27 changes: 27 additions & 0 deletions tests/Doctrine/Tests/DBAL/Schema/ForeignKeyConstraintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Doctrine\DBAL\Schema\ForeignKeyConstraint;
use Doctrine\DBAL\Schema\Index;
use Doctrine\DBAL\Schema\Table;
use PHPUnit\Framework\TestCase;

class ForeignKeyConstraintTest extends TestCase
Expand Down Expand Up @@ -58,4 +59,30 @@ public static function getIntersectsIndexColumnsData() : iterable
[['FOO'], true],
];
}

/**
* @param string|Table $foreignTableName
*
* @group DBAL-1062
* @dataProvider getUnqualifiedForeignTableNameData
*/
public function testGetUnqualifiedForeignTableName($foreignTableName, string $expectedUnqualifiedTableName) : void
{
$foreignKey = new ForeignKeyConstraint(['foo', 'bar'], $foreignTableName, ['fk_foo', 'fk_bar']);

self::assertSame($expectedUnqualifiedTableName, $foreignKey->getUnqualifiedForeignTableName());
}

/**
* @return mixed[][]
*/
public static function getUnqualifiedForeignTableNameData() : iterable
{
return [
['schema.foreign_table', 'foreign_table'],
['foreign_table', 'foreign_table'],
[new Table('schema.foreign_table'), 'foreign_table'],
[new Table('foreign_table'), 'foreign_table'],
];
}
}

0 comments on commit e144166

Please sign in to comment.