文件
Henglianshutong/tests/partner/verify_agent_upgrade_php8_spec.php

88 行
3.1 KiB
PHP

<?php
namespace tests\partner;
define('APP_PATH', __DIR__ . '/../../application/');
define('ROOT_PATH', dirname(realpath(APP_PATH)) . '/');
require_once __DIR__ . '/../../thinkphp/base.php';
require_once __DIR__ . '/../../thinkphp/helper.php';
require_once __DIR__ . '/../../application/common.php';
\think\Config::set(\think\Config::load(APP_PATH . 'config.php'));
\think\Config::set(include APP_PATH . 'database.php', 'database');
\think\Loader::addNamespace('app', APP_PATH);
require_once __DIR__ . '/../../addons/shopro/helper/helper.php';
use addons\shopro\service\commission\Goods as GoodsCommissionService;
use addons\shopro\service\commission\Agent as AgentService;
use app\admin\model\shopro\commission\Level as LevelModel;
class VerifyAgentUpgradePhp8Spec
{
private $passed = 0;
private $failed = 0;
public function run()
{
echo "========================================================\n";
echo " 创客升级与 PHP 8.0 兼容性专项回归测试 \n";
echo "========================================================\n\n";
$this->testGoodsCommissionConfigNullSafe();
$this->testUserUpgradeLevelMatch();
echo "\n--------------------------------------------------------\n";
echo "测试执行结果: 通过 {$this->passed} 项, 失败 {$this->failed} 项\n";
echo "========================================================\n";
return $this->failed === 0 ? 0 : 1;
}
private function assert($condition, $testName, $detail = '')
{
if ($condition) {
$this->passed++;
echo " [✓ PASS] {$testName}\n";
} else {
$this->failed++;
echo " [✗ FAIL] {$testName} - {$detail}\n";
}
}
private function testGoodsCommissionConfigNullSafe()
{
try {
// 模拟一个 commission_config 为 null 的商品对象
$fakeGoods = new \stdClass();
$fakeGoods->commission_config = null;
$fakeGoods->self_rules = 0;
$fakeGoods->commission_rules = null;
$goodsService = new GoodsCommissionService($fakeGoods, 0);
$this->assert($goodsService !== null, 'GoodsCommissionService 空配置对象构造兼容测试');
} catch (\Throwable $e) {
$this->assert(false, 'GoodsCommissionService 空配置对象构造兼容测试', $e->getMessage());
}
}
private function testUserUpgradeLevelMatch()
{
try {
$levels = LevelModel::where('level', '>=', 2)->select();
$allStrict = true;
foreach ($levels as $l) {
if ($l->upgrade_type !== 1) {
$allStrict = false;
}
}
$this->assert($allStrict, '创客等级全部条件升级模式校验 (upgrade_type === 1)');
} catch (\Throwable $e) {
$this->assert(false, '创客等级全部条件升级模式校验', $e->getMessage());
}
}
}
if (PHP_SAPI === 'cli') {
$tester = new VerifyAgentUpgradePhp8Spec();
exit($tester->run());
}