Passed
Push — master ( dba830...8c74b2 )
by Adam
02:04
created

CacheTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 9
c 3
b 0
f 0
lcom 1
cbo 1
dl 0
loc 47
rs 10
1
<?php
2
namespace DBAL\Tests\Caching;
3
4
use PHPUnit\Framework\TestCase;
5
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