Passed
Pull Request — master (#30)
by Alexander
02:06
created

TagDependencyTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 26
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createCache() 0 5 1
A testInvalidateByTag() 0 17 1
1
<?php
2
namespace Yiisoft\CacheOld\Tests\Dependency;
3
4
use Yiisoft\CacheOld\ArrayCache;
5
use Yiisoft\CacheOld\Cache;
6
use Yiisoft\CacheOld\CacheInterface;
7
use Yiisoft\CacheOld\Dependency\TagDependency;
0 ignored issues
show
Bug introduced by
The type Yiisoft\CacheOld\Dependency\TagDependency was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
9
class TagDependencyTest extends DependencyTestCase
10
{
11
    protected function createCache(): CacheInterface
12
    {
13
        // isChanged of TagDependency needs cache access.
14
        // Using real cache.
15
        return new Cache(new ArrayCache());
16
    }
17
18
    public function testInvalidateByTag(): void
19
    {
20
        $cache = $this->getCache();
21
        $cache->set('item_42_price', 13, null, new TagDependency('item_42'));
22
        $cache->set('item_42_total', 26, null, new TagDependency('item_42'));
23
24
        $this->assertSame(13, $cache->get('item_42_price'));
25
        $this->assertSame(26, $cache->get('item_42_total'));
26
27
        TagDependency::invalidate($cache, 'item_42');
28
29
        // keys are invalidated but are still there
30
        $this->assertTrue($cache->has('item_42_price'));
31
        $this->assertTrue($cache->has('item_42_total'));
32
33
        $this->assertNull($cache->get('item_42_price'));
34
        $this->assertNull($cache->get('item_42_total'));
35
    }
36
}
37