summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorknut <>2007-06-11 13:07:43 +0000
committerknut <>2007-06-11 13:07:43 +0000
commit9cd30d599e11a37d74146158ee928a627fcd80a5 (patch)
tree5d5383956063d5e547f1813dd3a0b69fb933fcb4
parent7315ec25dc4ad7ef6cfdff47655d8a3c5f5cac4c (diff)
added some caching tests
-rw-r--r--.gitattributes2
-rw-r--r--tests/unit/Caching/TAPCCacheTest.php72
-rw-r--r--tests/unit/Caching/TSqliteCacheTest.php80
3 files changed, 154 insertions, 0 deletions
diff --git a/.gitattributes b/.gitattributes
index 976fcbab..897d2f7c 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -2824,8 +2824,10 @@ tests/test_tools/simpletest/simpletest.php -text
tests/test_tools/simpletest/test_case.php -text
tests/unit/AllTests.php -text
tests/unit/Caching/AllTests.php -text
+tests/unit/Caching/TAPCCacheTest.php -text
tests/unit/Caching/TDirectoryCacheDependencyTest.php -text
tests/unit/Caching/TFileCacheDependencyTest.php -text
+tests/unit/Caching/TSqliteCacheTest.php -text
tests/unit/Collections/AllTests.php -text
tests/unit/Collections/TAttributeCollectionTest.php -text
tests/unit/Collections/TListTest.php -text
diff --git a/tests/unit/Caching/TAPCCacheTest.php b/tests/unit/Caching/TAPCCacheTest.php
new file mode 100644
index 00000000..2bf1d5d3
--- /dev/null
+++ b/tests/unit/Caching/TAPCCacheTest.php
@@ -0,0 +1,72 @@
+<?php
+require_once dirname(__FILE__).'/../phpunit.php';
+
+Prado::using('System.Caching.TAPCCache');
+
+/**
+ * @package System.Caching
+ */
+class TAPCCacheTest extends PHPUnit_Framework_TestCase {
+
+ protected $app = null;
+ protected static $cache = null;
+
+ protected function setUp() {
+ if(!extension_loaded('apc')) {
+ self::markTestSkipped('The APC extension is not available');
+ } else {
+ $basePath = dirname(__FILE__).'/mockapp';
+ $runtimePath = $basePath.'/runtime';
+ if(!is_writable($runtimePath)) {
+ self::markTestSkipped("'$runtimePath' is writable");
+ }
+ $this->app = new TApplication($basePath);
+ self::$cache = new TAPCCache();
+ self::$cache->init(null);
+ }
+ }
+
+ protected function tearDown() {
+ $this->app = null;
+ $this->cache = null;
+ }
+
+ public function testInit() {
+ throw new PHPUnit_Framework_IncompleteTestError();
+ }
+
+ public function testPrimaryCache() {
+ self::$cache->PrimaryCache = true;
+ self::assertEquals(true, self::$cache->PrimaryCache);
+ self::$cache->PrimaryCache = false;
+ self::assertEquals(false, self::$cache->PrimaryCache);
+ }
+
+ public function testKeyPrefix() {
+ self::$cache->KeyPrefix = 'prefix';
+ self::assertEquals('prefix', self::$cache->KeyPrefix);
+ }
+
+ public function testSetAndGet() {
+ self::$cache->set('key', 'value');
+ self::assertEquals('value', self::$cache->get('key'));
+ }
+
+ public function testAdd() {
+ self::$cache->add('key', 'value');
+ self::assertEquals('value', self::$cache->get('key'));
+ }
+
+ public function testDelete() {
+ self::$cache->delete('key');
+ self::assertEquals(false, self::$cache->get('key'));
+ }
+
+ public function testFlush() {
+ $this->testAdd();
+ self::assertEquals(true, self::$cache->flush());
+ }
+
+}
+
+?>
diff --git a/tests/unit/Caching/TSqliteCacheTest.php b/tests/unit/Caching/TSqliteCacheTest.php
new file mode 100644
index 00000000..59e74420
--- /dev/null
+++ b/tests/unit/Caching/TSqliteCacheTest.php
@@ -0,0 +1,80 @@
+<?php
+require_once dirname(__FILE__).'/../phpunit.php';
+
+Prado::using('System.Caching.TSqliteCache');
+
+/**
+ * @package System.Caching
+ */
+class TSqliteCacheTest extends PHPUnit_Framework_TestCase {
+
+ protected static $app = null;
+ protected static $cache = null;
+
+ protected function setUp() {
+ if(!extension_loaded('sqlite')) {
+ self::markTestSkipped('The SQLite extension is not available');
+ } else {
+ if(self::$app === null) {
+
+ $basePath = dirname(__FILE__).'/mockapp';
+ $runtimePath = $basePath.'/runtime';
+ if(!is_writable($runtimePath)) {
+ self::markTestSkipped("'$runtimePath' is writable");
+ }
+ self::$app = new TApplication($basePath);
+ self::$cache = new TSqliteCache();
+ self::$cache->init(null);
+ }
+
+ }
+ }
+
+ protected function tearDown() {
+ /*Prado::setApplication(null);
+ self::$cache = null;*/
+ }
+
+ public function testInit() {
+ throw new PHPUnit_Framework_IncompleteTestError();
+ }
+
+ public function testPrimaryCache() {
+ self::$cache->PrimaryCache = true;
+ self::assertEquals(true, self::$cache->PrimaryCache);
+ self::$cache->PrimaryCache = false;
+ self::assertEquals(false, self::$cache->PrimaryCache);
+ }
+
+ public function testKeyPrefix() {
+ self::$cache->KeyPrefix = 'prefix';
+ self::assertEquals('prefix', self::$cache->KeyPrefix);
+ }
+
+ public function testDbFile() {
+ self::assertEquals('sqlite.cache', basename(self::$cache->DbFile));
+ }
+
+ public function testSetAndGet() {
+ self::$cache->set('key', 'value');
+ self::assertEquals('value', self::$cache->get('key'));
+ }
+
+ public function testAdd() {
+ self::$cache->add('key', 'value');
+ self::assertEquals('value', self::$cache->get('key'));
+ }
+
+ public function testDelete() {
+ self::$cache->delete('key');
+ self::assertEquals(false, self::$cache->get('key'));
+ }
+
+ public function testFlush() {
+ $this->testAdd();
+ self::assertEquals(true, self::$cache->flush());
+ }
+
+}
+
+?>