Completed
Push — master ( 0629e4...73c381 )
by David
17s queued 10s
created

ClassBoundCacheTest::testClassBoundCache()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 16
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 1
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 TheCodingMachine\CacheUtils\Fixtures\B;
16
use TheCodingMachine\CacheUtils\Fixtures\C;
17
use TheCodingMachine\CacheUtils\Fixtures\D;
18
use function touch;
19
20
class ClassBoundCacheTest extends TestCase
21
{
22
    /**
23
     * @dataProvider touchFile
24
     */
25
    public function testClassBoundCache($classToTouch)
26
    {
27
        $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

27
        $cache = /** @scrutinizer ignore-deprecated */ new ArrayCache();
Loading history...
28
        $fileBoundCache = new FileBoundCache($cache, 'prefix');
29
        $classBoundCache = new ClassBoundCache($fileBoundCache, true, true, true);
30
31
        $classBoundCache->set('foo', 'bar', new ReflectionClass(A::class));
32
33
        $this->assertSame('bar', $classBoundCache->get('foo'));
34
35
        $classToTouch = new ReflectionClass($classToTouch);
36
        sleep(1);
37
        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

37
        clearstatcache(/** @scrutinizer ignore-type */ $classToTouch->getFileName());
Loading history...
38
        touch($classToTouch->getFileName());
39
40
        $this->assertNull($classBoundCache->get('foo'));
41
    }
42
43
    public function touchFile()
44
    {
45
        return [
46
            [ B::class ],
47
            [ C::class ],
48
            [ D::class ],
49
        ];
50
    }
51
}
52