|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace TheCodingMachine\CacheUtils; |
|
4
|
|
|
|
|
5
|
|
|
use function clearstatcache; |
|
6
|
|
|
use function file_get_contents; |
|
7
|
|
|
use function file_put_contents; |
|
8
|
|
|
use ReflectionClass; |
|
9
|
|
|
use function sleep; |
|
10
|
|
|
use function str_replace; |
|
11
|
|
|
use Symfony\Component\Cache\Simple\ArrayCache; |
|
12
|
|
|
use function sys_get_temp_dir; |
|
13
|
|
|
use PHPUnit\Framework\TestCase; |
|
14
|
|
|
use TheCodingMachine\CacheUtils\Fixtures\A; |
|
15
|
|
|
use function touch; |
|
16
|
|
|
|
|
17
|
|
|
class ClassBoundMemoryAdapterTest extends TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
public function testMemory() |
|
20
|
|
|
{ |
|
21
|
|
|
$cache = new ArrayCache(); |
|
|
|
|
|
|
22
|
|
|
$fileBoundCache = new FileBoundCache($cache, 'prefix'); |
|
23
|
|
|
$classBoundCache = new ClassBoundCache($fileBoundCache); |
|
24
|
|
|
$adapter = new ClassBoundMemoryAdapter($classBoundCache); |
|
25
|
|
|
|
|
26
|
|
|
$classToTouch = new ReflectionClass(A::class); |
|
27
|
|
|
sleep(1); |
|
28
|
|
|
clearstatcache($classToTouch->getFileName()); |
|
|
|
|
|
|
29
|
|
|
touch($classToTouch->getFileName()); |
|
30
|
|
|
|
|
31
|
|
|
$adapter->set('foo', 'bar', $classToTouch); |
|
32
|
|
|
|
|
33
|
|
|
$this->assertSame('bar', $adapter->get('foo')); |
|
34
|
|
|
|
|
35
|
|
|
$adapter2 = new ClassBoundMemoryAdapter($classBoundCache); |
|
36
|
|
|
$this->assertSame('bar', $adapter2->get('foo')); |
|
37
|
|
|
|
|
38
|
|
|
sleep(1); |
|
39
|
|
|
clearstatcache($classToTouch->getFileName()); |
|
40
|
|
|
touch($classToTouch->getFileName()); |
|
41
|
|
|
|
|
42
|
|
|
$this->assertSame('bar', $adapter->get('foo')); |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
|