CacheTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
c 2
b 0
f 0
lcom 1
cbo 5
dl 0
loc 56
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testCacheSetETagWithStringValueReturnTrue() 0 6 1
A testCacheGetETagByFixedIdReturnValidEtag() 0 6 1
A testCacheGetETagByNullIdShouldBeNull() 0 6 1
A setUp() 0 10 1
A testETagCreateWithStringValueShouldReturnValidEtag() 0 6 1
A testETagCreateWithEmptyValueShouldReturnNull() 0 6 1
1
<?php
2
namespace Kpicaza\Tests\RedisETagCache;
3
4
use Kpicaza\RedisETagCache\RedisETagCache;
5
use Kpicaza\RedisETagCache\RedisETagGenerator;
6
use M6Web\Component\RedisMock\RedisMockFactory;
7
use Faker;
8
9
class CacheTest extends \PHPUnit_Framework_TestCase
10
{
11
    const FIXED_ID = '/api/users';
12
    const STRING_VALUE = 'MyStringValue';
13
14
    private $redis;
15
    private $generator;
16
    private $cache;
17
    private $faker;
18
19
    public function setUp()
20
    {
21
        parent::setUp();
22
23
        $factory = new RedisMockFactory();
24
        $this->redis = $factory->getAdapter('Predis\Client', true);
25
        $this->generator = new RedisETagGenerator();
26
        $this->cache = new RedisETagCache($this->generator, $this->redis);
27
        $this->faker = Faker\Factory::create();
28
    }
29
30
    public function testETagCreateWithStringValueShouldReturnValidEtag()
31
    {
32
        $etag = $this->generator->create(self::STRING_VALUE);
33
34
        $this->assertEquals(md5(self::STRING_VALUE), $etag);
35
    }
36
37
    public function testETagCreateWithEmptyValueShouldReturnNull()
38
    {
39
        $etag = $this->generator->create('');
40
41
        $this->assertEquals(null, $etag);
42
    }
43
44
    public function testCacheSetETagWithStringValueReturnTrue()
45
    {
46
        $etagSaved = $this->cache->setEtag(self::FIXED_ID, self::STRING_VALUE);
47
48
        $this->assertEquals(true, $etagSaved);
49
    }
50
51
    public function testCacheGetETagByFixedIdReturnValidEtag()
52
    {
53
        $etag = $this->cache->getETag(self::FIXED_ID);
54
55
        $this->assertEquals($etag, md5(self::STRING_VALUE));
56
    }
57
58
    public function testCacheGetETagByNullIdShouldBeNull()
59
    {
60
        $etag = $this->cache->getETag(null);
61
62
        $this->assertEquals($etag, null);
63
    }
64
}
65