TransactionTestCase.php 2.84 KB
Newer Older
zYne's avatar
zYne committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
<?php
class Doctrine_Transaction_TestCase extends Doctrine_Driver_UnitTestCase {
    public function __construct() {
        parent::__construct('sqlite', true);
    }
    public function testCreateSavepointIsOnlyImplementedAtDriverLevel() {
        try {
            $this->transaction->createSavePoint('point');
            $this->fail();
        } catch(Doctrine_Transaction_Exception $e) {
            $this->pass();
        }
    }
    public function testReleaseSavepointIsOnlyImplementedAtDriverLevel() {
        try {
            $this->transaction->releaseSavePoint('point');
            $this->fail();
        } catch(Doctrine_Transaction_Exception $e) {
            $this->pass();
        }
    }
    public function testRollbackSavepointIsOnlyImplementedAtDriverLevel() {
        try {
            $this->transaction->rollbackSavePoint('point');
            $this->fail();
        } catch(Doctrine_Transaction_Exception $e) {
            $this->pass();
        }
    }
    public function testSetIsolationIsOnlyImplementedAtDriverLevel() {
        try {
            $this->transaction->setIsolation('READ UNCOMMITTED');
            $this->fail();
        } catch(Doctrine_Transaction_Exception $e) {
            $this->pass();
        }
    }
    public function testGetIsolationIsOnlyImplementedAtDriverLevel() {
        try {
            $this->transaction->GetIsolation('READ UNCOMMITTED');
            $this->fail();
        } catch(Doctrine_Transaction_Exception $e) {
            $this->pass();
        }
    }
    public function testTransactionLevelIsInitiallyZero() {
        $this->assertEqual($this->transaction->getTransactionLevel(), 0);
    }
    public function testGetStateReturnsStateConstant() {
        $this->assertEqual($this->transaction->getState(), Doctrine_Transaction::STATE_SLEEP);                                                  	
    }
    public function testExceptionIsThrownWhenCommittingNotActiveTransaction() {
        try {
            $this->transaction->commit();
            $this->fail();
        } catch(Doctrine_Transaction_Exception $e) {
            $this->pass();
        }
    }
    public function testExceptionIsThrownWhenUsingRollbackOnNotActiveTransaction() {
        try {
            $this->transaction->rollback();
            $this->fail();
        } catch(Doctrine_Transaction_Exception $e) {
            $this->pass();
        }
    }
    public function testBeginTransactionStartsNewTransaction() {
        $this->transaction->beginTransaction();  

        $this->assertEqual($this->adapter->pop(), 'BEGIN TRANSACTION');                                                     	
    }
    public function testCommitMethodCommitsCurrentTransaction() {
        $this->transaction->commit();

        $this->assertEqual($this->adapter->pop(), 'COMMIT');
    }

}