2008-07-21 00:13:24 +04:00
|
|
|
<?php
|
|
|
|
|
2009-01-22 22:38:10 +03:00
|
|
|
namespace Doctrine\Tests\Mocks;
|
2009-01-04 19:15:32 +03:00
|
|
|
|
2009-01-22 22:38:10 +03:00
|
|
|
class ConnectionMock extends \Doctrine\DBAL\Connection
|
2008-07-21 00:13:24 +04:00
|
|
|
{
|
2009-03-14 12:05:52 +03:00
|
|
|
private $_fetchOneResult;
|
2008-08-01 22:46:14 +04:00
|
|
|
private $_platformMock;
|
2008-09-07 17:48:40 +04:00
|
|
|
private $_lastInsertId = 0;
|
2008-08-16 23:40:59 +04:00
|
|
|
private $_inserts = array();
|
2008-07-21 00:13:24 +04:00
|
|
|
|
2009-02-18 10:59:11 +03:00
|
|
|
public function __construct(array $params, $driver, $config = null, $eventManager = null)
|
|
|
|
{
|
2009-01-22 22:38:10 +03:00
|
|
|
$this->_platformMock = new DatabasePlatformMock();
|
2010-04-30 05:46:51 +04:00
|
|
|
|
|
|
|
parent::__construct($params, $driver, $config, $eventManager);
|
|
|
|
|
|
|
|
// Override possible assignment of platform to database platform mock
|
2008-09-12 21:25:38 +04:00
|
|
|
$this->_platform = $this->_platformMock;
|
2008-08-01 22:46:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @override
|
|
|
|
*/
|
2008-09-07 17:48:40 +04:00
|
|
|
public function getDatabasePlatform()
|
2008-07-21 00:13:24 +04:00
|
|
|
{
|
2008-09-07 17:48:40 +04:00
|
|
|
return $this->_platformMock;
|
2008-07-21 00:13:24 +04:00
|
|
|
}
|
|
|
|
|
2008-08-01 22:46:14 +04:00
|
|
|
/**
|
|
|
|
* @override
|
|
|
|
*/
|
2008-09-07 17:48:40 +04:00
|
|
|
public function insert($tableName, array $data)
|
2008-08-01 22:46:14 +04:00
|
|
|
{
|
2008-09-07 17:48:40 +04:00
|
|
|
$this->_inserts[$tableName][] = $data;
|
2008-08-01 22:46:14 +04:00
|
|
|
}
|
|
|
|
|
2008-08-16 23:40:59 +04:00
|
|
|
/**
|
|
|
|
* @override
|
|
|
|
*/
|
2008-09-07 17:48:40 +04:00
|
|
|
public function lastInsertId($seqName = null)
|
2008-08-16 23:40:59 +04:00
|
|
|
{
|
2008-09-07 17:48:40 +04:00
|
|
|
return $this->_lastInsertId;
|
|
|
|
}
|
2009-03-14 12:05:52 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @override
|
|
|
|
*/
|
2009-11-08 14:07:49 +03:00
|
|
|
public function fetchColumn($statement, array $params = array(), $colnum = 0)
|
2009-03-14 12:05:52 +03:00
|
|
|
{
|
|
|
|
return $this->_fetchOneResult;
|
|
|
|
}
|
2008-09-07 17:48:40 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @override
|
|
|
|
*/
|
|
|
|
public function quote($input, $type = null)
|
|
|
|
{
|
2009-06-14 21:34:28 +04:00
|
|
|
if (is_string($input)) {
|
2008-09-07 17:48:40 +04:00
|
|
|
return "'" . $input . "'";
|
|
|
|
}
|
|
|
|
return $input;
|
2008-08-16 23:40:59 +04:00
|
|
|
}
|
|
|
|
|
2008-08-01 22:46:14 +04:00
|
|
|
/* Mock API */
|
2009-03-14 12:05:52 +03:00
|
|
|
|
|
|
|
public function setFetchOneResult($fetchOneResult)
|
|
|
|
{
|
|
|
|
$this->_fetchOneResult = $fetchOneResult;
|
|
|
|
}
|
2008-08-01 22:46:14 +04:00
|
|
|
|
|
|
|
public function setDatabasePlatform($platform)
|
|
|
|
{
|
|
|
|
$this->_platformMock = $platform;
|
|
|
|
}
|
|
|
|
|
2008-09-07 17:48:40 +04:00
|
|
|
public function setLastInsertId($id)
|
2008-08-01 22:46:14 +04:00
|
|
|
{
|
2008-09-07 17:48:40 +04:00
|
|
|
$this->_lastInsertId = $id;
|
2008-08-01 22:46:14 +04:00
|
|
|
}
|
2008-08-16 23:40:59 +04:00
|
|
|
|
|
|
|
public function getInserts()
|
|
|
|
{
|
|
|
|
return $this->_inserts;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function reset()
|
|
|
|
{
|
|
|
|
$this->_inserts = array();
|
2008-09-07 17:48:40 +04:00
|
|
|
$this->_lastInsertId = 0;
|
2008-08-16 23:40:59 +04:00
|
|
|
}
|
2009-02-18 10:59:11 +03:00
|
|
|
}
|