summaryrefslogtreecommitdiff
path: root/tests/simple_unit/SqlMap/CacheTest.php
diff options
context:
space:
mode:
authorFabio Bas <ctrlaltca@gmail.com>2016-03-25 17:55:51 +0100
committerFabio Bas <ctrlaltca@gmail.com>2016-03-25 17:55:51 +0100
commita3388622287e218beddfa14a47ed677d4307b36b (patch)
tree1b4c7ac8597b1cc798b6683d4a81c90d38de12f6 /tests/simple_unit/SqlMap/CacheTest.php
parentc7fd3e1167b6f2fa7746edbd0fb8f8c1694c61f9 (diff)
Removed simpletest and moved all tests in the unit tree
Tests are executed now, but a lot of them need fixing.
Diffstat (limited to 'tests/simple_unit/SqlMap/CacheTest.php')
-rw-r--r--tests/simple_unit/SqlMap/CacheTest.php162
1 files changed, 0 insertions, 162 deletions
diff --git a/tests/simple_unit/SqlMap/CacheTest.php b/tests/simple_unit/SqlMap/CacheTest.php
deleted file mode 100644
index ff87cd3a..00000000
--- a/tests/simple_unit/SqlMap/CacheTest.php
+++ /dev/null
@@ -1,162 +0,0 @@
-<?php
-
-require_once(dirname(__FILE__).'/BaseCase.php');
-
-/**
- * @package System.DataAccess.SQLMap
- */
-class CacheTest extends BaseCase
-{
- function __construct()
- {
- parent::__construct();
-
- $this->initSqlMap();
-
- //force autoload
- new Account;
- }
-
- function resetDatabase()
- {
- $this->initScript('account-init.sql');
- }
-
- /**
- * Test for JIRA 29
- */
- function testJIRA28()
- {
- $account = $this->sqlmap->queryForObject("GetNoAccountWithCache",-99);
- $this->assertNull($account);
- }
-
- /**
- * Test Cache query
- */
- function testQueryWithCache()
- {
- $this->resetDatabase();
-
- $list1 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap");
-
- $list2 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap");
-
- $this->assertTrue($list1 === $list2);
-
- $account = $list1[1];
- $account->setEmailAddress("somebody@cache.com");
-
- //this will cause the cache to flush
- $this->sqlmap->update("UpdateAccountViaInlineParameters", $account);
-
- $list3 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap");
-
- $this->assertTrue($list1 !== $list3);
-
- $this->resetDatabase();
- }
-
-
- /**
- * Test flush Cache
- */
- function testFlushDataCache()
- {
- $list1 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap");
- $list2 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap");
-
- $this->assertTrue($list1 === $list2);
- $this->sqlmap->flushCaches();
-
- $list3 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap");
-
- $this->assertTrue($list1 !== $list3);
- }
-
- /**
- *
- */
- function testFlushDataCacheOnExecute()
- {
- $list1 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap");
-
- $list2 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap");
-
- $this->assertTrue($list1 === $list2);
- $this->sqlmap->update("UpdateAccountViaInlineParameters", $list1[0]);
-
- $list3 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap");
-
- $this->assertTrue($list1 !== $list3);
- }
-
- /**
- */
- protected function getCacheModel()
- {
- $cache = new TSqlMapCacheModel();
- // $cache->setFlushInterval(5*60);
- $cache->setImplementation('LRU');
- $cache->initialize();
- return $cache;
- }
-
- /**
- * Test CacheHit
- */
- function testCacheHit()
- {
- $cache = $this->getCacheModel();
- $key = new TSqlMapCacheKey('testkey');
- $cache->set($key, 'a');
-
- $returnedObject = $cache->get($key);
-
- $this->assertIdentical('a', $returnedObject);
-
- $this->assertIdentical(1, $cache->getHitRatio());
- }
-
-
-
- /**
- * Test CacheMiss
- */
- function testCacheMiss()
- {
- $cache = $this->getCacheModel();
- $key = new TSqlMapCacheKey('testKey');
- $value = 'testValue';
- $cache->set($key, $value);
-
- $wrongKey = new TSqlMapCacheKey('wrongKey');
-
- $returnedObject = $cache->get($wrongKey);
- $this->assertNotEqual($value, $returnedObject);
- $this->assertNull($returnedObject) ;
- $this->assertIdentical(0, $cache->getHitRatio());
- }
-
- /**
- * Test CacheHitMiss
- */
- function testCacheHitMiss()
- {
- $cache = $this->getCacheModel();
- $key = new TSqlMapCacheKey('testKey');
-
- $value = "testValue";
- $cache->set($key, $value);
-
- $returnedObject = $cache->get($key);
- $this->assertIdentical($value, $returnedObject);
-
- $wrongKey = new TSqlMapCacheKey('wrongKey');
-
- $returnedObject = $cache->get($wrongKey);
- $this->assertNotEqual($value, $returnedObject);
- $this->assertNull($returnedObject) ;
- $this->assertIdentical(0.5, $cache->getHitRatio());
- }
-}