MicroDbalAdapterTest::setUpAdapter()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace Hgraca\Phorensic\Test\SharedKernel\Port\Database\Adapter\MicroDbal;
4
5
use Hgraca\MicroDbal\CrudClientInterface;
6
use Hgraca\MicroDbal\RawClientInterface;
7
use Hgraca\Phorensic\SharedKernel\Port\Database\Adapter\MicroDbal\MicroDbalAdapter;
8
use Mockery;
9
use Mockery\MockInterface;
10
use PHPUnit_Framework_TestCase;
11
12
final class MicroDbalAdapterTest extends PHPUnit_Framework_TestCase
13
{
14
    /**
15
     * @var MockInterface|CrudClientInterface
16
     */
17
    private $crudClientMock;
18
19
    /**
20
     * @var MockInterface|RawClientInterface
21
     */
22
    private $rawClientMock;
23
24
    /**
25
     * @var MicroDbalAdapter
26
     */
27
    private $adapter;
28
29
    /**
30
     * @before
31
     */
32
    public function setUpAdapter()
33
    {
34
        $this->crudClientMock = Mockery::mock(CrudClientInterface::class);
35
        $this->rawClientMock = Mockery::mock(RawClientInterface::class);
36
        $this->adapter = new MicroDbalAdapter($this->crudClientMock, $this->rawClientMock);
37
    }
38
39
    /**
40
     * @test
41
     *
42
     * @small
43
     */
44 View Code Duplication
    public function executeQuery()
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...
45
    {
46
        $query = 'some query';
47
        $bindingsList = ['a', 'B', 'C'];
48
        $this->rawClientMock->shouldReceive('executeQuery')
0 ignored issues
show
Bug introduced by
The method shouldReceive does only exist in Mockery\MockInterface, but not in Hgraca\MicroDbal\RawClientInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
49
            ->once()
50
            ->with($query, $bindingsList)
51
            ->andReturn([]);
52
53
        $this->adapter->executeQuery($query, $bindingsList);
54
    }
55
56
    /**
57
     * @test
58
     *
59
     * @small
60
     */
61 View Code Duplication
    public function create()
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...
62
    {
63
        $table = 'some table';
64
        $data = ['a', 'B', 'C'];
65
        $this->crudClientMock->shouldReceive('create')
0 ignored issues
show
Bug introduced by
The method shouldReceive does only exist in Mockery\MockInterface, but not in Hgraca\MicroDbal\CrudClientInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
66
            ->once()
67
            ->with($table, $data);
68
69
        $this->adapter->create($table, $data);
70
    }
71
72
    /**
73
     * @test
74
     *
75
     * @small
76
     */
77
    public function read()
78
    {
79
        $table = 'some table';
80
        $filter = ['C', 'D', 'E'];
81
        $orderBy = ['a', 'B', 'C'];
82
        $limit = 2;
83
        $offset = 3;
84
        $this->crudClientMock->shouldReceive('read')
0 ignored issues
show
Bug introduced by
The method shouldReceive does only exist in Mockery\MockInterface, but not in Hgraca\MicroDbal\CrudClientInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
85
            ->once()
86
            ->with($table, $filter, $orderBy, $limit, $offset);
87
88
        $this->adapter->read($table, $filter, $orderBy, $limit, $offset);
89
    }
90
91
    /**
92
     * @test
93
     *
94
     * @small
95
     */
96
    public function update()
97
    {
98
        $table = 'some table';
99
        $data = ['a', 'B', 'C'];
100
        $filter = ['C', 'D', 'E'];
101
        $this->crudClientMock->shouldReceive('update')
0 ignored issues
show
Bug introduced by
The method shouldReceive does only exist in Mockery\MockInterface, but not in Hgraca\MicroDbal\CrudClientInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
102
            ->once()
103
            ->with($table, $data, $filter);
104
105
        $this->adapter->update($table, $data, $filter);
106
    }
107
}
108