1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Yiisoft\Cache\Tests\Dependency; |
4
|
|
|
|
5
|
|
|
use Yiisoft\Cache\ArrayCache; |
6
|
|
|
use Yiisoft\Cache\Cache; |
7
|
|
|
use Yiisoft\Cache\Dependency\Dependency; |
8
|
|
|
use Yiisoft\Cache\Dependency\TagDependency; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Dependency (abstract) tests. |
12
|
|
|
* @group caching |
13
|
|
|
*/ |
14
|
|
|
class DependencyTest extends DependencyTestCase |
15
|
|
|
{ |
16
|
|
|
public function testResetReusableData(): void |
17
|
|
|
{ |
18
|
|
|
$value = ['dummy']; |
19
|
|
|
$dependency = new MockDependency(); |
20
|
|
|
$this->setInaccessibleProperty($dependency, 'reusableData', $value, false); |
21
|
|
|
$this->assertSameExceptObject($value, $this->getInaccessibleProperty($dependency, 'reusableData')); |
22
|
|
|
|
23
|
|
|
$dependency->resetReusableData(); |
24
|
|
|
|
25
|
|
|
$this->assertSameExceptObject([], $this->getInaccessibleProperty($dependency, 'reusableData')); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testGenerateReusableHash(): void |
29
|
|
|
{ |
30
|
|
|
$dependency = $this->getMockForAbstractClass(Dependency::class); |
31
|
|
|
$this->setInaccessibleProperty($dependency, 'data', 'dummy'); |
32
|
|
|
|
33
|
|
|
$result = $this->invokeMethod($dependency, 'generateReusableHash'); |
34
|
|
|
|
35
|
|
|
$this->assertSameExceptObject(5, strlen($this->getInaccessibleProperty($dependency, 'data'))); |
36
|
|
|
$this->assertSameExceptObject(40, strlen($result)); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testIsChanged(): void |
40
|
|
|
{ |
41
|
|
|
/* @var $dependency Dependency */ |
42
|
|
|
$dependency = $this->getMockForAbstractClass(Dependency::class); |
43
|
|
|
$this->assertDependencyNotChanged($dependency); |
44
|
|
|
|
45
|
|
|
$this->setInaccessibleProperty($dependency, 'data', 'changed'); |
46
|
|
|
|
47
|
|
|
$this->assertDependencyChanged($dependency); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testEvaluateDependencyReusable() |
51
|
|
|
{ |
52
|
|
|
$cache = new Cache(new ArrayCache()); |
53
|
|
|
$dependency = new TagDependency('test'); |
54
|
|
|
$dependency->markAsReusable(); |
55
|
|
|
$cache->set('a', 1, null, $dependency); |
56
|
|
|
TagDependency::invalidate($cache, 'test'); |
57
|
|
|
$data1 = $this->getInaccessibleProperty($dependency, 'data'); |
58
|
|
|
$cache->set('b', 2, null, $dependency); |
59
|
|
|
$data2 = $this->getInaccessibleProperty($dependency, 'data'); |
60
|
|
|
$this->assertEquals($data1, $data2); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|