summaryrefslogtreecommitdiff
path: root/tests/unit/Caching/TAPCCacheTest.php
blob: 84ff02ca6b3dd177c5b4508ac8f8e18cf1dc8b5b (plain)
1
2
3
4
5
6
7
8
9
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?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");
				}
				try {
					$this->app = new TApplication($basePath);
					self::$cache = new TAPCCache();
					self::$cache->init(null);
				} catch(TConfigurationException $e) {
					self::markTestSkipped($e->getMessage());
				}
				
		}
	}

	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() {
		try {
			self::$cache->add('anotherkey', 'value');
		} catch(TNotSupportedException $e) {
			self::markTestSkipped('apc_add is not supported');
			return;
		}
		self::assertEquals('value', self::$cache->get('anotherkey'));
	}
	
	public function testDelete() {
		self::$cache->delete('key');
		self::assertEquals(false, self::$cache->get('key'));
	}
	
	public function testFlush() {
		$this->testSetAndGet();
		self::assertEquals(true, self::$cache->flush());
	}

}

?>