= 8.1\n"; exit(1); } echo "✅ PHP版本检查通过\n\n"; // 检查必需扩展 echo "📋 检查必需扩展...\n"; $requiredExtensions = ['pdo', 'redis', 'json', 'mbstring']; foreach ($requiredExtensions as $ext) { if (!extension_loaded($ext)) { echo "❌ 缺少扩展: $ext\n"; exit(1); } echo "✅ $ext 扩展已安装\n"; } echo "\n"; // 检查文件结构 echo "📋 检查项目结构...\n"; $requiredDirs = [ 'app', 'config', 'fendx-framework', 'public', 'runtime', 'docs' ]; foreach ($requiredDirs as $dir) { if (!is_dir($dir)) { echo "❌ 缺少目录: $dir\n"; exit(1); } echo "✅ 目录 $dir 存在\n"; } echo "\n"; // 检查核心文件 echo "📋 检查核心文件...\n"; $requiredFiles = [ 'fendx.php', 'public/index.php', 'config/config.php', 'FendxPHP_项目架构.txt', 'README.md' ]; foreach ($requiredFiles as $file) { if (!file_exists($file)) { echo "❌ 缺少文件: $file\n"; exit(1); } echo "✅ 文件 $file 存在\n"; } echo "\n"; // 检查配置文件 echo "📋 检查配置文件...\n"; $configFiles = [ 'config/app.php', 'config/database.php', 'config/cache.php', 'config/routes.php' ]; foreach ($configFiles as $file) { if (!file_exists($file)) { echo "❌ 缺少配置文件: $file\n"; exit(1); } echo "✅ 配置文件 $file 存在\n"; } echo "\n"; // 检查框架模块 echo "📋 检查框架模块...\n"; $frameworkModules = [ 'fendx-framework/fendx-common', 'fendx-framework/fendx-core', 'fendx-framework/fendx-web', 'fendx-framework/fendx-db', 'fendx-framework/fendx-cache', 'fendx-framework/fendx-security', 'fendx-framework/fendx-log', 'fendx-framework/fendx-starter', 'fendx-framework/fendx-job', 'fendx-framework/fendx-file' ]; foreach ($frameworkModules as $module) { if (!is_dir($module)) { echo "❌ 缺少模块: $module\n"; exit(1); } echo "✅ 模块 $module 存在\n"; } echo "\n"; // 检查应用模块 echo "📋 检查应用模块...\n"; $appModules = [ 'app/Controller', 'app/Service', 'app/Dao', 'app/Entity', 'app/Job', 'app/Command' ]; foreach ($appModules as $module) { if (!is_dir($module)) { echo "⚠️ 应用模块 $module 不存在(可选)\n"; continue; } echo "✅ 应用模块 $module 存在\n"; } echo "\n"; // 检查运行时目录权限 echo "📋 检查运行时目录权限...\n"; $runtimeDirs = ['runtime/logs', 'runtime/cache', 'runtime/temp', 'runtime/storage']; foreach ($runtimeDirs as $dir) { if (!is_dir($dir)) { mkdir($dir, 0755, true); echo "📁 创建目录: $dir\n"; } if (!is_writable($dir)) { echo "❌ 目录 $dir 不可写\n"; exit(1); } echo "✅ 目录 $dir 可写\n"; } echo "\n"; // 尝试加载配置 echo "📋 测试配置加载...\n"; try { $config = require 'config/config.php'; if (!is_array($config)) { echo "❌ 配置文件格式错误\n"; exit(1); } echo "✅ 配置文件加载成功\n"; // 检查必需配置项 $requiredConfigKeys = ['app', 'database', 'cache']; foreach ($requiredConfigKeys as $key) { if (!isset($config[$key])) { echo "❌ 缺少配置项: $key\n"; exit(1); } echo "✅ 配置项 $key 存在\n"; } } catch (Exception $e) { echo "❌ 配置加载失败: " . $e->getMessage() . "\n"; exit(1); } echo "\n"; // 测试数据库连接(可选) echo "📋 测试数据库连接...\n"; try { $dbConfig = require 'config/database.php'; $dsn = "mysql:host={$dbConfig['default']['host']};dbname={$dbConfig['default']['dbname']}"; $pdo = new PDO($dsn, $dbConfig['default']['username'], $dbConfig['default']['password']); $pdo->query('SELECT 1'); echo "✅ 数据库连接成功\n"; } catch (Exception $e) { echo "⚠️ 数据库连接失败: " . $e->getMessage() . "\n"; echo " 请检查数据库配置和服务状态\n"; } echo "\n"; // 测试Redis连接(可选) echo "📋 测试Redis连接...\n"; try { $cacheConfig = require 'config/cache.php'; $redis = new Redis(); $redis->connect($cacheConfig['host'], $cacheConfig['port']); if (!empty($cacheConfig['password'])) { $redis->auth($cacheConfig['password']); } $redis->ping(); echo "✅ Redis连接成功\n"; } catch (Exception $e) { echo "⚠️ Redis连接失败: " . $e->getMessage() . "\n"; echo " 请检查Redis配置和服务状态\n"; } echo "\n"; // 检查语法错误 echo "📋 检查PHP语法...\n"; $phpFiles = []; $iterator = new RecursiveIteratorIterator( new RecursiveDirectoryIterator('.', RecursiveDirectoryIterator::SKIP_DOTS) ); foreach ($iterator as $file) { if ($file->isFile() && $file->getExtension() === 'php') { $phpFiles[] = $file->getPathname(); } } $syntaxErrors = 0; foreach ($phpFiles as $file) { $output = []; $returnCode = 0; exec("php -l \"$file\" 2>&1", $output, $returnCode); if ($returnCode !== 0) { echo "❌ 语法错误: $file\n"; echo " " . implode("\n ", $output) . "\n"; $syntaxErrors++; } } if ($syntaxErrors === 0) { echo "✅ 所有PHP文件语法正确\n"; } else { echo "❌ 发现 $syntaxErrors 个语法错误\n"; exit(1); } echo "\n"; // 生成测试报告 echo "📊 生成测试报告...\n"; $report = [ 'test_time' => date('Y-m-d H:i:s'), 'php_version' => PHP_VERSION, 'extensions' => get_loaded_extensions(), 'memory_limit' => ini_get('memory_limit'), 'max_execution_time' => ini_get('max_execution_time'), 'file_count' => count($phpFiles), 'directory_structure' => $requiredDirs, 'framework_modules' => $frameworkModules ]; file_put_contents('runtime/test_report.json', json_encode($report, JSON_PRETTY_PRINT)); echo "✅ 测试报告已保存到 runtime/test_report.json\n\n"; // 最终结果 echo "🎉 FendxPHP 冒烟测试完成!\n"; echo "✅ 所有检查通过,框架可以正常运行\n\n"; echo "📝 下一步操作:\n"; echo "1. 启动Web服务: php -S localhost:8000 -t public\n"; echo "2. 访问健康检查: curl http://localhost:8000/health\n"; echo "3. 测试API接口: curl http://localhost:8000/api/users\n"; echo "4. 查看详细文档: docs/冒烟测试指南.md\n\n"; echo "🚀 框架已准备就绪,开始开发吧!\n";