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

IndexTest   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 159
Duplicated Lines 28.93 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 13
c 1
b 0
f 0
lcom 1
cbo 2
dl 46
loc 159
rs 10

13 Methods

Rating   Name   Duplication   Size   Complexity  
A createIndex() 0 4 1
A testCreateIndex() 0 10 1
A testCreatePrimary() 0 6 1
A testCreateUnique() 0 6 1
A testFulfilledByUnique() 9 9 1
A testFulfilledByPrimary() 9 9 1
A testFulfilledByIndex() 0 11 1
A testFulfilledByCompoundIndex() 0 7 1
A testFulfilledWithPartial() 14 14 1
A testOverrulesWithPartial() 14 14 1
A testFlags() 0 15 1
A testIndexQuotes() 0 11 1
A testOptions() 0 13 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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