# Source for file Mock.php

Documentation is available at Mock.php

1. <?php
2. /*
3. * $Id: Mock.php 1917 2007-07-01 11:27:45Z zYne $
4. *
5. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
10. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16. *
17. * This software consists of voluntary contributions made by many individuals
18. * and is licensed under the LGPL. For more information, see
19. * <http://www.phpdoctrine.com>.
20. */
21. /**
22. * Doctrine_Adapter_Statement_Mock
23. * This class is used for special testing purposes.
24. *
25. * @package Doctrine
26. * @subpackage Doctrine_Adapter
27. * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
28. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
29. * @category Object Relational Mapping
30. * @link www.phpdoctrine.com
31. * @since 1.0
32. * @version $Revision: 1917 $
33. */
34. class Doctrine_Adapter_Statement_Mock implements Doctrine_Adapter_Statement_Interface
35. {
36. private $mock;
38. public $queryString;
40. public function __construct($mock)
41. {
42. $this->mock = $mock;
43. }
44. /**
45. * bindColumn
46. * Bind a column to a PHP variable
47. *
48. * @param mixed $column Number of the column (1-indexed) or name of the column in the result set.
49. * If using the column name, be aware that the name should match
50. * the case of the column, as returned by the driver.
51. * @param string $param Name of the PHP variable to which the column will be bound.
52. * @param integer $type Data type of the parameter, specified by the Doctrine::PARAM_* constants.
53. * @return boolean Returns TRUE on success or FALSE on failure
54. */
55. public function bindColumn($column, $param, $type = null)
56. {
58. }
59. /**
60. * bindValue
61. * Binds a value to a corresponding named or question mark
62. * placeholder in the SQL statement that was use to prepare the statement.
63. *
64. * @param mixed $param Parameter identifier. For a prepared statement using named placeholders,
65. * this will be a parameter name of the form :name. For a prepared statement
66. * using question mark placeholders, this will be the 1-indexed position of the parameter
67. *
68. * @param mixed $value The value to bind to the parameter.
69. * @param integer $type Explicit data type for the parameter using the Doctrine::PARAM_* constants.
70. *
71. * @return boolean Returns TRUE on success or FALSE on failure.
72. */
73. public function bindValue($param, $value, $type = null)
74. {
76. }
77. /**
78. * bindParam
79. * Binds a PHP variable to a corresponding named or question mark placeholder in the
80. * SQL statement that was use to prepare the statement. Unlike Doctrine_Adapter_Statement_Interface->bindValue(),
81. * the variable is bound as a reference and will only be evaluated at the time
82. * that Doctrine_Adapter_Statement_Interface->execute() is called.
83. *
84. * Most parameters are input parameters, that is, parameters that are
85. * used in a read-only fashion to build up the query. Some drivers support the invocation
86. * of stored procedures that return data as output parameters, and some also as input/output
87. * parameters that both send in data and are updated to receive it.
88. *
89. * @param mixed $param Parameter identifier. For a prepared statement using named placeholders,
90. * this will be a parameter name of the form :name. For a prepared statement
91. * using question mark placeholders, this will be the 1-indexed position of the parameter
92. *
93. * @param mixed $variable Name of the PHP variable to bind to the SQL statement parameter.
94. *
95. * @param integer $type Explicit data type for the parameter using the Doctrine::PARAM_* constants. To return
96. * an INOUT parameter from a stored procedure, use the bitwise OR operator to set the
97. * Doctrine::PARAM_INPUT_OUTPUT bits for the data_type parameter.
98. *
99. * @param integer $length Length of the data type. To indicate that a parameter is an OUT parameter
100. * from a stored procedure, you must explicitly set the length.
101. * @param mixed $driverOptions
102. * @return boolean Returns TRUE on success or FALSE on failure.
103. */
104. public function bindParam($column, $variable, $type = null, $length = null, $driverOptions = array())
105. {
107. }
108. /**
109. * closeCursor
110. * Closes the cursor, enabling the statement to be executed again.
111. *
112. * @return boolean Returns TRUE on success or FALSE on failure.
113. */
114. public function closeCursor()
115. {
116. return true;
117. }
118. /**
119. * columnCount
120. * Returns the number of columns in the result set
121. *
122. * @return integer Returns the number of columns in the result set represented
123. * by the Doctrine_Adapter_Statement_Interface object. If there is no result set,
124. * this method should return 0.
125. */
126. public function columnCount()
127. {
128. return 0;
129. }
130. /**
131. * errorCode
132. * Fetch the SQLSTATE associated with the last operation on the statement handle
133. *
134. * @see Doctrine_Adapter_Interface::errorCode()
135. * @return string error code string
136. */
137. public function errorCode()
138. {
139. return array();
140. }
141. /**
142. * errorInfo
143. * Fetch extended error information associated with the last operation on the statement handle
144. *
145. * @see Doctrine_Adapter_Interface::errorInfo()
146. * @return array error info array
147. */
148. public function errorInfo()
149. {
150. return array();
151. }
152. /**
153. * fetch
154. *
155. * @see Doctrine::FETCH_* constants
156. * @param integer $fetchStyle Controls how the next row will be returned to the caller.
157. * This value must be one of the Doctrine::FETCH_* constants,
158. * defaulting to Doctrine::FETCH_BOTH
159. *
160. * @param integer $cursorOrientation For a PDOStatement object representing a scrollable cursor,
161. * this value determines which row will be returned to the caller.
162. * This value must be one of the Doctrine::FETCH_ORI_* constants, defaulting to
163. * Doctrine::FETCH_ORI_NEXT. To request a scrollable cursor for your
164. * Doctrine_Adapter_Statement_Interface object,
165. * you must set the Doctrine::ATTR_CURSOR attribute to Doctrine::CURSOR_SCROLL when you
166. * prepare the SQL statement with Doctrine_Adapter_Interface->prepare().
167. *
168. * @param integer $cursorOffset For a Doctrine_Adapter_Statement_Interface object representing a scrollable cursor for which the
169. * $cursorOrientation parameter is set to Doctrine::FETCH_ORI_ABS, this value specifies
170. * the absolute number of the row in the result set that shall be fetched.
171. *
172. * For a Doctrine_Adapter_Statement_Interface object representing a scrollable cursor for
173. * which the $cursorOrientation parameter is set to Doctrine::FETCH_ORI_REL, this value
174. * specifies the row to fetch relative to the cursor position before
175. * Doctrine_Adapter_Statement_Interface->fetch() was called.
176. *
177. * @return mixed
178. */
179. public function fetch($fetchStyle = Doctrine::FETCH_BOTH,
180. $cursorOrientation = Doctrine::FETCH_ORI_NEXT,
181. $cursorOffset = null)
182. {
183. return array();
184. }
185. /**
186. * fetchAll
187. * Returns an array containing all of the result set rows
188. *
189. * @param integer $fetchStyle Controls how the next row will be returned to the caller.
190. * This value must be one of the Doctrine::FETCH_* constants,
191. * defaulting to Doctrine::FETCH_BOTH
192. *
193. * @param integer $columnIndex Returns the indicated 0-indexed column when the value of $fetchStyle is
194. * Doctrine::FETCH_COLUMN. Defaults to 0.
195. *
196. * @return array
197. */
198. public function fetchAll($fetchMode = Doctrine::FETCH_BOTH)
199. {
200. return array();
201. }
202. /**
203. * execute
204. * Executes a prepared statement
205. *
206. * If the prepared statement included parameter markers, you must either:
207. * call PDOStatement->bindParam() to bind PHP variables to the parameter markers:
208. * bound variables pass their value as input and receive the output value,
209. * if any, of their associated parameter markers or pass an array of input-only
210. * parameter values
211. *
212. *
213. * @param array $params An array of values with as many elements as there are
214. * bound parameters in the SQL statement being executed.
215. * @return boolean Returns TRUE on success or FALSE on failure.
216. */
217. public function execute($params = null)
218. {
219. if(is_object($this->mock)) {
220. $this->mock->addQuery($this->queryString);
221. }
222. return true;
223. }
224. /**
225. * fetchColumn
226. * Returns a single column from the next row of a
227. * result set or FALSE if there are no more rows.
228. *
229. * @param integer $columnIndex 0-indexed number of the column you wish to retrieve from the row. If no
230. * value is supplied, Doctrine_Adapter_Statement_Interface->fetchColumn()
231. * fetches the first column.
232. *
233. * @return string returns a single column in the next row of a result set.
234. */
235. public function fetchColumn($columnIndex = 0)
236. {
237. return 0;
238. }
239. /**
240. * fetchObject
241. * Fetches the next row and returns it as an object.
242. *
243. * Fetches the next row and returns it as an object. This function is an alternative to
244. * Doctrine_Adapter_Statement_Interface->fetch() with Doctrine::FETCH_CLASS or Doctrine::FETCH_OBJ style.
245. *
246. * @param string $className Name of the created class, defaults to stdClass.
247. * @param array $args Elements of this array are passed to the constructor.
248. *
249. * @return mixed an instance of the required class with property names that correspond
250. * to the column names or FALSE in case of an error.
251. */
252. public function fetchObject($className = 'stdClass', $args = array())
253. {
254. return new $className();
255. }
256. /**
257. * nextRowset
258. * Advances to the next rowset in a multi-rowset statement handle
259. *
260. * Some database servers support stored procedures that return more than one rowset
261. * (also known as a result set). The nextRowset() method enables you to access the second
262. * and subsequent rowsets associated with a PDOStatement object. Each rowset can have a
263. * different set of columns from the preceding rowset.
264. *
265. * @return boolean Returns TRUE on success or FALSE on failure.
266. */
267. public function nextRowset()
268. {
269. return true;
270. }
271. /**
272. * rowCount
273. * rowCount() returns the number of rows affected by the last DELETE, INSERT, or UPDATE statement
274. * executed by the corresponding object.
275. *
276. * If the last SQL statement executed by the associated Statement object was a SELECT statement,
277. * some databases may return the number of rows returned by that statement. However,
278. * this behaviour is not guaranteed for all databases and should not be
279. * relied on for portable applications.
280. *
281. * @return integer Returns the number of rows.
282. */
283. public function rowCount()
284. {
285. return 0;
286. }
287. /**
288. * getColumnMeta
289. * Returns metadata for a column in a result set
290. *
291. * @param integer $column The 0-indexed column in the result set.
292. *
293. * @return array Associative meta data array with the following structure:
294. *
295. * native_type The PHP native type used to represent the column value.
296. * driver:decl_ type The SQL type used to represent the column value in the database. If the column in the result set is the result of a function, this value is not returned by PDOStatement->getColumnMeta().
297. * flags Any flags set for this column.
298. * name The name of this column as returned by the database.
299. * len The length of this column. Normally -1 for types other than floating point decimals.
300. * precision The numeric precision of this column. Normally 0 for types other than floating point decimals.
301. * pdo_type The type of this column as represented by the PDO::PARAM_* constants.
302. */
303. public function getColumnMeta($column)
304. { }
305. /**
306. * getAttribute
307. * Retrieve a statement attribute
308. *
309. * @param integer $attribute
310. * @see Doctrine::ATTR_* constants
311. * @return mixed the attribute value
312. */
313. public function getAttribute($attribute)
314. { }
315. /**
316. * setAttribute
317. * Set a statement attribute
318. *
319. * @param integer $attribute
320. * @param mixed $value the value of given attribute
321. * @return boolean Returns TRUE on success or FALSE on failure.
322. */
323. public function setAttribute($attribute, $value)
324. { }
325. /**
326. * setFetchMode
327. * Set the default fetch mode for this statement
328. *
329. * @param integer $mode The fetch mode must be one of the Doctrine::FETCH_* constants.
330. * @return boolean Returns 1 on success or FALSE on failure.
331. */
332. public function setFetchMode($mode, $arg1 = null, $arg2 = null)
333. { }
334. }