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

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

doctrine's avatar
doctrine committed
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
        $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);

        $this->manager->setAttribute(Doctrine::ATTR_LISTENER, new Doctrine_Debugger());
        $this->assertTrue($this->manager->getAttribute(Doctrine::ATTR_LISTENER) instanceof Doctrine_Debugger);

        $this->manager->setAttribute(Doctrine::ATTR_PK_COLUMNS, array("id"));
        $this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_PK_COLUMNS), array("id"));

        $this->manager->setAttribute(Doctrine::ATTR_PK_TYPE, Doctrine::INCREMENT_KEY);
        $this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_PK_TYPE), Doctrine::INCREMENT_KEY);

        $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 {
            $this->session->beginTransaction();
            $this->manager->setAttribute(Doctrine::ATTR_LOCKMODE, Doctrine::LOCK_OPTIMISTIC);
        } catch(Exception $e) {
            $this->assertTrue($e instanceof Exception);
            $this->session->commit();
        }
doctrine's avatar
doctrine committed
61 62 63 64 65 66 67 68 69 70

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

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

        $e = true;
        try {
78
            $table->setAttribute(Doctrine::ATTR_COLL_KEY, "name");
doctrine's avatar
doctrine committed
79 80 81 82 83
        } catch(Exception $e) {
        }
        $this->assertTrue($e);

        $e = false;
doctrine's avatar
doctrine committed
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
        try {
            $this->session->beginTransaction();
            $this->session->setAttribute(Doctrine::ATTR_LOCKMODE, Doctrine::LOCK_PESSIMISTIC);
        } catch(Exception $e) {
            $this->assertTrue($e instanceof Exception);
            $this->session->commit();
        }
        try {
            $this->manager->setAttribute(Doctrine::ATTR_PK_TYPE,-12);
        } catch(Exception $e) {
            $this->assertTrue($e instanceof Exception);
        }
    }
    public function testGetAttributes() {
        $this->assertTrue(is_array($this->manager->getAttributes()));
    }
}
?>