Passed
Pull Request — master (#79)
by David
02:19
created

testIsValid()

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
c 0
b 0
f 0
eloc 10
nc 1
nop 0
1
<?php
2
3
namespace TheCodingMachine\GraphQL\Controllers\Cache;
4
5
use function clearstatcache;
6
use PHPUnit\Framework\TestCase;
7
use function stat;
8
use function strtotime;
9
use function sys_get_temp_dir;
10
use function time;
11
use function touch;
12
use function unlink;
13
14
class FileModificationTimeCacheValidatorTraitTest extends TestCase
15
{
16
17
    public function testIsValid()
18
    {
19
        $cacheItem = new class implements CacheValidatorInterface {
20
            use FileModificationTimeCacheValidatorTrait;
21
        };
22
23
        $file = sys_get_temp_dir().'/test_file_graphql_controllers';
24
        touch($file, strtotime('2019-01-01'));
25
        $cacheItem->addTrackedFile($file);
26
27
        $this->assertTrue($cacheItem->isValid());
28
29
        touch($file, strtotime('2019-01-02'));
30
        clearstatcache($file);
0 ignored issues
show
Bug introduced by
$file 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

30
        clearstatcache(/** @scrutinizer ignore-type */ $file);
Loading history...
31
        $this->assertFalse($cacheItem->isValid());
32
        unlink($file);
33
    }
34
}
35