Passed
Pull Request — master (#380)
by Wilmer
02:44
created

AbstractSchemaCacheTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
dl 0
loc 53
rs 10
c 1
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testConstruct() 0 5 1
A testSetDuration() 0 7 1
A testInvalidate() 0 11 1
A testSetEnabled() 0 11 1
A testSetExclude() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Tests;
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\TestTrait;
13
14
abstract class AbstractSchemaCacheTest extends TestCase
15
{
16
    use TestTrait;
17
18
    public function testConstruct(): void
19
    {
20
        $queryCache = new SchemaCache($this->getCache());
21
22
        $this->assertInstanceOf(CacheInterface::class, Assert::getInaccessibleProperty($queryCache, 'cache'));
23
    }
24
25
    public function testInvalidate(): void
26
    {
27
        $schemaCache = $this->getSchemaCache();
28
29
        $schemaCache->set('key', 'value', 3600, new TagDependency('tag'));
30
31
        $this->assertSame('value', $schemaCache->getOrSet('key'));
32
33
        $schemaCache->invalidate('tag');
34
35
        $this->assertNull($schemaCache->getOrSet('key'));
36
    }
37
38
    public function testSetDuration(): void
39
    {
40
        $schemaCache = $this->getSchemaCache();
41
42
        $schemaCache->setDuration(3600);
43
44
        $this->assertSame(3600, $schemaCache->getDuration());
45
    }
46
47
    public function testSetEnabled(): void
48
    {
49
        $schemaCache = $this->getSchemaCache();
50
51
        $schemaCache->setEnable(false);
52
53
        $this->assertFalse($schemaCache->isEnabled());
54
55
        $schemaCache->setEnable(true);
56
57
        $this->assertTrue($schemaCache->isEnabled());
58
    }
59
60
    public function testSetExclude(): void
61
    {
62
        $schemaCache = $this->getSchemaCache();
63
64
        $schemaCache->setExclude(['table1', 'table2']);
65
66
        $this->assertSame(['table1', 'table2'], Assert::getInaccessibleProperty($schemaCache, 'exclude'));
67
    }
68
}
69