modified tests for new DbDriver hierarchy

This commit is contained in:
Anton Grebnev
2011-11-15 16:55:55 +04:00
parent 5bff74f20b
commit b9353065b8
4 changed files with 184 additions and 124 deletions

View File

@ -25,6 +25,8 @@ class MySQLiStatementTest extends PHPUnit_Framework_TestCase
private $stmt;
private $sql;
private $testData = array(
array('one' => 11, 'two' => 12),
array('one' => 21, 'two' => 22),
@ -50,6 +52,72 @@ class MySQLiStatementTest extends PHPUnit_Framework_TestCase
}
}
public function testBindParam()
{
$val = $this->getMockBuilder('DbExpr')
->disableOriginalConstructor()
->getMock();
$this->assertFalse($this->stmt->bindParam('var', $val));
$this->assertTrue($this->stmt->bindParam('place', $val));
}
/**
* @expectedException Exception
* @expectedExceptionMessage Placeholder must be an array or string
* @TODO: change Exception Message 'Placeholder must be an array or string' - no arrays available
*/
public function testBindParamExceptionParam()
{
$val = 1;
$this->stmt->bindParam(array(), $val);
}
/**
* @expectedException Exception
* @expectedExceptionMessage Objects excepts DbExpr not allowed.
*/
public function testBindParamExceptionWrongObject()
{
$val = $this->getMock('NotDbExpr');
$this->stmt->bindParam('paa', $val);
}
/**
* @runInSeparateProcess
*/
public function testExecute()
{
if (!defined('DEBUG')) {
define('DEBUG', false);
}
$this->driver
->expects($this->any())
->method('quote')
->with($this->anything())
->will($this->returnCallback(array($this, 'driverQuote')));
$this->setDriverGetConnectionMethod();
$result = $this->stmt->execute(array('place' => 'place_val', 'new' => 'new_val'));
$this->assertEquals('SELECT * place_val FROM place_val AND new_val', $result);
}
/**
* @runInSeparateProcess
*/
public function testExecuteNoPlaceholders()
{
if (!defined('DEBUG')) {
define('DEBUG', false);
}
$this->setDriverGetConnectionMethod();
$this->sql = 'PLAIN SQL';
$result = $this->stmt->execute(array());
$this->assertEquals('PLAIN SQL', $result);
}
/**
* @runInSeparateProcess
*/
@ -240,4 +308,14 @@ class MySQLiStatementTest extends PHPUnit_Framework_TestCase
return $this;
}
public function driverQuote($val)
{
return $val;
}
public function dbStatementAssemble($val)
{
return $val;
}
}