<?php
declare(strict_types=1);
namespace think {class Config {public static $driver='mysql';public static function get($key){return self::$driver;}}}
namespace {
$root=$argv[1]??'';require $root.'/application/p/logic/Restaurant.php';$r=new \ReflectionClass('app\\p\\logic\\Restaurant');$checks=0;$fails=[];$check=static function($label,$a,$b)use(&$checks,&$fails){$checks++;if($a!==$b){$fails[]=$label;}};
$check('row-helper-present',$r->hasMethod('normalizeRestaurantResponseRow'),true);if($fails){echo json_encode(['assertions'=>$checks,'failures'=>$fails,'database_operations'=>0]),PHP_EOL;exit(1);}$object=$r->newInstanceWithoutConstructor();$method=$r->getMethod('normalizeRestaurantResponseRow');$method->setAccessible(true);
$keys=['zpterm'=>'zpTerm','zpchargeterm'=>'zpChargeTerm','zpkey'=>'zpKey','zpchargekey'=>'zpChargeKey','zpchargeapiurl'=>'zpChargeApiUrl','zpbzapiurl'=>'zpBzApiUrl','zpapiurl'=>'zpApiUrl'];
$dates=[['2026-10-11 12:34:56.000000','2026-10-11 12:34:56'],['2026-10-11 12:34:56.487265','2026-10-11 12:34:56'],['2026-10-11 12:34:56.999999','2026-10-11 12:34:56'],['2024-02-29 00:00:00.1','2024-02-29 00:00:00'],['2026-10-11 12:34:56','2026-10-11 12:34:56'],['2026-02-31 12:34:56.1','2026-02-31 12:34:56.1'],['2026-10-11 24:00:00.1','2026-10-11 24:00:00.1'],['2026-10-11 12:60:00.1','2026-10-11 12:60:00.1'],['2026-10-11 12:34:60.1','2026-10-11 12:34:60.1'],['0999-01-01 00:00:00.1','0999-01-01 00:00:00.1'],['0000-00-00 00:00:00.1','0000-00-00 00:00:00.1'],['2026-10-11 12:34:56.0000000','2026-10-11 12:34:56.0000000'],[null,null],['',''],[0,0],[[],[]]];
foreach(['mysql','app\\cores\\database\\Dm','\\app\\cores\\database\\Dm','other'] as $driver){\think\Config::$driver=$driver;$dm=ltrim($driver,'\\')==='app\\cores\\database\\Dm';
 foreach($keys as $lower=>$camel){foreach([null,'',0,'SYNTHETIC',[]] as $i=>$value){$row=[$lower=>$value,'unknowncamel'=>3,'id'=>7];$want=$dm?[$camel=>$value,'unknowncamel'=>3,'id'=>7]:$row;$got=$method->invoke($object,$row);ksort($got);ksort($want);$check($driver.'.'.$lower.$i,$got,$want);}$row=[$lower=>'old',$camel=>'existing'];$check($driver.'.collision.'.$lower,$method->invoke($object,$row),$row);}
 foreach(['package_fee','locker_package_fee'] as $field){foreach([[0,'0.00'],[1,'1.00'],[1.25,'1.25'],[99999999.99,'99999999.99'],[-1.25,-1.25],[100000000,100000000],['1.20','1.20'],['not-a-number','not-a-number'],[null,null],[INF,INF],[NAN,NAN]] as $i=>[$value,$formatted]){$row=[$field=>$value,'other_decimal'=>1.25,'id'=>7];$want=$row;$want[$field]=$dm?$formatted:$value;$got=$method->invoke($object,$row);if(is_float($value)&&is_nan($value)){$check($driver.$field.$i,is_nan($got[$field]),true);}else{$check($driver.$field.$i,$got,$want);}}}
 foreach($dates as $i=>[$value,$formatted]){$row=['create_time'=>$value,'update_time'=>$value];$want=$row;$want['create_time']=$dm?$formatted:$value;$check($driver.'.date'.$i,$method->invoke($object,$row),$want);}
 $check($driver.'.no-fields-added',$method->invoke($object,[]),[]);
}
$source=file_get_contents($root.'/application/p/logic/Restaurant.php');$start=strpos($source,'public function restaurant_list(');$end=strpos($source,'public function restaurant_edit(',$start);$check('list-real-call',strpos(substr($source,$start,$end-$start),'$item = $this->normalizeRestaurantResponseRow($item);')!==false,true);$start=strpos($source,'public function restaurant_read(');$end=strpos($source,'public function restaurant_name(',$start);$check('read-real-call',strpos(substr($source,$start,$end-$start),'$result = $this->normalizeRestaurantResponseRow($result);')!==false,true);
echo json_encode(['assertions'=>$checks,'failures'=>$fails,'database_operations'=>0]),PHP_EOL;exit($fails?1:0);
}
