ConfigurableTestCase.php 3.54 KB
Newer Older
doctrine's avatar
doctrine committed
1
<?php
2
require_once("UnitTestCase.php");
doctrine's avatar
doctrine committed
3 4

class Doctrine_ConfigurableTestCase extends Doctrine_UnitTestCase {
5 6
    public function prepareTables() { }
    public function prepareData() { }
doctrine's avatar
doctrine committed
7
    public function testSetAttribute() {
zYne's avatar
zYne committed
8
        $table = $this->connection->getTable("User");
9

doctrine's avatar
doctrine committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
        $this->manager->setAttribute(Doctrine::ATTR_CACHE_TTL,100);
        $this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_CACHE_TTL),100);
    
        $this->manager->setAttribute(Doctrine::ATTR_CACHE_SIZE,1);
        $this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_CACHE_SIZE),1);

        $this->manager->setAttribute(Doctrine::ATTR_CACHE_DIR,"%ROOT%".DIRECTORY_SEPARATOR."cache");
        $this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_CACHE_DIR),$this->manager->getRoot().DIRECTORY_SEPARATOR."cache");

        $this->manager->setAttribute(Doctrine::ATTR_FETCHMODE,Doctrine::FETCH_LAZY);
        $this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_FETCHMODE),Doctrine::FETCH_LAZY);

        $this->manager->setAttribute(Doctrine::ATTR_BATCH_SIZE, 5);
        $this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_BATCH_SIZE),5);

doctrine's avatar
doctrine committed
25 26
        $this->manager->setAttribute(Doctrine::ATTR_LISTENER, new Doctrine_EventListener_Debugger());
        $this->assertTrue($this->manager->getAttribute(Doctrine::ATTR_LISTENER) instanceof Doctrine_EventListener_Debugger);
doctrine's avatar
doctrine committed
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48

        $this->manager->setAttribute(Doctrine::ATTR_LOCKMODE, Doctrine::LOCK_PESSIMISTIC);
        $this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_LOCKMODE), Doctrine::LOCK_PESSIMISTIC);

        // test invalid arguments
        try {
            $this->manager->setAttribute(Doctrine::ATTR_CACHE_TTL,-12);
        } catch(Exception $e) {
            $this->assertTrue($e instanceof Exception);
        }
        try {
            $this->manager->setAttribute(Doctrine::ATTR_CACHE_SIZE,-12);
        } catch(Exception $e) {
            $this->assertTrue($e instanceof Exception);
        }
        try {
            $this->manager->setAttribute(Doctrine::ATTR_BATCH_SIZE,-12);
        } catch(Exception $e) {
            $this->assertTrue($e instanceof Exception);
        }

        try {
zYne's avatar
zYne committed
49
            $this->connection->beginTransaction();
doctrine's avatar
doctrine committed
50 51 52
            $this->manager->setAttribute(Doctrine::ATTR_LOCKMODE, Doctrine::LOCK_OPTIMISTIC);
        } catch(Exception $e) {
            $this->assertTrue($e instanceof Exception);
zYne's avatar
zYne committed
53
            $this->connection->commit();
doctrine's avatar
doctrine committed
54
        }
doctrine's avatar
doctrine committed
55 56 57 58 59 60 61 62 63 64

        $e = false;
        try {
            $this->manager->setAttribute(Doctrine::ATTR_COLL_KEY, "name");
        } catch(Exception $e) {
        }
        $this->assertTrue($e instanceof Exception);

        $e = false;
        try {
65
            $table->setAttribute(Doctrine::ATTR_COLL_KEY, "unknown");
doctrine's avatar
doctrine committed
66 67 68 69 70 71
        } catch(Exception $e) {
        }
        $this->assertTrue($e instanceof Exception);

        $e = true;
        try {
72
            $table->setAttribute(Doctrine::ATTR_COLL_KEY, "name");
doctrine's avatar
doctrine committed
73 74 75 76 77
        } catch(Exception $e) {
        }
        $this->assertTrue($e);

        $e = false;
doctrine's avatar
doctrine committed
78
        try {
zYne's avatar
zYne committed
79 80
            $this->connection->beginTransaction();
            $this->connection->setAttribute(Doctrine::ATTR_LOCKMODE, Doctrine::LOCK_PESSIMISTIC);
doctrine's avatar
doctrine committed
81 82
        } catch(Exception $e) {
            $this->assertTrue($e instanceof Exception);
zYne's avatar
zYne committed
83
            $this->connection->commit();
doctrine's avatar
doctrine committed
84
        }
zYne's avatar
zYne committed
85

doctrine's avatar
doctrine committed
86 87 88 89 90 91
    }
    public function testGetAttributes() {
        $this->assertTrue(is_array($this->manager->getAttributes()));
    }
}
?>