1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* File: CacheAdapterTest.php |
4
|
|
|
* |
5
|
|
|
* @author Maciej Sławik <[email protected]> |
6
|
|
|
* Github: https://github.com/maciejslawik |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace MSlwk\Otomoto\Middleware\Test\Integration\Cache\Adapter; |
10
|
|
|
|
11
|
|
|
use MSlwk\Otomoto\Middleware\Cache\Adapter\CacheAdapterInterface; |
12
|
|
|
use MSlwk\Otomoto\Middleware\Cache\Factory\File\FileCacheAdapterFactory; |
13
|
|
|
use MSlwk\Otomoto\Middleware\Cache\Factory\File\OptionsProvider\FileDriverOptionsProvider; |
14
|
|
|
use PHPUnit\Framework\TestCase; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class CacheAdapterTest |
18
|
|
|
* @package MSlwk\Otomoto\Middleware\Test\Integration\Cache\Adapter |
19
|
|
|
*/ |
20
|
|
|
class CacheAdapterTest extends TestCase |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var CacheAdapterInterface |
24
|
|
|
*/ |
25
|
|
|
private $cacheAdapter; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @return void |
29
|
|
|
*/ |
30
|
|
|
public function setUp() |
31
|
|
|
{ |
32
|
|
|
$optionsProvider = new FileDriverOptionsProvider(); |
33
|
|
|
$cacheAdapterFactory = new FileCacheAdapterFactory($optionsProvider); |
34
|
|
|
$this->cacheAdapter = $cacheAdapterFactory->createAdapter(); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @return array |
39
|
|
|
*/ |
40
|
|
|
public function cacheDataProvider() |
41
|
|
|
{ |
42
|
|
|
return [ |
43
|
|
|
[ |
44
|
|
|
'key_1', |
45
|
|
|
'value_1' |
46
|
|
|
], |
47
|
|
|
[ |
48
|
|
|
'key_2', |
49
|
|
|
'value_2' |
50
|
|
|
], |
51
|
|
|
[ |
52
|
|
|
'key_3', |
53
|
|
|
'value_3' |
54
|
|
|
], |
55
|
|
|
]; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @test |
60
|
|
|
* @dataProvider cacheDataProvider |
61
|
|
|
* @param $key |
62
|
|
|
* @param $value |
63
|
|
|
*/ |
64
|
|
|
public function testCacheKeyStoredCorrectlyInFilesystem($key, $value) |
65
|
|
|
{ |
66
|
|
|
$optionsProvider = new FileDriverOptionsProvider(); |
67
|
|
|
$cacheAdapterFactory = new FileCacheAdapterFactory($optionsProvider); |
68
|
|
|
$cacheAdapter = $cacheAdapterFactory->createAdapter(); |
69
|
|
|
|
70
|
|
|
$cacheItem = $cacheAdapter->retrieve($key); |
71
|
|
|
$this->assertEmpty($cacheItem->get()); |
72
|
|
|
|
73
|
|
|
$cacheItem->set($value); |
74
|
|
|
$cacheAdapter->store($cacheItem); |
75
|
|
|
|
76
|
|
|
$cacheItem = $cacheAdapter->retrieve($key); |
77
|
|
|
$this->assertEquals($value, $cacheItem->get()); |
78
|
|
|
|
79
|
|
|
$cacheItem->set(null); |
80
|
|
|
$cacheAdapter->store($cacheItem); |
81
|
|
|
|
82
|
|
|
$cacheItem = $cacheAdapter->retrieve($key); |
83
|
|
|
$this->assertEmpty($cacheItem->get()); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|