1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use HSAL\HSAL; |
4
|
|
|
|
5
|
|
View Code Duplication |
class HandlersocketiTest extends PHPUnit_Framework_TestCase |
|
|
|
|
6
|
|
|
{ |
7
|
|
|
public function testFetchArray() |
8
|
|
|
{ |
9
|
|
|
$hs = new HSAL('localhost', 'hstest', ['driver' => HSAL::DRIVER_HANDLERSOCKETI]); |
10
|
|
|
|
11
|
|
|
$result = $hs->fetchArray('test2', ['id','name','cnt'], [HSAL::INDEX_PRIMARY => 3]); |
12
|
|
|
|
13
|
|
|
$this->assertTrue(is_array($result)); |
14
|
|
|
$this->assertEquals(3, count($result)); |
15
|
|
|
$this->assertEquals(3, $result[0]); |
16
|
|
|
$this->assertEquals('page 3', $result[1]); |
17
|
|
|
$this->assertEquals(0, $result[2]); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function testFetchAssoc() |
21
|
|
|
{ |
22
|
|
|
$hs = new HSAL('localhost', 'hstest', ['driver' => HSAL::DRIVER_HANDLERSOCKETI]); |
23
|
|
|
|
24
|
|
|
$result = $hs->fetchAssoc('test2', ['id','name','cnt'], [HSAL::INDEX_PRIMARY => 3]); |
25
|
|
|
|
26
|
|
|
$this->assertTrue(is_array($result)); |
27
|
|
|
$this->assertEquals(3, count($result)); |
28
|
|
|
$this->assertEquals(3, $result['id']); |
29
|
|
|
$this->assertEquals('page 3', $result['name']); |
30
|
|
|
$this->assertEquals(0, $result['cnt']); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testFetchColumn() |
34
|
|
|
{ |
35
|
|
|
$hs = new HSAL('localhost', 'hstest', ['driver' => HSAL::DRIVER_HANDLERSOCKETI]); |
36
|
|
|
|
37
|
|
|
$result = $hs->fetchColumn('test2', 'name', [HSAL::INDEX_PRIMARY => 3]); |
38
|
|
|
|
39
|
|
|
$this->assertEquals('page 3', $result); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testFetchAll() |
43
|
|
|
{ |
44
|
|
|
$hs = new HSAL('localhost', 'hstest', ['driver' => HSAL::DRIVER_HANDLERSOCKETI]); |
45
|
|
|
|
46
|
|
|
$result = $hs->fetchAll('test2', ['id', 'name'], [HSAL::INDEX_PRIMARY => 3], HSAL::OPERATOR_LESS_EQUAL); |
47
|
|
|
|
48
|
|
|
$this->assertTrue(is_array($result)); |
49
|
|
|
$this->assertEquals(3, count($result)); |
50
|
|
|
|
51
|
|
|
$this->assertEquals(3, $result[0]['id']); |
52
|
|
|
$this->assertEquals(1, $result[2]['id']); |
53
|
|
|
|
54
|
|
|
$this->assertEquals('page 3', $result[0]['name']); |
55
|
|
|
$this->assertEquals('page 1', $result[2]['name']); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testDelete() |
59
|
|
|
{ |
60
|
|
|
$hs = new HSAL('localhost', 'hstest', ['driver' => HSAL::DRIVER_HANDLERSOCKETI]); |
61
|
|
|
|
62
|
|
|
$result = $hs->delete('test2', [HSAL::INDEX_PRIMARY => 3]); |
63
|
|
|
|
64
|
|
|
$this->assertTrue($result); |
65
|
|
|
|
66
|
|
|
$result = $hs->delete('test2', [HSAL::INDEX_PRIMARY => 3]); |
67
|
|
|
|
68
|
|
|
$this->assertFalse($result); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function testInsert() |
72
|
|
|
{ |
73
|
|
|
$hs = new HSAL('localhost', 'hstest', ['driver' => HSAL::DRIVER_HANDLERSOCKETI]); |
74
|
|
|
|
75
|
|
|
$result = $hs->insert('test2', ['id' => 3, 'name' => 'new page', 'cnt' => 0]); |
|
|
|
|
76
|
|
|
|
77
|
|
|
$result = $hs->fetchColumn('test2', 'name', [HSAL::INDEX_PRIMARY => 3]); |
78
|
|
|
|
79
|
|
|
$this->assertEquals('new page', $result); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function testUpdate() |
83
|
|
|
{ |
84
|
|
|
$hs = new HSAL('localhost', 'hstest', ['driver' => HSAL::DRIVER_HANDLERSOCKETI]); |
85
|
|
|
|
86
|
|
|
$result = $hs->update('test2', ['name' => 'updated page'], [HSAL::INDEX_PRIMARY => 3]); |
87
|
|
|
|
88
|
|
|
$this->assertTrue($result); |
89
|
|
|
|
90
|
|
|
$result = $hs->fetchColumn('test2', 'name', [HSAL::INDEX_PRIMARY => 3]); |
91
|
|
|
|
92
|
|
|
$this->assertEquals('updated page', $result); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function testIncrement() |
96
|
|
|
{ |
97
|
|
|
$hs = new HSAL('localhost', 'hstest', ['driver' => HSAL::DRIVER_HANDLERSOCKETI]); |
98
|
|
|
|
99
|
|
|
$result = $hs->increment('test2', 'cnt', [HSAL::INDEX_PRIMARY => 3]); |
100
|
|
|
|
101
|
|
|
$this->assertTrue($result); |
102
|
|
|
|
103
|
|
|
$result = $hs->fetchColumn('test2', 'cnt', [HSAL::INDEX_PRIMARY => 3]); |
104
|
|
|
|
105
|
|
|
$this->assertEquals(1, $result); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function testDecrement() |
109
|
|
|
{ |
110
|
|
|
$hs = new HSAL('localhost', 'hstest', ['driver' => HSAL::DRIVER_HANDLERSOCKETI]); |
111
|
|
|
|
112
|
|
|
$result = $hs->decrement('test2', 'cnt', [HSAL::INDEX_PRIMARY => 3]); |
113
|
|
|
|
114
|
|
|
$this->assertTrue($result); |
115
|
|
|
|
116
|
|
|
$result = $hs->fetchColumn('test2', 'cnt', [HSAL::INDEX_PRIMARY => 3]); |
117
|
|
|
|
118
|
|
|
$this->assertEquals(0, $result); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
} |
122
|
|
|
|
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.