优化游戏通知

This commit is contained in:
pllx
2026-04-30 15:41:50 +08:00
parent 4af4468fc4
commit 9764961519
8 changed files with 225 additions and 65 deletions
+17 -5
View File
@@ -60,7 +60,7 @@ class HorseRaceControllerTest extends TestCase
/**
* 方法功能:验证可获取当前进行中的场次。
*/
public function test_can_get_current_race()
public function test_can_get_current_race(): void
{
/** @var \App\Models\User $user */
$user = User::factory()->create(['jjb' => 4567]);
@@ -214,7 +214,7 @@ class HorseRaceControllerTest extends TestCase
/**
* 方法功能:验证用户可以成功下注。
*/
public function test_can_bet()
public function test_can_bet(): void
{
Event::fake();
@@ -249,12 +249,24 @@ class HorseRaceControllerTest extends TestCase
'horse_id' => 1,
'amount' => 100,
]);
$messages = Redis::lrange('room:1:messages', 0, -1);
$publicMessage = collect($messages)
->map(fn (string $item) => json_decode($item, true))
->first(fn (array $item) => ($item['to_user'] ?? null) === '大家'
&& ($item['toast_notification']['title'] ?? null) === '🐎 有人下注赛马'
&& str_contains((string) ($item['toast_notification']['message'] ?? ''), $user->username));
$this->assertNotNull($publicMessage);
$this->assertFalse((bool) ($publicMessage['is_secret'] ?? true));
$this->assertStringContainsString($user->username, (string) ($publicMessage['toast_notification']['message'] ?? ''));
$this->assertSame('🐎', $publicMessage['toast_notification']['icon'] ?? null);
}
/**
* 方法功能:验证超出配置范围的下注会被拦截。
*/
public function test_cannot_bet_out_of_range()
public function test_cannot_bet_out_of_range(): void
{
/** @var \App\Models\User $user */
$user = User::factory()->create(['jjb' => 500]);
@@ -284,7 +296,7 @@ class HorseRaceControllerTest extends TestCase
/**
* 方法功能:验证同一用户同一场只能下注一次。
*/
public function test_cannot_bet_twice_in_same_race()
public function test_cannot_bet_twice_in_same_race(): void
{
/** @var \App\Models\User $user */
$user = User::factory()->create(['jjb' => 500]);
@@ -322,7 +334,7 @@ class HorseRaceControllerTest extends TestCase
/**
* 方法功能:验证可读取最近的赛马历史记录。
*/
public function test_can_get_history()
public function test_can_get_history(): void
{
/** @var \App\Models\User $user */
$user = User::factory()->create();