避免测试清空登录会话

This commit is contained in:
pllx
2026-04-30 09:58:18 +08:00
parent 181cc6a0b0
commit 363c45a140
4 changed files with 19 additions and 4 deletions
+1 -1
View File
@@ -46,7 +46,7 @@ class ChatControllerTest extends TestCase
protected function setUp(): void protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
Redis::flushall(); $this->flushChatRoomRedisState();
} }
/** /**
+1 -1
View File
@@ -30,7 +30,7 @@ class RideControllerTest extends TestCase
protected function setUp(): void protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
Redis::flushall(); $this->flushChatRoomRedisState();
} }
/** /**
+1 -1
View File
@@ -32,7 +32,7 @@ class ShopControllerTest extends TestCase
protected function setUp(): void protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
Redis::flushall(); $this->flushChatRoomRedisState();
} }
/** /**
+16 -1
View File
@@ -3,8 +3,23 @@
namespace Tests; namespace Tests;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase; use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Illuminate\Support\Facades\Redis;
/**
* 测试基类
* 提供项目 Feature Test 共用的辅助方法。
*/
abstract class TestCase extends BaseTestCase abstract class TestCase extends BaseTestCase
{ {
// /**
* 清理聊天室测试产生的 Redis 房间状态,避免误删浏览器登录会话。
*/
protected function flushChatRoomRedisState(): void
{
$keys = Redis::keys('room:*');
if ($keys !== []) {
Redis::del(...$keys);
}
}
} }