Skip to content

Commit cdc8ee8

Browse files
committed
test(Session): isolate RedisHandlerTest to DB 1 and clean up test suites
1 parent f8c6d39 commit cdc8ee8

5 files changed

Lines changed: 5 additions & 66 deletions

File tree

‎tests/system/Cache/Handlers/MemcachedHandlerTest.php‎

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,10 @@ protected function setUp(): void
3737
$this->handler = CacheFactory::getHandler(new Cache(), 'memcached');
3838
}
3939

40-
/**
41-
* @return list<string>
42-
*/
43-
private static function getKeyArray(): array
44-
{
45-
return [
46-
self::$key1,
47-
self::$key2,
48-
self::$key3,
49-
];
50-
}
51-
5240
protected function tearDown(): void
5341
{
5442
if (isset($this->handler)) {
55-
foreach (self::getKeyArray() as $key) {
56-
$this->handler->delete($key);
57-
}
43+
$this->handler->clean();
5844
}
5945

6046
parent::tearDown();

‎tests/system/Cache/Handlers/PredisHandlerTest.php‎

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,10 @@ protected function setUp(): void
3535
$this->handler = CacheFactory::getHandler($this->config, 'predis');
3636
}
3737

38-
/**
39-
* @return list<string>
40-
*/
41-
private static function getKeyArray(): array
42-
{
43-
return [
44-
self::$key1,
45-
self::$key2,
46-
self::$key3,
47-
'counter',
48-
];
49-
}
50-
5138
protected function tearDown(): void
5239
{
5340
if (isset($this->handler)) {
54-
foreach (self::getKeyArray() as $key) {
55-
$this->handler->delete($key);
56-
}
41+
$this->handler->clean();
5742
}
5843

5944
parent::tearDown();

‎tests/system/Cache/Handlers/RedisHandlerTest.php‎

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,10 @@ protected function setUp(): void
4040
$this->handler = CacheFactory::getHandler($this->config, 'redis');
4141
}
4242

43-
/**
44-
* @return list<string>
45-
*/
46-
private static function getKeyArray(): array
47-
{
48-
return [
49-
self::$key1,
50-
self::$key2,
51-
self::$key3,
52-
'counter',
53-
];
54-
}
55-
5643
protected function tearDown(): void
5744
{
5845
if (isset($this->handler)) {
59-
foreach (self::getKeyArray() as $key) {
60-
$this->handler->delete($key);
61-
}
46+
$this->handler->clean();
6247
}
6348

6449
parent::tearDown();

‎tests/system/Session/Handlers/Database/RedisHandlerTest.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ final class RedisHandlerTest extends CIUnitTestCase
3434
{
3535
private string $sessionDriver = RedisHandler::class;
3636
private string $sessionName = 'ci_session';
37-
private string $sessionSavePath = 'tcp://127.0.0.1:6379';
37+
private string $sessionSavePath = 'tcp://127.0.0.1:6379?database=1';
3838
private string $userIpAddress = '127.0.0.1';
3939

4040
/**
@@ -79,6 +79,7 @@ public static function tearDownAfterClass(): void
7979
try {
8080
$redis = new Redis();
8181
if ($redis->connect('127.0.0.1', 6379, 1.0)) {
82+
$redis->select(1);
8283
$keys = $redis->keys('ci_session:*');
8384
if ($keys !== false && $keys !== []) {
8485
$redis->del($keys);

‎tests/system/Session/Handlers/MemcachedHandlerTest.php‎

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use CodeIgniter\Test\TestLogger;
1919
use Config\Logger as LoggerConfig;
2020
use Config\Session as SessionConfig;
21-
use Memcached;
2221
use PHPUnit\Framework\Attributes\Group;
2322
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
2423

@@ -61,28 +60,11 @@ protected function getInstance($options = []): MemcachedHandler
6160
return $handler;
6261
}
6362

64-
protected function setUp(): void
65-
{
66-
parent::setUp();
67-
68-
if (extension_loaded('memcached')) {
69-
$memcached = new Memcached();
70-
$memcached->addServer('127.0.0.1', 11211);
71-
$memcached->flush();
72-
}
73-
}
74-
7563
protected function tearDown(): void
7664
{
7765
parent::tearDown();
7866

7967
MemcachedHandler::resetPersistentConnections();
80-
81-
if (extension_loaded('memcached')) {
82-
$memcached = new Memcached();
83-
$memcached->addServer('127.0.0.1', 11211);
84-
$memcached->flush();
85-
}
8668
}
8769

8870
public function testConstructorThrowsWithEmptySavePath(): void

0 commit comments

Comments
 (0)