Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3652282

Browse files
committed
Add tests and some minor fixes
1 parent 7978645 commit 3652282

15 files changed

+416
-136
lines changed

phpunit.xml.dist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@
7373
<element key="4"><string>Symfony\Component\Cache\Traits</string></element>
7474
<element key="5"><string>Symfony\Component\Console</string></element>
7575
<element key="6"><string>Symfony\Component\HttpFoundation</string></element>
76+
<element key="7"><string>Symfony\Component\Cache\Tests\Adapter</string></element>
77+
<element key="8"><string>Symfony\Component\Cache\Tests\Traits</string></element>
7678
</array>
7779
</element>
7880
</array>

src/Symfony/Component/Cache/Adapter/TagAware/AbstractTagAwareAdapter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ static function ($key, $value, $isHit) use ($defaultLifetime) {
4949
$item->isHit = $isHit;
5050
$item->defaultLifetime = $defaultLifetime;
5151
//<diff:AbstractAdapter> extract Value and Tags from the cache value
52+
$item->isTaggable = true;
5253
$item->value = $v = $value['value'];
5354
$item->metadata[CacheItem::METADATA_TAGS] = $value['tags'] ?? [];
5455
// Detect wrapped values that encode for their expiry and creation duration

src/Symfony/Component/Cache/Adapter/TagAware/FilesystemTagAwareAdapter.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function invalidateTags(array $tags)
9494
continue;
9595
}
9696

97-
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->getTagFolder($tag), \FilesystemIterator::SKIP_DOTS)) as $itemLink) {
97+
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($tagsFolder, \FilesystemIterator::SKIP_DOTS)) as $itemLink) {
9898
if (!$itemLink->isLink()) {
9999
throw new \Exception('Tag link is not a link: '.$itemLink);
100100
}
@@ -108,6 +108,9 @@ public function invalidateTags(array $tags)
108108
}
109109
}
110110

111+
// Commit deferred changes after invalidation to emulate logic in TagAwareAdapter
112+
$this->commit();
113+
111114
return true;
112115
}
113116

src/Symfony/Component/Cache/Adapter/TagAware/RedisTagAwareAdapter.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ public function invalidateTags(array $tags)
151151
$this->doDelete($chunkIds);
152152
}
153153

154+
// Commit deferred changes after invalidation to emulate logic in TagAwareAdapter
155+
$this->commit();
156+
154157
return true;
155158
}
156159
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Cache\Tests\Adapter\TagAware;
13+
14+
use Symfony\Component\Cache\Adapter\TagAware\FilesystemTagAwareAdapter;
15+
use Symfony\Component\Cache\Tests\Adapter\FilesystemAdapterTest;
16+
use Symfony\Component\Cache\Tests\Traits\TagAwareTestTrait;
17+
18+
/**
19+
* @group time-sensitive
20+
*/
21+
class FilesystemTagAwareAdapterTest extends FilesystemAdapterTest
22+
{
23+
use TagAwareTestTrait;
24+
25+
public function createCachePool($defaultLifetime = 0)
26+
{
27+
return new FilesystemTagAwareAdapter('', $defaultLifetime);
28+
}
29+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Cache\Tests\Adapter\TagAware;
13+
14+
use Symfony\Component\Cache\Adapter\TagAware\RedisTagAwareAdapter;
15+
use Symfony\Component\Cache\Tests\Adapter\PredisAdapterTest;
16+
use Symfony\Component\Cache\Tests\Traits\TagAwareTestTrait;
17+
18+
class PredisTagAwareAdapterTest extends PredisAdapterTest
19+
{
20+
use TagAwareTestTrait;
21+
22+
protected function setUp()
23+
{
24+
parent::setUp();
25+
$this->skippedTests['testTagItemExpiry'] = 'Testing expiration slows down the test suite';
26+
}
27+
28+
public function createCachePool($defaultLifetime = 0)
29+
{
30+
$this->assertInstanceOf(\Predis\Client::class, self::$redis);
31+
$adapter = new RedisTagAwareAdapter(self::$redis, str_replace('\\', '.', __CLASS__), $defaultLifetime);
32+
33+
return $adapter;
34+
}
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Cache\Tests\Adapter\TagAware;
13+
14+
use Symfony\Component\Cache\Adapter\TagAware\RedisTagAwareAdapter;
15+
use Symfony\Component\Cache\Tests\Adapter\PredisClusterAdapterTest;
16+
use Symfony\Component\Cache\Tests\Traits\TagAwareTestTrait;
17+
18+
class PredisTagAwareClusterAdapterTest extends PredisClusterAdapterTest
19+
{
20+
use TagAwareTestTrait;
21+
22+
protected function setUp()
23+
{
24+
parent::setUp();
25+
$this->skippedTests['testTagItemExpiry'] = 'Testing expiration slows down the test suite';
26+
}
27+
28+
public function createCachePool($defaultLifetime = 0)
29+
{
30+
$this->assertInstanceOf(\Predis\Client::class, self::$redis);
31+
$adapter = new RedisTagAwareAdapter(self::$redis, str_replace('\\', '.', __CLASS__), $defaultLifetime);
32+
33+
return $adapter;
34+
}
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Cache\Tests\Adapter\TagAware;
13+
14+
use Symfony\Component\Cache\Adapter\TagAware\RedisTagAwareAdapter;
15+
use Symfony\Component\Cache\Tests\Adapter\PredisRedisClusterAdapterTest;
16+
use Symfony\Component\Cache\Tests\Traits\TagAwareTestTrait;
17+
18+
class PredisTagAwareRedisClusterAdapterTest extends PredisRedisClusterAdapterTest
19+
{
20+
use TagAwareTestTrait;
21+
22+
protected function setUp()
23+
{
24+
parent::setUp();
25+
$this->skippedTests['testTagItemExpiry'] = 'Testing expiration slows down the test suite';
26+
}
27+
28+
public function createCachePool($defaultLifetime = 0)
29+
{
30+
$this->assertInstanceOf(\Predis\Client::class, self::$redis);
31+
$adapter = new RedisTagAwareAdapter(self::$redis, str_replace('\\', '.', __CLASS__), $defaultLifetime);
32+
33+
return $adapter;
34+
}
35+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Cache\Tests\Adapter\TagAware;
13+
14+
use Symfony\Component\Cache\Adapter\TagAware\RedisTagAwareAdapter;
15+
use Symfony\Component\Cache\Traits\RedisProxy;
16+
use Symfony\Component\Cache\Tests\Adapter\RedisAdapterTest;
17+
use Symfony\Component\Cache\Tests\Traits\TagAwareTestTrait;
18+
19+
class RedisTagAwareAdapterTest extends RedisAdapterTest
20+
{
21+
use TagAwareTestTrait;
22+
23+
protected function setUp()
24+
{
25+
parent::setUp();
26+
$this->skippedTests['testTagItemExpiry'] = 'Testing expiration slows down the test suite';
27+
}
28+
29+
public function createCachePool($defaultLifetime = 0)
30+
{
31+
$this->assertInstanceOf(RedisProxy::class, self::$redis);
32+
$adapter = new RedisTagAwareAdapter(self::$redis, str_replace('\\', '.', __CLASS__), $defaultLifetime);
33+
34+
return $adapter;
35+
}
36+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Cache\Tests\Adapter\TagAware;
13+
14+
use Symfony\Component\Cache\Tests\Adapter\RedisArrayAdapterTest;
15+
use Symfony\Component\Cache\Tests\Traits\TagAwareTestTrait;
16+
17+
class RedisTagAwareArrayAdapterTest extends RedisArrayAdapterTest
18+
{
19+
use TagAwareTestTrait;
20+
21+
protected function setUp()
22+
{
23+
parent::setUp();
24+
$this->skippedTests['testTagItemExpiry'] = 'Testing expiration slows down the test suite';
25+
}
26+
27+
public function createCachePool($defaultLifetime = 0)
28+
{
29+
$this->assertInstanceOf(\RedisArray::class, self::$redis);
30+
$adapter = new RedisTagAwareAdapter(self::$redis, str_replace('\\', '.', __CLASS__), $defaultLifetime);
31+
32+
return $adapter;
33+
}
34+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Cache\Tests\Adapter\TagAware;
13+
14+
use Symfony\Component\Cache\Adapter\TagAware\RedisTagAwareAdapter;
15+
use Symfony\Component\Cache\Traits\RedisClusterProxy;
16+
use Symfony\Component\Cache\Tests\Adapter\RedisClusterAdapterTest;
17+
use Symfony\Component\Cache\Tests\Traits\TagAwareTestTrait;
18+
19+
20+
class RedisTagAwareClusterAdapterTest extends RedisClusterAdapterTest
21+
{
22+
use TagAwareTestTrait;
23+
24+
protected function setUp()
25+
{
26+
parent::setUp();
27+
$this->skippedTests['testTagItemExpiry'] = 'Testing expiration slows down the test suite';
28+
}
29+
30+
public function createCachePool($defaultLifetime = 0)
31+
{
32+
$this->assertInstanceOf(RedisClusterProxy::class, self::$redis);
33+
$adapter = new RedisTagAwareAdapter(self::$redis, str_replace('\\', '.', __CLASS__), $defaultLifetime);
34+
35+
return $adapter;
36+
}
37+
}

0 commit comments

Comments
 (0)