1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use HSAL\HSAL; |
4
|
|
|
|
5
|
|
|
class HSPHPTest extends PHPUnit_Framework_TestCase |
|
|
|
|
6
|
|
|
{ |
7
|
|
|
public function testFetchArray() |
8
|
|
|
{ |
9
|
|
|
$hs = new HSAL('localhost', 'hstest', HSAL::DRIVER_HSPHP); |
10
|
|
|
|
11
|
|
|
$result = $hs->fetchArray('test', ['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', HSAL::DRIVER_HSPHP); |
23
|
|
|
|
24
|
|
|
$result = $hs->fetchAssoc('test', ['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', HSAL::DRIVER_HSPHP); |
36
|
|
|
|
37
|
|
|
$result = $hs->fetchColumn('test', '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', HSAL::DRIVER_HSPHP); |
45
|
|
|
|
46
|
|
|
$result = $hs->fetchAll('test', ['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', HSAL::DRIVER_HSPHP); |
61
|
|
|
|
62
|
|
|
$result = $hs->delete('test', [HSAL::INDEX_PRIMARY => 3]); |
63
|
|
|
|
64
|
|
|
$this->assertTrue($result); |
65
|
|
|
|
66
|
|
|
$result = $hs->delete('test', [HSAL::INDEX_PRIMARY => 3]); |
67
|
|
|
|
68
|
|
|
$this->assertFalse($result); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function testInsert() |
72
|
|
|
{ |
73
|
|
|
$hs = new HSAL('localhost', 'hstest', HSAL::DRIVER_HSPHP); |
74
|
|
|
|
75
|
|
|
$result = $hs->insert('test', ['id' => 3, 'name' => 'new page', 'cnt' => 0]); |
76
|
|
|
|
77
|
|
|
$this->assertTrue($result); |
78
|
|
|
|
79
|
|
|
$result = $hs->fetchColumn('test', 'name', [HSAL::INDEX_PRIMARY => 3]); |
80
|
|
|
|
81
|
|
|
$this->assertEquals('new page', $result); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
View Code Duplication |
public function testUpdate() |
|
|
|
|
85
|
|
|
{ |
86
|
|
|
$hs = new HSAL('localhost', 'hstest', HSAL::DRIVER_HSPHP); |
87
|
|
|
|
88
|
|
|
$result = $hs->update('test', ['name' => 'updated page'], [HSAL::INDEX_PRIMARY => 3]); |
89
|
|
|
|
90
|
|
|
$this->assertTrue($result); |
91
|
|
|
|
92
|
|
|
$result = $hs->fetchColumn('test', 'name', [HSAL::INDEX_PRIMARY => 3]); |
93
|
|
|
|
94
|
|
|
$this->assertEquals('updated page', $result); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
View Code Duplication |
public function testIncrement() |
|
|
|
|
98
|
|
|
{ |
99
|
|
|
$hs = new HSAL('localhost', 'hstest', HSAL::DRIVER_HSPHP); |
100
|
|
|
|
101
|
|
|
$result = $hs->increment('test', 'cnt', [HSAL::INDEX_PRIMARY => 3]); |
102
|
|
|
|
103
|
|
|
$this->assertTrue($result); |
104
|
|
|
|
105
|
|
|
$result = $hs->fetchColumn('test', 'cnt', [HSAL::INDEX_PRIMARY => 3]); |
106
|
|
|
|
107
|
|
|
$this->assertEquals(1, $result); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
View Code Duplication |
public function testDecrement() |
|
|
|
|
111
|
|
|
{ |
112
|
|
|
$hs = new HSAL('localhost', 'hstest', HSAL::DRIVER_HSPHP); |
113
|
|
|
|
114
|
|
|
$result = $hs->decrement('test', 'cnt', [HSAL::INDEX_PRIMARY => 3]); |
115
|
|
|
|
116
|
|
|
$this->assertTrue($result); |
117
|
|
|
|
118
|
|
|
$result = $hs->fetchColumn('test', 'cnt', [HSAL::INDEX_PRIMARY => 3]); |
119
|
|
|
|
120
|
|
|
$this->assertEquals(0, $result); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
} |
124
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.