Skip to content

Commit

Permalink
Added tests in each datasource to test the nested transactions.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrbasso committed Apr 14, 2012
1 parent 30258ac commit 22cd65b
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 1 deletion.
38 changes: 37 additions & 1 deletion lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php
Expand Up @@ -45,7 +45,7 @@ class MysqlTest extends CakeTestCase {
public $fixtures = array(
'core.apple', 'core.article', 'core.articles_tag', 'core.attachment', 'core.comment',
'core.sample', 'core.tag', 'core.user', 'core.post', 'core.author', 'core.data_test',
'core.binary_test'
'core.binary_test', 'app.address'

This comment has been minimized.

Copy link
@ceeram

ceeram Apr 24, 2012

Contributor

app.address isnt available in my app
this causes to fail 2.2-mysql now on jenkins
can you add it to core
Also the $model = ClassRegistry::init('Address'); Address model isnt present in core

This comment has been minimized.

Copy link
@ceeram

ceeram Apr 24, 2012

Contributor

I have already fixed here: 0785ace
now using existing fixture

This comment has been minimized.

Copy link
@ceeram

ceeram Apr 24, 2012

Contributor

And with that, i get msyql 42000 error again on jenkins, locally i dont get that, but both travis and jenkins give me the error code 42000 without any message :(

This comment has been minimized.

Copy link
@jrbasso

jrbasso Apr 24, 2012

Author Member

I am stupid. Thanks to fix the model name. I am fixing the 42000 error now.

);

/**
Expand Down Expand Up @@ -3579,4 +3579,40 @@ public function testTruncateStatements() {
->with("TRUNCATE TABLE `$schema`.`tbl_articles`");
$this->Dbo->truncate('articles');
}

/**
* Test nested transaction
*
* @return void
*/
public function testNestedTransaction() {
$obj = new ReflectionMethod($this->Dbo, '_supportNestedTransaction');
$obj->setAccessible(true);
$this->skipIf($obj->invoke($this->Dbo) === false, 'The MySQL server do not support nested transaction');

$this->loadFixtures('Address');
$model = ClassRegistry::init('Address');
$model->hasOne = $model->hasMany = $model->belongsTo = $model->hasAndBelongsToMany = array();
$model->cacheQueries = false;
$this->Dbo->cacheMethods = false;

$this->assertTrue($this->Dbo->begin());
$this->assertNotEmpty($model->read(null, 1));

$this->assertTrue($this->Dbo->begin());
$this->assertTrue($model->delete(1));
$this->assertEmpty($model->read(null, 1));
$this->assertTrue($this->Dbo->rollback());
$this->assertNotEmpty($model->read(null, 1));

$this->assertTrue($this->Dbo->begin());
$this->assertTrue($model->delete(1));
$this->assertEmpty($model->read(null, 1));
$this->assertTrue($this->Dbo->commit());
$this->assertEmpty($model->read(null, 1));

$this->assertTrue($this->Dbo->rollback());
$this->assertNotEmpty($model->read(null, 1));
}

}
35 changes: 35 additions & 0 deletions lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php
Expand Up @@ -909,4 +909,39 @@ public function testTruncateStatements() {
$this->Dbo->truncate('articles');
}

/**
* Test nested transaction
*
* @return void
*/
public function testNestedTransaction() {
$obj = new ReflectionMethod($this->Dbo, '_supportNestedTransaction');
$obj->setAccessible(true);
$this->skipIf($obj->invoke($this->Dbo) === false, 'The Postgres server do not support nested transaction');

$this->loadFixtures('Article');
$model = new Article();
$model->hasOne = $model->hasMany = $model->belongsTo = $model->hasAndBelongsToMany = array();
$model->cacheQueries = false;
$this->Dbo->cacheMethods = false;

$this->assertTrue($this->Dbo->begin());
$this->assertNotEmpty($model->read(null, 1));

$this->assertTrue($this->Dbo->begin());
$this->assertTrue($model->delete(1));
$this->assertEmpty($model->read(null, 1));
$this->assertTrue($this->Dbo->rollback());
$this->assertNotEmpty($model->read(null, 1));

$this->assertTrue($this->Dbo->begin());
$this->assertTrue($model->delete(1));
$this->assertEmpty($model->read(null, 1));
$this->assertTrue($this->Dbo->commit());
$this->assertEmpty($model->read(null, 1));

$this->assertTrue($this->Dbo->rollback());
$this->assertNotEmpty($model->read(null, 1));
}

}
35 changes: 35 additions & 0 deletions lib/Cake/Test/Case/Model/Datasource/Database/SqliteTest.php
Expand Up @@ -383,4 +383,39 @@ public function testUuidPrimaryKeyInsertion() {
$this->assertTrue(Validation::uuid($result['Uuid']['id']), 'Not a uuid');
}

/**
* Test nested transaction
*
* @return void
*/
public function testNestedTransaction() {
$obj = new ReflectionMethod($this->Dbo, '_supportNestedTransaction');
$obj->setAccessible(true);
$this->skipIf($obj->invoke($this->Dbo) === false, 'The Sqlite version do not support nested transaction');

$this->loadFixtures('User');
$model = new User();
$model->hasOne = $model->hasMany = $model->belongsTo = $model->hasAndBelongsToMany = array();
$model->cacheQueries = false;
$this->Dbo->cacheMethods = false;

$this->assertTrue($this->Dbo->begin());
$this->assertNotEmpty($model->read(null, 1));

$this->assertTrue($this->Dbo->begin());
$this->assertTrue($model->delete(1));
$this->assertEmpty($model->read(null, 1));
$this->assertTrue($this->Dbo->rollback());
$this->assertNotEmpty($model->read(null, 1));

$this->assertTrue($this->Dbo->begin());
$this->assertTrue($model->delete(1));
$this->assertEmpty($model->read(null, 1));
$this->assertTrue($this->Dbo->commit());
$this->assertEmpty($model->read(null, 1));

$this->assertTrue($this->Dbo->rollback());
$this->assertNotEmpty($model->read(null, 1));
}

}

0 comments on commit 22cd65b

Please sign in to comment.