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