Test Failed
Pull Request — 2.6 (#3146)
by
unknown
06:41
created

IndexTest::testIndexQuotes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
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
        $this->assertEquals("foo", $idx->getName());
18
        $columns = $idx->getColumns();
19
        $this->assertEquals(2, count($columns));
20
        $this->assertEquals(array("bar", "baz"), $columns);
21
        $this->assertFalse($idx->isUnique());
22
        $this->assertFalse($idx->isPrimary());
23
    }
24
25
    public function testCreatePrimary()
26
    {
27
        $idx = $this->createIndex(false, true);
28
        $this->assertTrue($idx->isUnique());
29
        $this->assertTrue($idx->isPrimary());
30
    }
31
32
    public function testCreateUnique()
33
    {
34
        $idx = $this->createIndex(true, false);
35
        $this->assertTrue($idx->isUnique());
36
        $this->assertFalse($idx->isPrimary());
37
    }
38
39
    /**
40
     * @group DBAL-50
41
     */
42 View Code Duplication
    public function testFulfilledByUnique()
0 ignored issues
show
Duplication introduced by
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...
43
    {
44
        $idx1 = $this->createIndex(true, false);
45
        $idx2 = $this->createIndex(true, false);
46
        $idx3 = $this->createIndex();
47
48
        $this->assertTrue($idx1->isFullfilledBy($idx2));
49
        $this->assertFalse($idx1->isFullfilledBy($idx3));
50
    }
51
52
    /**
53
     * @group DBAL-50
54
     */
55 View Code Duplication
    public function testFulfilledByPrimary()
0 ignored issues
show
Duplication introduced by
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...
56
    {
57
        $idx1 = $this->createIndex(true, true);
58
        $idx2 = $this->createIndex(true, true);
59
        $idx3 = $this->createIndex(true, false);
60
61
        $this->assertTrue($idx1->isFullfilledBy($idx2));
62
        $this->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
        $this->assertTrue($idx1->isFullfilledBy($idx2));
76
        $this->assertTrue($idx1->isFullfilledBy($pri));
77
        $this->assertTrue($idx1->isFullfilledBy($uniq));
78
    }
79
80
    public function testFulfilledByCompoundIndex()
81
    {
82
        $idx1 = new Index('foo', array('col1', 'col2'), false, false, array(), array());
83
        $idx2 = new Index('bar', array('col1'), false, false, array(), array());
84
85
        $this->assertTrue($idx2->isFullfilledBy($idx1));
86
    }
87
88 View Code Duplication
    public function testFulfilledWithPartial()
0 ignored issues
show
Duplication introduced by
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...
89
    {
90
        $without = new Index('without', array('col1', 'col2'), true, false, array(), array());
91
        $partial = new Index('partial', array('col1', 'col2'), true, false, array(), array('where' => 'col1 IS NULL'));
92
        $another = new Index('another', array('col1', 'col2'), true, false, array(), array('where' => 'col1 IS NULL'));
93
94
        $this->assertFalse($partial->isFullfilledBy($without));
95
        $this->assertFalse($without->isFullfilledBy($partial));
96
97
        $this->assertTrue($partial->isFullfilledBy($partial));
98
99
        $this->assertTrue($partial->isFullfilledBy($another));
100
        $this->assertTrue($another->isFullfilledBy($partial));
101
    }
102
103 View Code Duplication
    public function testOverrulesWithPartial()
0 ignored issues
show
Duplication introduced by
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...
104
    {
105
        $without = new Index('without', array('col1', 'col2'), true, false, array(), array());
106
        $partial = new Index('partial', array('col1', 'col2'), true, false, array(), array('where' => 'col1 IS NULL'));
107
        $another = new Index('another', array('col1', 'col2'), true, false, array(), array('where' => 'col1 IS NULL'));
108
109
        $this->assertFalse($partial->overrules($without));
110
        $this->assertFalse($without->overrules($partial));
111
112
        $this->assertTrue($partial->overrules($partial));
113
114
        $this->assertTrue($partial->overrules($another));
115
        $this->assertTrue($another->overrules($partial));
116
    }
117
118
    /**
119
     * @group DBAL-220
120
     */
121
    public function testFlags()
122
    {
123
        $idx1 = $this->createIndex();
124
        $this->assertFalse($idx1->hasFlag('clustered'));
125
        $this->assertEmpty($idx1->getFlags());
126
127
        $idx1->addFlag('clustered');
128
        $this->assertTrue($idx1->hasFlag('clustered'));
129
        $this->assertTrue($idx1->hasFlag('CLUSTERED'));
130
        $this->assertSame(array('clustered'), $idx1->getFlags());
131
132
        $idx1->removeFlag('clustered');
133
        $this->assertFalse($idx1->hasFlag('clustered'));
134
        $this->assertEmpty($idx1->getFlags());
135
    }
136
137
    /**
138
     * @group DBAL-285
139
     */
140
    public function testIndexQuotes()
141
    {
142
        $index = new Index("foo", array("`bar`", "`baz`"));
143
144
        $this->assertTrue($index->spansColumns(array("bar", "baz")));
145
        $this->assertTrue($index->hasColumnAtPosition("bar", 0));
146
        $this->assertTrue($index->hasColumnAtPosition("baz", 1));
147
148
        $this->assertFalse($index->hasColumnAtPosition("bar", 1));
149
        $this->assertFalse($index->hasColumnAtPosition("baz", 0));
150
    }
151
152
    public function testOptions()
153
    {
154
        $idx1 = $this->createIndex();
155
        $this->assertFalse($idx1->hasOption('where'));
156
        $this->assertEmpty($idx1->getOptions());
157
158
        $idx2 = $this->createIndex(false, false, array('where' => 'name IS NULL'));
159
        $this->assertTrue($idx2->hasOption('where'));
160
        $this->assertTrue($idx2->hasOption('WHERE'));
161
        $this->assertSame('name IS NULL', $idx2->getOption('where'));
162
        $this->assertSame('name IS NULL', $idx2->getOption('WHERE'));
163
        $this->assertSame(array('where' => 'name IS NULL'), $idx2->getOptions());
164
    }
165
}
166