<?php
declare(strict_types=1);date_default_timezone_set('Asia/Shanghai');$root=__DIR__.'/source';require $root.'/vendor/autoload.php';spl_autoload_register(static function($class)use($root){foreach(['app\\'=>'app/','cores\\'=>'cores/'] as $p=>$d)if(strpos($class,$p)===0){$f=$root.'/'.$d.str_replace('\\','/',substr($class,strlen($p))).'.php';if(is_file($f))require $f;}});require __DIR__.'/NativePdo.php';$lane=getenv('INV_LANE')?:'B';putenv('INV_LANE='.$lane);$cases=json_decode(file_get_contents(__DIR__.'/cases-'.$lane.'.json'),true);InvGate::$case=$cases['PROBLEM_CREATE'];InvGate::$case['create_by']='CDX_OPERATOR';InvGate::$scenario='PROBLEM_CREATE';InvGate::$started=time();$count=0;$reject=static function($fn)use(&$count){$failed=false;try{$fn();}catch(RuntimeException $e){$failed=true;}if(!$failed)throw new RuntimeException('Negative accepted');$count++;};
$data=['staff_id'=>$lane==='B'?46334:1851,'set_date'=>'2097-11-11','user_id'=>$lane==='B'?10074:10010,'store_id'=>2147001111,'create_by'=>'CDX_OPERATOR','create_time'=>date('Y-m-d H:i:s'),'update_time'=>date('Y-m-d H:i:s'),'type'=>6,'other_text'=>'CDXIW11C8F2_PROBLEM1'];$bind=[];foreach($data as $k=>$v)$bind[$k]=[$v,PDO::PARAM_STR];$sql='INSERT INTO `yoshop_nutrition_meals` SET '.implode(' , ',array_map(static function($k){return '`'.$k.'` = :'.$k;},array_keys($data)));InvGate::plan($sql,$bind);$count++;
foreach(['staff_id'=>1,'user_id'=>1,'store_id'=>2147001112,'set_date'=>'2031-04-05','create_by'=>'natural','type'=>11,'other_text'=>'wrong','create_time'=>'2000-01-01 00:00:00'] as $k=>$bad){$b=$bind;$b[$k][0]=$bad;$reject(static function()use($sql,$b){InvGate::plan($sql,$b);});}
foreach([$sql.', `id` = :id',str_replace('nutrition_meals','user',$sql),$sql.'; SELECT 1',str_replace(':other_text',"'literal'",$sql)] as $bad)$reject(static function()use($bad,$bind){InvGate::plan($bad,$bind);});
foreach(['DELETE FROM yoshop_nutrition_lack','UPDATE yoshop_user SET is_delete=0','SELECT * FROM yoshop_order','CALL SP_TABLEDEF(?, ?)','SELECT 1 INTO x','SELECT SLEEP(1)'] as $bad)$reject(static function()use($bad){InvGate::kind($bad);});
$u='UPDATE `yoshop_nutrition_lack` SET `is_delete` = :gone WHERE `yoshop_nutrition_lack`.`store_id` = :store AND `staff_id` = :staff AND `set_date` = :date AND `user_id` = :user AND `type` = :type AND `is_delete` = :active';$b=['gone'=>[1,1],'store'=>[2147001111,2],'staff'=>[$data['staff_id'],1],'date'=>['2097-11-11',2],'user'=>[$data['user_id'],1],'type'=>[6,1],'active'=>[0,1]];InvGate::plan($u,$b);$count++;
foreach(['store'=>2147001112,'staff'=>1,'date'=>'2031-04-05','user'=>1,'type'=>11,'active'=>1] as $k=>$bad){$x=$b;$x[$k][0]=$bad;$reject(static function()use($u,$x){InvGate::plan($u,$x);});}
$reject(static function()use($u,$b){InvGate::plan($u.' OR 1=1',$b);});$reject(static function()use($u,$b){InvGate::plan(str_replace(' AND `is_delete` = :active','',$u),$b);});
InvGate::$masterId=42;$answer=['staff_id'=>$data['staff_id'],'set_date'=>'2097-11-11','user_id'=>$data['user_id'],'store_id'=>2147001111,'create_by'=>'CDX_OPERATOR','create_time'=>date('Y-m-d H:i:s'),'update_time'=>date('Y-m-d H:i:s'),'master_id'=>42,'type'=>6,'reference_id'=>'1','checkout_status'=>1,'v1'=>0,'v2'=>0];$aBind=[];foreach($answer as $k=>$v)$aBind[$k]=[$v,PDO::PARAM_STR];$aSql='INSERT INTO `yoshop_nutrition_lack` SET '.implode(' , ',array_map(static function($k){return '`'.$k.'` = :'.$k;},array_keys($answer)));InvGate::plan($aSql,$aBind);$count++;foreach(['v1'=>99,'v2'=>99,'master_id'=>1] as $key=>$bad){$mut=$aBind;$mut[$key][0]=$bad;$reject(static function()use($aSql,$mut){InvGate::plan($aSql,$mut);});}$reject(static function()use($aSql,$aBind){InvGate::plan($aSql.', `v3` = :v3',$aBind);});
InvGate::metadata('CALL SP_TABLEDEF(?, ?)',[['AIZHCT_APP',2],['YOSHOP_NUTRITION_MEALS',2]]);InvGate::kind('CALL SP_TABLEDEF(?, ?)');$count++;$reject(static function(){InvGate::metadata('CALL SP_TABLEDEF(?, ?)',[['OTHER',2],['YOSHOP_NUTRITION_MEALS',2]]);});$reject(static function(){InvGate::metadata('CALL SP_TABLEDEF(?, ?)',[['AIZHCT_APP',1],['YOSHOP_NUTRITION_MEALS',2]]);});
echo json_encode(['lane'=>$lane,'assertions'=>$count,'HTTP'=>0,'DML'=>0,'DDL'=>0,'business_connections'=>0]),"\n";
