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