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

DatabaseTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 76.09 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 35
loc 46
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B testTables() 35 35 6

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 Taisiya\PropelBundle\Database;
4
5
use Taisiya\PropelBundle\Database\Exception\InvalidArgumentException;
6
use Taisiya\PropelBundle\Database\TestDatabase\FirstTestTable;
7
use Taisiya\PropelBundle\Database\TestDatabase\TestDatabase;
8
use Taisiya\PropelBundle\PHPUnitTestCase;
9
10
class DatabaseTest extends PHPUnitTestCase
11
{
12
    /**
13
     * @covers Database::createTable
14
     * @covers Database::createTableIfNotExists
15
     * @covers Database::getTables
16
     * @covers Database::getTable
17
     * @covers Database::hasTable
18
     * @covers Database::removeTable
19
     */
20 View Code Duplication
    public function testTables()
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...
21
    {
22
        $database = new TestDatabase();
23
        $this->assertCount(0, $database->getTables());
24
25
        $table = new FirstTestTable();
26
27
        for ($i = 0; $i < 2; $i++) {
28
            try {
29
                $database->createTable($table);
30
            } catch (InvalidArgumentException $e) {
31
                $this->assertGreaterThan(0, $i);
32
            }
33
34
            $this->assertCount(1, $database->getTables());
35
            $this->assertEquals($table, $database->getTables()[FirstTestTable::getName()]);
36
            $this->assertEquals($table, $database->getTable(FirstTestTable::getName()));
37
            $this->assertTrue($database->hasTable(FirstTestTable::getName()));
38
        }
39
40
        for ($i = 0; $i < 2; $i++) {
41
            try {
42
                $database->removeTable($table);
43
            } catch (InvalidArgumentException $e) {
44
                $this->assertGreaterThan(0, $i);
45
            }
46
            $this->assertCount(0, $database->getTables());
47
        }
48
49
        for ($i = 0; $i < 2; $i++) {
50
            $database->createTableIfNotExists($table);
51
            $this->assertCount(1, $database->getTables());
52
            $this->assertEquals($table, $database->getTable(FirstTestTable::getName()));
53
        }
54
    }
55
}
56