1 | <?php |
||
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 | |||
53 |