1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
<?php
namespace Doctrine\DBAL\Tests\Schema;
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
use Doctrine\DBAL\Schema\Index;
use Doctrine\DBAL\Schema\Table;
use PHPUnit\Framework\TestCase;
class ForeignKeyConstraintTest extends TestCase
{
/**
* @param string[] $indexColumns
*
* @dataProvider getIntersectsIndexColumnsData
*/
public function testIntersectsIndexColumns(array $indexColumns, bool $expectedResult): void
{
$foreignKey = new ForeignKeyConstraint(['foo', 'bar'], 'foreign_table', ['fk_foo', 'fk_bar']);
$index = $this->getMockBuilder(Index::class)
->disableOriginalConstructor()
->getMock();
$index->expects(self::once())
->method('getColumns')
->willReturn($indexColumns);
self::assertSame($expectedResult, $foreignKey->intersectsIndexColumns($index));
}
/** @return mixed[][] */
public static function getIntersectsIndexColumnsData(): iterable
{
return [
[['baz'], false],
[['baz', 'bloo'], false],
[['foo'], true],
[['bar'], true],
[['foo', 'bar'], true],
[['bar', 'foo'], true],
[['foo', 'baz'], true],
[['baz', 'foo'], true],
[['bar', 'baz'], true],
[['baz', 'bar'], true],
[['foo', 'bloo', 'baz'], true],
[['bloo', 'foo', 'baz'], true],
[['bloo', 'baz', 'foo'], true],
[['FOO'], true],
];
}
/**
* @param string|Table $foreignTableName
*
* @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'],
];
}
}
|