Completed
Push — master ( 9de5b8...ddab96 )
by Matteo
03:46
created

RowCountTest::testUpdateAffectedRows()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
class RowCountTest extends BridgeTestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
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 View Code Duplication
    public function testInsertAffectedRows()
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...
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 View Code Duplication
    public function testDeleteAffectedRows()
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...
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));
0 ignored issues
show
Bug introduced by
It seems like $result defined by $this->bridge->query('SE..._table WHERE id > 100') on line 38 can also be of type false or null; however, Mattbit\MysqlCompat\Bridge::numRows() does only seem to accept object<Mattbit\MysqlCompat\Result>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
40
41
        $result = $this->bridge->query('SELECT id FROM test_table where id < 5');
42
        $this->assertEquals(4, $this->bridge->numRows($result));
0 ignored issues
show
Bug introduced by
It seems like $result defined by $this->bridge->query('SE...st_table where id < 5') on line 41 can also be of type false or null; however, Mattbit\MysqlCompat\Bridge::numRows() does only seem to accept object<Mattbit\MysqlCompat\Result>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
43
    }
44
}