HydratorMockStatement.php 2.1KB

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