ClassBoundCacheContractTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
eloc 18
c 1
b 0
f 0
dl 0
loc 33
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A testClassBoundCacheContract() 0 31 1
1
<?php
2
3
namespace TheCodingMachine\CacheUtils;
4
5
use Symfony\Component\Cache\Adapter\ArrayAdapter;
6
use function clearstatcache;
7
use PHPUnit\Framework\TestCase;
8
use ReflectionClass;
9
use function sleep;
10
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...
11
use TheCodingMachine\CacheUtils\Fixtures\A;
12
use function touch;
13
14
class ClassBoundCacheContractTest extends TestCase
15
{
16
    public function testClassBoundCacheContract(): void
17
    {
18
        $cache = new ArrayAdapter();
19
        $fileBoundCache = new FileBoundCache($cache, 'prefix');
20
        $classBoundCache = new ClassBoundCache($fileBoundCache, true, true, true);
21
        $classBoundCacheContract = new ClassBoundCacheContract($classBoundCache);
22
23
        $val = 0;
24
25
        $newVal = $classBoundCacheContract->get(new ReflectionClass(A::class), function() use (&$val) {
26
            return ++$val;
27
        });
28
29
        $this->assertSame(1, $newVal);
30
31
        $newVal2 = $classBoundCacheContract->get(new ReflectionClass(A::class), function() use (&$val) {
32
            return ++$val;
33
        });
34
35
        $this->assertSame(1, $newVal2);
36
37
        $classToTouch = new ReflectionClass(A::class);
38
        sleep(1);
39
        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

39
        clearstatcache(/** @scrutinizer ignore-type */ $classToTouch->getFileName());
Loading history...
40
        touch($classToTouch->getFileName());
41
42
        $newVal3 = $classBoundCacheContract->get(new ReflectionClass(A::class), function() use (&$val) {
43
            return ++$val;
44
        });
45
46
        $this->assertSame(2, $newVal3);
47
    }
48
49
}
50