2009-01-04 19:15:32 +03:00
|
|
|
<?php
|
|
|
|
|
2009-01-22 22:38:10 +03:00
|
|
|
namespace Doctrine\Tests\Mocks;
|
2008-04-13 01:35:21 +04:00
|
|
|
|
|
|
|
/**
|
2009-12-11 00:27:20 +03:00
|
|
|
* This class is a mock of the Statement interface that can be passed in to the Hydrator
|
2008-04-13 01:35:21 +04:00
|
|
|
* to test the hydration standalone with faked result sets.
|
|
|
|
*
|
|
|
|
* @author Roman Borschel <roman@code-factory.org>
|
|
|
|
*/
|
2011-11-12 15:56:44 +04:00
|
|
|
class HydratorMockStatement implements \IteratorAggregate, \Doctrine\DBAL\Driver\Statement
|
2008-04-13 01:35:21 +04:00
|
|
|
{
|
2012-12-14 22:55:28 +04:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2011-11-12 15:56:44 +04:00
|
|
|
private $_resultSet;
|
|
|
|
|
2008-04-13 01:35:21 +04:00
|
|
|
/**
|
|
|
|
* Creates a new mock statement that will serve the provided fake result set to clients.
|
|
|
|
*
|
2012-12-14 22:55:28 +04:00
|
|
|
* @param array $resultSet The faked SQL result set.
|
2008-04-13 01:35:21 +04:00
|
|
|
*/
|
|
|
|
public function __construct(array $resultSet)
|
|
|
|
{
|
|
|
|
$this->_resultSet = $resultSet;
|
|
|
|
}
|
2011-11-12 15:56:44 +04:00
|
|
|
|
2008-04-13 01:35:21 +04:00
|
|
|
/**
|
|
|
|
* Fetches all rows from the result set.
|
|
|
|
*
|
2012-12-14 22:55:28 +04:00
|
|
|
* @param int|null $fetchStyle
|
|
|
|
* @param int|null $columnIndex
|
|
|
|
* @param array|null $ctorArgs
|
|
|
|
*
|
2008-04-13 01:35:21 +04:00
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function fetchAll($fetchStyle = null, $columnIndex = null, array $ctorArgs = null)
|
|
|
|
{
|
|
|
|
return $this->_resultSet;
|
|
|
|
}
|
2011-11-12 15:56:44 +04:00
|
|
|
|
2012-12-14 22:55:28 +04:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2008-05-18 20:21:55 +04:00
|
|
|
public function fetchColumn($columnNumber = 0)
|
|
|
|
{
|
2009-12-11 00:27:20 +03:00
|
|
|
$row = current($this->_resultSet);
|
2008-05-18 20:21:55 +04:00
|
|
|
if ( ! is_array($row)) return false;
|
|
|
|
$val = array_shift($row);
|
|
|
|
return $val !== null ? $val : false;
|
|
|
|
}
|
2011-11-12 15:56:44 +04:00
|
|
|
|
2008-04-13 01:35:21 +04:00
|
|
|
/**
|
2012-12-14 22:55:28 +04:00
|
|
|
* {@inheritdoc}
|
2008-04-13 01:35:21 +04:00
|
|
|
*/
|
2009-12-11 00:27:20 +03:00
|
|
|
public function fetch($fetchStyle = null)
|
2008-04-13 01:35:21 +04:00
|
|
|
{
|
2009-12-11 00:27:20 +03:00
|
|
|
$current = current($this->_resultSet);
|
|
|
|
next($this->_resultSet);
|
|
|
|
return $current;
|
2008-04-13 01:35:21 +04:00
|
|
|
}
|
2011-11-12 15:56:44 +04:00
|
|
|
|
2008-04-13 01:35:21 +04:00
|
|
|
/**
|
2012-12-14 22:55:28 +04:00
|
|
|
* {@inheritdoc}
|
2008-04-13 01:35:21 +04:00
|
|
|
*/
|
|
|
|
public function closeCursor()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2011-11-12 15:56:44 +04:00
|
|
|
|
2012-12-14 22:55:28 +04:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2009-12-11 00:27:20 +03:00
|
|
|
public function bindValue($param, $value, $type = null)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-12-14 22:55:28 +04:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2013-03-14 22:33:21 +04:00
|
|
|
public function bindParam($column, &$variable, $type = null, $length = null)
|
2009-12-11 00:27:20 +03:00
|
|
|
{
|
|
|
|
}
|
2011-11-12 15:56:44 +04:00
|
|
|
|
2012-12-14 22:55:28 +04:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2009-12-11 00:27:20 +03:00
|
|
|
public function columnCount()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-12-14 22:55:28 +04:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2009-12-11 00:27:20 +03:00
|
|
|
public function errorCode()
|
|
|
|
{
|
|
|
|
}
|
2011-11-12 15:56:44 +04:00
|
|
|
|
2012-12-14 22:55:28 +04:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2009-12-11 00:27:20 +03:00
|
|
|
public function errorInfo()
|
|
|
|
{
|
|
|
|
}
|
2011-11-12 15:56:44 +04:00
|
|
|
|
2012-12-14 22:55:28 +04:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2009-12-11 00:27:20 +03:00
|
|
|
public function execute($params = array())
|
|
|
|
{
|
|
|
|
}
|
2011-11-12 15:56:44 +04:00
|
|
|
|
2012-12-14 22:55:28 +04:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2009-12-11 00:27:20 +03:00
|
|
|
public function rowCount()
|
|
|
|
{
|
2011-11-12 15:56:44 +04:00
|
|
|
}
|
|
|
|
|
2012-12-14 22:55:28 +04:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2011-11-12 15:56:44 +04:00
|
|
|
public function getIterator()
|
|
|
|
{
|
|
|
|
return $this->_resultSet;
|
|
|
|
}
|
|
|
|
|
2012-12-14 22:55:28 +04:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2012-06-25 07:29:14 +04:00
|
|
|
public function setFetchMode($fetchStyle, $arg2 = null, $arg3 = null)
|
2011-11-12 15:56:44 +04:00
|
|
|
{
|
|
|
|
}
|
2012-12-14 22:55:28 +04:00
|
|
|
}
|