Completed
Push — master ( e1b391...0629e4 )
by David
14s queued 10s
created

ClassBoundMemoryAdapterTest::testMemory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 24
rs 9.7333
c 0
b 0
f 0
cc 1
nc 1
nop 0
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();
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Component\Cache\Simple\ArrayCache has been deprecated: since Symfony 4.3, use ArrayAdapter and type-hint for CacheInterface instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

21
        $cache = /** @scrutinizer ignore-deprecated */ new ArrayCache();
Loading history...
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());
0 ignored issues
show
Bug introduced by
$classToTouch->getFileName() of type string is incompatible with the type boolean expected by parameter $clear_realpath_cache of clearstatcache(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

28
        clearstatcache(/** @scrutinizer ignore-type */ $classToTouch->getFileName());
Loading history...
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