db->dsn; MyDB::setParams( $dbparams ); } // normal: test nested transactions public function test1() { try { $db = MyDB::create(); $db->beginTransaction(); $db->beginTransaction(); $db->commit(); $db->beginTransaction(); $db->commit(); $db->commit(); unset( $db ); } catch ( ezcDbTransactionException $e ) { $this->fail( "Exception (" . get_class( $e ) . ") caught: " . $e->getMessage() ); } } public function test2() { try { $db = MyDB::create(); $db->beginTransaction(); $db->beginTransaction(); $db->beginTransaction(); $db->beginTransaction(); $db->commit(); $db->commit(); unset( $db ); // destroy db connection } catch ( Exception $e ) { $this->fail( "Should not throw exception here since the action doesn't have to be user initiated" ); } } // error: more COMMITs than BEGINs public function test3() { try { $db = MyDB::create(); $db->beginTransaction(); $db->commit(); $db->commit(); $db->commit(); $db->commit(); $db->commit(); unset( $db ); // destroy db connection } catch ( ezcDbTransactionException $e ) { return; } $this->fail( "The case when there were more COMMITs than BEGINs did not fail.\n" ); } // normal: BEGIN, BEGIN, COMMIT, then ROLLBACK public function test4() { try { $db = MyDB::create(); $db->beginTransaction(); $db->beginTransaction(); $db->commit(); $db->rollback(); unset( $db ); } catch ( ezcDbException $e ) { $this->fail( "Exception (" . get_class( $e ) . ") caught: " . $e->getMessage() ); } } // normal: BEGIN, BEGIN, ROLLBACK, then COMMIT public function test5() { try { $db = MyDB::create(); $db->beginTransaction(); $db->beginTransaction(); $db->rollback(); $db->commit(); unset( $db ); } catch ( ezcDbException $e ) { $this->fail( "Exception (" . get_class( $e ) . ") caught: " . $e->getMessage() ); } } // error: BEGIN, ROLLBACK, COMMIT public function test6() { try { $db = MyDB::create(); $db->beginTransaction(); $db->rollback(); $db->commit(); unset( $db ); } catch ( ezcDbTransactionException $e ) { return; } $this->fail( "The case with consequent BEGIN, ROLLBACK, COMMIT did not fail.\n" ); } // error: BEGIN, COMMIT, ROLLBACK public function test7() { try { $db = MyDB::create(); $db->beginTransaction(); $db->commit(); $db->rollback(); unset( $db ); } catch ( ezcDbTransactionException $e ) { return; } $this->fail( "The case with consequent BEGIN, COMMIT, ROLLBACK did not fail.\n" ); } public static function suite() { return new ezcTestSuite( "ezcDatabaseTransactionsTest" ); } } ?>