ClassBoundMemoryAdapterTest::testMemory()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 24
rs 9.7333
cc 1
nc 1
nop 0
1
<?php
2
3
namespace TheCodingMachine\CacheUtils;
4
5
use Symfony\Component\Cache\Adapter\ArrayAdapter;
6
use function clearstatcache;
7
use function file_get_contents;
8
use function file_put_contents;
9
use ReflectionClass;
10
use function sleep;
11
use function str_replace;
12
use Symfony\Component\Cache\Simple\ArrayCache;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Cache\Simple\ArrayCache was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use function sys_get_temp_dir;
14
use PHPUnit\Framework\TestCase;
15
use TheCodingMachine\CacheUtils\Fixtures\A;
16
use function touch;
17
18
class ClassBoundMemoryAdapterTest extends TestCase
19
{
20
    public function testMemory(): void
21
    {
22
        $cache = new ArrayAdapter();
23
        $fileBoundCache = new FileBoundCache($cache, 'prefix');
24
        $classBoundCache = new ClassBoundCache($fileBoundCache);
25
        $adapter = new ClassBoundMemoryAdapter($classBoundCache);
26
27
        $classToTouch = new ReflectionClass(A::class);
28
        sleep(1);
29
        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

29
        clearstatcache(/** @scrutinizer ignore-type */ $classToTouch->getFileName());
Loading history...
30
        touch($classToTouch->getFileName());
31
32
        $adapter->set('foo', 'bar', $classToTouch);
33
34
        $this->assertSame('bar', $adapter->get('foo'));
35
36
        $adapter2 = new ClassBoundMemoryAdapter($classBoundCache);
37
        $this->assertSame('bar', $adapter2->get('foo'));
38
39
        sleep(1);
40
        clearstatcache($classToTouch->getFileName());
41
        touch($classToTouch->getFileName());
42
43
        $this->assertSame('bar', $adapter->get('foo'));
44
    }
45
}
46