ConnectionMock.php 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. public function __construct(array $params, $driver, $config = null, $eventManager = null)
  10. {
  11. $this->_platformMock = new DatabasePlatformMock();
  12. parent::__construct($params, $driver, $config, $eventManager);
  13. // Override possible assignment of platform to database platform mock
  14. $this->_platform = $this->_platformMock;
  15. }
  16. /**
  17. * @override
  18. */
  19. public function getDatabasePlatform()
  20. {
  21. return $this->_platformMock;
  22. }
  23. /**
  24. * @override
  25. */
  26. public function insert($tableName, array $data)
  27. {
  28. $this->_inserts[$tableName][] = $data;
  29. }
  30. /**
  31. * @override
  32. */
  33. public function lastInsertId($seqName = null)
  34. {
  35. return $this->_lastInsertId;
  36. }
  37. /**
  38. * @override
  39. */
  40. public function fetchColumn($statement, array $params = array(), $colnum = 0)
  41. {
  42. return $this->_fetchOneResult;
  43. }
  44. /**
  45. * @override
  46. */
  47. public function quote($input, $type = null)
  48. {
  49. if (is_string($input)) {
  50. return "'" . $input . "'";
  51. }
  52. return $input;
  53. }
  54. /* Mock API */
  55. public function setFetchOneResult($fetchOneResult)
  56. {
  57. $this->_fetchOneResult = $fetchOneResult;
  58. }
  59. public function setDatabasePlatform($platform)
  60. {
  61. $this->_platformMock = $platform;
  62. }
  63. public function setLastInsertId($id)
  64. {
  65. $this->_lastInsertId = $id;
  66. }
  67. public function getInserts()
  68. {
  69. return $this->_inserts;
  70. }
  71. public function reset()
  72. {
  73. $this->_inserts = array();
  74. $this->_lastInsertId = 0;
  75. }
  76. }