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() |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
$query = 'some query'; |
47
|
|
|
$bindingsList = ['a', 'B', 'C']; |
48
|
|
|
$this->rawClientMock->shouldReceive('executeQuery') |
|
|
|
|
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() |
|
|
|
|
62
|
|
|
{ |
63
|
|
|
$table = 'some table'; |
64
|
|
|
$data = ['a', 'B', 'C']; |
65
|
|
|
$this->crudClientMock->shouldReceive('create') |
|
|
|
|
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') |
|
|
|
|
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') |
|
|
|
|
102
|
|
|
->once() |
103
|
|
|
->with($table, $data, $filter); |
104
|
|
|
|
105
|
|
|
$this->adapter->update($table, $data, $filter); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
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.