blob: 0e489bd33017c0e7161b492e7ca2859cd691a8fd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
<?php
require_once dirname(__FILE__) . '/../idiorm.php';
/**
*
* Mock version of the PDOStatement class.
*
*/
class MockPDOStatement extends PDOStatement {
private $current_row = 0;
public function __construct() {}
public function execute($params) {}
/**
* Return some dummy data
*/
public function fetch($fetch_style=PDO::FETCH_BOTH, $cursor_orientation=PDO::FETCH_ORI_NEXT, $cursor_offset=0) {
if ($this->current_row == 5) {
return false;
} else {
return array('name' => 'Fred', 'age' => 10, 'id' => ++$this->current_row);
}
}
}
/**
* Another mock PDOStatement class, used for testing multiple connections
*/
class MockDifferentPDOStatement extends MockPDOStatement { }
/**
*
* Mock database class implementing a subset
* of the PDO API.
*
*/
class MockPDO extends PDO {
/**
* Return a dummy PDO statement
*/
public function prepare($statement, $driver_options=array()) {
$this->last_query = new MockPDOStatement($statement);
return $this->last_query;
}
}
/**
* A different mock database class, for testing multiple connections
* Mock database class implementing a subset of the PDO API.
*/
class MockDifferentPDO extends MockPDO {
/**
* Return a dummy PDO statement
*/
public function prepare($statement, $driver_options = array()) {
$this->last_query = new MockDifferentPDOStatement($statement);
return $this->last_query;
}
}
class MockMsSqlPDO extends MockPDO {
public $fake_driver = 'mssql';
/**
* If we are asking for the name of the driver, check if a fake one
* has been set.
*/
public function getAttribute($attribute) {
if ($attribute == self::ATTR_DRIVER_NAME) {
if (!is_null($this->fake_driver)) {
return $this->fake_driver;
}
}
return parent::getAttribute($attribute);
}
}
|