5, 'work_status' => 'on']; } protected function uid() { return 7; } protected function error($message) { throw new \RuntimeException($message); } } } namespace think { class Db { public static $order; public static $certs = []; public static function name($name) { return new Query($name); } } class Query { private $table; public function __construct($table) { $this->table = $table; } public function where(...$args) { return $this; } public function field(...$args) { return $this; } public function find() { return $this->table === 'order' ? Db::$order : null; } public function select() { return Db::$certs; } public function update($values) { throw new \RuntimeException('REACHED_GRAB_UPDATE'); } public function insert($values) { throw new \RuntimeException('REACHED_QUOTE_INSERT'); } } } namespace { require __DIR__ . '/../server/application/common/library/OrderStatus.php'; require __DIR__ . '/../server/application/common/library/OrderQualification.php'; require __DIR__ . '/../server/application/api/controller/Master.php'; class RequestStub { public function post($key, $default = null) { return ['order_id' => 12, 'amount' => 100][$key] ?? $default; } } $api = new \app\api\controller\Master(); $api->request = new RequestStub(); $base = ['id' => 12, 'user_id' => 8, 'master_id' => 0, 'status' => \app\common\library\OrderStatus::PENDING_ACCEPT, 'qual_req' => '电工证']; function expectResult($api, $method, $expected) { try { $api->$method(); throw new \RuntimeException('unexpected success'); } catch (\RuntimeException $e) { if (strpos($e->getMessage(), $expected) === false) throw $e; } } foreach (['grab' => 'fixed', 'quote' => 'quote'] as $method => $type) { \think\Db::$order = $base + ['price_type' => $type]; \think\Db::$certs = []; expectResult($api, $method, '请先上传认证证书'); \think\Db::$certs = [['cert_name'=>'电工证', 'cert_code'=>'electrician', 'is_custom'=>0, 'status'=>'pass', 'is_long_term'=>1, 'expire_date'=>null]]; expectResult($api, $method, $method === 'grab' ? 'REACHED_GRAB_UPDATE' : 'REACHED_QUOTE_INSERT'); \think\Db::$order['qual_req'] = ''; \think\Db::$certs = []; expectResult($api, $method, $method === 'grab' ? 'REACHED_GRAB_UPDATE' : 'REACHED_QUOTE_INSERT'); } echo "Order qualification endpoint checks passed\n"; }