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

@ -43,68 +43,7 @@ class DbStatementTest extends PHPUnit_Framework_TestCase
public function testConstruct()
{
$this->assertAttributeEquals($this->driver, 'driver', $this->stmt);
$this->assertAttributeEquals($this->sql, 'sql', $this->stmt);
}
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);
}
public function testExecute()
{
$this->stmt
->expects($this->once())
->method('driverExecute')
->with($this->anything())
->will($this->returnCallback(array($this, 'dbStatementAssemble')));
$this->driver
->expects($this->any())
->method('quote')
->with($this->anything())
->will($this->returnCallback(array($this, 'driverQuote')));
$result = $this->stmt->execute(array('place' => 'place_val', 'new' => 'new_val'));
$this->assertEquals('SELECT * place_val FROM place_val AND new_val', $result);
}
public function testExecuteNoPlaceholders()
{
$this->sql = 'PLAIN SQL';
$this->stmt = $this->getMockForAbstractClass('DbStatement', array($this->driver, $this->sql));
$this->stmt
->expects($this->once())
->method('driverExecute')
->with($this->anything())
->will($this->returnCallback(array($this, 'dbStatementAssemble')));
$result = $this->stmt->execute(array());
$this->assertEquals('PLAIN SQL', $result);
$this->assertAttributeEquals($this->sql, 'request', $this->stmt);
}
public function testFetch()
@ -131,16 +70,6 @@ class DbStatementTest extends PHPUnit_Framework_TestCase
$this->assertEquals(31, $result['one']);
}
public function dbStatementAssemble($val)
{
return $val;
}
public function driverQuote($val)
{
return $val;
}
public function dbStatementFetch($style)
{
$result = null;