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

FileBoundMemoryAdapterTest::testMemory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 23
rs 9.7998
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 function sleep;
9
use function str_replace;
10
use Symfony\Component\Cache\Simple\ArrayCache;
11
use function sys_get_temp_dir;
12
use PHPUnit\Framework\TestCase;
13
use function touch;
14
15
class FileBoundMemoryAdapterTest extends TestCase
16
{
17
    public function testMemory()
18
    {
19
        $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

19
        $cache = /** @scrutinizer ignore-deprecated */ new ArrayCache();
Loading history...
20
        $fileBoundCache = new FileBoundCache($cache, 'prefix');
21
        $adapter = new FileBoundMemoryAdapter($fileBoundCache);
22
23
        $tmpPath = sys_get_temp_dir().'/tmpCacheTest';
24
        touch($tmpPath);
25
26
        $adapter->set('foo', 'bar', [
27
            $tmpPath
28
        ]);
29
30
        $this->assertSame('bar', $adapter->get('foo'));
31
32
        $adapter2 = new FileBoundMemoryAdapter($fileBoundCache);
33
        $this->assertSame('bar', $adapter2->get('foo'));
34
35
        sleep(1);
36
        clearstatcache($tmpPath);
0 ignored issues
show
Bug introduced by
$tmpPath 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

36
        clearstatcache(/** @scrutinizer ignore-type */ $tmpPath);
Loading history...
37
        touch($tmpPath);
38
39
        $this->assertSame('bar', $adapter->get('foo'));
40
    }
41
}
42