Completed
Push — master ( 4025c4...856f8c )
by Nikita
02:41
created

TableTest::testForeignKeyMethods()   B

Complexity

Conditions 5
Paths 9

Size

Total Lines 31
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 8.439
c 0
b 0
f 0
cc 5
eloc 21
nc 9
nop 0
1
<?php
2
3
namespace Taisiya\PropelBundle\Database;
4
5
use Taisiya\PropelBundle\Database\Exception\InvalidArgumentException;
6
use Taisiya\PropelBundle\Database\TestDatabase\FirstTestTable;
7
use Taisiya\PropelBundle\Database\TestDatabase\SecondTestTable;
8
use Taisiya\PropelBundle\Database\TestDatabase\TestColumn;
9
use Taisiya\PropelBundle\Database\TestDatabase\TestForeignKey;
10
use Taisiya\PropelBundle\PHPUnitTestCase;
11
12
class TableTest extends PHPUnitTestCase
13
{
14
    /**
15
     * @covers Table::createColumn
16
     * @covers Table::createColumnIfNotExists
17
     * @covers Table::getColumns
18
     * @covers Table::getColumn
19
     * @covers Table::hasColumn
20
     * @covers Table::removeColumn
21
     */
22 View Code Duplication
    public function testColumnMethods()
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...
23
    {
24
        $table = new FirstTestTable();
25
        $this->assertCount(0, $table->getColumns());
26
27
        $column = new TestColumn();
28
29
        for ($i = 0; $i < 2; $i++) {
30
            try {
31
                $table->createColumn($column);
32
            } catch (InvalidArgumentException $e) {
33
                $this->assertGreaterThan(0, $i);
34
            }
35
36
            $this->assertCount(1, $table->getColumns());
37
            $this->assertEquals($column, $table->getColumns()[TestColumn::getName()]);
38
            $this->assertEquals($column, $table->getColumn(TestColumn::getName()));
39
            $this->assertTrue($table->hasColumn(TestColumn::getName()));
40
        }
41
42
        for ($i = 0; $i < 2; $i++) {
43
            try {
44
                $table->removeColumn($column);
45
            } catch (InvalidArgumentException $e) {
46
                $this->assertGreaterThan(0, $i);
47
            }
48
            $this->assertCount(0, $table->getColumns());
49
        }
50
51
        for ($i = 0; $i < 2; $i++) {
52
            $table->createColumnIfNotExists($column);
53
            $this->assertCount(1, $table->getColumns());
54
            $this->assertEquals($column, $table->getColumn(TestColumn::getName()));
55
        }
56
    }
57
58
    /**
59
     * @covers Table::addForeignKey
60
     * @covers Table::getForeignKeys
61
     * @covers Table::getForeignKey
62
     * @covers Table::hasForeignKey
63
     * @covers Table::removeForeignKey
64
     */
65
    public function testForeignKeyMethods()
66
    {
67
        $table = new FirstTestTable();
68
        $this->assertCount(0, $table->getForeignKeys());
69
70
        $foreignKey = new TestForeignKey(
71
            new SecondTestTable(),
72
            new ForeignKeyReference(new FirstTestTable\IdColumn(), new SecondTestTable\FirstTestTableId())
73
        );
74
75
        for ($i = 0; $i < 2; $i++) {
76
            try {
77
                $table->addForeignKey($foreignKey);
78
            } catch (InvalidArgumentException $e) {
79
                $this->assertGreaterThan(0, $i);
80
            }
81
            $this->assertCount(1, $table->getForeignKeys());
82
            $this->assertInstanceOf(TestForeignKey::class, $table->getForeignKeys()[$foreignKey::getName()]);
83
            $this->assertInstanceOf(TestForeignKey::class, $table->getForeignKey($foreignKey::getName()));
84
            $this->assertTrue($table->hasForeignKey($foreignKey::getName()));
85
        }
86
87
        for ($i = 0; $i < 2; $i++) {
88
            try {
89
                $table->removeForeignKey($foreignKey);
90
            } catch (InvalidArgumentException $e) {
91
                $this->assertGreaterThan(0, $i);
92
            }
93
            $this->assertCount(0, $table->getForeignKeys());
94
        }
95
    }
96
97
    /**
98
     * @covers Table::addIndex
99
     * @covers Table::getIndexes
100
     * @covers Table::getIndex
101
     * @covers Table::hasIndex
102
     * @covers Table::removeIndex
103
     */
104 View Code Duplication
    public function testIndexMethods()
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...
105
    {
106
        $table = new FirstTestTable();
107
        $this->assertCount(0, $table->getIndexes());
108
109
        $index = new FirstTestTable\TestIndex();
110
111
        for ($i = 0; $i < 2; $i++) {
112
            try {
113
                $table->addIndex($index);
114
            } catch (InvalidArgumentException $e) {
115
                $this->assertGreaterThan(0, $i);
116
            }
117
            $this->assertCount(1, $table->getIndexes());
118
            $this->assertInstanceOf(FirstTestTable\TestIndex::class, $table->getIndexes()[$index::getName()]);
119
            $this->assertInstanceOf(FirstTestTable\TestIndex::class, $table->getIndex($index::getName()));
120
            $this->assertTrue($table->hasIndex($index::getName()));
121
        }
122
123
        for ($i = 0; $i < 2; $i++) {
124
            try {
125
                $table->removeIndex($index);
126
            } catch (InvalidArgumentException $e) {
127
                $this->assertGreaterThan(0, $i);
128
            }
129
            $this->assertCount(0, $table->getIndexes());
130
        }
131
    }
132
133
    /**
134
     * @covers Table::addUnique
135
     * @covers Table::getUniques
136
     * @covers Table::getUnique
137
     * @covers Table::hasUnique
138
     * @covers Table::removeUnique
139
     */
140 View Code Duplication
    public function testUniqueIndexMethods()
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...
141
    {
142
        $table = new FirstTestTable();
143
        $this->assertCount(0, $table->getUniques());
144
145
        $index = new FirstTestTable\TestUniqueIndex();
146
147
        for ($i = 0; $i < 2; $i++) {
148
            try {
149
                $table->addUnique($index);
150
            } catch (InvalidArgumentException $e) {
151
                $this->assertGreaterThan(0, $i);
152
            }
153
            $this->assertCount(1, $table->getUniques());
154
            $this->assertInstanceOf(FirstTestTable\TestUniqueIndex::class, $table->getUniques()[$index::getName()]);
155
            $this->assertInstanceOf(FirstTestTable\TestUniqueIndex::class, $table->getUnique($index::getName()));
156
            $this->assertTrue($table->hasUnique($index::getName()));
157
        }
158
159
        for ($i = 0; $i < 2; $i++) {
160
            try {
161
                $table->removeUnique($index);
162
            } catch (InvalidArgumentException $e) {
163
                $this->assertGreaterThan(0, $i);
164
            }
165
            $this->assertCount(0, $table->getUniques());
166
        }
167
    }
168
}
169