Added test to check when driver do not support nested support.

This commit is contained in:
Juan Basso 2012-04-01 00:41:16 -04:00
parent 79f7ca7d33
commit b0a3a1a5aa

View file

@ -35,6 +35,8 @@ class MockDataSource extends DataSource {
class DboTestSource extends DboSource {
public static $nested = true;
public function connect($config = array()) {
$this->connected = true;
}
@ -52,7 +54,7 @@ class DboTestSource extends DboSource {
}
public function supportNestedTransaction() {
return true;
return self::$nested;
}
}
@ -854,6 +856,7 @@ class DboSourceTest extends CakeTestCase {
$conn = $this->getMock('MockPDO');
$db = new DboTestSource();
$db->setConnection($conn);
DboTestSource::$nested = true;
$conn->expects($this->at(0))->method('beginTransaction')->will($this->returnValue(true));
$conn->expects($this->at(1))->method('exec')->with($this->equalTo('SAVEPOINT LEVEL1'))->will($this->returnValue(true));
@ -870,6 +873,29 @@ class DboSourceTest extends CakeTestCase {
$db->commit();
}
/**
* Test nested transaction calls without support
*
* @return void
*/
public function testTransactionNestedWithoutSupport() {
$conn = $this->getMock('MockPDO');
$db = new DboTestSource();
$db->setConnection($conn);
DboTestSource::$nested = false;
$conn->expects($this->once())->method('beginTransaction')->will($this->returnValue(true));
$conn->expects($this->never())->method('exec');
$conn->expects($this->once())->method('commit')->will($this->returnValue(true));
$db->begin();
$db->begin();
$db->commit();
$db->begin();
$db->rollback();
$db->commit();
}
/**
* Test build statement with some fields missing
*