testInfoIniStateEnabled(); $this->testPayServiceProfitSharingParameter(); $this->testDeployScriptContainsPhpFpmReload(); $this->testAddonsHooksRegistered(); echo "\n测试结果: {$this->passed} 通过, {$this->failed} 失败\n"; if ($this->failed > 0) { exit(1); } } private function assert($condition, $message) { if ($condition) { echo " [PASS] {$message}\n"; $this->passed++; } else { echo " [FAIL] {$message}\n"; $this->failed++; } } /** * 测试 addons/shopro_huifu/info.ini 中 state 必须为 1 */ public function testInfoIniStateEnabled() { $iniPath = __DIR__ . '/../addons/shopro_huifu/info.ini'; $this->assert(is_file($iniPath), "info.ini 必须存在: {$iniPath}"); $info = parse_ini_file($iniPath); $state = $info['state'] ?? null; $this->assert($state === '1' || $state === 1, "shopro_huifu 插件 state 必须为 1 (启用),当前为: " . var_export($state, true)); } /** * 测试 PayService.php 中不能向 Yansongda v2 传递 settle_info 数组,避免 Array to string conversion 报错 */ public function testPayServiceProfitSharingParameter() { $payServicePath = __DIR__ . '/../addons/shopro/library/PayService.php'; $this->assert(is_file($payServicePath), "PayService.php 必须存在"); $content = file_get_contents($payServicePath); $hasSettleInfoArray = strpos($content, "\$order['settle_info'] = ['profit_sharing' => true]") !== false; $this->assert(!$hasSettleInfoArray, "PayService 中不能包含 settle_info 数组赋值 (会导致 Yansongda v2 XML 序列化报 Array to string conversion)"); } /** * 测试 deploy.sh 部署脚本中必须包含 php-fpm reload 命令刷新 OPcache */ public function testDeployScriptContainsPhpFpmReload() { $deployScriptPath = __DIR__ . '/../deploy.sh'; $this->assert(is_file($deployScriptPath), "deploy.sh 脚本必须存在"); $content = file_get_contents($deployScriptPath); $hasReload = strpos($content, 'php-fpm-73 reload') !== false || strpos($content, 'php-fpm reload') !== false; $this->assert($hasReload, "deploy.sh 部署脚本必须包含 php-fpm reload 刷新 OPcache"); } /** * 测试 application/extra/addons.php 中必须注册 shopro_huifu 及 shopro_pay_create 钩子 */ public function testAddonsHooksRegistered() { $addonsPath = __DIR__ . '/../application/extra/addons.php'; $this->assert(is_file($addonsPath), "addons.php 必须存在"); $addons = require $addonsPath; $appInit = $addons['hooks']['app_init'] ?? []; $this->assert(in_array('shopro_huifu', $appInit), "addons.php app_init 必须包含 shopro_huifu"); $payCreate = $addons['hooks']['shopro_pay_create'] ?? []; $this->assert(!empty($payCreate), "addons.php 必须注册 shopro_pay_create 钩子"); } } $test = new HuifuBridgeTest(); $test->run();