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()); }