1 | <?php |
||
6 | abstract class CacheTest extends TestCase{ |
||
7 | |||
8 | protected $host = '127.0.0.1'; |
||
9 | protected $port = 1; |
||
10 | |||
11 | protected $cache; |
||
12 | |||
13 | public function setUp() { |
||
14 | $this->cache->connect($this->host, $this->port); |
||
15 | if(!$this->cache->save('servicetest', 'isactive', 60)){ |
||
16 | $this->markTestSkipped( |
||
17 | 'No connection is available to the caching server' |
||
18 | ); |
||
19 | } |
||
20 | } |
||
21 | |||
22 | public function tearDown() { |
||
23 | unset($this->cache); |
||
24 | } |
||
25 | |||
26 | public function testConnect(){ |
||
27 | $this->assertObjectHasAttribute('cache', $this->cache->connect($this->host, $this->port)); |
||
28 | } |
||
29 | |||
30 | public function testCacheAdd(){ |
||
31 | $this->assertTrue($this->cache->save('key1', 'testvalue', 60)); |
||
32 | } |
||
33 | |||
34 | public function testCacheRetrieve(){ |
||
35 | $this->assertEquals('testvalue', $this->cache->fetch('key1')); |
||
36 | } |
||
37 | |||
38 | public function testCacheOverride(){ |
||
39 | $this->cache->replace('key1', 'newvalue', 60); |
||
40 | $this->assertEquals('newvalue', $this->cache->fetch('key1')); |
||
41 | } |
||
42 | |||
43 | public function testCacheDelete(){ |
||
44 | $this->assertTrue($this->cache->delete('key1')); |
||
45 | $this->assertFalse($this->cache->delete('key1')); |
||
46 | } |
||
47 | |||
48 | public function testCacheClear(){ |
||
49 | $this->cache->save('key1', 'testvalue', 60); |
||
50 | $this->assertTrue($this->cache->deleteAll()); |
||
51 | } |
||
52 | } |
||
53 |