TransactionTestCase.php 2.65 KB
Newer Older
zYne's avatar
zYne committed
1 2 3 4 5
<?php
class Doctrine_Transaction_TestCase extends Doctrine_Driver_UnitTestCase {
    public function __construct() {
        parent::__construct('sqlite', true);
    }
zYne's avatar
zYne committed
6
/**
zYne's avatar
zYne committed
7 8
    public function testCreateSavepointIsOnlyImplementedAtDriverLevel() {
        try {
zYne's avatar
zYne committed
9
            $this->transaction->beginTransaction('point');
zYne's avatar
zYne committed
10 11 12 13 14 15 16
            $this->fail();
        } catch(Doctrine_Transaction_Exception $e) {
            $this->pass();
        }
    }
    public function testReleaseSavepointIsOnlyImplementedAtDriverLevel() {
        try {
zYne's avatar
zYne committed
17
            $this->transaction->commit('point');
zYne's avatar
zYne committed
18 19 20 21 22
            $this->fail();
        } catch(Doctrine_Transaction_Exception $e) {
            $this->pass();
        }
    }
zYne's avatar
zYne committed
23
*/
zYne's avatar
zYne committed
24 25
    public function testRollbackSavepointIsOnlyImplementedAtDriverLevel() {
        try {
zYne's avatar
zYne committed
26 27 28
            $this->transaction->beginTransaction();

            $this->transaction->rollback('point');
zYne's avatar
zYne committed
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
            $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);                                                  	
    }
zYne's avatar
zYne committed
56 57
    public function testCommittingNotActiveTransactionReturnsFalse() {
        $this->assertEqual($this->transaction->commit(), false);
zYne's avatar
zYne committed
58 59
    }
    public function testExceptionIsThrownWhenUsingRollbackOnNotActiveTransaction() {
zYne's avatar
zYne committed
60
        $this->assertEqual($this->transaction->rollback(), false);
zYne's avatar
zYne committed
61 62 63 64 65 66 67 68 69 70 71 72 73
    }
    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');
    }

}