feat: 添加E2E测试环境配置支持
Some checks failed
lotterLaravel CI / test (push) Has been cancelled

添加LOTTERY_E2E环境变量来控制E2E测试相关功能,
包括绕过验证码、登录限制和钱包API URL验证,
同时更新composer.json以包含E2E专用的提供者和服务。
This commit is contained in:
2026-06-18 14:42:22 +08:00
parent 6b2ea39ea1
commit 6ec9634704
45 changed files with 3702 additions and 6 deletions

View File

@@ -0,0 +1,127 @@
<?php
namespace App\Http\Controllers\Api\V1\E2E;
use App\Lottery\DrawStatus;
use App\Support\ApiResponse;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
/**
* E2E 辅助:期号时间/状态快进。
*
* 真实生产链路下"等 12 分钟后封盘"是脆的——CI e2e 不可能等。
* 这里允许 e2e 直接 SQL close_time / draw_time模拟
* - close-now: close_time 改到 1 秒前、status=closed
* - reopen: status=open、重置冷却期
* - inspect: 返回 draw 完整时间/状态快照
*
* 严格仅在 LOTTERY_E2E=true 时由 E2EServiceProvider 注册。
*/
final class E2EDrawController extends \App\Http\Controllers\Controller
{
public function closeNow(Request $request, string $drawNo): JsonResponse
{
$draw = DB::table('draws')->where('draw_no', $drawNo)->first();
if (! $draw) {
return ApiResponse::error('draw not found', 'e2e_draw_missing', null, 404);
}
DB::table('draws')
->where('id', $draw->id)
->update([
'status' => DrawStatus::Closed->value,
'close_time' => now()->subSeconds(5),
'draw_time' => now()->subSeconds(3),
]);
return $this->inspectById((int) $draw->id);
}
/** 将冷静期结束时间改到过去,便于 tick 推进 cooldown → settling。 */
public function finishCooldown(Request $request, string $drawNo): JsonResponse
{
$draw = DB::table('draws')->where('draw_no', $drawNo)->first();
if (! $draw) {
return ApiResponse::error('draw not found', 'e2e_draw_missing', null, 404);
}
DB::table('draws')
->where('id', $draw->id)
->update([
'cooling_end_time' => now()->subSeconds(5),
'draw_time' => now()->subMinutes(2),
'close_time' => now()->subMinutes(3),
]);
return $this->inspectById((int) $draw->id);
}
public function reopen(Request $request, string $drawNo): JsonResponse
{
$draw = DB::table('draws')->where('draw_no', $drawNo)->first();
if (! $draw) {
return ApiResponse::error('draw not found', 'e2e_draw_missing', null, 404);
}
DB::table('draws')
->where('id', $draw->id)
->update([
'status' => DrawStatus::Open->value,
'start_time' => now()->subMinutes(5),
'close_time' => now()->addMinutes(20),
'draw_time' => now()->addMinutes(21),
'cooling_end_time' => null,
]);
return $this->inspectById((int) $draw->id);
}
public function inspect(Request $request, string $drawNo): JsonResponse
{
$draw = DB::table('draws')->where('draw_no', $drawNo)->first();
if (! $draw) {
return ApiResponse::error('draw not found', 'e2e_draw_missing', null, 404);
}
return $this->inspectById((int) $draw->id);
}
/** 同步跑一次 lottery:draw-tick不开调度。返回该 tick 推进的 draw_no 列表。 */
public function tick(Request $request): JsonResponse
{
try {
$exit = \Illuminate\Support\Facades\Artisan::call('lottery:draw-tick');
} catch (\Throwable $e) {
return ApiResponse::error(
'draw-tick failed: '.$e->getMessage(),
'e2e_tick_failed',
['trace' => array_slice(explode("\n", $e->getTraceAsString()), 0, 5)],
500,
);
}
return ApiResponse::success([
'exit_code' => $exit,
'output' => \Illuminate\Support\Facades\Artisan::output(),
]);
}
private function inspectById(int $id): JsonResponse
{
$d = DB::table('draws')->where('id', $id)->first();
return ApiResponse::success([
'id' => (int) $d->id,
'draw_no' => $d->draw_no,
'status' => (string) $d->status,
'business_date' => $d->business_date,
'start_time' => $d->start_time,
'close_time' => $d->close_time,
'draw_time' => $d->draw_time,
'cooling_end_time' => $d->cooling_end_time,
'current_result_version' => (int) $d->current_result_version,
'settle_version' => (int) $d->settle_version,
'is_reopened' => (bool) $d->is_reopened,
]);
}
}