TableMapperTest::testcheckTableName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 1
Metric Value
c 4
b 0
f 1
dl 0
loc 7
rs 9.4286
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
/**
4
 * @package A simple ORM that performs basic CRUD operations
5
 * @author Surajudeen AKANDE <[email protected]>
6
 * @license MIT <https://opensource.org/licenses/MIT>
7
 * @link http://www.github.com/andela-sakande
8
 * */
9
namespace Sirolad\Test;
10
11
use Mockery;
12
use Sirolad\DB\DBConnect;
13
use Sirolad\Libraries\TableMapper;
14
15
class TableMapperTest extends \PHPUnit_Framework_TestCase
16
{
17
    /**
18
     * Tear down all mock objects
19
     */
20
    public function tearDown()
21
    {
22
        Mockery::close();
23
    }
24
25
    /**
26
     * Test to check the table exists
27
     * @return string
28
     * @return Exception
29
     * **/
30
    public function testcheckTableName()
31
    {
32
        $dbMock = Mockery::mock('Sirolad\DB\DBConnect');
33
        $statement = Mockery::mock('\PDOStatement');
0 ignored issues
show
Unused Code introduced by
$statement is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
34
        $dbMock->shouldReceive('query')->with('SELECT 1 FROM users LIMIT 1')->andReturn('string');
35
        $this->assertInternalType('string', (TableMapper::checkTableName('users', $dbMock)));
0 ignored issues
show
Unused Code introduced by
The call to TableMapper::checkTableName() has too many arguments starting with $dbMock.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
36
    }
37
38
    /**
39
     * Test to get classname from class namespace
40
     * */
41
    public function testGetClassName()
42
    {
43
        $this->assertInternalType("string", TableMapper::getClassName('Sirolad\Potato\User'));
44
    }
45
}
46