ConnectionMock.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace Doctrine\Tests\Mocks;
  3. class ConnectionMock extends \Doctrine\DBAL\Connection
  4. {
  5. private $_fetchOneResult;
  6. private $_platformMock;
  7. private $_lastInsertId = 0;
  8. private $_inserts = array();
  9. private $_executeUpdates = array();
  10. public function __construct(array $params, $driver, $config = null, $eventManager = null)
  11. {
  12. $this->_platformMock = new DatabasePlatformMock();
  13. parent::__construct($params, $driver, $config, $eventManager);
  14. // Override possible assignment of platform to database platform mock
  15. $this->_platform = $this->_platformMock;
  16. }
  17. /**
  18. * @override
  19. */
  20. public function getDatabasePlatform()
  21. {
  22. return $this->_platformMock;
  23. }
  24. /**
  25. * @override
  26. */
  27. public function insert($tableName, array $data, array $types = array())
  28. {
  29. $this->_inserts[$tableName][] = $data;
  30. }
  31. /**
  32. * @override
  33. */
  34. public function executeUpdate($query, array $params = array(), array $types = array())
  35. {
  36. $this->_executeUpdates[] = array('query' => $query, 'params' => $params, 'types' => $types);
  37. }
  38. /**
  39. * @override
  40. */
  41. public function lastInsertId($seqName = null)
  42. {
  43. return $this->_lastInsertId;
  44. }
  45. /**
  46. * @override
  47. */
  48. public function fetchColumn($statement, array $params = array(), $colnum = 0)
  49. {
  50. return $this->_fetchOneResult;
  51. }
  52. /**
  53. * @override
  54. */
  55. public function quote($input, $type = null)
  56. {
  57. if (is_string($input)) {
  58. return "'" . $input . "'";
  59. }
  60. return $input;
  61. }
  62. /* Mock API */
  63. public function setFetchOneResult($fetchOneResult)
  64. {
  65. $this->_fetchOneResult = $fetchOneResult;
  66. }
  67. public function setDatabasePlatform($platform)
  68. {
  69. $this->_platformMock = $platform;
  70. }
  71. public function setLastInsertId($id)
  72. {
  73. $this->_lastInsertId = $id;
  74. }
  75. public function getInserts()
  76. {
  77. return $this->_inserts;
  78. }
  79. public function getExecuteUpdates()
  80. {
  81. return $this->_executeUpdates;
  82. }
  83. public function reset()
  84. {
  85. $this->_inserts = array();
  86. $this->_lastInsertId = 0;
  87. }
  88. }