1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Db\Tests\Cache; |
6
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
use Yiisoft\Cache\CacheInterface; |
9
|
|
|
use Yiisoft\Cache\Dependency\TagDependency; |
10
|
|
|
use Yiisoft\Db\Cache\SchemaCache; |
11
|
|
|
use Yiisoft\Db\Tests\Support\Assert; |
12
|
|
|
use Yiisoft\Db\Tests\Support\DbHelper; |
13
|
|
|
use Yiisoft\Db\Tests\Support\TestTrait; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @group db |
17
|
|
|
*/ |
18
|
|
|
final class SchemaCacheTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
use TestTrait; |
21
|
|
|
|
22
|
|
|
public function testConstruct(): void |
23
|
|
|
{ |
24
|
|
|
$schemaCache = new SchemaCache(DbHelper::getCache()); |
25
|
|
|
|
26
|
|
|
$this->assertInstanceOf(CacheInterface::class, Assert::getInaccessibleProperty($schemaCache, 'cache')); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testInvalidate(): void |
30
|
|
|
{ |
31
|
|
|
$schemaCache = new SchemaCache(DbHelper::getCache()); |
32
|
|
|
|
33
|
|
|
$schemaCache->set('key', 'value', 3600, new TagDependency('tag')); |
34
|
|
|
|
35
|
|
|
$this->assertSame('value', $schemaCache->getOrSet('key')); |
36
|
|
|
|
37
|
|
|
$schemaCache->invalidate('tag'); |
38
|
|
|
|
39
|
|
|
$this->assertNull($schemaCache->getOrSet('key')); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testSetDuration(): void |
43
|
|
|
{ |
44
|
|
|
$schemaCache = new SchemaCache(DbHelper::getCache()); |
45
|
|
|
|
46
|
|
|
$schemaCache->setDuration(3600); |
47
|
|
|
|
48
|
|
|
$this->assertSame(3600, $schemaCache->getDuration()); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testSetEnabled(): void |
52
|
|
|
{ |
53
|
|
|
$schemaCache = new SchemaCache(DbHelper::getCache()); |
54
|
|
|
|
55
|
|
|
$schemaCache->setEnable(false); |
56
|
|
|
|
57
|
|
|
$this->assertFalse($schemaCache->isEnabled()); |
58
|
|
|
|
59
|
|
|
$schemaCache->setEnable(true); |
60
|
|
|
|
61
|
|
|
$this->assertTrue($schemaCache->isEnabled()); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testSetExclude(): void |
65
|
|
|
{ |
66
|
|
|
$schemaCache = new SchemaCache(DbHelper::getCache()); |
67
|
|
|
|
68
|
|
|
$schemaCache->setExclude(['table1', 'table2']); |
69
|
|
|
|
70
|
|
|
$this->assertSame(['table1', 'table2'], Assert::getInaccessibleProperty($schemaCache, 'exclude')); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|