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

doctrine's avatar
doctrine committed
4
class Doctrine_Cache_FileTestCase extends Doctrine_UnitTestCase {
doctrine's avatar
doctrine committed
5 6 7 8
    public function setUp() {
        parent::setUp();
        $this->manager->setAttribute(Doctrine::ATTR_CACHE, Doctrine::CACHE_FILE);
    }
doctrine's avatar
doctrine committed
9 10 11 12 13
    public function testStore() {
        $this->cache->store($this->old);
        $this->assertTrue($this->cache->exists(4));

        $record = $this->cache->fetch(4);
14
        $this->assertTrue($record instanceof Doctrine_Entity);
15
        $this->assertTrue($record->obtainIdentifier() == $this->old->obtainIdentifier());
doctrine's avatar
doctrine committed
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
        
        $this->assertTrue($this->cache->getTable() == $this->objTable);
    }
    public function testGetFetched() {
        $this->assertTrue(is_array($this->cache->getFetched()));
    }
    public function testGetFileName() {
        $this->assertEqual($this->manager->getRoot().DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR."entity".DIRECTORY_SEPARATOR."4.cache", $this->cache->getFileName(4));
    }
    public function testGetStats() {
        $this->assertTrue(gettype($this->cache->getStats()) == "array");
    }
    public function testDestructor() {
        $this->objTable->setAttribute(Doctrine::ATTR_CACHE_TTL,1);
        $this->objTable->setAttribute(Doctrine::ATTR_CACHE_SIZE,5);
        $this->cache->__destruct();
        $this->assertTrue($this->cache->count() == 5);

        $this->objTable->setAttribute(Doctrine::ATTR_CACHE_TTL,1);
        $this->objTable->setAttribute(Doctrine::ATTR_CACHE_SIZE,1);
        $this->cache->__destruct();
        $this->assertTrue($this->cache->count() == 1);

    }
    public function testDeleteMultiple() {
        $this->objTable->find(5);
        $this->objTable->find(6);
        
        $deleted = $this->cache->deleteMultiple(array(5,6));
        $this->assertTrue($deleted == 2);
    }
    public function testDeleteAll() {
        $this->cache->deleteAll();
        $this->assertTrue($this->cache->count() == 0);
    }
    public function testExists() {
        $this->assertFalse($this->cache->exists(313213123));
        $this->assertTrue($this->cache->exists(4));
    }
    public function testGetFactory() {
        $this->assertTrue($this->cache->getTable() == $this->objTable);
    }

}