From 363c45a1403b18e42c6ba596d90119f2bbb39dfc Mon Sep 17 00:00:00 2001 From: pllx Date: Thu, 30 Apr 2026 09:58:18 +0800 Subject: [PATCH] =?UTF-8?q?=E9=81=BF=E5=85=8D=E6=B5=8B=E8=AF=95=E6=B8=85?= =?UTF-8?q?=E7=A9=BA=E7=99=BB=E5=BD=95=E4=BC=9A=E8=AF=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Feature/ChatControllerTest.php | 2 +- tests/Feature/RideControllerTest.php | 2 +- tests/Feature/ShopControllerTest.php | 2 +- tests/TestCase.php | 17 ++++++++++++++++- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/tests/Feature/ChatControllerTest.php b/tests/Feature/ChatControllerTest.php index 8798791..5ee4ea8 100644 --- a/tests/Feature/ChatControllerTest.php +++ b/tests/Feature/ChatControllerTest.php @@ -46,7 +46,7 @@ class ChatControllerTest extends TestCase protected function setUp(): void { parent::setUp(); - Redis::flushall(); + $this->flushChatRoomRedisState(); } /** diff --git a/tests/Feature/RideControllerTest.php b/tests/Feature/RideControllerTest.php index 33ab14a..ea4525a 100644 --- a/tests/Feature/RideControllerTest.php +++ b/tests/Feature/RideControllerTest.php @@ -30,7 +30,7 @@ class RideControllerTest extends TestCase protected function setUp(): void { parent::setUp(); - Redis::flushall(); + $this->flushChatRoomRedisState(); } /** diff --git a/tests/Feature/ShopControllerTest.php b/tests/Feature/ShopControllerTest.php index bf43b2a..c70644e 100644 --- a/tests/Feature/ShopControllerTest.php +++ b/tests/Feature/ShopControllerTest.php @@ -32,7 +32,7 @@ class ShopControllerTest extends TestCase protected function setUp(): void { parent::setUp(); - Redis::flushall(); + $this->flushChatRoomRedisState(); } /** diff --git a/tests/TestCase.php b/tests/TestCase.php index fe1ffc2..271fdc0 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -3,8 +3,23 @@ namespace Tests; use Illuminate\Foundation\Testing\TestCase as BaseTestCase; +use Illuminate\Support\Facades\Redis; +/** + * 测试基类 + * 提供项目 Feature Test 共用的辅助方法。 + */ abstract class TestCase extends BaseTestCase { - // + /** + * 清理聊天室测试产生的 Redis 房间状态,避免误删浏览器登录会话。 + */ + protected function flushChatRoomRedisState(): void + { + $keys = Redis::keys('room:*'); + + if ($keys !== []) { + Redis::del(...$keys); + } + } }