<?php
declare(strict_types=1);require __DIR__.'/native.php';require $root.'/vendor/autoload.php';spl_autoload_register(static function($class)use($root){if(strpos($class,'app\\')===0){$file=$root.'/app/'.str_replace('\\','/',substr($class,4)).'.php';if(is_file($file))require $file;}},true,true);require __DIR__.'/NativePdo.php';CoreGate::$ids=['AI_U1'=>101,'AI_U2'=>102,'STORE_U1'=>201,'STORE_U2'=>202,'STORE_R1'=>301,'STORE_P1'=>401];CoreGate::$scenario='PREPAY_FIRST';CoreGate::$started=time();$checks=0;
$want=['order_no'=>'20261011000000123456','total_price'=>'0.01','ori_total_price'=>'0.01','order_price'=>'0.01','pay_price'=>'0.01','pay_method'=>'balance','pay_status'=>10,'pay_time'=>'2000-01-01 00:00:00','meal_date'=>date('Y-m-d'),'meal_times'=>(int)date('H')<10?1:((int)date('H')<16?2:3),'meal_number'=>1,'bind_id'=>0,'bind_time'=>date('Y-m-d H:i:s'),'equipment_code'=>'','last_meal_time'=>date('Y-m-d H:i:s'),'source'=>8,'user_id'=>201,'restaurant_id'=>301,'user_mobile'=>'00000001111','user_name'=>'CDXCORE11S1_U1','restaurant_method'=>1,'remark'=>'CDXCORE11S1_COFFEE','order_status'=>10,'create_time'=>date('Y-m-d H:i:s'),'update_time'=>date('Y-m-d H:i:s')];
$make=static function($v){$b=[];$p=[];foreach($v as $k=>$x){$b['data__'.$k]=[$x,is_int($x)?PDO::PARAM_INT:PDO::PARAM_STR];$p[]='`'.$k.'`=:data__'.$k;}return ['INSERT INTO `ydy_meal_order` SET '.implode(',',$p),$b];};[$sql,$bind]=$make($want);CoreGate::plan('ZHCT',$sql,$bind);$checks++;
foreach(['user_id'=>999,'restaurant_id'=>999,'source'=>4,'pay_status'=>20,'pay_price'=>'0.02','equipment_code'=>'real-device','remark'=>'other-run'] as $key=>$value){$v=$want;$v[$key]=$value;[$bad,$b]=$make($v);try{CoreGate::plan('ZHCT',$bad,$b);throw new LogicException('Gate accepted corrupted '.$key);}catch(RuntimeException $e){$checks++;}}
foreach(['DELETE FROM ydy_meal_order WHERE id=201','CREATE TABLE x (id int)','CALL SP_TABLEDEF(?, ?)','SELECT * FROM ydy_equipment','INSERT INTO ydy_meal_order DEFAULT VALUES'] as $bad){try{CoreGate::plan('ZHCT',$bad,[]);throw new LogicException('Gate accepted unknown SQL');}catch(RuntimeException $e){$checks++;}}
CoreGate::$scenario='PREPAY_REPEAT';try{CoreGate::plan('ZHCT',$sql,$bind);throw new LogicException('Boundary accepted DML');}catch(RuntimeException $e){$checks++;}echo json_encode(['checks'=>$checks,'counterexamples'=>13,'SQL'=>0,'HTTP'=>0]),"\n";
