Completed
Push — master ( b789e9...4dfee6 )
by Matteo
02:19
created

RowCountTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 47.62 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 1
cbo 2
dl 20
loc 42
rs 10

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
class RowCountTest extends BridgeTestCase
4
{
5
    public function testUpdateAffectedRows()
6
    {
7
        $this->bridge->query("UPDATE test_table SET testfield = 'updated' WHERE id > 100");
8
        $this->assertEquals(0, $this->bridge->affectedRows());
9
10
        $this->bridge->query("UPDATE test_table SET testfield = 'updated' WHERE id > 5");
11
        $this->assertEquals(5, $this->bridge->affectedRows());
12
    }
13
14
    public function testInsertAffectedRows()
15
    {
16
        $this->assertEquals(0, $this->bridge->affectedRows());
17
18
        $this->bridge->query("INSERT INTO test_table VALUES (100, 'test insert 100')");
19
        $this->assertEquals(1, $this->bridge->affectedRows());
20
21
        $this->bridge->query("INSERT INTO test_table VALUES (101, 'test insert 101'), (102, 'test insert 102')");
22
        $this->assertEquals(2, $this->bridge->affectedRows());
23
    }
24
25
    public function testDeleteAffectedRows()
26
    {
27
        $this->assertEquals(0, $this->bridge->affectedRows());
28
29
        $this->bridge->query('DELETE FROM test_table WHERE id = 1');
30
        $this->assertEquals(1, $this->bridge->affectedRows());
31
32
        $this->bridge->query('DELETE FROM test_table WHERE id > 5');
33
        $this->assertEquals(5, $this->bridge->affectedRows());
34
    }
35
36
    public function testNumRows()
37
    {
38
        $result = $this->bridge->query('SELECT * FROM test_table WHERE id > 100');
39
        $this->assertEquals(0, $this->bridge->numRows($result));
40
41
        $result = $this->bridge->query('SELECT id FROM test_table where id < 5');
42
        $this->assertEquals(4, $this->bridge->numRows($result));
43
    }
44
}