Issues (10)

tests/ClassBoundCacheContractTest.php (1 issue)

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;
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
$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