Completed
Push — master ( c7757e...39cb21 )
by Luís
16s
created

tests/Doctrine/Tests/DBAL/Schema/IndexTest.php (1 issue)

1
<?php
2
3
namespace Doctrine\Tests\DBAL\Schema;
4
5
use Doctrine\DBAL\Schema\Index;
6
7
class IndexTest extends \PHPUnit\Framework\TestCase
8
{
9
    public function createIndex($unique = false, $primary = false, $options = array())
10
    {
11
        return new Index("foo", array("bar", "baz"), $unique, $primary, array(), $options);
12
    }
13
14
    public function testCreateIndex()
15
    {
16
        $idx = $this->createIndex();
17
        self::assertEquals("foo", $idx->getName());
18
        $columns = $idx->getColumns();
19
        self::assertEquals(2, count($columns));
20
        self::assertEquals(array("bar", "baz"), $columns);
21
        self::assertFalse($idx->isUnique());
22
        self::assertFalse($idx->isPrimary());
23
    }
24
25
    public function testCreatePrimary()
26
    {
27
        $idx = $this->createIndex(false, true);
28
        self::assertTrue($idx->isUnique());
29
        self::assertTrue($idx->isPrimary());
30
    }
31
32
    public function testCreateUnique()
33
    {
34
        $idx = $this->createIndex(true, false);
35
        self::assertTrue($idx->isUnique());
36
        self::assertFalse($idx->isPrimary());
37
    }
38
39
    /**
40
     * @group DBAL-50
41
     */
42 View Code Duplication
    public function testFulfilledByUnique()
43
    {
44
        $idx1 = $this->createIndex(true, false);
45
        $idx2 = $this->createIndex(true, false);
46
        $idx3 = $this->createIndex();
47
48
        self::assertTrue($idx1->isFullfilledBy($idx2));
49
        self::assertFalse($idx1->isFullfilledBy($idx3));
50
    }
51
52
    /**
53
     * @group DBAL-50
54
     */
55 View Code Duplication
    public function testFulfilledByPrimary()
56
    {
57
        $idx1 = $this->createIndex(true, true);
58
        $idx2 = $this->createIndex(true, true);
59
        $idx3 = $this->createIndex(true, false);
60
61
        self::assertTrue($idx1->isFullfilledBy($idx2));
62
        self::assertFalse($idx1->isFullfilledBy($idx3));
63
    }
64
65
    /**
66
     * @group DBAL-50
67
     */
68
    public function testFulfilledByIndex()
69
    {
70
        $idx1 = $this->createIndex();
71
        $idx2 = $this->createIndex();
72
        $pri = $this->createIndex(true, true);
73
        $uniq = $this->createIndex(true);
74
75
        self::assertTrue($idx1->isFullfilledBy($idx2));
76
        self::assertTrue($idx1->isFullfilledBy($pri));
77
        self::assertTrue($idx1->isFullfilledBy($uniq));
78
    }
79
80 View Code Duplication
    public function testFulfilledWithPartial()
81
    {
82
        $without = new Index('without', array('col1', 'col2'), true, false, array(), array());
83
        $partial = new Index('partial', array('col1', 'col2'), true, false, array(), array('where' => 'col1 IS NULL'));
84
        $another = new Index('another', array('col1', 'col2'), true, false, array(), array('where' => 'col1 IS NULL'));
85
86
        self::assertFalse($partial->isFullfilledBy($without));
87
        self::assertFalse($without->isFullfilledBy($partial));
88
89
        self::assertTrue($partial->isFullfilledBy($partial));
90
91
        self::assertTrue($partial->isFullfilledBy($another));
92
        self::assertTrue($another->isFullfilledBy($partial));
93
    }
94
95 View Code Duplication
    public function testOverrulesWithPartial()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
96
    {
97
        $without = new Index('without', array('col1', 'col2'), true, false, array(), array());
98
        $partial = new Index('partial', array('col1', 'col2'), true, false, array(), array('where' => 'col1 IS NULL'));
99
        $another = new Index('another', array('col1', 'col2'), true, false, array(), array('where' => 'col1 IS NULL'));
100
101
        self::assertFalse($partial->overrules($without));
102
        self::assertFalse($without->overrules($partial));
103
104
        self::assertTrue($partial->overrules($partial));
105
106
        self::assertTrue($partial->overrules($another));
107
        self::assertTrue($another->overrules($partial));
108
    }
109
110
    /**
111
     * @group DBAL-220
112
     */
113
    public function testFlags()
114
    {
115
        $idx1 = $this->createIndex();
116
        self::assertFalse($idx1->hasFlag('clustered'));
117
        self::assertEmpty($idx1->getFlags());
118
119
        $idx1->addFlag('clustered');
120
        self::assertTrue($idx1->hasFlag('clustered'));
121
        self::assertTrue($idx1->hasFlag('CLUSTERED'));
122
        self::assertSame(array('clustered'), $idx1->getFlags());
123
124
        $idx1->removeFlag('clustered');
125
        self::assertFalse($idx1->hasFlag('clustered'));
126
        self::assertEmpty($idx1->getFlags());
127
    }
128
129
    /**
130
     * @group DBAL-285
131
     */
132
    public function testIndexQuotes()
133
    {
134
        $index = new Index("foo", array("`bar`", "`baz`"));
135
136
        self::assertTrue($index->spansColumns(array("bar", "baz")));
137
        self::assertTrue($index->hasColumnAtPosition("bar", 0));
138
        self::assertTrue($index->hasColumnAtPosition("baz", 1));
139
140
        self::assertFalse($index->hasColumnAtPosition("bar", 1));
141
        self::assertFalse($index->hasColumnAtPosition("baz", 0));
142
    }
143
144
    public function testOptions()
145
    {
146
        $idx1 = $this->createIndex();
147
        self::assertFalse($idx1->hasOption('where'));
148
        self::assertEmpty($idx1->getOptions());
149
150
        $idx2 = $this->createIndex(false, false, array('where' => 'name IS NULL'));
151
        self::assertTrue($idx2->hasOption('where'));
152
        self::assertTrue($idx2->hasOption('WHERE'));
153
        self::assertSame('name IS NULL', $idx2->getOption('where'));
154
        self::assertSame('name IS NULL', $idx2->getOption('WHERE'));
155
        self::assertSame(array('where' => 'name IS NULL'), $idx2->getOptions());
156
    }
157
}
158