Coverage for Doctrine_Adapter_Statement_Mock

Back to coverage report

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