Completed
Pull Request — master (#3395)
by Vytautas
15:11
created

testIntersectsIndexEscapedColumns()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Doctrine\Tests\DBAL\Schema;
4
5
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
6
use Doctrine\DBAL\Schema\Index;
7
use PHPUnit\Framework\TestCase;
8
9
class ForeignKeyConstraintTest extends TestCase
10
{
11
    /**
12
     * @param string[] $indexColumns
13
     *
14
     * @dataProvider getIntersectsIndexColumnsData
15
     */
16
    public function testIntersectsIndexEscapedColumns(array $indexColumns, bool $expectedResult)
17
    {
18
        $foreignKey = new ForeignKeyConstraint(['`foo`', '`bar`'], 'foreign_table', ['fk_foo', 'fk_bar']);
19
20
        $index = new Index('INDEX_NAME', $indexColumns);
21
22
        self::assertSame($expectedResult, $foreignKey->intersectsIndexColumns($index));
23
    }
24
25
    /**
26
     * @param string[] $indexColumns
27
     *
28
     * @group DBAL-1062
29
     * @dataProvider getIntersectsIndexColumnsData
30
     */
31
    public function testIntersectsIndexColumns(array $indexColumns, bool $expectedResult)
32
    {
33
        $foreignKey = new ForeignKeyConstraint(['foo', 'bar'], 'foreign_table', ['fk_foo', 'fk_bar']);
34
35
        $index = new Index('INDEX_NAME', $indexColumns);
36
37
        self::assertSame($expectedResult, $foreignKey->intersectsIndexColumns($index));
38
    }
39
40
    /**
41
     * @return mixed[]
42
     */
43
    public function getIntersectsIndexColumnsData()
44
    {
45
        return [
46
            [['baz'], false],
47
            [['baz', 'bloo'], false],
48
49
            [['`foo`'], true],
50
            [['`bar`'], true],
51
            [['foo'], true],
52
            [['bar'], true],
53
54
            [['foo', 'bar'], true],
55
            [['bar', 'foo'], true],
56
57
            [['foo', 'baz'], true],
58
            [['baz', 'foo'], true],
59
60
            [['bar', 'baz'], true],
61
            [['baz', 'bar'], true],
62
63
            [['foo', 'bloo', 'baz'], true],
64
            [['bloo', 'foo', 'baz'], true],
65
            [['bloo', 'baz', 'foo'], true],
66
67
            [['FOO'], true],
68
        ];
69
    }
70
}
71