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