-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for transaction nesting (issue #10)
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -908,6 +908,58 @@ public function testGlobalTransactionRollback() | |
}); | ||
} | ||
|
||
public function testTransactionNesting() | ||
{ | ||
$this->assertFalse($this->db->isTransaction()); | ||
$this->assertEquals(0, $this->db->getTransactionDepth()); | ||
$user = Users::start([ | ||
'username' => 'testuser264', | ||
'password' => 'password27', | ||
'email' => '[email protected]', | ||
'logins' => 1 | ||
]); | ||
$this->assertEquals(1, $this->db->getTransactionDepth()); | ||
|
||
// Adapter transaction management | ||
$this->db->beginTransaction(); | ||
$this->assertEquals(2, $this->db->getTransactionDepth()); | ||
$this->db->query("INSERT INTO users (username, password, email) values ('testuser266', 'password27', '[email protected]')"); | ||
$this->db->commit(); | ||
$this->assertTrue($this->db->isTransaction()); | ||
$this->assertEquals(1, $this->db->getTransactionDepth()); | ||
|
||
// Record transaction management | ||
$admin = new Users([ | ||
'username' => 'testuser265', | ||
'password' => 'password27', | ||
'email' => '[email protected]', | ||
'logins' => 1 | ||
]); | ||
$admin->startTransaction(); | ||
$this->assertEquals(2, $this->db->getTransactionDepth()); | ||
$admin->save(); | ||
$this->assertEquals(1, $this->db->getTransactionDepth()); | ||
|
||
// Adapter transaction rollback, visibility | ||
$this->db->beginTransaction(); | ||
$this->assertEquals(2, $this->db->getTransactionDepth()); | ||
$this->db->query("INSERT INTO users (username, password, email) values ('testuser267', 'password27', '[email protected]')"); | ||
$test = Users::findOne(['username' => 'testuser267']); | ||
$this->assertNotNull($test->id); | ||
$this->db->rollback(); | ||
$this->assertTrue($this->db->isTransaction()); | ||
$this->assertEquals(1, $this->db->getTransactionDepth()); | ||
$test = Users::findOne(['username' => 'testuser267']); | ||
$this->assertNull($test->id); | ||
|
||
// Commits outer transaction | ||
$user->save(); | ||
$this->assertFalse($this->db->isTransaction()); | ||
$this->assertEquals(0, $this->db->getTransactionDepth()); | ||
|
||
$this->db->disconnect(); | ||
} | ||
|
||
public function testFindWhere() | ||
{ | ||
$user = new Users([ | ||
|