|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\Mocks; |
|
4
|
|
|
use Doctrine\DBAL\Connection; |
|
5
|
|
|
use Doctrine\DBAL\Driver\Statement; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Mock class for Connection. |
|
9
|
|
|
*/ |
|
10
|
|
|
class ConnectionMock extends Connection |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var mixed |
|
14
|
|
|
*/ |
|
15
|
|
|
private $_fetchOneResult; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var Statement |
|
19
|
|
|
*/ |
|
20
|
|
|
private $_queryResult; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var DatabasePlatformMock |
|
24
|
|
|
*/ |
|
25
|
|
|
private $_platformMock; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var int |
|
29
|
|
|
*/ |
|
30
|
|
|
private $_lastInsertId = 0; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var array |
|
34
|
|
|
*/ |
|
35
|
|
|
private $_inserts = array(); |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var array |
|
39
|
|
|
*/ |
|
40
|
|
|
private $_executeUpdates = array(); |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param array $params |
|
44
|
|
|
* @param \Doctrine\DBAL\Driver $driver |
|
45
|
|
|
* @param \Doctrine\DBAL\Configuration|null $config |
|
46
|
|
|
* @param \Doctrine\Common\EventManager|null $eventManager |
|
47
|
|
|
*/ |
|
48
|
|
|
public function __construct(array $params, $driver, $config = null, $eventManager = null) |
|
49
|
|
|
{ |
|
50
|
|
|
$this->_platformMock = new DatabasePlatformMock(); |
|
51
|
|
|
|
|
52
|
|
|
parent::__construct($params, $driver, $config, $eventManager); |
|
53
|
|
|
|
|
54
|
|
|
// Override possible assignment of platform to database platform mock |
|
55
|
|
|
$this->_platform = $this->_platformMock; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* {@inheritdoc} |
|
60
|
|
|
*/ |
|
61
|
|
|
public function getDatabasePlatform() |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->_platformMock; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* {@inheritdoc} |
|
68
|
|
|
*/ |
|
69
|
|
|
public function insert($tableName, array $data, array $types = array()) |
|
70
|
|
|
{ |
|
71
|
|
|
$this->_inserts[$tableName][] = $data; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* {@inheritdoc} |
|
76
|
|
|
*/ |
|
77
|
|
|
public function executeUpdate($query, array $params = array(), array $types = array()) |
|
78
|
|
|
{ |
|
79
|
|
|
$this->_executeUpdates[] = array('query' => $query, 'params' => $params, 'types' => $types); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* {@inheritdoc} |
|
84
|
|
|
*/ |
|
85
|
|
|
public function lastInsertId($seqName = null) |
|
86
|
|
|
{ |
|
87
|
|
|
return $this->_lastInsertId; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* {@inheritdoc} |
|
92
|
|
|
*/ |
|
93
|
|
|
public function fetchColumn($statement, array $params = array(), $colnum = 0, array $types = array()) |
|
94
|
|
|
{ |
|
95
|
|
|
return $this->_fetchOneResult; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* {@inheritdoc} |
|
100
|
|
|
*/ |
|
101
|
|
|
public function query() |
|
102
|
|
|
{ |
|
103
|
|
|
return $this->_queryResult; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* {@inheritdoc} |
|
108
|
|
|
*/ |
|
109
|
|
|
public function quote($input, $type = null) |
|
110
|
|
|
{ |
|
111
|
|
|
if (is_string($input)) { |
|
112
|
|
|
return "'" . $input . "'"; |
|
113
|
|
|
} |
|
114
|
|
|
return $input; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/* Mock API */ |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @param mixed $fetchOneResult |
|
121
|
|
|
* |
|
122
|
|
|
* @return void |
|
123
|
|
|
*/ |
|
124
|
|
|
public function setFetchOneResult($fetchOneResult) |
|
125
|
|
|
{ |
|
126
|
|
|
$this->_fetchOneResult = $fetchOneResult; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform |
|
131
|
|
|
* |
|
132
|
|
|
* @return void |
|
133
|
|
|
*/ |
|
134
|
|
|
public function setDatabasePlatform($platform) |
|
135
|
|
|
{ |
|
136
|
|
|
$this->_platformMock = $platform; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* @param int $id |
|
141
|
|
|
* |
|
142
|
|
|
* @return void |
|
143
|
|
|
*/ |
|
144
|
|
|
public function setLastInsertId($id) |
|
145
|
|
|
{ |
|
146
|
|
|
$this->_lastInsertId = $id; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* @param Statement $result |
|
151
|
|
|
*/ |
|
152
|
|
|
public function setQueryResult($result) |
|
153
|
|
|
{ |
|
154
|
|
|
$this->_queryResult = $result; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* @return array |
|
159
|
|
|
*/ |
|
160
|
|
|
public function getInserts() |
|
161
|
|
|
{ |
|
162
|
|
|
return $this->_inserts; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* @return array |
|
167
|
|
|
*/ |
|
168
|
|
|
public function getExecuteUpdates() |
|
169
|
|
|
{ |
|
170
|
|
|
return $this->_executeUpdates; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* @return void |
|
175
|
|
|
*/ |
|
176
|
|
|
public function reset() |
|
177
|
|
|
{ |
|
178
|
|
|
$this->_inserts = array(); |
|
179
|
|
|
$this->_lastInsertId = 0; |
|
180
|
|
|
} |
|
181
|
|
|
} |
|
182
|
|
|
|