summaryrefslogtreecommitdiff
path: root/tests/UnitTests/framework/Data/utMemCache.php
blob: 26981f63d56f0fd822cecf59da46a6bd4974c500 (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
<?php

require_once(dirname(__FILE__).'/../common.php');
require_once(dirname(__FILE__).'/CacheTestCase.php');
Prado::using('System.Data.TMemCache');

class utMemCache extends UnitTestCase
{
	private $_prefix='';
	private $_server='localhost';
	private $_port=11211;

	public function testInit()
	{
		if(!extension_loaded('memcache'))
		{
			$this->fail('TMemCache is not tested. PHP extension "memcache" is required by TMemCache.');
			return;
		}
		$cache=new TMemCache;

		$this->assertTrue($cache->getHost()==='localhost');
		$cache->setHost('localhost2');
		$this->assertTrue($cache->getHost()==='localhost2');

		$this->assertTrue($cache->getPort()===11211);
		$cache->setPort(1000);
		$this->assertTrue($cache->getPort()===1000);

		$cache->init(null,null);
		try
		{
			$cache->setHost('newhost');
			$this->fail('exception not raised when setting Server after init');
		}
		catch(TInvalidOperationException $e)
		{
			$this->pass();
		}
		try
		{
			$cache->setPort(10000);
			$this->fail('exception not raised when setting Port after init');
		}
		catch(TInvalidOperationException $e)
		{
			$this->pass();
		}
	}

	public function testBasicOperations()
	{
		if(!extension_loaded('memcache'))
		{
			$this->fail('TMemCache is not tested. PHP extension "memcache" is required by TMemCache.');
			return;
		}
		$cache=new TMemCache;
		$cache->init(null,null);
		$this->setCache($cache);
		$this->basicOperations();
		$this->setCache(null);
	}
}

?>