Completed
Pull Request — master (#11)
by Elisha-Wigwe Chijioke
03:03
created

DatabaseTest::testGetAllAsStatic()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 1
Metric Value
c 3
b 1
f 1
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
use Elchroy\PotatoORM\PotatoModel;
4
use Mockery as m;
5
6
class DatabaseTest extends PHPUnit_Framework_TestCase
7
{
8
    private $connection;
9
    private $query;
10
    private $connector;
11
    private $db;
12
13
    public function setUp()
14
    {
15
        $this->connector = m::mock('Elchroy\PotatoORM\PotatoConnector');
16
        $this->connector->shouldReceive('setConnection')->andReturn($this->connection);
17
        $this->query = m::mock('Elchroy\PotatoORM\PotatoQuery', [$this->connector]);
18
    }
19
20
    public function testGetAllAsStatic()
21
    {
22
        $this->query->connection = $this->db;
0 ignored issues
show
Bug introduced by
Accessing connection on the interface Mockery\MockInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
23
        $this->query->shouldReceive('getFrom');
24
        $dogs = Dog::getAll($this->query);
0 ignored issues
show
Unused Code introduced by
$dogs 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...
25
    }
26
27
    public function testFindIdAsStatic()
28
    {
29
        $this->query->connection = $this->db;
0 ignored issues
show
Bug introduced by
Accessing connection on the interface Mockery\MockInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
30
        $this->query->shouldReceive('getOne')->with('dog', 3);
31
        $dog = Dog::find(3, $this->query);
0 ignored issues
show
Unused Code introduced by
$dog 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...
32
    }
33
34
    public function testDeleteIdAsStatic()
35
    {
36
        $this->query->connection = $this->db;
0 ignored issues
show
Bug introduced by
Accessing connection on the interface Mockery\MockInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
37
        $this->query->shouldReceive('deleteFrom')->with('dog', 1);
38
        $this->query->shouldReceive('getFrom');
39
        $dog = Dog::destroy(1, $this->query);
0 ignored issues
show
Unused Code introduced by
$dog 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...
40
    }
41
42
    public function testDataBasecolumn()
43
    {
44
    }
45
}
46
47
class Dog extends PotatoModel
48
{
49
}
50