|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Nip\Cache\Tests\Stores; |
|
4
|
|
|
|
|
5
|
|
|
use Nip\Cache\Stores\Repository; |
|
6
|
|
|
use Nip\Cache\Tests\AbstractTest; |
|
7
|
|
|
use Symfony\Component\Cache\Adapter\FilesystemAdapter; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class RepositoryTest |
|
11
|
|
|
* @package Nip\Cache\Tests\Stores |
|
12
|
|
|
*/ |
|
13
|
|
|
class RepositoryTest extends AbstractTest |
|
14
|
|
|
{ |
|
15
|
|
|
public function test_get() |
|
16
|
|
|
{ |
|
17
|
|
|
$store = $this->initFileStore(); |
|
18
|
|
|
|
|
19
|
|
|
$value = $store->get('test', 'default'); |
|
20
|
|
|
self::assertSame('default', $value); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function test_sey() |
|
24
|
|
|
{ |
|
25
|
|
|
$store = $this->initFileStore(); |
|
26
|
|
|
$store->set('test', 'myValue'); |
|
27
|
|
|
|
|
28
|
|
|
$store = $this->initFileStore(); |
|
29
|
|
|
|
|
30
|
|
|
self::assertSame('myValue', $store->get('test')); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
public function test_remember() |
|
35
|
|
|
{ |
|
36
|
|
|
$store = $this->initFileStore(); |
|
37
|
|
|
self::assertFalse($store->has('foo')); |
|
38
|
|
|
|
|
39
|
|
|
$result = $store->remember('foo', 10, function () { |
|
40
|
|
|
return 'bar'; |
|
41
|
|
|
}); |
|
42
|
|
|
self::assertSame('bar', $result); |
|
43
|
|
|
self::assertSame('bar', $store->get('foo')); |
|
44
|
|
|
|
|
45
|
|
|
$result = $store->remember('foo', 10, function () { |
|
46
|
|
|
return 'bar2'; |
|
47
|
|
|
}); |
|
48
|
|
|
|
|
49
|
|
|
self::assertSame('bar', $result); |
|
50
|
|
|
self::assertSame('bar', $store->get('foo')); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
protected function initFileStore() |
|
54
|
|
|
{ |
|
55
|
|
|
$adapter = new FilesystemAdapter('', 0, CACHE_PATH); |
|
56
|
|
|
return new Repository($adapter); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|