Files
ulthon_admin/tests/setup_test_db.sh
augushong 37cb8291f8 feat(test): 引入测试规则文档与参数化测试库初始化脚本
对齐 wkbox 衍生项目的测试规则体系,剥离业务特定内容后移植到框架:

- 规则 .agents/rules/ulthon-testing.md(设计哲学/决策树/4层模型/安全规范/fixture原则)
- 技能 .agents/skills/ulthon-testing(运行/编写/模板/决策/回归验证)
- 参数化建库脚本 tests/setup_test_db.{php,ps1,sh} + README
- AGENTS.md 索引补充

与 wkbox 差异:测试库参数化(复用 .env 连接,database=env+'_test'),不硬编码 Docker;删去 canBind Oracle 业务约束与具体 fixture 工厂,业务工厂由衍生项目自行实现。
2026-07-18 23:56:32 +08:00

36 lines
1.4 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# 测试数据库初始化bash / CI 包装器)。
#
# 调用 PHP 运行器 tests/setup_test_db.php在同一进程内
# 1. 从 .env 读连接参数hostname/hostport/username/password/charset/prefix/database
# 2. 派生测试库名 = {env.database} + '_test'(如 ulthon_admin -> ulthon_admin_test
# 3. 在同一 MySQL 实例上 CREATE DATABASE IF NOT EXISTS无需专用 Docker 容器)
# 4. config 级覆盖 connections.main 指向测试库
# 5. php think migrate:run 建系统/框架表database/migrations/
# 6. php think scheme:sync 建业务表app/admin/scheme/
# 7. php think seed:run 插参考数据database/seeds/
# 8. 查 information_schema 验证表已落到测试库
#
# 完全参数化:不硬编码 host/port/credentials。MySQL 实例 = .env 指向的那个。
# 详见 tests/README.md。
set -euo pipefail
# 项目根目录(脚本位于 tests/ 下,取上一级)
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
RUNNER="$PROJECT_ROOT/tests/setup_test_db.php"
# 1. 确保 php 在 PATH 上
if ! command -v php >/dev/null 2>&1; then
echo "[错误] PATH 上找不到 php。请安装 PHP 8+ 并加入 PATH。"
exit 1
fi
# 2. 运行 PHP 运行器
echo "==== 运行 setup_test_db.php ===="
php "$RUNNER"
code=$?
echo ""
echo "==== 完成PHP 退出码 = $code ===="
exit "$code"