Completed
Branch master (4dfee6)
by Matteo
04:02 queued 02:05
created

RowCountTest::testInsertAffectedRows()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 10
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 10
loc 10
rs 9.4285
cc 1
eloc 6
nc 1
nop 0
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
}