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 81 82 83 84 85
|
<?php
declare(strict_types=1);
namespace Doctrine\DBAL\Tests\Schema;
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
use Doctrine\DBAL\Schema\Index;
use PHPUnit\Framework\Attributes\DataProvider;
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],
];
}
#[DataProvider('getUnqualifiedForeignTableNameData')]
public function testGetUnqualifiedForeignTableName(
string $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'],
['schema."foreign_table"', 'foreign_table'],
['"schema"."foreign_table"', 'foreign_table'],
['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());
}
}
|