ソースを参照

Added test for nested methods sequence.

Juan Basso 14 年 前
コミット
30258ac817
1 ファイル変更29 行追加0 行削除
  1. 29 0
      lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php

+ 29 - 0
lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php

@@ -51,6 +51,10 @@ class DboTestSource extends DboSource {
 		$this->_connection = $conn;
 	}
 
+	protected function _supportNestedTransaction() {
+		return true;
+	}
+
 }
 
 /**
@@ -842,6 +846,31 @@ class DboSourceTest extends CakeTestCase {
 	}
 
 /**
+ * Test nested transaction calls
+ *
+ * @return void
+ */
+	public function testTransactionNested() {
+		$conn = $this->getMock('MockPDO');
+		$db = new DboTestSource();
+		$db->setConnection($conn);
+
+		$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));
+		$conn->expects($this->at(2))->method('exec')->with($this->equalTo('RELEASE SAVEPOINT LEVEL1'))->will($this->returnValue(true));
+		$conn->expects($this->at(3))->method('exec')->with($this->equalTo('SAVEPOINT LEVEL1'))->will($this->returnValue(true));
+		$conn->expects($this->at(4))->method('exec')->with($this->equalTo('ROLLBACK TO SAVEPOINT LEVEL1'))->will($this->returnValue(true));
+		$conn->expects($this->at(5))->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
  *
  * @return void