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 PHPUnit\Framework\TestCase; |
10
|
|
|
|
11
|
|
|
class ForeignKeyConstraintTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @param string[] $indexColumns |
15
|
|
|
* |
16
|
|
|
* @dataProvider getIntersectsIndexColumnsData |
17
|
|
|
*/ |
18
|
|
|
public function testIntersectsIndexEscapedColumns(array $indexColumns, bool $expectedResult) |
19
|
|
|
{ |
20
|
|
|
$foreignKey = new ForeignKeyConstraint(['`foo`', '`bar`'], 'foreign_table', ['fk_foo', 'fk_bar']); |
21
|
|
|
|
22
|
|
|
$index = new Index('INDEX_NAME', $indexColumns); |
23
|
|
|
|
24
|
|
|
self::assertSame($expectedResult, $foreignKey->intersectsIndexColumns($index)); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param string[] $indexColumns |
29
|
|
|
* |
30
|
|
|
* @group DBAL-1062 |
31
|
|
|
* @dataProvider getIntersectsIndexColumnsData |
32
|
|
|
*/ |
33
|
|
|
public function testIntersectsIndexColumns(array $indexColumns, bool $expectedResult) : void |
34
|
|
|
{ |
35
|
|
|
$foreignKey = new ForeignKeyConstraint(['foo', 'bar'], 'foreign_table', ['fk_foo', 'fk_bar']); |
36
|
|
|
|
37
|
|
|
$index = new Index('INDEX_NAME', $indexColumns); |
38
|
|
|
|
39
|
|
|
self::assertSame($expectedResult, $foreignKey->intersectsIndexColumns($index)); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return mixed[][] |
44
|
|
|
*/ |
45
|
|
|
public static function getIntersectsIndexColumnsData() : iterable |
46
|
|
|
{ |
47
|
|
|
return [ |
48
|
|
|
[['baz'], false], |
49
|
|
|
[['baz', 'bloo'], false], |
50
|
|
|
|
51
|
|
|
[['`foo`'], true], |
52
|
|
|
[['`bar`'], true], |
53
|
|
|
[['foo'], true], |
54
|
|
|
[['bar'], true], |
55
|
|
|
|
56
|
|
|
[['foo', 'bar'], true], |
57
|
|
|
[['bar', 'foo'], true], |
58
|
|
|
|
59
|
|
|
[['foo', 'baz'], true], |
60
|
|
|
[['baz', 'foo'], true], |
61
|
|
|
|
62
|
|
|
[['bar', 'baz'], true], |
63
|
|
|
[['baz', 'bar'], true], |
64
|
|
|
|
65
|
|
|
[['foo', 'bloo', 'baz'], true], |
66
|
|
|
[['bloo', 'foo', 'baz'], true], |
67
|
|
|
[['bloo', 'baz', 'foo'], true], |
68
|
|
|
|
69
|
|
|
[['FOO'], true], |
70
|
|
|
]; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|