Completed
Push — master ( 1dc35d...01a53f )
by Alexander
01:42
created

FileDependencyTest::createDependency()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
namespace Yiisoft\Cache\Tests\Dependency;
3
4
use Yiisoft\Cache\Dependency\FileDependency;
5
6
class FileDependencyTest extends DependencyTestCase
7
{
8
    private function getFilePath(): string
9
    {
10
        return dirname(__DIR__) . '/runtime/file.txt';
11
    }
12
13
    private function createDependency(): FileDependency
14
    {
15
        return new FileDependency($this->getFilePath());
16
    }
17
18
    private function touchFile(): void
19
    {
20
        $this->createDirectory(dirname($this->getFilePath()), 0775);
21
        touch($this->getFilePath());
22
    }
23
24
    public function testTouchingFileMarksDependencyAsChanged(): void
25
    {
26
        $this->touchFile();
27
        $dependency = $this->createDependency();
28
        $this->touchFile();
29
30
        $this->assertDependencyChanged($dependency);
31
    }
32
33
    private function createDirectory(string $path, int $mode): bool
34
    {
35
        return is_dir($path) || (mkdir($path, $mode, true) && is_dir($path));
36
    }
37
}
38