1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use HSAL\HSAL; |
4
|
|
|
|
5
|
|
|
class HSPHPTest extends PHPUnit_Framework_TestCase |
|
|
|
|
6
|
|
|
{ |
7
|
|
View Code Duplication |
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
|
|
View Code Duplication |
public function testFetchAssoc() |
|
|
|
|
21
|
|
|
{ |
22
|
|
|
$hs = new HSAL('localhost', 'hstest', HSAL::DRIVER_HSPHP); |
23
|
|
|
|
24
|
|
|
$result = $hs->fetchArray('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->fetchArray('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(1, $result[0]['id']); |
52
|
|
|
$this->assertEquals(3, $result[2]['id']); |
53
|
|
|
|
54
|
|
|
$this->assertEquals('page 1', $result[0]['name']); |
55
|
|
|
$this->assertEquals('page 3', $result[2]['name']); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
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.