1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\Mocks; |
4
|
|
|
|
5
|
|
|
class ConnectionMock extends \Doctrine\DBAL\Connection |
6
|
|
|
{ |
7
|
|
|
private $_fetchOneResult; |
8
|
|
|
private $_platformMock; |
9
|
|
|
private $_lastInsertId = 0; |
10
|
|
|
private $_inserts = array(); |
11
|
|
|
|
12
|
|
|
public function __construct(array $params, $driver, $config = null, $eventManager = null) |
13
|
|
|
{ |
14
|
|
|
$this->_platformMock = new DatabasePlatformMock(); |
15
|
|
|
|
16
|
|
|
parent::__construct($params, $driver, $config, $eventManager); |
17
|
|
|
|
18
|
|
|
// Override possible assignment of platform to database platform mock |
19
|
|
|
$this->_platform = $this->_platformMock; |
|
|
|
|
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @override |
24
|
|
|
*/ |
25
|
|
|
public function getDatabasePlatform() |
26
|
|
|
{ |
27
|
|
|
return $this->_platformMock; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @override |
32
|
|
|
*/ |
33
|
|
|
public function insert($tableName, array $data, array $types = array()) |
34
|
|
|
{ |
35
|
|
|
$this->_inserts[$tableName][] = $data; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @override |
40
|
|
|
*/ |
41
|
|
|
public function lastInsertId($seqName = null) |
42
|
|
|
{ |
43
|
|
|
return $this->_lastInsertId; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @override |
48
|
|
|
*/ |
49
|
|
|
public function fetchColumn($statement, array $params = array(), $colnum = 0, array $types = array()) |
50
|
|
|
{ |
51
|
|
|
return $this->_fetchOneResult; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @override |
56
|
|
|
*/ |
57
|
|
|
public function quote($input, $type = null) |
58
|
|
|
{ |
59
|
|
|
if (is_string($input)) { |
60
|
|
|
return "'" . $input . "'"; |
61
|
|
|
} |
62
|
|
|
return $input; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/* Mock API */ |
66
|
|
|
|
67
|
|
|
public function setFetchOneResult($fetchOneResult) |
68
|
|
|
{ |
69
|
|
|
$this->_fetchOneResult = $fetchOneResult; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function setLastInsertId($id) |
73
|
|
|
{ |
74
|
|
|
$this->_lastInsertId = $id; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function getInserts() |
78
|
|
|
{ |
79
|
|
|
return $this->_inserts; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function reset() |
83
|
|
|
{ |
84
|
|
|
$this->_inserts = array(); |
85
|
|
|
$this->_lastInsertId = 0; |
86
|
|
|
} |
87
|
|
|
} |