Skip to content
Permalink
Browse files

Tests for transactions using virtualized nesting and real save points

fixed smal bugs
  • Loading branch information...
lorenzo committed Jul 9, 2012
1 parent 27c5b4e commit 5f5f35f88f6752dd510297877012ce4205e2f77b
@@ -245,8 +245,9 @@ public function begin() {
return;
}
$this->_transactionLevel++;
if ($this->useSavePoints()) {
$this->createSavePoint(++$this->_transactionLevel);
$this->createSavePoint($this->_transactionLevel);
}
}
@@ -68,7 +68,7 @@ abstract class Driver {
* @return boolean true if save points are supported, false otherwise
**/
public function supportsSavePoints() {
true;
return true;
}
/**
@@ -365,4 +365,156 @@ public function testDeleteWithConditions() {
$this->assertCount(0, $result);
}
/**
* Tests that it is possible to use simple database transactions
*
* @return void
**/
public function testSimpleTransactions() {
$this->_insertTwoRecords();
$this->connection->begin();
$this->connection->delete('things', ['id' => 1]);
$this->connection->rollback();
$result = $this->connection->execute('SELECT * FROM things');
$this->assertCount(2, $result);
$this->connection->begin();
$this->connection->delete('things', ['id' => 1]);
$this->connection->commit();
$result = $this->connection->execute('SELECT * FROM things');
$this->assertCount(1, $result);
}
/**
* Tests that it is possible to use virtualized nested transaction
* with early rollback algorithm
*
* @return void
**/
public function testVirtualNestedTrasanction() {
$this->_insertTwoRecords();
//starting 3 virtual transaction
$this->connection->begin();
$this->connection->begin();
$this->connection->begin();
$this->connection->delete('things', ['id' => 1]);
$result = $this->connection->execute('SELECT * FROM things');
$this->assertCount(1, $result);
$this->connection->commit();
$this->connection->rollback();
$result = $this->connection->execute('SELECT * FROM things');
$this->assertCount(2, $result);
}
/**
* Tests that it is possible to use virtualized nested transaction
* with early rollback algorithm
*
* @return void
**/
public function testVirtualNestedTrasanction2() {
$this->_insertTwoRecords();
//starting 3 virtual transaction
$this->connection->begin();
$this->connection->begin();
$this->connection->begin();
$this->connection->delete('things', ['id' => 1]);
$result = $this->connection->execute('SELECT * FROM things');
$this->assertCount(1, $result);
$this->connection->rollback();
$result = $this->connection->execute('SELECT * FROM things');
$this->assertCount(2, $result);
}
/**
* Tests that it is possible to use virtualized nested transaction
* with early rollback algorithm
*
* @return void
**/
public function testVirtualNestedTrasanction3() {
$this->_insertTwoRecords();
//starting 3 virtual transaction
$this->connection->begin();
$this->connection->begin();
$this->connection->begin();
$this->connection->delete('things', ['id' => 1]);
$result = $this->connection->execute('SELECT * FROM things');
$this->assertCount(1, $result);
$this->connection->commit();
$this->connection->commit();
$this->connection->commit();
$result = $this->connection->execute('SELECT * FROM things');
$this->assertCount(1, $result);
}
/**
* Tests that it is possible to real use nested transactions
*
* @return void
**/
public function testSavePoints() {
$this->skipIf(!$this->connection->useSavePoints(true));
$this->_insertTwoRecords();
$this->connection->begin();
$this->connection->delete('things', ['id' => 1]);
$result = $this->connection->execute('SELECT * FROM things');
$this->assertCount(1, $result);
$this->connection->begin();
$this->connection->delete('things', ['id' => 2]);
$result = $this->connection->execute('SELECT * FROM things');
$this->assertCount(0, $result);
$this->connection->rollback();
$result = $this->connection->execute('SELECT * FROM things');
$this->assertCount(1, $result);
$this->connection->rollback();
$result = $this->connection->execute('SELECT * FROM things');
$this->assertCount(2, $result);
}
/**
* Tests that it is possible to real use nested transactions
*
* @return void
**/
public function testSavePoints2() {
$this->skipIf(!$this->connection->useSavePoints(true));
$this->_insertTwoRecords();
$this->connection->begin();
$this->connection->delete('things', ['id' => 1]);
$result = $this->connection->execute('SELECT * FROM things');
$this->assertCount(1, $result);
$this->connection->begin();
$this->connection->delete('things', ['id' => 2]);
$result = $this->connection->execute('SELECT * FROM things');
$this->assertCount(0, $result);
$this->connection->rollback();
$result = $this->connection->execute('SELECT * FROM things');
$this->assertCount(1, $result);
$this->connection->commit();
$result = $this->connection->execute('SELECT * FROM things');
$this->assertCount(1, $result);
}
}

0 comments on commit 5f5f35f

Please sign in to comment.
You can’t perform that action at this time.