HydratorMockStatement.php 2.15 KB
Newer Older
romanb's avatar
romanb committed
1 2
<?php

3
namespace Doctrine\Tests\Mocks;
4 5

/**
6
 * This class is a mock of the Statement interface that can be passed in to the Hydrator
7 8 9 10
 * to test the hydration standalone with faked result sets.
 *
 * @author  Roman Borschel <roman@code-factory.org>
 */
11
class HydratorMockStatement implements \Doctrine\DBAL\Driver\Statement
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
{
    private $_resultSet;    
    
    /**
     * Creates a new mock statement that will serve the provided fake result set to clients.
     *
     * @param array $resultSet  The faked SQL result set.
     */
    public function __construct(array $resultSet)
    {
        $this->_resultSet = $resultSet;
    }
    
    /**
     * Fetches all rows from the result set.
     *
     * @return array
     */
    public function fetchAll($fetchStyle = null, $columnIndex = null, array $ctorArgs = null)
    {
        return $this->_resultSet;
    }
    
35 36
    public function fetchColumn($columnNumber = 0)
    {
37
        $row = current($this->_resultSet);
38 39 40 41 42
        if ( ! is_array($row)) return false;
        $val = array_shift($row);
        return $val !== null ? $val : false;
    }
    
43 44
    /**
     * Fetches the next row in the result set.
45
     * 
46
     */
47
    public function fetch($fetchStyle = null)
48
    {
49 50 51
        $current = current($this->_resultSet);
        next($this->_resultSet);
        return $current;
52 53 54 55 56 57 58 59 60 61 62 63 64 65
    }
    
    /**
     * Closes the cursor, enabling the statement to be executed again.
     *
     * @return boolean
     */
    public function closeCursor()
    {
        return true;
    }
    
    public function setResultSet(array $resultSet)
    {
66
        reset($resultSet);
67 68
        $this->_resultSet = $resultSet;
    }
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
    
    public function bindColumn($column, &$param, $type = null)
    {
    }

    public function bindValue($param, $value, $type = null)
    {
    }

    public function bindParam($column, &$variable, $type = null, $length = null, $driverOptions = array())
    {
    }
    
    public function columnCount()
    {
    }

    public function errorCode()
    {
    }
    
    public function errorInfo()
    {
    }
    
    public function execute($params = array())
    {
    }
    
    public function rowCount()
    {
    }  
101
}