Issues (10)

tests/FileBoundMemoryAdapterTest.php (2 issues)

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 function sleep;
10
use function str_replace;
11
use Symfony\Component\Cache\Simple\ArrayCache;
0 ignored issues
show
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...
12
use function sys_get_temp_dir;
13
use PHPUnit\Framework\TestCase;
14
use function touch;
15
16
class FileBoundMemoryAdapterTest extends TestCase
17
{
18
    public function testMemory(): void
19
    {
20
        $cache = new ArrayAdapter();
21
        $fileBoundCache = new FileBoundCache($cache, 'prefix');
22
        $adapter = new FileBoundMemoryAdapter($fileBoundCache);
23
24
        $tmpPath = sys_get_temp_dir().'/tmpCacheTest';
25
        touch($tmpPath);
26
27
        $adapter->set('foo', 'bar', [
28
            $tmpPath
29
        ]);
30
31
        $this->assertSame('bar', $adapter->get('foo'));
32
33
        $adapter2 = new FileBoundMemoryAdapter($fileBoundCache);
34
        $this->assertSame('bar', $adapter2->get('foo'));
35
36
        sleep(1);
37
        clearstatcache($tmpPath);
0 ignored issues
show
$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

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