8000 [Cache] Add more Unit tests for Ephemeral aware adapters · symfony/symfony@14e4802 · GitHub
[go: up one dir, main page]

Skip to content

Commit 14e4802

Browse files
committed
[Cache] Add more Unit tests for Ephemeral aware adapters
1 parent fbca467 commit 14e4802

5 files changed

+173
-2
lines changed

src/Symfony/Component/Cache/Tests/Adapter/EphemeralTagAwareTestTrait.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@
2020
*/
2121
trait EphemeralTagAwareTestTrait
2222
{
23-
public function testOptimisticConcurrencyControl()
23+
/**
24+
* @dataProvider provideDefaultLifetime
25+
*/
26+
public function testOptimisticConcurrencyControl($defaultLifetime)
2427
{
2528
if (isset($this->skippedTests[__FUNCTION__])) {
2629
$this->markTestSkipped($this->skippedTests[__FUNCTION__]);
2730
}
2831

29-
$cache = $this->createCachePool(0, __FUNCTION__);
32+
$cache = $this->createCachePool($defaultLifetime, __FUNCTION__);
3033
$anotherCacheClient = clone $cache;
3134
$value = mt_rand();
3235

@@ -72,4 +75,9 @@ public function testOptimisticConcurrencyControl()
7275
$this->assertFalse($item->isHit(), 'The item must be invalidated if invalidation happens during deferred computation');
7376
$this->assertNull($item->get(), 'The item must be invalidated if invalidation happens during deferred computation');
7477
}
78+
79+
function provideDefaultLifetime()
80+
{
81+
return [[0], [1000]];
82+
}
7583
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
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;
13+
14+
use Psr\Cache\CacheItemPoolInterface;
15+
use Symfony\Component\Cache\Adapter\RedisEphemeralTagAwareAdapter;
16+
17+
/**
18+
* @group integration
19+
*/
20+
class PredisEphemeralTagAwareAdapterTest extends PredisAdapterTest
21+
{
22+
use TagAwareTestTrait;
23+
24+
protected function setUp(): void
25+
{
26+
parent::setUp();
27+
$this->skippedTests['testPrune'] = 'Just proxies to underlying pools';
28+
$this->skippedTests['testTagItemExpiry'] = 'Testing expiration slows down the test suite';
29+
}
30+
31+
public function createCachePool(int $defaultLifetime = 0, string $testMethod = null): CacheItemPoolInterface
32+
{
33+
$this->assertInstanceOf(\Predis\Client::class, self::$redis);
34+
$adapter = new RedisEphemeralTagAwareAdapter(self::$redis, null, str_replace('\\', '.', __CLASS__), $defaultLifetime);
35+
36+
return $adapter;
37+
}
38+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@< 57AE /div>
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
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;
13+
14+
use Psr\Cache\CacheItemPoolInterface;
15+
use Symfony\Component\Cache\Adapter\RedisEphemeralTagAwareAdapter;
16+
17+
/**
18+
* @group integration
19+
*/
20+
class PredisEphemeralTagAwareClusterAdapterTest extends PredisClusterAdapterTest
21+
{
22+
use TagAwareTestTrait;
23+
use EphemeralTagAwareTestTrait;
24+
25+
protected function setUp(): void
26+
{
27+
parent::setUp();
28+
$this->skippedTests['testPrune'] = 'Just proxies to underlying pools';
29+
$this->skippedTests['testTagItemExpiry'] = 'Testing expiration slows down the test suite';
30+
}
31+
32+
public function createCachePool(int $defaultLifetime = 0, string $testMethod = null): CacheItemPoolInterface
33+
{
34+
$this->assertInstanceOf(\Predis\Client::class, self::$redis);
35+
$adapter = new RedisEphemeralTagAwareAdapter(self::$redis, null, str_replace('\\', '.', __CLASS__), $defaultLifetime);
36+
37+
return $adapter;
38+
}
39+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
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;
13+
14+
use Psr\Cache\CacheItemPoolInterface;
15+
use Symfony\Component\Cache\Adapter\RedisEphemeralTagAwareAdapter;
16+
17+
/**
18+
* @group integration
19+
*/
20+
class RedisEphemeralTagAwareArrayAdapterTest extends RedisArrayAdapterTest
21+
{
22+
use TagAwareTestTrait;
23+
24+
protected function setUp(): void
25+
{
26+
parent::setUp();
27+
$this->skippedTests['testPrune'] = 'Just proxies to underlying pools';
28+
$this->skippedTests['testTagItemExpiry'] = 'Testing expiration slows down the test suite';
29+
}
30+
31+
public function createCachePool(int $defaultLifetime = 0, string $testMethod = null): CacheItemPoolInterface
32+
{
33+
if ('testClearWithPrefix' === $testMethod && \defined('Redis::SCAN_PREFIX')) {
34+
self::$redis->setOption(\Redis::OPT_SCAN, \Redis::SCAN_PREFIX);
35+
}
36+
37+
$this->assertInstanceOf(\RedisArray::class, self::$redis);
38+
$adapter = new RedisEphemeralTagAwareAdapter(self::$redis, null, str_replace('\\', '.', __CLASS__), $defaultLifetime);
39+
40+
return $adapter;
41+
}
42+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
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;
13+
14+
use Psr\Cache\CacheItemPoolInterface;
15+
use Symfony\Component\Cache\Adapter\RedisEphemeralTagAwareAdapter;
16+
use Symfony\Component\Cache\Traits\RedisClusterProxy;
17+
18+
/**
19+
* @group integration
20+
*/
21+
class RedisEphemeralTagAwareClusterAdapterTest extends RedisClusterAdapterTest
22+
{
23+
use TagAwareTestTrait;
24+
use EphemeralTagAwareTestTrait;
25+
26+
protected function setUp(): void
27+
{
28+
parent::setUp();
29+
$this->skippedTests['testPrune'] = 'Just proxies to underlying pools';
30+
$this->skippedTests['testTagItemExpiry'] = 'Testing expiration slows down the test suite';
31+
}
32+
33+
public function createCachePool(int $defaultLifetime = 1000, string $testMethod = null): CacheItemPoolInterface
34+
{
35+
if ('testClearWithPrefix' === $testMethod && \defined('Redis::SCAN_PREFIX')) {
36+
self::$redis->setOption(\Redis::OPT_SCAN, \Redis::SCAN_PREFIX);
37+
}
38+
39+
$this->assertInstanceOf(RedisClusterProxy::class, self::$redis);
40+
$adapter = new RedisEphemeralTagAwareAdapter(self::$redis, null, str_replace('\\', '.', __CLASS__), $defaultLifetime);
41+
42+
return $adapter;
43+
}
44+
}

0 commit comments

Comments
 (0)
0