Commit 66e9cfde authored by Jan Rosier's avatar Jan Rosier

Remove unneeded connect calls

parent a5e885af
......@@ -349,7 +349,9 @@ class Connection implements DriverConnection
*/
public function connect()
{
if ($this->_isConnected) return false;
if ($this->_isConnected) {
return false;
}
$driverOptions = isset($this->_params['driverOptions']) ?
$this->_params['driverOptions'] : array();
......@@ -580,8 +582,6 @@ class Connection implements DriverConnection
throw InvalidArgumentException::fromEmptyCriteria();
}
$this->connect();
$criteria = array();
foreach (array_keys($identifier) as $columnName) {
......@@ -649,7 +649,6 @@ class Connection implements DriverConnection
*/
public function update($tableExpression, array $data, array $identifier, array $types = array())
{
$this->connect();
$set = array();
foreach ($data as $columnName => $value) {
......@@ -682,8 +681,6 @@ class Connection implements DriverConnection
*/
public function insert($tableExpression, array $data, array $types = array())
{
$this->connect();
if (empty($data)) {
return $this->executeUpdate('INSERT INTO ' . $tableExpression . ' ()' . ' VALUES ()');
}
......@@ -749,6 +746,7 @@ class Connection implements DriverConnection
$this->connect();
list($value, $bindingType) = $this->getBindingInfo($input, $type);
return $this->_conn->quote($value, $bindingType);
}
......@@ -771,14 +769,12 @@ class Connection implements DriverConnection
*
* @param string $statement The SQL statement to prepare.
*
* @return \Doctrine\DBAL\Driver\Statement The prepared statement.
* @return \Doctrine\DBAL\Statement The prepared statement.
*
* @throws \Doctrine\DBAL\DBALException
*/
public function prepare($statement)
{
$this->connect();
try {
$stmt = new Statement($statement, $this);
} catch (\Exception $ex) {
......
......@@ -480,4 +480,39 @@ SQLSTATE[HY000]: General error: 1 near \"MUUHAAAAHAAAA\"");
$this->setExpectedException('Doctrine\DBAL\Exception\InvalidArgumentException');
$conn->delete('kittens', array());
}
public function dataCallConnectOnce()
{
return array(
array('delete', array('tbl', array('id' => 12345))),
array('insert', array('tbl', array('data' => 'foo'))),
array('update', array('tbl', array('data' => 'bar'), array('id' => 12345))),
array('prepare', array('select * from dual')),
array('executeUpdate', array('insert into tbl (id) values (?)'), array(123)),
);
}
/**
* @dataProvider dataCallConnectOnce
*/
public function testCallConnectOnce($method, $params)
{
$driverMock = $this->getMock('Doctrine\DBAL\Driver');
$pdoMock = $this->getMock('Doctrine\DBAL\Driver\Connection');
$platformMock = new Mocks\MockPlatform();
$stmtMock = $this->getMock('Doctrine\DBAL\Driver\Statement');
$pdoMock->expects($this->any())
->method('prepare')
->will($this->returnValue($stmtMock));
$conn = $this->getMockBuilder('Doctrine\DBAL\Connection')
->setConstructorArgs(array(array('pdo' => $pdoMock, 'platform' => $platformMock), $driverMock))
->setMethods(array('connect'))
->getMock();
$conn->expects($this->once())->method('connect');
call_user_func_array(array($conn, $method), $params);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment