Files
youlegames/codes/agent/game/api/tests/run_all_tests.php
2026-03-15 01:27:05 +08:00

289 lines
11 KiB
PHP
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.
<?php
/**
* PHP8升级测试套件主运行器
* 统一运行所有测试并生成综合报告
*/
error_reporting(E_ALL);
ini_set('display_errors', 1);
// 检查命令行参数
$testType = 'all';
if (isset($argv[1])) {
if (strpos($argv[1], '--type=') === 0) {
$testType = substr($argv[1], 7);
}
}
echo "<!DOCTYPE html><html><head><meta charset='UTF-8'><title>PHP8升级测试套件</title>";
echo "<style>
body{font-family: Arial, sans-serif; margin: 20px; background: #f8f9fa;}
.container{max-width: 1600px; margin: 0 auto; background: white; padding: 20px; border-radius: 10px; box-shadow: 0 4px 6px rgba(0,0,0,0.1);}
.header{background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 20px; margin: -20px -20px 30px -20px; border-radius: 10px 10px 0 0;}
.test-suite{margin: 25px 0; padding: 20px; border: 2px solid #dee2e6; border-radius: 8px;}
.suite-header{background: #007bff; color: white; padding: 15px; margin: -20px -20px 20px -20px; border-radius: 6px 6px 0 0;}
.test-result{margin: 15px 0; padding: 15px; border-left: 5px solid #007bff; background: #f8f9fa;}
.success{border-left-color: #28a745; background: #d4f7d4;}
.warning{border-left-color: #ffc107; background: #fff8d4;}
.error{border-left-color: #dc3545; background: #f8d7da;}
.summary{background: #e3f2fd; padding: 20px; border-radius: 8px; margin: 20px 0;}
.nav-links{margin: 20px 0; display: flex; gap: 15px; flex-wrap: wrap;}
.nav-link{padding: 10px 20px; background: #007bff; color: white; text-decoration: none; border-radius: 5px; font-weight: bold;}
.nav-link:hover{background: #0056b3;}
table{width: 100%; border-collapse: collapse; margin: 15px 0;}
th,td{border: 1px solid #dee2e6; padding: 12px; text-align: left;}
th{background-color: #e9ecef; font-weight: bold;}
.progress-bar{background: #e9ecef; border-radius: 10px; overflow: hidden; height: 20px; margin: 10px 0;}
.progress-fill{height: 100%; background: linear-gradient(45deg, #28a745, #20c997); transition: width 0.3s;}
</style>";
echo "</head><body>";
echo "<div class='container'>";
echo "<div class='header'>";
echo "<h1>🚀 PHP8升级测试套件</h1>";
echo "<p><strong>测试时间:</strong> " . date('Y-m-d H:i:s') . " | <strong>PHP版本:</strong> " . PHP_VERSION . " | <strong>测试类型:</strong> " . strtoupper($testType) . "</p>";
echo "</div>";
// 测试结果汇总
$allResults = [];
$totalTests = 0;
$totalSuccess = 0;
$totalWarnings = 0;
$totalErrors = 0;
/**
* 运行测试文件并解析结果
*/
function runTestFile($filePath, $suiteName) {
global $allResults, $totalTests, $totalSuccess, $totalWarnings, $totalErrors;
echo "<div class='test-result'>";
echo "<h4>🔍 " . basename($filePath) . "</h4>";
if (!file_exists($filePath)) {
echo "<div class='error'>❌ 测试文件不存在: $filePath</div>";
$allResults[] = ['suite' => $suiteName, 'file' => basename($filePath), 'status' => 'error', 'message' => '文件不存在'];
$totalErrors++;
echo "</div>";
return;
}
$startTime = microtime(true);
// 捕获测试输出
ob_start();
$errorLevel = error_reporting(E_ERROR | E_PARSE); // 减少错误报告级别
try {
include $filePath;
$output = ob_get_clean();
$duration = round((microtime(true) - $startTime) * 1000, 2);
// 简单解析输出判断测试结果
$successCount = substr_count($output, '✅');
$warningCount = substr_count($output, '⚠️');
$errorCount = substr_count($output, '❌');
$totalTests += ($successCount + $warningCount + $errorCount);
$totalSuccess += $successCount;
$totalWarnings += $warningCount;
$totalErrors += $errorCount;
$status = $errorCount > 0 ? 'error' : ($warningCount > 0 ? 'warning' : 'success');
$statusText = $status === 'success' ? '✅ 测试通过' : ($status === 'warning' ? '⚠️ 有警告' : '❌ 有错误');
echo "<div class='$status'>";
echo "<strong>$statusText</strong> (耗时: {$duration}ms)";
echo "<div>成功: $successCount, 警告: $warningCount, 错误: $errorCount</div>";
echo "</div>";
$allResults[] = [
'suite' => $suiteName,
'file' => basename($filePath),
'status' => $status,
'duration' => $duration,
'success' => $successCount,
'warnings' => $warningCount,
'errors' => $errorCount
];
} catch (Exception $e) {
ob_end_clean();
$duration = round((microtime(true) - $startTime) * 1000, 2);
echo "<div class='error'>";
echo "<strong>❌ 执行异常</strong> (耗时: {$duration}ms)";
echo "<div>异常信息: " . $e->getMessage() . "</div>";
echo "</div>";
$allResults[] = [
'suite' => $suiteName,
'file' => basename($filePath),
'status' => 'error',
'duration' => $duration,
'message' => '执行异常: ' . $e->getMessage()
];
$totalErrors++;
} finally {
error_reporting($errorLevel);
}
echo "</div>";
}
// 定义测试套件
$testSuites = [
'unit' => [
'name' => '🧪 单元测试',
'description' => '验证单个功能组件',
'tests' => [
__DIR__ . '/unit/check_session_config.php',
__DIR__ . '/unit/test_session_persistence.php',
__DIR__ . '/unit/test_curl_fix.php',
__DIR__ . '/unit/test_weixin_curl_fix.php'
]
],
'integration' => [
'name' => '🔗 集成测试',
'description' => '验证完整业务流程',
'tests' => [
__DIR__ . '/integration/system_verification.php',
__DIR__ . '/integration/business_function_test.php',
__DIR__ . '/integration/test_full_weixin_flow.php'
]
],
'debug' => [
'name' => '🔧 调试工具',
'description' => '问题排查和诊断',
'tests' => [
__DIR__ . '/debug/debug_weixin.php',
__DIR__ . '/debug/test_weixin_callback.php'
]
]
];
// 生成导航链接
echo "<div class='nav-links'>";
echo "<a href='?type=all' class='nav-link'>🚀 全部测试</a>";
foreach ($testSuites as $type => $suite) {
echo "<a href='?type=$type' class='nav-link'>" . $suite['name'] . "</a>";
}
echo "</div>";
// 运行指定的测试套件
$suitesToRun = ($testType === 'all') ? array_keys($testSuites) : [$testType];
foreach ($suitesToRun as $suiteType) {
if (!isset($testSuites[$suiteType])) {
echo "<div class='error'>❌ 未知的测试类型: $suiteType</div>";
continue;
}
$suite = $testSuites[$suiteType];
echo "<div class='test-suite'>";
echo "<div class='suite-header'>";
echo "<h2>" . $suite['name'] . "</h2>";
echo "<p>" . $suite['description'] . "</p>";
echo "</div>";
foreach ($suite['tests'] as $testFile) {
runTestFile($testFile, $suite['name']);
}
echo "</div>";
}
// 生成综合报告
echo "<div class='summary'>";
echo "<h2>📊 测试结果汇总</h2>";
$overallSuccessRate = $totalTests > 0 ? round(($totalSuccess / $totalTests) * 100, 1) : 0;
echo "<div class='progress-bar'>";
echo "<div class='progress-fill' style='width: {$overallSuccessRate}%'></div>";
echo "</div>";
echo "<table>";
echo "<tr><th>指标</th><th>数量</th><th>百分比</th></tr>";
echo "<tr><td>总测试数</td><td><strong>$totalTests</strong></td><td>100%</td></tr>";
echo "<tr style='color: #28a745;'><td>成功</td><td><strong>$totalSuccess</strong></td><td>" . ($totalTests > 0 ? round(($totalSuccess / $totalTests) * 100, 1) : 0) . "%</td></tr>";
echo "<tr style='color: #ffc107;'><td>警告</td><td><strong>$totalWarnings</strong></td><td>" . ($totalTests > 0 ? round(($totalWarnings / $totalTests) * 100, 1) : 0) . "%</td></tr>";
echo "<tr style='color: #dc3545;'><td>错误</td><td><strong>$totalErrors</strong></td><td>" . ($totalTests > 0 ? round(($totalErrors / $totalTests) * 100, 1) : 0) . "%</td></tr>";
echo "</table>";
// 详细测试结果表
if (!empty($allResults)) {
echo "<h3>📋 详细测试结果</h3>";
echo "<table>";
echo "<tr><th>测试套件</th><th>测试文件</th><th>状态</th><th>成功</th><th>警告</th><th>错误</th><th>耗时(ms)</th></tr>";
foreach ($allResults as $result) {
$statusClass = $result['status'];
$statusIcon = $result['status'] === 'success' ? '✅' : ($result['status'] === 'warning' ? '⚠️' : '❌');
echo "<tr class='$statusClass'>";
echo "<td>" . $result['suite'] . "</td>";
echo "<td>" . $result['file'] . "</td>";
echo "<td>$statusIcon " . ucfirst($result['status']) . "</td>";
echo "<td>" . ($result['success'] ?? 0) . "</td>";
echo "<td>" . ($result['warnings'] ?? 0) . "</td>";
echo "<td>" . ($result['errors'] ?? 0) . "</td>";
echo "<td>" . ($result['duration'] ?? 0) . "</td>";
echo "</tr>";
}
echo "</table>";
}
// 综合评估和建议
echo "<h3>🎯 综合评估</h3>";
if ($totalErrors === 0) {
if ($totalWarnings === 0) {
echo "<div class='success'>";
echo "<h4>🎉 系统完全就绪!</h4>";
echo "<p>所有测试通过PHP8升级成功系统可以安全部署到生产环境。</p>";
echo "</div>";
} else {
echo "<div class='warning'>";
echo "<h4>⚠️ 系统基本就绪</h4>";
echo "<p>有 $totalWarnings 个警告需要关注,建议评估影响后再部署。</p>";
echo "</div>";
}
} else {
echo "<div class='error'>";
echo "<h4>❌ 系统未就绪</h4>";
echo "<p>有 $totalErrors 个严重问题需要立即修复,不建议部署到生产环境。</p>";
echo "</div>";
}
echo "<h3>📅 下一步行动计划</h3>";
echo "<ol>";
if ($totalErrors > 0) {
echo "<li><strong>🚨 立即修复错误项</strong>:优先解决所有失败的测试</li>";
}
if ($totalWarnings > 0) {
echo "<li><strong>⚠️ 评估警告项</strong>:确认警告对实际业务的影响</li>";
}
echo "<li><strong>🔄 进行端到端测试</strong>:完整的业务流程验证</li>";
echo "<li><strong>📊 性能基准测试</strong>对比PHP8与原系统性能</li>";
echo "<li><strong>🚀 生产环境部署</strong>:准备上线发布</li>";
echo "</ol>";
echo "</div>";
// 工具链接
echo "<div style='margin-top: 30px; padding: 20px; background: #f8f9fa; border-radius: 8px;'>";
echo "<h3>🔗 快速访问</h3>";
echo "<div class='nav-links'>";
echo "<a href='integration/business_function_test.php' class='nav-link'>核心业务测试</a>";
echo "<a href='integration/system_verification.php' class='nav-link'>系统验证</a>";
echo "<a href='debug/debug_weixin.php' class='nav-link'>微信调试</a>";
echo "<a href='unit/check_session_config.php' class='nav-link'>Session检查</a>";
echo "</div>";
echo "<p style='color: #6c757d; margin-top: 15px;'><strong>测试完成时间:</strong> " . date('Y-m-d H:i:s') . "</p>";
echo "</div>";
echo "</div>";
echo "</body></html>";
?>