Passed
Push — master ( 34997b...09cd63 )
by Koldo
02:54
created

TagException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
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