Completed
Push — master ( 6cab55...c82b86 )
by Roman
02:16
created

CacheStorageTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 46
rs 10
wmc 2
lcom 0
cbo 6
1
<?php
2
3
use Mockery as m;
4
5
class CacheStorageTest extends PHPUnit_Framework_TestCase
6
{
7
    public function testBasicStorageUsage()
8
    {
9
        $cache = m::mock(\Illuminate\Contracts\Cache\Repository::class);
10
        $cache->shouldReceive('put')->once()->with('foo', 'bar', 1);
11
        $cache->shouldReceive('forever')->once()->with('foo', 'bar');
12
        $cache->shouldReceive('has')->once()->andReturn(true);
13
        $cache->shouldReceive('forget')->once()->with('foo')->andReturn(true);
14
        $cache->shouldReceive('flush')->once();
15
16
        $storage = new \Framgia\Jwt\Storage\CacheStorage($cache);
17
18
        $storage->add('foo', 'bar', 1);
19
        $storage->forever('foo', 'bar');
20
        $this->assertTrue($storage->has('foo'));
21
        $this->assertTrue($storage->destroy('foo'));
22
        $storage->flush();
23
    }
24
25
    public function testTaggedStorageUsage()
26
    {
27
        $tagged = m::mock(Illuminate\Cache\TaggedCache::class);
28
29
        $tagged->shouldReceive('setDefaultCacheTime')->once();
30
        $tagged->shouldReceive('put')->once()->with('foo', 'bar', 1);
31
        $tagged->shouldReceive('forever')->once()->with('foo', 'bar');
32
        $tagged->shouldReceive('has')->once()->andReturn(true);
33
        $tagged->shouldReceive('forget')->once()->with('foo')->andReturn(true);
34
        $tagged->shouldReceive('flush')->once();
35
36
        $store = m::mock(TaggedStoreStub::class);
37
38
        $store->shouldReceive('tags')->once()->with('jwt')->andReturn($tagged);
39
40
        $cache = new \Illuminate\Cache\Repository($store);
41
42
        $storage = new \Framgia\Jwt\Storage\CacheStorage($cache, 'jwt');
43
44
        $storage->add('foo', 'bar', 1);
45
        $storage->forever('foo', 'bar');
46
        $this->assertTrue($storage->has('foo'));
47
        $this->assertTrue($storage->destroy('foo'));
48
        $storage->flush();
49
    }
50
}
51
52
abstract class TaggedStoreStub extends \Illuminate\Cache\TaggableStore implements \Illuminate\Contracts\Cache\Store {}
53