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

TagDependencyTest::testInvalidateByTag()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 17
rs 9.9332
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