Completed
Pull Request — master (#3395)
by Vytautas
63:35
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, $expectedResult)
32
    {
33
        $foreignKey = new ForeignKeyConstraint(['foo', 'bar'], 'foreign_table', ['fk_foo', 'fk_bar']);
34
35
        $index = $this->getMockBuilder(Index::class)
36
            ->disableOriginalConstructor()
37
            ->getMock();
38
        $index->expects($this->once())
39
            ->method('getColumns')
40
            ->will($this->returnValue($indexColumns));
41
42
        self::assertSame($expectedResult, $foreignKey->intersectsIndexColumns($index));
43
    }
44
45
    /**
46
     * @return mixed[]
47
     */
48
    public function getIntersectsIndexColumnsData()
49
    {
50
        return [
51
            [['baz'], false],
52
            [['baz', 'bloo'], false],
53
54
            [['`foo`'], true],
55
            [['`bar`'], true],
56
            [['foo'], true],
57
            [['bar'], true],
58
59
            [['foo', 'bar'], true],
60
            [['bar', 'foo'], true],
61
62
            [['foo', 'baz'], true],
63
            [['baz', 'foo'], true],
64
65
            [['bar', 'baz'], true],
66
            [['baz', 'bar'], true],
67
68
            [['foo', 'bloo', 'baz'], true],
69
            [['bloo', 'foo', 'baz'], true],
70
            [['bloo', 'baz', 'foo'], true],
71
72
            [['FOO'], true],
73
        ];
74
    }
75
}
76