diff --git a/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php b/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php index aeaef41402..47aeea4814 100644 --- a/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php +++ b/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php @@ -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); diff --git a/tests/Doctrine/Tests/DBAL/Schema/ForeignKeyConstraintTest.php b/tests/Doctrine/Tests/DBAL/Schema/ForeignKeyConstraintTest.php index f1f5c6aa05..66162ae2e6 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/ForeignKeyConstraintTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/ForeignKeyConstraintTest.php @@ -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 @@ -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'], + ]; + } }