diff options
author | xue <> | 2006-11-24 04:21:06 +0000 |
---|---|---|
committer | xue <> | 2006-11-24 04:21:06 +0000 |
commit | 9478fba18018c1f072f5f6dd4335c5828f23bc80 (patch) | |
tree | f3718d9fd6af53c8aebc591b047a1b257804fa17 /tests/unit/Data/TDbTransactionTest.php | |
parent | 750f6c453bb21d6cef0eed50ed742fe7048709d2 (diff) |
Added DB layer.
Diffstat (limited to 'tests/unit/Data/TDbTransactionTest.php')
-rw-r--r-- | tests/unit/Data/TDbTransactionTest.php | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/tests/unit/Data/TDbTransactionTest.php b/tests/unit/Data/TDbTransactionTest.php new file mode 100644 index 00000000..9d34857d --- /dev/null +++ b/tests/unit/Data/TDbTransactionTest.php @@ -0,0 +1,73 @@ +<?php + +require_once(dirname(__FILE__).'/../phpunit2.php'); + +Prado::using('System.Data.*'); + +define('TEST_DB_FILE',dirname(__FILE__).'/db/test.db'); + +/** + * @package System.Data.PDO + */ +class TDbTransactionTest extends PHPUnit2_Framework_TestCase +{ + private $_connection; + + public function setUp() + { + @unlink(TEST_DB_FILE); + $this->_connection=new TDbConnection('sqlite:'.TEST_DB_FILE); + $this->_connection->Active=true; + $this->_connection->createCommand('CREATE TABLE foo (id INTEGER NOT NULL PRIMARY KEY, name VARCHAR(8))')->execute(); + } + + public function tearDown() + { + $this->_connection=null; + } + + public function testRollBack() + { + $sql='INSERT INTO foo(id,name) VALUES (1,\'my name\')'; + $transaction=$this->_connection->beginTransaction(); + try + { + $this->_connection->createCommand($sql)->execute(); + $this->_connection->createCommand($sql)->execute(); + $this->fail('Expected exception not raised'); + $transaction->commit(); + } + catch(Exception $e) + { + $this->assertTrue($transaction->Active); + $transaction->rollBack(); + $this->assertFalse($transaction->Active); + $reader=$this->_connection->createCommand('SELECT * FROM foo')->query(); + $this->assertFalse($reader->read()); + } + } + + public function testCommit() + { + $sql1='INSERT INTO foo(id,name) VALUES (1,\'my name\')'; + $sql2='INSERT INTO foo(id,name) VALUES (2,\'my name\')'; + $transaction=$this->_connection->beginTransaction(); + try + { + $this->_connection->createCommand($sql1)->execute(); + $this->_connection->createCommand($sql2)->execute(); + $this->assertTrue($transaction->Active); + $transaction->commit(); + $this->assertFalse($transaction->Active); + } + catch(Exception $e) + { + $transaction->rollBack(); + $this->fail('Unexpected exception'); + } + $result=$this->_connection->createCommand('SELECT * FROM foo')->query()->readAll(); + $this->assertEquals(count($result),2); + } +} + +?>
\ No newline at end of file |