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); + } + } }